Repository navigation
fix: match a permission request to background work by its session - #353
Merged
Merged
Conversation
… handler Follows the v2 protocol docs that landed after schema v2.0.0-alpha.17. A v2 agent app without a handler for `tool_call/cancel` or `terminal/cancel` answered every such request with `-32602`. The protocol now says that `-32602` is the answer of an Agent that implements the method, and that such a request for an unknown session gets `-32002`, which the default could not know. An app without the handler does not implement the method, so it now answers `-32601`, as for any other method. An Agent that advertises `capabilities.cancel` on a tool call or terminal registers the handler. - `ActiveSession.isForBackgroundWork` compares a request's subject with the listed tool calls and terminals only for a request of its own session, because those IDs are scoped to the session that reports them. A request of a child session is for listed work when the child is a listed `subagent`. - The dual-version example agent rejects a `systemPrompt` with `-32602` and creates or resumes no session. It advertises no `session.systemPrompt`, and it used to ignore the field. - Handler docs: the error codes of the two cancel requests, `-32602` for a `systemPrompt` the Agent cannot apply, a new session's non-idle state after the `session/new` response, the `replay_complete` of each replayed child session, the child session rules of `session/cancel`, how long an `idempotencyKey` is recognized, and that a fork does not share its source's keys.
…nt's systemPrompt check
benbrandt
enabled auto-merge (squash)
November 18, 2026 15:51
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.
What is left of the v2 protocol docs follow-up after #351. That PR landed the
-32601default fortool_call/cancelandterminal/cancel, the example agent'ssystemPromptcheck, and the handler docs for both. This branch now mergesmainand keeps only what #351 does not have.Behavior change
ActiveSession.isForBackgroundWorkIt compared the subject of any permission request with the session's listed tool calls and terminals. Those IDs are scoped to the session that reports them, so a child session's request with the same
toolCallIdas a listed tool call of the parent matched.It now compares subjects only for a request of its own session. A request of another session is for listed work when that session is a listed
subagent. A request of any other session, such as a listed child's own child, returnsfalse, which the doc already describes as "not established".Handler and module docs
tool_call/cancel,terminal/cancel: a child session that the Agent announced is not an unknown session, andsessionIdnames the child for an item that the child reports.session/new: the app sends the response once the handler's promise settles, so a notification sent inside the handler goes out before it.session/resume: each child session that a replay announces gets its ownreplay_complete, and the parent'sreplay_completeseparates a replayedsubagent_updatefrom a current one. A child'ssessionIdis rejected with-32602.session/cancel: the notification can name a child, is ignored for a child that does not advertisecancel, and covers the descendant work that the cancelled work waits on.session/prompt: how long anidempotencyKeyis recognized, for a retained message and for one that is not.session/fork: the fork does not share its source's keys.src/v2/stable/*is regenerated fromsrc/v2/*.Found, not fixed here
These need a decision first.
sessionIdto that session's stream, and buffers it until the client opens a stream for that ID. A client opens one for a session it created or resumed, never for a child. So a child's updates and permission requests are not delivered, and the permission request stays pending. WebSocket and stdio deliver them. The transport RFD does not say where a child's traffic goes.session/newresponse needs a timer.ActiveSessionand child sessions.nextUpdate()delivers only updates of the session's ownsessionId, and anActiveSessioncan only come fromsession/new, not fromsession/resume.Tests
acp.test.ts:isForBackgroundWorkis true for a request of a listed child, and false for a request of another session that names a listed ID.npm run checkpasses.