Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .agents/skills/verify-acp-go-sdk/features/session-delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A user removes a chat from the editor's session history. The editor calls `sessi
- `delete-advertised` shows `sessionCapabilities.list` and `sessionCapabilities.delete` as `{}` in the `initialize` result.
- `delete-listed` drops a deleted session from `session/list`, and keeps the other sessions of its cwd in creation order.
- `delete-again` answers a second `session/delete` for the same session with an empty result, as the ACP spec asks for an unknown session.
- `delete-then-prompt` answers `session/prompt` for a deleted session with `-32603`.
- `delete-then-prompt` answers `session/prompt` for a deleted session with `-32002` (resource not found) and the session's ID in `data.sessionId`, as the ACP spec asks for an unknown session.
- `delete-running` ends a running turn of the deleted session with `stopReason: "cancelled"`.
- `delete-cwd` leaves the sessions of another cwd in the list.

Expand All @@ -25,12 +25,12 @@ Preconditions:

Steps:

- **Delete sessions.** Run `"$V" wire session-delete.jsonl session-delete`. Each step prints PASS. `prompt A fails` prints `error -32603 Internal error`. `await turn` prints `stopReason cancelled, 3 notifications before the response`, and `close stdin` prints `agent exit code 0`.
- **Delete sessions.** Run `"$V" wire session-delete.jsonl session-delete`. Each step prints PASS. `prompt A fails` prints `error -32002 Resource not found`. `await turn` prints `stopReason cancelled, 3 notifications before the response`, and `close stdin` prints `agent exit code 0`.
- **Read the order.** Run `jq -r 'select(.dir=="agent->client") | .msg.params.update.sessionUpdate // .msg.method // ("response " + (.msg.id|tostring))' "$ACP_VERIFY_RUN/evidence/session-delete/transcript.jsonl" | paste -sd' '`. The output is exactly `response 1 response 2 response 3 response 4 response 5 response 6 response 7 response 8 response 9 agent_message_chunk agent_message_chunk tool_call response 11 response 10 response 12 response 13`. Request 11 is the delete of B, and request 10 is B's prompt, so the delete answers before the cancelled turn does.
- **Agent log.** Run `cat "$ACP_VERIFY_RUN/evidence/session-delete/agent.stderr.log"`. It is empty, or has one line: `INFO connection closed cause="peer connection closed"`. The agent exits as soon as its connection reports done, and the SDK logs that line after it reports done, so the line is in some logs and not in others.

## Gotchas

