Repository navigation
fix(agent-hooks): release a Claude permission wait that ended during an SSH disconnect - #29482
Conversation
…a relay disconnect The relay caches one status row per pane, so a hook that lands while the desktop is away overwrites the PostToolUse that ended the request the desktop still shows as waiting. On reconnect the desktop gets only the newer working row and its permission hold keeps the stale wait. The relay now keeps a bounded list of Claude requests it saw end (PostToolUse/PostToolUseFailure tool_use_id plus child owner) for the same launch and session, and sends it beside the replayed row as a new optional field. The desktop releases a held wait only when a replay lists that exact request from the same host, launch and session. Older peers ignore the field and keep today's behaviour. Validated against hooks captured from a real Claude Code 2.1.301 session. Part of #28186. Co-authored-by: JMensch <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to
|
ELI5
On an SSH workspace, if the connection drops while Claude is asking for permission, and the request is answered on the remote machine before Orca reconnects, Orca kept showing "needs permission" after reconnecting even though Claude had moved on. Now the reconnect clears it.
What Changed
PostToolUse) and Claude started its next tool (PreToolUse), the relay's saved status became that newer tool. On reconnect the desktop received only "working on the next tool". The desktop deliberately holds a Claude permission wait against unrelated tool activity (a parallel tool can run while a request is open), so the old wait stayed up indefinitely.src/wsl-guest/agent-hook-event-admission.ts) now keeps a bounded list (16) of Claude requests it saw end, taken fromPostToolUse/PostToolUseFailurehooks. Each entry is the exacttool_use_idplus the child agent id and type. The list resets when the launch, Claude session or process changes.claudeSettledRequests(src/wsl-guest/agent-hook-cached-pane-status.ts).shouldKeepClaudePermissionVisible) releases a held wait only when the field is on a replay and lists the waiting request's exact id and owner, from the same host, launch and session. The list is used for that one decision and is never stored on the status row.Why
PostToolUsefor the exact request is the same evidence the desktop already accepts live, so this only restores what the disconnect lost. It doesn't infer approval, denial or the end of the turn.This PR splits out and rewrites the reconnect part of #28187 by @thebestmensch (credited as co-author). That draft's other parts are handled separately.
Linked Issue
Part of #28186. It does not close it: a request that is rejected fires no Claude hook at all (confirmed in the capture below), so that case needs transcript evidence and is tracked separately. #29387 covers the
PostToolUseFailurecase.Visual Proof
N/A: there's no layout change. The pane's status row goes from waiting to working, and the integration test asserts that directly.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
New fixture
src/shared/__fixtures__/claude-permission-approve-deny-hooks.jsonl: hooks captured from a real Claude Code 2.1.301 session over a real PTY (config/scripts/capture-agent-pty-transcript.mjs). One Bash request is approved, then a second is rejected. The fixture is scrubbed (placeholder session and prompt ids, no username) and passes--scan. It confirms thatPermissionRequestcarries notool_use_id, the approved request ends withPostToolUsecarrying thePreToolUseid, and a rejection fires no hook.New
src/main/agent-hooks/server-relayed-claude-permission-replay.test.tsreplays those hooks through a real relay hook server into a real desktop hook server, with a switchable disconnect. The "request ended while the desktop was away" case fails on main (the row stayswaiting) and passes here. Controls: the live clear still works; an unrelated tool's end keeps the wait; a new Claude session carries no evidence; a non-replay envelope carrying the field is ignored.New unit tests in
claude-settled-permission-requests.test.tscover the bound, run boundaries, child-owner exactness and wire validation.Existing
server-claude-permission-visibility,server-relayed-claude-cancelandserver-relay-listener-replaysuites pass.pnpm tcandpnpm run check:code-quality:changedpass.src/main/claude/claude-structured-*is not touched, so the real-CLI suite does not apply.AI Disclosure
Review
Codex review (gpt-6.1-sol, high) found no issues.
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)