Skip to content

fix(agent-hooks): trust Claude Stop hooks over plain Escape (STA-3817) - #15674

Closed
brennanb2025 wants to merge 3 commits into
mainfrom
brennanb2025/sta-3817-false-interrupt
Closed

brennanb2025 wants to merge 3 commits into
mainfrom
brennanb2025/sta-3817-false-interrupt

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​252 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​250
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4

ELI5

Pressing Escape to close a Claude overlay such as /btw was being treated as “the agent stopped,” even though Claude kept working. Orca now treats plain Escape as ambiguous while Claude is working and waits for Claude’s own Stop hook to say whether the turn ended or was interrupted.

What Changed

  • inferInterrupt ignores plain Escape for a live Claude working row.
  • Claude AskUserQuestion dismissal remains on its existing answer-inference path.
  • Genuine Claude interruption still comes from Stop with is_interrupt: true.
  • Ctrl+C fallback and every non-Claude interrupt-inference policy remain unchanged.
  • Removed the prior cross-agent interrupt-hint cache and later-done correlation.

Why

Escape is routed inside Claude’s TUI and can dismiss overlays or unsubmitted input without stopping the active turn. A terminal observer cannot determine which Claude surface consumed the key, while Claude’s Stop hook provides the authoritative lifecycle result.

This fixes the reported class without adding pane-key lifecycle state or changing agents whose cancellation hooks do not provide the same evidence.

Linked Issue

Fixes #13547

Visual Proof

N/A — this is a main-process status contract. The acceptance tests pin the row that drives the red “Interrupted” state and prove plain Escape no longer rewrites it.

Testing

  • Automated tests added/updated
  • Manually tested in a live Claude pane

Acceptance file: src/main/agent-hooks/server-interrupt-inference-escape-navigation.test.ts

  • Fixed implementation: 4 passed
  • Neutered implementation (remove the Claude Escape guard): 4 failed because inferInterrupt returned true
  • Affected hook and SSH suites: 61 passed across 7 files
  • pnpm typecheck
  • node config/scripts/check-changed-code-quality.mjs
  • node config/scripts/check-react-doctor-changed.mjs

Covered: repeated navigation Escape keeps Claude working; later tool progress remains live; a normal Stop completes without interruption; Stop with is_interrupt: true reports interruption; late PostToolUse cannot resurrect a hook-confirmed interrupted turn.

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • No wire or persisted-format change.
  • SSH uses the same server-side decision.
  • Author: @BrennanKB5

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Visual proof is N/A with a reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and folder-workspace impact considered
  • Required typecheck, changed-code gates, and affected tests pass

Escape that a TUI consumes as navigation left the turn running, but Orca
rewrote the still-working hook row to done+interrupted after 500ms of
silence. Keep working as hook authority, record the keystroke as a hint
that can stamp a later lead done, and let Claude Stop/is_interrupt paint
the red Interrupted state.

Fixes #13547
STA-3817

Co-authored-by: bbingz <[email protected]>
@coderabbitai

coderabbitai Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

AgentHookServer now handles eligible Claude and Codex interrupt inference immediately. Claude plain Escape remains navigation and does not interrupt active work. Deferred interrupt hints and reconciliation logic were removed. Tests now cover immediate inference, inference-time timestamps, confirmed Claude Stop interruptions, replay cleanup, preserved working states, and protection against late tool progress.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation addresses issue #13547 by preventing false Claude interruptions while preserving genuine Stop-hook interruptions and existing agent behavior.
Out of Scope Changes check ✅ Passed The server change and related regression tests are focused on the linked issue and stated objectives.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Title check ✅ Passed The title clearly identifies the Claude Escape and Stop-hook behavior addressed by the pull request.
Description check ✅ Passed The description follows the template and explains the behavior, rationale, issue, testing, visual proof, and compatibility considerations.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8ba83209-1a9f-4696-a947-76bcc526b2dd

📥 Commits

Reviewing files that changed from the base of the PR and between 012e9f4 and 5a8cc38.

📒 Files selected for processing (10)
  • src/main/agent-hooks/server-interrupt-inference-escape-navigation.test.ts
  • src/main/agent-hooks/server-interrupt-inference-guards.test.ts
  • src/main/agent-hooks/server-interrupt-inference-resurrection.test.ts
  • src/main/agent-hooks/server-interrupt-inference-validation.test.ts
  • src/main/agent-hooks/server-relay-listener-replay.test.ts
  • src/main/agent-hooks/server.ts
  • src/main/ssh/ssh-relay-session-agent-hooks.integration.test.ts
  • src/shared/agent-interrupt-hint.test.ts
  • src/shared/agent-interrupt-hint.ts
  • src/shared/agent-status-types.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Comment thread src/main/agent-hooks/server.ts Outdated
Comment on lines +744 to +746
// Why: inference is a hint, not a terminal rewrite. Bounded per pane; cleared on
// status delete, live work, expiry, or a confirming lead `done`.
private interruptHintsByPaneKey = new Map<string, AgentInterruptHint>()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Move and clear interrupt hints with all pane lifecycle state.

The new map is only cleared in two cleanup paths. transferPaneAuthority does not move the hint to the new pane. clearPaneState, dropStatusEntriesByTabPrefix, clearPaneKeyAliasesForPty, and stop do not clear it.