- The `expect` values compare whole JSON values. `result.sessions` must match the full list, with each `sessionId` taken from a saved `session/new` response through `{{name.result.sessionId}}`.
- The ACP spec leaves `session/load` and other calls on a deleted session to the agent. The `-32603` of `prompt A fails` is the example agent's choice: its `Prompt` returns an error for a session that is not in its map.
- The ACP spec asks for `-32002` with `data.sessionId` when a session-scoped request names a session that does not exist. The example agent's `Prompt` returns `acp.NewResourceNotFound` for a session that is not in its map, so a deleted session gets it.
- The delete of B must come after the first `tool_call` update, or the turn has not started and the await step sees `end_turn`.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{"step":"delete A","send":"session/delete","params":{"sessionId":"{{a.result.sessionId}}"},"expect":{"result":{}}}
{"step":"list drops A","send":"session/list","params":{"cwd":"/tmp/acp-delete"},"expect":{"result.sessions":[{"sessionId":"{{b.result.sessionId}}","cwd":"/tmp/acp-delete"}]}}
{"step":"delete A again","send":"session/delete","params":{"sessionId":"{{a.result.sessionId}}"},"expect":{"result":{}}}
{"step":"prompt A fails","send":"session/prompt","params":{"sessionId":"{{a.result.sessionId}}","prompt":[{"type":"text","text":"Hello, agent!"}]},"expect":{"error.code":-32603}}
{"step":"prompt A fails","send":"session/prompt","params":{"sessionId":"{{a.result.sessionId}}","prompt":[{"type":"text","text":"Hello, agent!"}]},"expect":{"error.code":-32002,"error.data.sessionId":"{{a.result.sessionId}}"}}
{"send":"session/prompt","params":{"sessionId":"{{b.result.sessionId}}","prompt":[{"type":"text","text":"Hello, agent!"}]},"save":"turn","async":true}
{"waitFor":"session/update","where":{"params.update.sessionUpdate":"tool_call"},"timeout":"10s"}
{"step":"delete B during its turn","send":"session/delete","params":{"sessionId":"{{b.result.sessionId}}"},"expect":{"result":{}}}
Expand Down
1 change: 1 addition & 0 deletions .agents/skills/verify-session-cancel/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ The code column cites functions and the line that each step depends on. `check.s
- cancel-waits-later-prompt.cfg: a cancel whose `Cancel` waits on the client, a second cancel, then a prompt, 53 states.
- A handler calls the client only where the script says so (`peernote`, `cancelpeer`).
- The client sends each script in order. The agent can return from `Prompt` at any step, canceled or not.
- The connection is initialized: every script starts after `initialize` returned without an error. Before that, `handleWithExtensions` hands each message to `handleBeforeInitialize`, which drops a `session/cancel` and answers a prompt with -32600 before either reaches the agent, so no marker or cancel func exists yet. After it, the gate is one `a.openedAt.Load()` compared with the message's `messageArrival`, which reads only the handler's ctx, and the covered code runs as before. `handleWithExtensions` first waits on `a.ready`, which `NewAgentSideConnection` closes once `a.conn` is set, so a handler that runs before the constructor returns takes its next step (`PassBarrier`, `Register`, `RunCancel`) later, which the model's interleavings already include.
- Prompts and `session/cancel` requests are the requests in the model. Other requests in flight only keep markers longer.
- The model has fewer than `maxCancelMarkers` (1024) entries in `sessionCancelledAt` and `sessionNewest`, so `dropOldestAbove` never runs. A lost entry there loses only that peer's own cancel or prompt order, as the comment on `maxCancelMarkers` says. `TestAgentSideConnection_SessionCancelMarkersArePruned` and `TestAgentSideConnection_SessionNewestIsCapped` cover the caps.
- The three maps of `AgentSideConnection` key a session by `sessionKeyOf(id)`, the SHA-256 of its sessionId, so `sessionID` in `cancelPrompt` and `registerPrompt` is that digest. The model names sessions directly: it assumes that two sessionIds never share a digest. `TestAgentSideConnection_CancelMarkersKeepLongSessionIDsApart` covers two long ids that differ in their last byte.
Expand Down
4 changes: 2 additions & 2 deletions .agents/skills/verify-session-cancel/fingerprint.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
5983c3ed80de724587ad60393b7a2bd280cb9e03c5ccebeb7790ca273d1a8a30 agent.go|func NewAgentSideConnection(
7249883bd85313f2548377f9b55cdbee183b6f52f24960c57a4360f09ac8dfb6 agent.go|func NewAgentSideConnection(
2b579bc926a0ad30a67161f47d73e809c64f0c8e478a3028bc4980e41b52917c agent.go|func (a *AgentSideConnection) cancelPrompt(
219524e1c9d36a1ca258b6df5615564d2b03e76bca91ff5eb73cadf8b436c0f0 agent.go|func (a *AgentSideConnection) registerPrompt(
adbd7e72f96941a3a24be4208efd4751d5772745bfc8b43a85777055522d7f8f agent.go|func (a *AgentSideConnection) pruneCancelMarkers(
85ba1ceb0a7349763c030d155eab1800cce9489d213714d446be275908feb08f agent_gen.go| case AgentMethodSessionCancel:
4c1c05136ce1b6e1ca98ce4f00ad00e45f9f6da87951f099ee4598b91a949858 agent_gen.go| case AgentMethodSessionPrompt:
e1a98e274064cc3555b3df46988c93d2b8b462ad7335675a71473a88f1716c23 extensions.go|func (a *AgentSideConnection) handleWithExtensions(
1b684a9aaa24bfd6d5d3245f06030e6ed5dd37b474804d9ef31b52c1cc890a13 extensions.go|func (a *AgentSideConnection) handleWithExtensions(
45fcde3482116e83f0f8f1000a67ad95f68ceccb91743d5e98746fdff2f7835b connection.go|func NewConnection(
edb3eeb64a845734dc70d72f8447b16ffb70ec435787dba498a715d5a4008a45 connection.go|func (c *Connection) notificationSeq(
ffa1b899dba9ef6c4f71ba020c7bf0c80f4fc275039f6e0260024f6c0922bd4b connection.go|func (c *Connection) messageArrival(
Expand Down
12 changes: 12 additions & 0 deletions MIGRATION_v0.21.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ go build ./...
| A `null` in a `tool_call_update` field, or in `_meta` of a `session_info_update`, reads as unset, and `PatchNull` there is left out | [Null in a tool call update](#null-in-a-tool-call-update) |
| An object that holds one of its properties twice fails to decode | [Duplicate members](#duplicate-members) |
| A `cursor_update` session update (unstable) decodes into `SessionUpdate.CursorUpdate`, where v0.20.0 failed to decode it | [Schema 1.34.1](#schema-1341) |
| `AgentSideConnection` answers a request before a successful `initialize` with `-32600` and drops a notification | [Requests before initialize](#requests-before-initialize) |

## Required members

Expand Down Expand Up @@ -368,3 +369,14 @@ v0.21.0 is generated from ACP schema 1.34.1, up from 1.32.0, and `acp.SchemaVers
- **What reaches your handlers.** v0.20.0 did not decode a `cursor_update` session update: the connection dropped it and logged it at Error. v0.21.0 passes it to your `SessionUpdate` method with `CursorUpdate` set, so a switch over the variants of `SessionUpdate` meets a new case. The schema lets an agent send it only to a client that advertised `session.cursors`. An `UnstableForkSession` method now sees `CursorId`. The schema says to reject with `-32602` an ID that the agent did not announce on the source session, or whose cursor does not advertise `capabilities.fork`, and not to fork the whole session.
- **Stable since schema 1.34.0.** Plan updates (`plan_update`, `plan_removed`, `PlanCapabilities`), subagent sessions (`subagent_update`, `SubagentCapabilities`, `SessionReference`), the `session_message` and `session_message_chunk` updates, `StateUpdate` with its variants, and `SessionCancelCapabilities` moved from the unstable schema to the stable one, all but the `usage` member of an idle state, which the stable schema does not define. The SDK already generated them from the unstable schema, so their Go names and their decoding stay the same, and none of their type doc comments carries the `**UNSTABLE**` marker any more. The `Usage` field of each idle variant, such as `IdleStateUpdateEndTurn.Usage` and `StateUpdateIdleEndTurn.Usage`, keeps it.
- **Deserialize hints.** Schema 1.34.0 removed the spec text on malformed values and kept the `x-deserialize-*` hints. The stable schema gained 34 of them, 32 `x-deserialize-default-on-error` and 2 `x-deserialize-skip-invalid-items`, all on properties that the unstable schema, which the SDK reads, already marked, so no decoder changes. Schema 1.34.1 only renames one doc link, from "Cancellation" to "Request Cancellation".

## Requests before initialize

The ACP spec says an agent SHOULD answer a request other than `initialize` that arrives before initialization completes with `-32600` (invalid request). v0.20.0 passed every request and notification to your `Agent`, so a client could call `session/new` first. In v0.21.0 `AgentSideConnection` holds them back until your `Initialize` returns without an error:

- A request other than `initialize`, a `_` extension request included, gets `-32600` with `data.error` set to `initialize must complete before <method>`, and your handler is not called.
- A notification, such as `session/cancel`, is dropped, and the connection logs it at Debug.
- A failed `initialize` leaves the connection uninitialized, so the client can send it again. An `initialize` after a successful one reaches your `Agent`, as before.
- A message that arrived before the `initialize` that succeeded is held back the same way, even when its handler runs after that `initialize` returned. A request whose handler starts while `initialize` still runs gets `-32600` too. A client sends other requests only after the `initialize` reply. The clients in `example/` and `ClientSideConnection.Initialize` already wait for it.

`ClientSideConnection` and the proxy do not change. `NewResourceNotFound` builds the `-32002` (resource not found) error that the spec asks an agent to send, with `data.sessionId`, for a request that names a session that does not exist.
Loading