fix(actor): scope forkContext by session to prevent cross-session collisions#1870
Open
onlyfeng wants to merge 1 commit into
Open
fix(actor): scope forkContext by session to prevent cross-session collisions#1870onlyfeng wants to merge 1 commit into
onlyfeng wants to merge 1 commit into
Conversation
…lisions The Actor service's forkContexts map is keyed by actorID alone, but actorID is not globally unique. allocateActorID (actor/registry.ts) allocates its incrementing suffix scoped to (sessionID, agentType), so the first "explore" subagent spawned in any session gets actorID "explore-1" regardless of which session spawned it. Two concurrent sessions each spawning their first subagent of the same agentType therefore get the same actorID, and since forkContexts is a single process-wide Map keyed only by actorID, one session's frozen ForkContext snapshot (system prompt + inherited messages + tools) can overwrite or be deleted by the other's. Fix: scope every forkContexts.set/get/delete by a composite (sessionID, actorID) key instead of actorID alone. getForkContext now takes sessionID as its first parameter, matching the existing cancel(sessionID, actorID, mode) signature. Updated the one production call site (session/prompt.ts) and all test call sites/mocks accordingly, and added a regression test that spawns same-agentType subagents in two different sessions, confirms they collide on the same actorID, and asserts each session reads back only its own forkContext.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
forkContextsMap inActor.Serviceis keyed byactorIDalone, butactorIDis only unique within a(sessionID, agentType)scope (seeActorRegistry.allocateActorID). Two concurrent sessions spawning the same agent type (e.g.explore) get the sameactorID(e.g.explore-1), causing one session'sForkContextsnapshot to overwrite or be deleted by the other's.forkContexts.set/get/deleteby a composite(sessionID, actorID)key instead ofactorIDalone.getForkContextnow takessessionIDas its first parameter, matching the existingcancel(sessionID, actorID, mode)signature.actorID, and asserts each session reads back only its ownForkContext.Test plan
bun typecheckpassesbun test test/actor/spawn.test.ts— 24 pass, 0 fail (includes new cross-session collision test)getForkContext(sessionID, actorID)signature