Skip to content

fix(agent-hooks): release a Claude permission wait that ended during an SSH disconnect - #29482

Merged
nwparker merged 1 commit into
mainfrom
nwparker/claude-replay-settled-permission
Oct 16, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/claude-replay-settled-permission

Conversation

@nwparker

@nwparker nwparker commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​321 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​321
Prod 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​207 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​199

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

  • Before: the remote relay keeps only the latest status for each pane. If, during a disconnect, the approved tool finished (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.
  • After: the desktop shows the newer working status after reconnecting, and the stale wait is gone.
  • Mechanism:
    • The relay (src/wsl-guest/agent-hook-event-admission.ts) now keeps a bounded list (16) of Claude requests it saw end, taken from PostToolUse / PostToolUseFailure hooks. Each entry is the exact tool_use_id plus the child agent id and type. The list resets when the launch, Claude session or process changes.
    • When the relay replays its saved status after a reconnect, it sends that list next to the row as a new optional field, claudeSettledRequests (src/wsl-guest/agent-hook-cached-pane-status.ts).
    • The desktop (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

  • A PostToolUse for 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.
  • Alternatives considered:
    • Having the relay forward its full hook history on reconnect would change what the host publishes, and older clients would see a burst of outdated statuses.
    • Dropping the hold on any replay would let a parallel tool's activity hide a request that's still open.
  • Mixed versions: an older desktop ignores the new field and sees one current status, as today. An older relay doesn't send it, and the desktop keeps today's hold.

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 PostToolUseFailure case.

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 that PermissionRequest carries no tool_use_id, the approved request ends with PostToolUse carrying the PreToolUse id, and a rejection fires no hook.

  • New src/main/agent-hooks/server-relayed-claude-permission-replay.test.ts replays 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 stays waiting) 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.ts cover the bound, run boundaries, child-owner exactness and wire validation.

  • Existing server-claude-permission-visibility, server-relayed-claude-cancel and server-relay-listener-replay suites pass. pnpm tc and pnpm run check:code-quality:changed pass.

  • 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • SSH and WSL: the relay is the execution host. It records only what its own hooks reported, and the desktop applies that only to its own replay. Losing contact is never treated as evidence that a request ended.
  • Wire: one new optional envelope field. It is bounded, validated whole and dropped if malformed, and only sent on replays of non-waiting rows.
  • Local panes: unaffected, since they have no relay cache.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…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]>
@coderabbitai

coderabbitai Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e161cf7c-9f16-4abc-b00e-8d5f6d92c824
📥 Commits

Reviewing files that changed from the base of the PR and between adff94d and 05ab5a3.

📒 Files selected for processing: 14
  • src/main/agent-hooks/server-relayed-claude-permission-replay.test.ts
  • src/main/agent-hooks/server/server-claude-status-rules.ts
  • src/main/agent-hooks/server/server-ingest-remote.ts
  • src/main/agent-hooks/server/server-remote-envelope-normalization.ts
  • src/main/agent-hooks/server/server-status-update.ts
  • src/shared/__fixtures__/claude-permission-approve-deny-hooks.jsonl
  • src/shared/__fixtures__/claude-permission-approve-deny-hooks.meta.json
  • src/shared/agent-hook-listener/claude-settled-permission-requests.test.ts
  • src/shared/agent-hook-listener/claude-settled-permission-requests.ts
  • src/shared/agent-hook-listener/listener-event.ts
  • src/shared/agent-hook-relay.ts
  • src/wsl-guest/agent-hook-cached-pane-status.ts
  • src/wsl-guest/agent-hook-event-admission.ts
  • src/wsl-guest/agent-hook-server.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

📝 Walkthrough

The change tracks settled Claude tool requests and includes matching evidence in cached replay envelopes. Remote processing validates and carries that evidence without storing it in status rows. The permission-visibility rule uses matching replay evidence to hide a settled permission. Tests cover retention, replay matching, reconnect behavior, and captured permission-hook events.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 05ab5

No merge-blocking issue was identified in the reviewed change; normal checks remain appropriate.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 12 files. (2 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: clearing a Claude permission wait after an SSH disconnect.
Description check Passed The description is complete and focused. It covers the user impact, implementation, rationale, linked issues, testing, compatibility, and checklist items. The required visual proof is correctly marked…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 12 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit 6936409 into main Oct 16, 2026
40 of 41 checks passed
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