fix(acp): recover stale foreground turn on replace - #2679
Open
rinseaid wants to merge 3 commits into
Open
Conversation
Contributor
|
| Filename | Overview |
|---|---|
| packages/server/src/server/agent/agent-manager.ts | Adds forced-cancellation signaling, reloads stale provider sessions before replacement, and restores the existing agent if replacement registration fails. |
| packages/server/src/server/agent/agent-manager.test.ts | Covers stale foreground-turn recovery and verifies that registration failure retains both the live agent and its original durable session record. |
Sequence Diagram
sequenceDiagram
participant C as Client
participant M as AgentManager
participant Old as Stale provider session
participant New as Resumed provider session
C->>M: replaceAgentRun(prompt)
M->>Old: interrupt()
Old--xM: No terminal turn event
M->>M: Force-settle cancellation
M->>New: resumeSession(handle)
M->>M: Register replacement session
M->>Old: close()
M->>New: startTurn(prompt)
New-->>M: turn_completed
M-->>C: Replacement stream completes
Reviews (3): Last reviewed commit: "fix(acp): keep prior snapshot on reload ..." | Re-trigger Greptile
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.
Problem
If a provider acknowledges cancellation but never emits a terminal turn event, Paseo force-cancels its manager-side run after the timeout. The provider session can still retain its foreground turn. The next replacement prompt then fails with
A foreground turn is already active.Fix
After that forced cancellation path, reload the agent session before starting the replacement prompt. Reloading resumes the persisted provider session while retaining the Paseo agent, timeline, labels, and workspace. Normal cancellations keep their existing result shape and do not reload.
Regression coverage
The test models a provider that accepts cancellation, omits the terminal event, and rejects another foreground turn. It verifies that Paseo closes the stale session, resumes a replacement session, and completes the queued replacement prompt.
Validation
npx vitest run src/server/agent/agent-manager.test.tsnpm run typecheck --workspace=@getpaseo/servernpm run lint -- packages/server/src/server/agent/agent-manager.ts packages/server/src/server/agent/agent-manager.test.tsnpm run format:check:files -- packages/server/src/server/agent/agent-manager.ts packages/server/src/server/agent/agent-manager.test.tsFixes #1936