fix(session): concurrent prompt race, leaked callbacks, stale busy status#14222
Closed
ArmirKS wants to merge 8 commits intoanomalyco:devfrom
Closed
fix(session): concurrent prompt race, leaked callbacks, stale busy status#14222ArmirKS wants to merge 8 commits intoanomalyco:devfrom
ArmirKS wants to merge 8 commits intoanomalyco:devfrom
Conversation
…r messages Two prompt() calls can hit the same session at the same time. Both call createUserMessage() and the loop picks the wrong one, so subagents end up running on the parent model instead of their own. Added a Set to track active sessions and queue the second caller. Fixes anomalyco#6636 Relates: anomalyco#11699, anomalyco#6928, anomalyco#8700
cancel() deletes the session state without rejecting promises that are waiting on callbacks. Those promises never settle so GC can't collect them. Over a long-running session with frequent cancellations this adds up. Now rejects each callback with an AbortError before cleaning up.
With the _busy Set guard, concurrent callers never reach the callback array, so explicitly rejecting each promise is dead code. Just clear the array defensively.
Removing the early _busy.delete() + idle set before prompt() returns. The using disposer at prompt() scope exit already handles cleanup. Deleting _busy before return opened a window where a second caller could enter the session, create a user message with the wrong model, and run a loop iteration as the parent instead of the subagent.
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.
Issue for this PR
Closes #6636
Related: #11699, #6928
Type of change
What does this PR do?
Three fixes in
prompt.ts:concurrent prompt() — no check before
createUserMessage(), so two calls on the same session both create user messages. The backward scan picks the wrong one. Added a Set to make the second caller wait.cancel() leaks callbacks — deletes state without rejecting the promises from line 280-283. They never settle. Now rejects with AbortError first.
stale busy status — session stays busy during post-loop
prune()+ stream read. Set idle right after the while loop instead.How did you verify your code works?
Clean build from dev
802ccd37, no plugins. Twoprompt_asynccalls to the same session:Scout's model gets overwritten by the stray's
default.Screenshots / recordings
n/a — not a UI change
Checklist