From 9a7d4ed0f4454725843cadea6f58fa5ec8fee16b Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Sun, 18 Oct 2026 23:12:42 -0700 Subject: [PATCH] fix(core): canonicalize location in activity tracking (#56259) --- packages/core/src/location-activity.ts | 5 ++- packages/core/test/location-activity.test.ts | 32 +++++++++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/packages/core/src/location-activity.ts b/packages/core/src/location-activity.ts index 0425e9acab0..86fb36149ef 100644 --- a/packages/core/src/location-activity.ts +++ b/packages/core/src/location-activity.ts @@ -31,9 +31,8 @@ export function layer(options: { readonly timeToLive?: Duration.Input; readonly }) const unsubscribe = yield* bus.listen((event) => { - if (!isSessionEvent(event)) return Effect.void - const location = event.location - if (!location) return Effect.void + if (!isSessionEvent(event) || !event.location) return Effect.void + const location = LocationServiceMap.canonical(event.location) return RcMap.has(locations.rcMap, location).pipe( Effect.flatMap((active) => (active ? touch(location) : Effect.void)), ) diff --git a/packages/core/test/location-activity.test.ts b/packages/core/test/location-activity.test.ts index a71b0a82f45..f2e30411e85 100644 --- a/packages/core/test/location-activity.test.ts +++ b/packages/core/test/location-activity.test.ts @@ -204,7 +204,11 @@ describe("LocationActivity eviction", () => { yield* Location.Service.pipe(Effect.provide(map.get(later)), Effect.scoped) yield* TestClock.adjust("30 minutes") // Keep fresh work active while a different graph reaches its own deadline. - yield* bus.publish(SessionEvent.Execution.Started, { sessionID: newcomer }, { location: ref }) + yield* bus.publish( + SessionEvent.Execution.Started, + { sessionID: newcomer }, + { location: Location.Ref.make({ directory: ref.directory }) }, + ) yield* TestClock.adjust("32 minutes") expect(Array.from(yield* execution.active)).toEqual([newcomer]) expect(Array.from(yield* RcMap.keys(map.rcMap))).toEqual([ref]) @@ -219,4 +223,30 @@ describe("LocationActivity eviction", () => { }), ) } + + it.effect("refreshes inactivity deadline for session events with non-canonical location refs", () => + Effect.gen(function* () { + const bus = yield* Bus.Service + const map = yield* LocationServiceMap.Service + const raw = Location.Ref.make({ directory: AbsolutePath.make("/project") }) + const ref = LocationServiceMap.canonical(raw) + + yield* Location.Service.pipe(Effect.provide(map.get(raw)), Effect.scoped) + expect(yield* RcMap.has(map.rcMap, raw)).toBe(false) + expect(yield* RcMap.has(map.rcMap, ref)).toBe(true) + + yield* TestClock.adjust("31 minutes") + yield* bus.publish( + SessionEvent.Execution.Started, + { sessionID: Session.ID.make("ses_activity") }, + { location: raw }, + ) + + yield* TestClock.adjust("32 minutes") + expect(Array.from(yield* RcMap.keys(map.rcMap))).toEqual([ref]) + + yield* TestClock.adjust("30 minutes") + expect(Array.from(yield* RcMap.keys(map.rcMap))).toEqual([]) + }), + ) })