Skip to content

fix(agent-hooks): reconcile Claude request waits across reconnects - #28187

Closed
thebestmensch wants to merge 4 commits into
stablyai:mainfrom
thebestmensch:fix/claude-request-wait-reconciliation
Closed

thebestmensch wants to merge 4 commits into
stablyai:mainfrom
thebestmensch:fix/claude-request-wait-reconciliation

Conversation

@thebestmensch

@thebestmensch thebestmensch commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Orca can keep showing a Claude permission request after that request has finished, or report no wait while a workspace-trust dialog is visible. This change makes those reports follow the exact request and current terminal screen.

What Changed

  • A matching PostToolUseFailure clears the pending request even when Claude has cleared the tool's display fields.
  • The execution host can reconcile a terminal transcript result for the same request, session, process and child. It retains the current agent/child state instead of treating an error result as cancellation or turn completion.
  • Reconnect replays one current status with bounded, optional request-settlement facts. A later tool hook no longer erases the evidence needed to clear an older wait. Older peers still receive one current status.
  • Polling survives transient admission failures, rejects superseded observations, and preserves pending state when admission fails.
  • After execution-host restart, saved local requests resume polling with frozen ownership and a live process check. Recovery rechecks the current row before applying the result and preserves the restored-unconfirmed status of the wider agent state.
  • Interactive-wait queries use the existing rendered-screen reader for Claude dialogs, with bounded reads and terminal-generation/output checks. A plain Claude title does not prove the dialog was answered.

Why

A missing hook or network interruption should not require another user prompt to repair status. Exact ownership and transcript-branch checks let the execution host reconcile completed requests without guessing a permission decision. Reusing the existing status store, scheduler, screen reader and replay metadata avoids a second source of agent status.

Linked Issue

Fixes #28186.

Related to the Claude dialog portions of #25854 and #25623; this PR does not claim to fix those issues' other providers or CodeBuddy injection.

Visual Proof

Pending installed-runtime before/after capture. Existing raw PTY fixtures cover wide, narrow and answered Claude workspace-trust dialogs in headless replay. This draft is not evidence of an installed UI fix.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

Automated checks ran on macOS:

  • Runtime dialog/visibility suite: 50 passed.
  • Request/reader/scheduler/relay suite: 124 passed, 5 relay-only scenarios skipped in the local-host parameterization.
  • Additional ownership/hydration/poll suite: 51 passed.
  • Final integration/hydration/replay-facts suite after the last stale-replay fix: 62 passed, 6 relay-only scenarios skipped in the local-host parameterization.
  • Restart recovery and ownership matrix: 54 passed. Adjacent request visibility, child lifecycle, transcript and replay suites: 83 passed, 6 skipped. A fixture-only type correction was followed by another 10/10 admission tests and a successful full build.
  • Built headless runtime acceptance passed: the existing runtime-serve-terminal-smoke.mjs paired a client to the built Electron server, created a disposable worktree and terminal, executed a command and observed its output, then shut down and cleaned up. This verifies the built terminal path, not real Claude permission or Windows-client acceptance.
  • Hidden Electron/Playwright prompt-submission suite: 3 passed. Its simulated Codex agent covers slow composition, a swallowed Enter without duplicate submission, and zero prompt bytes sent into an active permission dialog. This is shared submission-path regression evidence, not real Claude cancellation acceptance.
  • Full pnpm run build passed, including the configured TypeScript checks, relay, CLI, desktop, mobile-web and macOS native builds. Changed-file oxlint, diff checks, and normal commit hooks also passed. Broader test coverage and upstream CI remain pending.

The first full build stopped at missing mobile-workspace dependencies. Installing that workspace with pnpm install --frozen-lockfile resolved it; package manifests and lockfiles remain unchanged. The optional global orca-dev symlink could not be installed, so the build used the checkout's output without changing the running app.

The final regression first reproduced an old result with retained facts changing a later completed row back to working. The fix limits retained-fact settlement to a pending request and preserves the existing strict restatement checks for already-settled rows.