After a clear, previousStateStartedAt is undefined. A matching done event within 500 ms can stamp a recreated row as interrupted. After a pane transfer, a valid matching completion cannot find its hint.

Move the hint during transferPaneAuthority. Delete it in every path that clears pane state. Add transfer and clear/reuse tests.

Also applies to: 1888-1888, 2678-2678

Comment thread src/shared/agent-interrupt-hint.ts Outdated
Comment on lines +26 to +29
/** Claude/Kimi Stop already carry `is_interrupt`; absence of the flag is authoritative. */
export function isHookAuthoritativeInterruptAgent(agentType: AgentType | undefined): boolean {
return agentType === 'claude' || agentType === 'openclaude' || agentType === 'kimi'
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Restrict the authority exception to Stop hooks.

isHookAuthoritativeInterruptAgent clears the hint for every done event from Claude, OpenClaude, or Kimi. The required contract makes their Stop hooks authoritative. A non-Stop completion with omitted interruption metadata cannot use the fallback.

Pass hookEventName to this check. Suppress inference only for the applicable Stop event. Add a non-Stop completion test.

Proposed fix
-export function isHookAuthoritativeInterruptAgent(agentType: AgentType | undefined): boolean {
-  return agentType === 'claude' || agentType === 'openclaude' || agentType === 'kimi'
+export function isHookAuthoritativeInterruptEvent(
+  agentType: AgentType | undefined,
+  hookEventName: string | undefined
+): boolean {
+  return (
+    hookEventName === 'Stop' &&
+    (agentType === 'claude' || agentType === 'openclaude' || agentType === 'kimi')
+  )
 }
...
-  if (isHookAuthoritativeInterruptAgent(incoming.payload.agentType)) {
+  if (isHookAuthoritativeInterruptEvent(incoming.payload.agentType, incoming.hookEventName)) {

Also applies to: 84-85

The helper declared a hand-written structural shape for its baseline, but the
snapshot payload's fields are optional, so TS2345 rejected every call site.
@brennanb2025 brennanb2025 changed the title fix(agent-hooks): do not infer interrupt over a live working hook row (STA-3817) fix(agent-hooks): trust Claude Stop hooks over plain Escape (STA-3817) Aug 23, 2026
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Codex revision complete.

Changed: replaced the cross-agent interrupt-hint cache with a focused Claude rule—plain Escape cannot retire a live Claude working row. Kept: AskUserQuestion dismissal, Ctrl+C fallback, non-Claude inference policies, and hook-confirmed interruption/resurrection protection, because those existing contracts remain valid.

Verified:

  • acceptance: 4/4 pass
  • neutered guard: 4/4 fail with the original true inference
  • affected hook + SSH suites: 61/61 pass
  • pnpm typecheck
  • changed-code quality and type-aware quality: 0 findings
  • React Doctor: 0 findings

The final PR diff is four focused files; the transient hint module and its lifecycle complexity are gone.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/agent-hooks/server.ts (1)

978-993: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Allow authoritative terminal hooks to update inferred rows.

Line 978 creates an inferred done row before the provider final hook arrives. If a matching Claude Stop arrives within 15 seconds, applyNormalizedStatus returns the inferred row before it applies the hook. This can discard terminal fields such as lastAssistantMessage and turnCompletedAt.

Exclude authoritative terminal hooks from the suppression path, or merge their payload into the inferred row. Add coverage for Ctrl+C inference followed by a Claude Stop with terminal fields.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cdc3de91-1d5e-4d87-864d-5b351208d758

📥 Commits

Reviewing files that changed from the base of the PR and between 5a8cc38 and 857ae15.

📒 Files selected for processing (3)
  • src/main/agent-hooks/server-interrupt-inference-escape-navigation.test.ts
  • src/main/agent-hooks/server-interrupt-inference-guards.test.ts
  • src/main/agent-hooks/server.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@nwparker

Copy link
Copy Markdown
Contributor

Thank you for this — and an apology for how long it sat.

You got here first, and the rule that just merged is yours. #20149 landed as fe4237c, and you are a co-author on the commit.

Your four lines were the whole insight: for a Claude working row, a plain Escape is not evidence of anything, and Claude's own Stop hook already reports whether the turn ended or was interrupted. You also found the load-bearing detail independently — placing the check immediately after the dismissesClaudeQuestion branch, because AskUserQuestion dismissal is itself a plain Escape and an earlier check swallows it. We hit exactly that constraint and ended up at the same anchor.

For transparency about the detour: we first built something more elaborate, keyed on which hook event the pane's row last sat on, refusing to infer only while a tool call was open. It was wrong twice in a single review cycle — it missed OMP's tool_approval_resolved and Pi's ui_prompt_end, both of which land working with work still outstanding. It was also incoherent: it trusted the provider's hook during an open tool call while still inferring from a keystroke outside one. Either the provider's signal is authoritative or it is not. We deleted all of it and shipped your rule.

What #20149 adds on top is scope and evidence rather than design: @rodboev's half for OMP and Pi (#9289), Prime Agent alongside them, wire-level verification over the real loopback hook listener, and an end-to-end exercise in the running app.

Closing as superseded by the merged change — but the credit is yours, not ours.

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]: Escape dismissing Claude Code's /btw composer is inferred as a turn interrupt (false red "Interrupted")

2 participants