Repository navigation
fix(codex): install Codex's Interrupt hook so an Esc-cancelled turn settles - #24332
Conversation
…ettles Codex 0.150+ fires an Interrupt hook when the user presses Esc on an approval prompt or mid-tool, and nothing else. Orca did not install it, so the pane stayed blocked/working until the next prompt. - Add Interrupt to the managed Codex events and label maps, written with Codex's 3s cap (a larger value triggers a startup clamp warning). - Hash the timeout Codex hashes (Interrupt is clamped to [1,3], default 1) so self-computed trust matches Codex; pinned against a real 0.159.3 hash. - Map a root Interrupt to the existing cancelled-turn record (markCodexLeadTurnInterrupted), keeping child work in the fold; a child-scoped Interrupt is ignored. Relayed rows take the same path.
|
| export function getCodexManagedHookTimeoutSeconds( | ||
| eventName: (typeof CODEX_EVENTS)[number] | ||
| ): number { | ||
| return eventName === 'Interrupt' | ||
| ? CODEX_INTERRUPT_HOOK_MAX_TIMEOUT_SECONDS | ||
| : MANAGED_HOOK_TIMEOUT_SECONDS | ||
| } |
There was a problem hiding this comment.
WSL Fallback Exceeds Interrupt Timeout
If the first WSL post fails and the curl.exe fallback takes more than the remaining time, Codex can kill the hook at its new three-second deadline. The fallback allows up to five seconds, and spooling happens only after it returns. That can lose the cancellation update and leave the pane showing its previous status.
Knowledge Base Used: Agent integrations and hooks
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe change adds Codex Priority: ➖ Normal Merge Risk: 🔵 Low · up to On affected WSL setups, cancelling a Codex turn may leave Orca showing it as active until another event arrives. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to Existing access controls are preserved. The remaining risks concern cancellation notifications being attributed to a later turn or lost during slow delivery, rather than a demonstrated permission bypass. Retained concerns
Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description is detailed and covers the user impact, mechanism, rationale, testing, compatibility, known limitation, and checklist. However, the required Linked Issue section contains only
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
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.
✅ No new issues found.
Reviewed changes — initial review of 0cedca9 (single commit, 17 files).
- Install the
Interrupthook —CODEX_EVENTSgainsInterrupt, written with a 3s timeout (Codex clampsInterrupt/SessionEndto[1,3], default 1) across the local, real-home, WSL, and SSH install paths, with trust granted for the new key. - Trust hash normalization —
normalizeCodexHookTimeoutSecreproduces Codex'snormalize_command_hookclamp so the Interrupt entry hashes correctly;matcheris dropped forinterrupt, matching Codex'sHOOK_EVENT_NAMES_WITH_MATCHERS. - Listener / relay — a root
InterruptreusesmarkCodexLeadTurnInterrupted(roster kept, child-scoped Interrupts ignored) and settles the pane todone/cancelled; relayedInterruptrows reconcile the same way.
I verified the load-bearing external contract directly against openai/codex source (codex-rs/hooks/src/lib.rs, engine/discovery.rs, config/src/hook_config.rs): Interrupt is a real event, its key label is interrupt, it is excluded from matcher events, and normalize_command_hook clamps it to [1,3] (default 1) while other hooks default to 600 — all matching this implementation. Old Codex versions ignore the unknown Interrupt key because deny_unknown_fields is on HooksFile, not on HookEventsToml.
Tests: the new/updated Codex suites pass; src/main/codex is 2498 passed with only the two pre-existing env-dependent app-server integration files failing (same as main); the codex cancel-verdict/resurrection server tests pass; tsc -p config/tsconfig.node.json is clean.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
The managed hook's timeout is now Codex's own normalization of the shared budget, and every installer derives its trust entry from the hook it wrote, so no installer repeats the Interrupt special case. Claude-Session: codex-interrupt-hook review
… outcome Interrupt now writes the lead record through the same setCodexMainAgentTurnState call as Stop, so markCodexLeadTurnInterrupted keeps its original signature. Drops the child-scoped Interrupt guard: Codex never runs Interrupt hooks for subagents and its input schema has no agent_id. Claude-Session: codex-interrupt-hook review
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — re-review of the two commits since the prior pullfrog review at 0cedca9 (f90c4b9, 9c8ded8). Both are refactors of the Interrupt plumbing added by 0cedca9; behavior is preserved.
- Per-event timeout now lives in a builder —
buildCodexManagedHookowns the Interrupt 3s clamp by routing throughnormalizeCodexHookTimeoutSec, and every install path (local, real-home, WSL, SSH) writeshook.timeoutand takes its trust entry'stimeoutSecfrom that same hook.getCodexManagedHookTimeoutSecondsandCODEX_INTERRUPT_HOOK_MAX_TIMEOUT_SECONDSare gone. - Interrupt routed through the shared lead update —
codexOutcomeRestatedByStopbecamecodexLeadOutcomeForEvent, returningcancellationforInterruptand otherwise preserving a prior done verdict. The listener and the relay path now use it instead of a dedicated helper, andmarkCodexLeadTurnInterruptedreverts to the void helper used only by server-inferred interrupts. - Dead child-scoped Interrupt guard removed — the listener no longer drops
Interruptpayloads carrying anagent_id. Codex's Interrupt schema has noagent_idandhook_runtime.rsskips subagent sessions; a synthesizedagent_idpayload would route down the existing child branch, which does not update the lead record. Behavior is unchanged for real traffic. - Tests realigned — dropped assertions tied to the deleted helper and the unreachable child-Interrupt case, and added per-event timeout coverage in
managed-hook-timeout.test.ts.
Verified locally against 9c8ded8: the reviewed-commit suites pass (22 tests), the related listener/install/trust suites pass (54 tests), pnpm tc:node is clean, and oxlint over the touched directories reports no findings.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…rn has started A replayed or late Interrupt carries the old turn's turn_id; matching it against the turn_id from the running turn's UserPromptSubmit keeps it from cancelling the new turn. Missing ids still cancel.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — re-review of the one code commit since the prior pullfrog review at 9c8ded8 (1a030f8; 9badc3c was a clean merge of origin/main and changed no PR code). The commit closes the stale-turn risk flagged at 9c8ded8.
- Interrupt now carries a turn identity —
CodexLeadTurnStategains an optionalturnId, recorded fromUserPromptSubmit'sturn_idand preserved across every other lead write bysetCodexMainAgentTurnState. - Stale Interrupts are dropped —
isStaleCodexInterruptmakesnormalizeCodexEventreturn early when a rootInterruptnames aturn_iddifferent from the running turn's, so a queued Interrupt replayed after the next turn started no longer cancels that new turn. Missing ids on either side keep the previous accept-and-cancel behavior. - Tests — three cases added: an old-turn Interrupt ignored (new turn then reaches
working/ a cleanStop), plus cancellation on a matching-id and an id-less Interrupt. ThetoBeNull()assertion fails without the guard.
I confirmed the turnId field stays internal to the in-memory lead record and that relayed Codex rows keep applying the check on the execution host before forwarding, so the desktop's reconcile path not tracking turnId is not a gap. The reviewed listener suite passes (agent-hook-listener-codex-interrupt, 8 tests).
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
…ordered Hook events reach Orca in order: Codex waits for the Interrupt hook before the next turn, and the restart spool is one append-only file per pane, replayed in order before live events. The guard protected an unreachable case and could drop a real cancel if the ids ever differed.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — re-review of the one commit since the prior pullfrog review at 1a030f8 (a5153ef), which reverts the turn-id guard that commit had added.
- Reverted the stale-
Interruptturn-id guard —CodexLeadTurnState.turnId,isStaleCodexInterrupt, and the earlyreturn nullinnormalizeCodexEventare gone, restoring plain accept-and-cancel for a rootInterrupt. - Removed the now-unused plumbing — the
turnIdpersistence insetCodexMainAgentTurnStateand thereadStringimport incodex-state.ts. - Removed the three guard tests — the stale-id, matching-id, and id-less cases in
agent-hook-listener-codex-interrupt.test.ts.
I checked the revert's stated rationale against openai/codex@main source: the session submission loop is serial and awaits interrupt_task → handle_task_abort → run_turn_interrupt_hooks, and Orca's managed hooks are written without async, so Codex reaps each command hook (child.wait_with_output()) before the next turn's UserPromptSubmit can be dispatched. The out-of-order case the guard targeted is unreachable in normal operation, and the guard could have dropped a genuine cancel had the ids ever differed. The only ordering-relevant hole is the 1–3s timeout branch, which kills a slow hook (a drop, not a reorder) — that is the WSL fallback already documented as out of scope.
Verification on a5153ef: agent-hook-listener-codex-interrupt (5), managed-hook-timeout (5), and codex-interrupt-hook-trust (4) all pass; pnpm tc:node is clean; no dangling references to the removed symbol or field remain.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟡 Minor · Bound the WSL curl.exe fallback to the Interrupt deadline. · codex-hook-wsl-runtime.ts:84-93
src/main/codex/codex-hook-wsl-runtime.ts:84-93
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winBound the WSL
curl.exefallback to theInterruptdeadline.When the Linux
curlattempt fails andcurl.exeis available, the generated WSL hook retries synchronously with--connect-timeout 3and--max-time 5. TheInterrupthook timeout is only three seconds. A slowcurl.exestartup or connection can therefore be terminated before the POST reaches Orca.spool_hook_eventruns only after the retry returns, so this path can leave the cancelled turn unmarked.Use an outer deadline for the complete WSL fallback, including process startup, and keep the existing spool fallback when the deadline expires.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 4a541f43-870d-4fb2-a108-87138c644780
📒 Files selected for processing (3)
src/shared/agent-hook-listener-codex-interrupt.test.tssrc/shared/agent-hook-listener/providers/codex-events.tssrc/shared/agent-hook-listener/providers/codex-state.ts
💤 Files with no reviewable changes (2)
- src/shared/agent-hook-listener/providers/codex-events.ts
- src/shared/agent-hook-listener-codex-interrupt.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
…oks-write-once Conflicts with #24332 (Codex's Interrupt hook): - codex-hook-local-install.ts, codex-real-home-hook-entry-plan.ts and codex-real-home-frozen-entry.test.ts stay deleted: this branch removed the managed-home and real-home installers they belong to. - hook-service-managed-install.test.ts and hook-service-trust-grant.test.ts keep this branch's side: main's side extends tests of those deleted installers. #24332's intent carried into the session flag: - The flag defines Interrupt too, and every event's timeout comes from buildCodexManagedHook, so Codex's per-event normalization (Interrupt capped at 3 s) is what the flag carries and codexHookSessionFlagDefines checks. - Interrupt is optional: derivation requires the original 8 events, adds Interrupt's approval when Codex lists it, and the pre-publish check requires it trusted and enabled only then. An older Codex drops the definition silently. Real-binary runs: 0.133.0 lists 8 and verifies, with Interrupt defined and no warning; 0.150.1 and 0.159.2 list and trust all 9. - The contract accepts either shape and checks Interrupt is trusted wherever Codex lists it, and that a real turn prints no hook warning.

ELI5
When you press Esc in Codex to cancel a turn (for example to decline a command it wants to run, or to stop a command that is already running), Orca kept showing the pane as "needs you" or "working". Codex tells hook listeners about the cancel through a hook called
Interrupt, but Orca never subscribed to it. Now it does, and the pane settles as soon as you cancel.What Changed
Before: Orca subscribes to 8 Codex hook events. After an Esc, the last one Orca saw was
PermissionRequest(pane shows waiting) orPreToolUse(pane shows working), and it stayed that way until the next prompt. The only fallback was Orca guessing a cancel from the Esc keystroke, and that guess deliberately backs off in several cases.After: Orca also installs Codex's
Interrupthook (Codex 0.150+). When it fires, the pane goes to done and the turn is marked as cancelled.Mechanism:
CODEX_EVENTSand the Codex event-label maps gainInterrupt/interrupt. Every install path that walks that list (local managed home, real~/.codex, WSL, SSH remote) now writes it, using the same fast posting script as every other event.Interrupthooks at 3 seconds, so Orca writestimeout: 3for it. One builder (buildCodexManagedHook) owns the per-event timeout, and each installer's trust entry is taken from the hook it actually writes. Writing Orca's usual 10 would make Codex print a clamp warning at every startup.Interruptgoes through the same lead-turn update asStop, with a cancelled outcome: the same cancelled-turn record the keystroke guess writes. Subagents stay in the roster and fold in as before, so a pane with a subagent still running reads "working" with the main agent marked cancelled. Codex never sendsInterruptfor subagent sessions (its input has noagent_id), so no subagent guard is needed. The relay path (SSH) handles a forwardedInterruptrow the same way.Why
The hook is Codex's own statement that the turn was cancelled, so it is more reliable than guessing from keystrokes, and it covers cases the guess skips. Reusing the existing cancelled-turn outcome (rather than a new state) means the store's existing hold against late same-turn events also applies here. That matters: in the live check, Codex sent a
PostToolUsefor the cancelledsleep 4024 seconds after theInterrupt. The store holds it, so the pane does not flip back to working (covered by a test).Alternative considered: keep the 10s timeout and only fix the hash. Rejected because Codex would show a clamp warning on every launch.
Compatibility:
hooks.jsonevents are parsed intoHookEventsToml, which has never haddeny_unknown_fields(checked at rust-v0.114.0, 0.120.0, 0.125.0, 0.130.0, 0.140.0 and 0.149.0). The unknownInterruptkey is ignored, the same way Codex versions beforePermissionRequest/SubagentStartalready ignore those keys. The extra[hooks.state."…:interrupt:0:0"]entry is a map key that old Codex never looks up.<file>:<event>:<group>:<handler>). Adding an event adds one new key and leaves every existing key and hash unchanged, so existing hooks are not re-prompted. Orca writes the new key's trust in the same install pass that writes the hook.Interrupt(no status change, same as today). An older desktop receiving a newer relay'sInterruptrow recomputes from its own record and shows what it shows today. Nothing regresses.Known limitation
On WSL, if the hook's normal status post fails, the shared hook script falls back to Windows
curl.exe, which can take up to about 5 s. Codex capsInterrupthooks at 3 s, so on that rare path Codex may kill the hook before it delivers, and that one cancel is lost. The pane then behaves as it does today, without this PR. A fix would need per-event time budgets in the shared hook script; it is deliberately out of scope here.Linked Issue
Refs STA-9100 (one part of it)
Visual Proof
N/A: this changes the agent status Orca records, not any UI. The sidebar's existing done/cancelled rendering is unchanged. Live evidence is under Testing.
Testing
Live check (macOS, codex-cli 0.159.3, isolated
CODEX_HOME): I generatedhooks.jsonand the trust entries with Orca's own installer functions, pointed Orca's managed hook script at a local listener, and drove Codex in a PTY withcapture-agent-pty-transcript.mjs.hooks/listfrom Codex's app-server reported all 9 managed hooks astrusted, with Interrupt attimeoutSec: 3.UserPromptSubmit → PreToolUse → PermissionRequest → Interrupt.sleep 40ran:UserPromptSubmit → PreToolUse → Interrupt, then a latePostToolUsewhen the shell finished.{"session_id":"…","turn_id":"…","transcript_path":"…","cwd":"…","hook_event_name":"Interrupt","model":"…","permission_mode":"default"}. Noagent_id, and Codex skips Interrupt for subagent sessions.PermissionRequest→ waiting, thenInterrupt→ done, interrupted,mainAgent.outcome = cancellation.Automated:
codex-interrupt-hook-trust.test.ts: event list and labels, the 3s timeout, the real-Codex hash pin, clamp-equivalent hashing, matcher ignored.agent-hook-listener-codex-interrupt.test.ts: blocked → done, working → done, child work kept in the fold, next turn clears the verdict, relayed row.server-codex-interrupt-hook.test.ts: the live event order through the real hook HTTP server, including the latePostToolUse24s after.Interruptoutcome mapping, the relay-state update, the hook builder's timeout, the event-list entry, or the hash clamp each fails a test.pnpm tc, oxlint on the changed files, andcheck:code-quality:changedall pass.src/main/codex,src/main/agent-hooks,src/shared,src/relayandsrc/main/startupall pass. Onesrc/sharedshell test fails on my machine because of a local fish config, unrelated to this change.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
.cmdhook script is unchanged. Only the event list and the timeout differ.curl.execan take up to 5s more, so on that rare path Codex may kill the Interrupt hook before it posts. That costs only this one status update.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)