Repository navigation
Conversation
When an ACP prompt ended with a non-cancelled stop reason, the translator closed every tool call that had no terminal update as completed and showed its last progress text as the result. Kimi Code reports a turn that failed inside the agent as stopReason end_turn, so tool calls that never ran were shown as successful, often with their echoed arguments as the "result". A tool call that is still open when the agent ends the turn never reported a result, so it now closes as failed. Cancelled turns still close open calls as interrupted, and the turn status is unchanged. Fixes get-bb#6775
3 tasks done
ymichael
added a commit
that referenced
this pull request
Nov 18, 2026
#7788) ## Human comments ## What was wrong Two ACP bridge bugs, both in `packages/provider-bridge-acp`, affecting OpenCode, Cursor, Copilot, Gemini, Qwen and other ACP threads. 1. **Null tool call fields.** ACP SDK 1.9.0 types `ToolCallUpdate.title`, `content` and `locations` as `T | null`. `acpToolCallFieldsSchema` (`wire.ts`) accepted null only for `name` (and `kind`/`status` through the enum preprocess). Any `tool_call_update` with `title: null`, `content: null` or `locations: null` failed `safeParse`, and `delta-translation.ts` dropped it as unhandled, even when it carried the call's final `failed`/`completed` status and output. The call then closed as `completed` at end of turn with no output. 2. **Lost agent session.** When the agent rejected `session/prompt` because it no longer had the session, `runTurn` reported the error and kept the same session. Every later message in the thread failed with the same error until bb restarted the bridge. `ACP_RESOURCE_NOT_FOUND_CODE` was defined but unused. Real agents don't only use `-32002`. Probing installed agents with a prompt on an unknown session id gave: - OpenCode 2.0.22: `-32602 "Invalid params: session not found: <id>"` - Gemini: `-32602 "Session not found: <id>"` - Copilot: `-32602 "Session <id> not found"` - Qwen: `-32603 "Internal error"`, `data.details: "Session not found: <id>"` - Cursor: `-32603 "Internal error"`, `data.details: "Session <id> not found"` T3 Code adds Copilot's `session lock unavailable …` cause. ## What changed - `wire.ts`: new `acpNullAsAbsent(schema)`, used for every SDK-nullable tool call field (`title`, `name`, `content`, `locations`). It also replaces the duplicate `acpOptionalString`/`acpToolCallNameSchema`. Null means "unchanged", as the SDK documents for `name`. This also covers the tool call inside `session/request_permission`, which shares the schema. - `bridge/bridge.ts`: `restartAfterCancelError: boolean` becomes `rebuildBeforeNextPrompt: "cancel-error" | "lost-session" | null`. `isLostSessionError` matches `-32002`, or an agent error whose message (including `data.details`) says the session was not found or its lock is unavailable. A lost-session error marks the session for rebuild in all three places a session-scoped request can fail: the turn prompt (and the settings reconcile before it), the `/compact` prompt, and `turn/start` session option changes. The next turn rebuilds through the existing `rebuildAgentSession`: restart the agent, then `session/load`/`session/resume`, or a fresh session with the existing "could not restore" warning. `session/replaced` reports "The ACP agent lost its session; the session was rebuilt before continuing." The failed turn is not retried automatically. - `fake-acp-agent.mjs`: `FAKE_ACP_LOST_SESSION_ERROR` + `FAKE_ACP_LOST_SESSION_FILE` make the first launched process reject every prompt with a given JSON-RPC error. - Unfinished tool calls at end of turn are left to #7433. - No server/daemon wire changes. Credit: T3 Code [#26651](pingdotgg/t3code#26651) (Copilot lost/locked session restart) and [#21448](https://github.com/pingdotgg/t3code/pull/21448)/[#25559](https://github.com/pingdotgg/t3code/pull/25559) (ACP tool calls ending as completed) pointed at these. ## How you verified **Real repro, lost session (bb's ACP bridge + real `opencode acp` 2.0.22).** A driver sends `thread/start` and `turn/start` to the bridge's `handleLine`, deletes the agent's session with `opencode session delete <id>` while `opencode acp` is still running, then sends three turns. - `origin/main`: all three turns fail with `Invalid params: session not found: ses_…`; no `session/replaced` notification, same session each time. - This branch: turn 1 fails with the same error. Turn 2 restarts the agent, emits `session/replaced` (reason above, `contextLost: true` since the deleted session can't load), the warning, and the prompt goes to the new session `ses_e0f9ac9d…`. On this machine, OpenCode's only configured provider then answered `credit_balance_exhausted` from OpenAI. That is an agent-side billing error, so I could not show a model reply through OpenCode; the bridge tests cover the completed reply. **Real repro, null fields (bb's ACP bridge + an agent built on `@agentclientprotocol/sdk` 1.9.0's `AgentSideConnection`)** sending SDK-typed updates: a `pnpm test` call, then `tool_call_update {status: "in_progress", title/content/locations: null}`, then `{status: "failed", title: null, locations: null, content: "3 tests failed"}`. - `origin/main`: both null updates dropped as `unhandled`; `call_1` closes `completed`. - This branch: `call_1` closes `failed`, and a read call closed with null fields closes `completed`. I didn't find a production agent that sends these nulls in a capture; the SDK types allow them. **Tests (fail on main, pass here):** - `wire.test.ts`: null `title`/`name`/`content`/`locations` parse as absent; a permission request tool call with nulls parses. - `delta-translation.test.ts`: a call whose updates send nulls settles `failed` with its output. - `bridge.test.ts`: a table of five real error shapes (`-32002`, OpenCode, Copilot, Cursor, Copilot lock): turn 1 fails, turn 2 completes after one restart, `session/load` of the same id and one `session/replaced`. Also a `/compact` failure followed by a rebuilt next turn. A negative row (`-32603` "upstream model overloaded") keeps the process and fails both turns, so the matcher can't widen silently. - Against `origin/main`'s source: the three null-field tests and the six lost-session tests fail; the negative row passes. Commands: - `pnpm exec turbo run typecheck lint test --filter=@bb/provider-bridge-acp` → 621 passed, 4 skipped - `pnpm exec turbo run typecheck lint:type-aware --filter='...@bb/provider-bridge-acp'` → 155/155 tasks 🤖 Generated with [Claude Code](https://claude.com/claude-code) > AGENT GENERATED Co-authored-by: Claude Opus 5.5 <[email protected]>
Contributor
|
This is an automated message. We have closed this pull request because it has been open for more than two weeks. |
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.
Human comments
What was wrong
When an ACP turn ends,
translateTurnCompletedinpackages/provider-bridge-acp/src/delta-translation.tscloses each tool call that never got a final status. It used the turn's status, so after anend_turnthose calls becamecompleted, andgenericCloseFieldsshowed the last progress text (the echoed arguments) as the result (#6775). Kimi Code 2.4.1 maps a failed turn tostopReason: "end_turn"and does not send a finaltool_call_updatefor the interrupted call (turnEndReasonToStopReasonin its publisheddist/main.mjs). So a turn that failed inside Kimi looked like a successful turn with successful tool calls.What changed
delta-translation.ts: intranslateTurnCompleted, a tool call that is still open when the turn ends closes asinterruptedwhen the turn was cancelled, and asfailedfor every other stop reason. Assistant and thought streams close as before, and they take no status.delta-translation.test.ts: a regression test that sends an in-progress Read call and thenend_turn. One assertion in the existing Add ACP dialect hook to normalize tool call progress events #6769 test, which checks the same situation, changes fromcompletedtofailed. Its main check (noresultText) is unchanged.What this does not change: the turn itself still shows as completed, with no error text. Kimi reports
end_turnand no error, and the only sign of the failure is the unfinished call. Marking the whole turn failed from that sign would be a guess. The complete fix is in Kimi: send a JSON-RPC error, or a finalfailedupdate for pending tool calls.No event shape or wire change.
How you verified
- "status": "failed"/+ "status": "completed".pnpm exec turbo run lint lint:type-aware typecheck test --filter=@bb/provider-bridge-acppasses, 6 of 6 tasks, 25 test files, 0 lint warnings.oxfmt --checkpasses.end_turn, so their normal turns do not change. A small ACP client asked each agent for a read, a listing and a shell command, then for one more read, and recorded the last status of each call:opencode acp):read,globandcat b.txtallcompleted,stopReason: "end_turn".@agentclientprotocol/claude-agent-acp0.106.0:Read a.txt,ls -la,cat b.txtandRead b.txtallcompleted,stopReason: "end_turn".Fixes #6775