fix(acp): centralize session activity lifecycle - #107
Merged
Conversation
Contributor
There was a problem hiding this comment.
Cancellation at AfterToolResult still leaves the driver's logical turn and pending continuation active while session activity settles to Idle. A subsequent prompt resumes that continuation without a new TurnStarted, so it can stream a response without Running or terminal Idle notifications. Retire the interrupted logical turn without executing additional cancelled work before settling activity.
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
Make one session-owned instrument the source of lifecycle state for ACP v1 and v2, and make the TUI consume ACP state directly. Background completion wakeups that find no work no longer produce synthetic turns or repeated
took 0msrows.Technical details
Shared state and execution finalization
The instrument owns activity identity, execution origin, Running/Settling/Idle state, and terminal settlement. Actual loop activity starts an interval; steering and background-result synthesis continue within it. Both protocols use shared domain outcomes and a common cancellation, structured-work cleanup, content-drain, and diagnostic finalization policy.
Ordered protocol projections
Protocol adapters translate the instrument鈥檚 transitions rather than maintain their own lifecycle state. ACP v1 preserves standard prompt responses and its autonomous-turn extension; ACP v2 emits native state updates. Lifecycle ownership is separate from response replacement.
V1 lifecycle notifications enter the SDK outbound queue synchronously, and terminal settlement follows the content-drain barrier, including on error paths. Flush failures are no longer silently treated as successful completion.
Reactive client state
The TUI retains ACP state and terminal reasons directly and uses one timer across Running and RequiresAction states.
Retiring cancelled driver continuations
Cancellation at a tool-result boundary retires the driver's logical turn before session activity settles, so a subsequent prompt starts a fresh activity interval without resuming cancelled work. The existing AgentKit Git pins advance to
513e92bonfeat/acp-v2-session-injectfor the retirement API; the audited source-only change introduces no package-version, feature, or transitive dependency changes.