AI Disclosure

Codex assisted implementation and testing. Claude performed a read-only review of the working-tree candidate.

Review

The latest independent review approved the complete 10-file restart-recovery diff with no concrete findings. It had no tool access and could not independently verify tests or surrounding scheduler behavior. A subsequent fixture-only correction replaced an invalid false value with undefined; that final type-corrected test and full build passed. Earlier concrete findings were reproduced and fixed.

Agent skill upstream boundary

  • Not applicable: no upstream skill-installer source or associated material is copied or translated.

Notes

A live rendered-screen probe on October 13 found an additional unresolved dialog: Claude's Auto Mode classifier confirmation (Yes/No, with 20 blocked actions) is visible while the installed runtime reports a null agentWait. Passing that same captured rendered text to this branch's detectTerminalWaitBlockedReason also returns null. The workspace-trust fix therefore does not cover this Auto Mode dialog. No dialog input was sent. A raw PTY fixture and detector repair are still required; the rendered-text diagnostic is not a raw-terminal replay or installed acceptance test.

This remains a draft pending real persisted Claude transcript validation, installed Windows-to-Mac operation, and a hands-off workflow canary. Execution-host restart recovery is now implemented and covered by the real hook-server restart test with a synthetic transcript and mocked process verdict. That test first reproduced a saved wait remaining stuck after restart with no fresh hook; it now settles the exact request. Missing or revoked ownership, unresolved parallel requests, sibling-child results, unverifiable or exited processes, newer waits, disabled hooks and pane teardown cannot use this recovery path to clear the wait. This does not establish installed-runtime acceptance.

Transcript fixtures are synthetic; existing SDK stream captures do not establish persisted JSONL ancestry. Local inspection of a real transcript was blocked by the environment's path guard and was not retried through another route.

The 16-result replay bound is conservative: an older pending request whose proof has fallen out of the retained set may remain held. No permission settings, approval dialogs, credentials, or installed runtime are changed by this PR. Actual Windows/Linux/SSH acceptance remains unverified; remote tests use the real relay and main servers locally.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots or videos attached for behavior changes
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path impact considered
  • Full lint, typecheck, test, and build coverage completed; targeted checks above passed

@nwparker

Copy link
Copy Markdown
Contributor

Thank you @thebestmensch for this work and for the careful write-up in #28186. Your reproduction and ownership checks made the split much easier. We need these fixes sooner than a full review of a ~3,000-line draft would allow, so we've split it into smaller PRs and credited you as co-author on each:

Not carried over, and why:

  • Transcript-result reader and poll. We checked it against a real 2.1.301 transcript of a rejected request. PermissionRequest never carries a tool_use_id, so the draft always takes its inferred-id path. On that path the reader returns false, because Claude writes a [Request interrupted by user for tool use] user row after the rejected tool_result. A rejected request fires no hook at all, so that case is still open on [Bug]: Claude request results leave stale permission waits across reconnects #28186 and needs its own PR, built against real transcripts.
  • Restart recovery. It depends on the transcript reader above. It also adds a second ownership path (frozen commitments plus a process check) for a narrow case. After a restart a restored row is already restoredUnconfirmed, and any new hook replaces it. We'll revisit it once the transcript piece lands.

Closing in favour of the PRs above. Thanks again!

@nwparker nwparker closed this Oct 16, 2026
nwparker added a commit that referenced this pull request Oct 16, 2026
…tive-wait query (#29488)

getTerminalInteractiveWait read only the line tail, which drops the rows
below the cursor Claude parks inside its dialog, so the query answered
"no wait" while the trust dialog owned the screen. For Claude panes it
now reads the rendered screen (bounded, discarded if newer output or a
pane exit overtakes the read) and lets a dialog seen there stand unless
a newer working or explicit idle signal clears it. Other agents keep the
synchronous path, so concurrent queries still share one hook probe.

Ported from #28187 onto the split runtime modules.

Co-authored-by: JMensch <[email protected]>
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.

[Bug]: Claude request results leave stale permission waits across reconnects

2 participants