Repository navigation
fix(agent-hooks): trust Claude Stop hooks over plain Escape (STA-3817) - #15674
brennanb2025 wants to merge 3 commits into
Conversation
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]>
📝 WalkthroughWalkthrough
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (10)
src/main/agent-hooks/server-interrupt-inference-escape-navigation.test.tssrc/main/agent-hooks/server-interrupt-inference-guards.test.tssrc/main/agent-hooks/server-interrupt-inference-resurrection.test.tssrc/main/agent-hooks/server-interrupt-inference-validation.test.tssrc/main/agent-hooks/server-relay-listener-replay.test.tssrc/main/agent-hooks/server.tssrc/main/ssh/ssh-relay-session-agent-hooks.integration.test.tssrc/shared/agent-interrupt-hint.test.tssrc/shared/agent-interrupt-hint.tssrc/shared/agent-status-types.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.
| // 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>() |
There was a problem hiding this comment.
🎯 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
| /** 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' | ||
| } |
There was a problem hiding this comment.
🎯 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.
|
Codex revision complete. Changed: replaced the cross-agent interrupt-hint cache with a focused Claude rule—plain Escape cannot retire a live Claude Verified:
The final PR diff is four focused files; the transient hint module and its lifecycle complexity are gone. |
There was a problem hiding this comment.
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 winAllow authoritative terminal hooks to update inferred rows.
Line 978 creates an inferred
donerow before the provider final hook arrives. If a matching ClaudeStoparrives within 15 seconds,applyNormalizedStatusreturns the inferred row before it applies the hook. This can discard terminal fields such aslastAssistantMessageandturnCompletedAt.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
Stopwith terminal fields.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: cdc3de91-1d5e-4d87-864d-5b351208d758
📒 Files selected for processing (3)
src/main/agent-hooks/server-interrupt-inference-escape-navigation.test.tssrc/main/agent-hooks/server-interrupt-inference-guards.test.tssrc/main/agent-hooks/server.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.
|
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 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 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. |
ELI5
Pressing Escape to close a Claude overlay such as
/btwwas 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
inferInterruptignores plain Escape for a live Claudeworkingrow.Stopwithis_interrupt: true.donecorrelation.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
Acceptance file:
src/main/agent-hooks/server-interrupt-inference-escape-navigation.test.tsinferInterruptreturnedtruepnpm typechecknode config/scripts/check-changed-code-quality.mjsnode config/scripts/check-react-doctor-changed.mjsCovered: repeated navigation Escape keeps Claude
working; later tool progress remains live; a normal Stop completes without interruption;Stopwithis_interrupt: truereports interruption; latePostToolUsecannot resurrect a hook-confirmed interrupted turn.Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Checklist