Skip to content

Keep ACP threads usable after null tool fields or a lost agent session - #7788

Merged
ymichael merged 1 commit into
mainfrom
bb/fix-acp-nullable-tool-fields-and-lost-session-re-thr_diqec62hhe
Nov 18, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/fix-acp-nullable-tool-fields-and-lost-session-re-thr_diqec62hhe

Conversation

@ymichael

@ymichael ymichael commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

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 ACP: mark tool calls still open at the end of a turn as failed #7433.
  • No server/daemon wire changes.

Credit: T3 Code #26651 (Copilot lost/locked session restart) and #21448/#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

AGENT GENERATED

The ACP SDK allows null title, content and locations on tool_call_update.
The bridge's schema rejected them, so an update carrying a call's final
status was dropped and the call later closed as completed. Read null as
absent for every SDK-nullable tool call field.

When an agent rejects session/prompt because it lost or locked the
session (-32002, or "session not found" / "session lock unavailable" in
-32602/-32603 errors from OpenCode, Gemini, Copilot, Qwen and Cursor),
the bridge kept prompting the dead session and every later message
failed. Mark the session for rebuild, the way a failed cancellation
already does, so the next turn restarts the agent and reloads the
session through rebuildAgentSession. Turns, /compact and session option
changes all mark it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ymichael
ymichael merged commit e48cac3 into main Nov 18, 2026
95 of 96 checks passed
@ymichael
ymichael deleted the bb/fix-acp-nullable-tool-fields-and-lost-session-re-thr_diqec62hhe branch November 18, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant