fix(core): canonicalize location in activity tracking (#56259)

This commit is contained in:
Kit Langton
2026-10-18 23:12:42 -07:00
committed by GitHub
Unverified
parent 3fb3e52ac7
commit 9a7d4ed0f4
2 changed files with 33 additions and 4 deletions
+2 -3
View File
@@ -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)),
)
+31 -1
View File
@@ -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([])
}),
)
})