Skip to content

Close approval cards the agent withdraws - #7797

Merged
ymichael merged 2 commits into
mainfrom
bb/6966-close-approval-cards-the-agent-withdraws-thr_y24w76r9m4
Nov 18, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/6966-close-approval-cards-the-agent-withdraws-thr_y24w76r9m4

Conversation

@ymichael

@ymichael ymichael commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

A provider can stop waiting on a request it raised: a Claude PermissionRequest hook answers it and the SDK aborts the can_use_tool request, Codex sends serverRequest/resolved, a Pi dialog reaches its timeout, or an ACP/Pi session ends with a permission open. In each case the bridge dropped its local waiter (Claude's onAbort only answered deny locally; Codex ignored serverRequest/resolved) and nothing reached the runtime, daemon, or server. The interaction row stayed pending, so the card stayed up and every later message queued behind it (#6966). The wire had no way to say a request was withdrawn: notifications/cancelled existed only for ACP tool calls, and the server only closed interactions per thread (provider exit) or on reconnect.

Pointed at by T3 Code's fix for the same bug, pingdotgg/t3code#27320.

What changed

  • Bridge → runtime: BRIDGE_NOTIFICATION_METHODS.requestCancelled (notifications/cancelled { requestId }) now covers interaction/request as well as tool calls. Every bridge that stops waiting sends it:
    • Claude: the SDK abort for permission requests and user questions, and session close/replace/stream end.
    • Codex: serverRequest/resolved for a request bb has not answered, plus child exit and session release. These apply to forwarded tool calls too.
    • ACP: cancelPendingPermissions, which covers stop, release, steer cancel, policy change, and agent exit.
    • Pi: dialog timeout and session close/replace.
  • Runtime: RuntimeToolCalls → RuntimeProviderRequests, also used for interactive requests. onInteractiveRequest(request, signal) gets an abort signal. A withdrawn request is never answered.
  • Daemon: InteractiveRequestRegistry.registerAndWait(request, signal) rejects a withdrawn wait. Once registration settles, it reports the withdrawal through the existing retrying interrupt queue to a new POST /session/interactive-request/withdraw route, so a withdrawal that races registration cannot leave a row behind.
  • Server: interruptWithdrawnProviderRequest closes the matching row as interrupted with the reason "The agent stopped waiting for this answer". The next queued message then dispatches. It writes the lifecycle record but not the approval's item/completed: interrupted. Writing that item made the projection drop the real result Claude sends after the hook allows the tool; the first live re-run caught this.
  • Projection (thread-view): a call that its turn ends without settling no longer keeps approvalStatus: waiting_for_approval (in interruptPendingToolMessages, event-projection-state.ts). This affects a provider that withdraws and never settles the item.
  • On top of Never report a failure as the user's answer to an agent #7723: ACP's withdrawPendingQuestions (bb answers on its own when a new prompt starts) now also aborts the forwarded request, so that card closes too. Codex and Pi keep Never report a failure as the user's answer to an agent #7723's unanswered-interaction warnings and add the withdrawal on top.
  • Wire: HOST_DAEMON_PROTOCOL_VERSION 268 → 269 (new route). Plugin SDK 0.6.160 → 0.6.161 (new BRIDGE_NOTIFICATION_METHODS key, bridge-grammar snapshot). Docs: docs/provider-bridge-protocol.md, docs/provider-plugin-api.md.
  • Test fixtures: the scripted-echo bridge gets withdraw_approval, and the fake Codex app-server gets withdrawAfterMs.

How you verified

Live repro, before (origin/main 502cf5a, pnpm start:worktree, claude 2.1.325). I used a project .claude/settings.json PermissionRequest hook (matcher Bash) that returns allow, and a claude-code thread in accept-edits that runs two unsandboxed curl commands. Both commands completed (HTTP/2 200) and the turn finished with DONE.. Then:

bb thread interactions list   -> pint_2dsywi5jzf pending, pint_r4b2sui9p5 pending
bb thread list --json         -> {"status":"idle","hasPendingInteraction":true}
bb thread tell 'Reply OK.'    -> message queued (waiting for a pending interaction); it dispatches when that clears

Same steps, after:

pending_interactions -> both interrupted, "The agent stopped waiting for this answer" (rows from the first after-run, which still used the earlier wording)
command items        -> completed, exitCode 0, "HTTP/2 200"; timeline rows status completed, no approval state
bb thread list       -> idle, hasPendingInteraction false
bb thread tell       -> dispatched; agent replied "OK."

I also stopped a thread with a genuinely pending approval (no hook). The card closed and the command row shows interrupted with no lingering "waiting for approval".

After rebasing onto #7754 (timeline rows rebuilt from item records) and #7723, I re-ran both live cases. The hook case shows both commands completed, exit 0, HTTP/2 200, approvalStatus: null, both cards interrupted, and the follow-up dispatched. The stop-while-pending case shows the card interrupted and the command row interrupted with no approval state.

Tests:

  • New tests:
    • Integration: tests/integration/fake/smoke/withdrawn-approvals.test.ts, full server + daemon + runtime + scripted bridge. The card closes, the row is not left waiting, and the follow-up message dispatches.
    • Runtime: abort on withdraw.
    • Daemon registry: withdraw after registration, during registration, never registered, and after the answer.
    • Daemon app: posts the withdraw route.
    • Server: route, idempotence, and the item left to the provider.
    • Bridges: Claude (approval + user question), Codex serverRequest/resolved (no late answer reaches Codex), ACP stop, Pi timeout/answer/close.
    • thread-view: the turn-end approval state.
  • They fail without the fix. With the runtime's interactive cancel disabled, the integration test fails with expected [ { id: 'pint_nk2fcgcggg', … } ] to deeply equal []. Without the projection change, the thread-view test fails.
  • pnpm exec turbo run typecheck and test pass for @bb/agent-runtime, @bb/host-daemon, @bb/server, @bb/host-daemon-contract, @bb/provider-bridge-protocol, @bb/provider-bridge-acp, @bb/thread-view, the Claude, Codex, and Pi plugins, and the scripted-echo bridge. lint passes on the touched packages.

Fixes #6966

AGENT GENERATED

🤖 Generated with Claude Code

@ymichael
ymichael force-pushed the bb/6966-close-approval-cards-the-agent-withdraws-thr_y24w76r9m4 branch 2 times, most recently from baf709f to fc951a9 Compare November 18, 2026 21:25
ymichael and others added 2 commits November 18, 2026 14:44
When a provider stops waiting on a request it raised (a Claude
PermissionRequest hook answered it, Codex resolved it itself, a Pi dialog
timed out, an ACP or Pi session ended), its bridge dropped the request
locally and told nobody, so the card stayed pending and held back the
thread's next message.

Bridges now send notifications/cancelled { requestId } for every
interaction/request they stop waiting on (Claude, Codex, ACP, Pi). The
runtime aborts the matching interactive request, the daemon waits for
registration to settle and posts the new
/session/interactive-request/withdraw route, and the server closes the
interaction as interrupted without overwriting the item the provider
settles itself. A turn that ends with a call still waiting for approval
no longer shows it as waiting.

HOST_DAEMON_PROTOCOL_VERSION 268 -> 269; plugin SDK 0.6.159 -> 0.6.160
for BRIDGE_NOTIFICATION_METHODS.requestCancelled.

Fixes #6966

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ymichael
ymichael force-pushed the bb/6966-close-approval-cards-the-agent-withdraws-thr_y24w76r9m4 branch from fc951a9 to 2cf5a4a Compare November 18, 2026 22:44
@ymichael
ymichael merged commit 6b779c8 into main Nov 18, 2026
53 checks passed
@ymichael
ymichael deleted the bb/6966-close-approval-cards-the-agent-withdraws-thr_y24w76r9m4 branch November 18, 2026 22:54
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.

Claude approval card stays pending after a PermissionRequest hook answers, holding back the next message

1 participant