Repository navigation
fix(agent-hooks): exit Windows hooks when Orca env is missing - #11568
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughWindows managed hook environment guards now exit successfully when required Orca port, token, or pane variables are missing. Windows hook execution refreshes endpoint credentials and applies environment guards before the Devin-specific skip. Lifecycle tests verify immediate exits, stdin draining for other failures, and permitted 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
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 |
Greptile SummaryThis PR fixes a Windows-specific process hang where managed agent hooks (Codex, Claude, etc.) registered as user-wide hooks would leave
Confidence Score: 5/5Safe to merge — the change is a one-function edit to a well-tested, centrally-consumed helper, and it directly eliminates the hanging process class without touching the happy path. The fix is minimal and mechanically correct: swapping Files Needing Attention: No files require special attention. Both changed files are straightforward — the implementation change is a 3-line swap in a pure string-builder function, and the test changes mirror it exactly.
|
| Filename | Overview |
|---|---|
| src/main/agent-hooks/hook-stdin-contract.ts | Core change: replaces goto :orca_agent_hook_drain_stdin with exit /b 0 in the env-guard lines; drain epilogue function is untouched and all 10+ hook services consume this function centrally, so the fix propagates consistently. |
| src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts | Test updated with both positive assertions for exit /b 0 and negative assertions confirming the old goto form is gone; the drain-epilogue assertion is preserved, confirming non-env failure paths still route to more.com. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Agent invokes Windows .cmd hook] --> B{ORCA_AGENT_HOOK_ENDPOINT defined?}
B -- Yes --> C[call endpoint file to refresh env]
B -- No --> D{ORCA_AGENT_HOOK_PORT set?}
C --> D
D -- No --> E["exit /b 0 (was: goto drain → more.com hangs)"]
D -- Yes --> F{ORCA_AGENT_HOOK_TOKEN set?}
F -- No --> E
F -- Yes --> G{ORCA_PANE_KEY set?}
G -- No --> E
G -- Yes --> H[curl POST hook payload to Orca server]
H --> I[exit /b 0]
H -- curl fails / other error --> J[goto :orca_agent_hook_drain_stdin]
J --> K["more.com reads stdin to EOF"]
K --> L[exit /b 0]
Reviews (1): Last reviewed commit: "fix(agent-hooks): exit Windows hooks whe..." | Re-trigger Greptile
…tdin handoff The Windows-only executable matrix still asserted every managed .cmd drains its writer, which the missing-env fast exit intentionally stops doing. That assertion never runs in CI (vitest is ubuntu-only), so it would only fail on a Windows dev machine. - Accept a broken writer for .cmd hooks on the missing-env path; keep the no-error contract for the PowerShell and Git Bash hooks that still read stdin first. - Correct the drain-epilogue comment: claude-hook.cmd is the remaining in-script jump to it.
…in the guard comment
runHookProcess always closes stdin, so the executable case cannot reproduce the abandoned-pipe hang; say so and name the guard strings as the real gate. Also record that the Devin skip guard still routes to the drain above these guards, so stablyai#11549 stays reachable for Devin outside an Orca pane.
…tdin policy The two templates now answer the same question opposite ways and nothing states the rule, so name the constraint (batch has no bounded stdin reader) and the evidence (POSIX callers have not shown the abandon; Windows callers have).
…aiming The renamed case covers two missing-script launchers that still read to EOF, so 'without stranding a reader' was false for them. Payload size was also the wrong reason for the .cmd exit — the statusline script buffers the same size through more.com; the real constraint is that any read-to-EOF hangs on an abandoned pipe. Also record that the broken-writer relaxation is only sound because hookEnvironment() strips every ORCA_* var, since the branch keys on .cmd.
The revert pin was three exact string denials, so a fourth ORCA_* guard — copied from the nearest in-repo pattern, which still routes to the drain — would have reintroduced stablyai#11549 with the suite green. Assert instead that no ORCA_* guard in a generated .cmd routes to the more.com drain. Verified both directions: reverting the source fails it, and adding a simulated ORCA_TAB_ID guard that gotos the drain fails it too. Does not match the Devin skip, which is not an ORCA_* guard and whose caller is a live Orca pane.
…-contradicting The previous wording set a rule that claude/statusline-script.ts breaks 25 lines away in the same export surface, and said nothing about the Windows .ps1 and Git Bash hooks. State the rule for generated .cmd, then name every hook that still reads first and why — the read is the payload capture, not a drain. Batch is the exception because it streams to curl, so owning stdin buys nothing there.
The guard-spelling regex only covered `if "%VAR%"==""`, but `if not defined VAR` is equally house idiom here — every Windows hook opens with `if defined ORCA_AGENT_HOOK_ENDPOINT`. A fourth guard written that way routed to the drain with the suite green. Match the whole line instead of one spelling, which also covers `goto` without its colon. Probed all eight cases: the five bypass spellings are caught, and the Devin skip, the endpoint refresh, and the fixed guard are correctly exempt.
… .cmd rule The list conflated them. POSIX, copilot .ps1 and kimi .sh read first because the read is the payload capture. claude/statusline-script.ts does route its guard to the drain — it is exempt because its caller closes stdin, which the in-pane capture already proves. Grouping them under 'the read is the capture' would let a future author reach the right conclusion from the wrong premise.
…vin skip claude-hook.cmd checked DEVIN_PROJECT_DIR before the Orca env guards, and that check jumps to the more.com drain. Outside an Orca pane the caller is not Orca's PTY, so it can abandon stdin and leave more.com waiting forever — the stablyai#11549 hang this guard reordering is meant to close. Both branches end the hook, so the only behavior that changes is Devin outside an Orca pane: it now exits 0 instead of parking in more.com. In-pane Devin still reaches the skip and still owns stdin. Depends on stablyai#11568.
|
Thanks for this — good catch on the root cause, and the fix is the right shape. Heads up that I pushed a few commits directly to this branch. Here's what changed and why: Folded in one more instance of the same bug
Made the regression test actually hold the line
Docs
Verified on a real Windows host: before the change, the missing-env path left a live Two things I saw but left out of this PR so they don't get lost:
One thing for the release notes whenever this lands: it stops new stuck processes but can't reap ones that leaked before the upgrade, so anyone with leftover |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/claude/hook-service.ts (1)
64-68: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueReduce these comments to concise rationale.
Keep only the non-obvious reason at each site.
src/main/claude/hook-service.ts#L64-L68: use short comments for endpoint refresh and guard ordering.src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts#L273-L284: shorten the regex rationale and drain-label note.src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts#L294-L296: shorten the guard-order rationale.src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts#L369-L374: shorten the broken-writer rationale.As per coding guidelines, comments must be concise, limited to non-obvious information, and preferably one line.
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: bd7b223a-e907-4c4e-a30a-e9acc69884f2
📒 Files selected for processing (3)
src/main/agent-hooks/hook-stdin-contract.tssrc/main/agent-hooks/managed-hook-stdin-lifecycle.test.tssrc/main/claude/hook-service.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/agent-hooks/hook-stdin-contract.ts
# Conflicts: # src/main/claude/hook-service.ts
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Correction on my earlier push: it left this branch conflicting with Fixed by merging latest
|
The three-line guard fix needed a three-line comment, not a thirteen-line taxonomy adjudicating three other files. Swap the hand-rolled drain gate and broken-writer set for the combinators already used repo-wide: not.toMatch (94 uses) and toContain on a literal.
|
Follow-up from a standard-fix audit pass over this PR — no change to your fix, which was right. Swapping the three The audit was aimed at my own review commits on top of yours, and it found two things worth cutting:
I also cut the comment I had grown on Behavior is unchanged and pinned: reverting the guards to |
|
@brennanb2025 Thank you for taking this so carefully — and for co-authoring on the branch. Your diagnosis of the Devin / I’m good with landing your tip as-is. The two follow-ups you left out (stale hook scripts on Also noted for release notes: this stops new stuck processes but can’t reap ones that already leaked before upgrade. |
|
Thank you for the PR!! |
… unavailable (#13378) * fix(agent-hooks): refresh existing shared hook scripts when the CLI is no longer detected A CLI that falls off PATH (moved npm prefix, relocated shim) keeps its user-wide config invoking Orca's launcher script under ~/.orca/agent-hooks, but the presence gate skips install() with no removal — freezing the script at whatever Orca generated last. Anyone in that state kept the pre-#11568 more.com-leaking .cmd forever, because no launcher script is ever deleted and Windows startup deliberately skips shell PATH hydration. Reconcile before gating: every existing shared launcher/statusline script is rewritten to the current template on each install pass. Creating scripts stays behind the presence gate — an existing file is proof of a prior install; a missing one means the gate did its job. Amp and Hermes are deliberately absent: they write provider-native plugin code with its own install lifecycle, not shared launchers. - refreshManagedScriptIfPresent() in installer-utils (no-op unless the file exists) - refreshManagedScripts() on the 11 launcher-writing services (openclaude via the shared Claude class) - reconcile pass in installManagedAgentHooks before presence detection, filtered by the agents option, best-effort per agent - coverage gate: a launcher written to ~/.orca/agent-hooks without a matching refresher entry fails the suite, in both directions * perf(agent-hooks): refresh launchers off the main thread * test(agent-hooks): keep refresh mode assertion POSIX-only
…n stdin (#13379) Same hang class #11568 closed for .cmd: copilot-hook.ps1 ran [Console]::In.ReadToEnd() and kimi-hook.sh captured stdin before checking the Orca env, so a user-wide hook fired outside an Orca pane blocked forever when the caller abandoned the pipe — one stranded powershell.exe or bash.exe per hook event. Move the env guard (after the endpoint refresh, which can supply PORT/TOKEN) above the read on the Windows-local variants. The payload is discarded on the missing-env path anyway; the broken writer is the trade #11568 established. POSIX variants keep capture-first — those callers close stdin, and exiting mid-write there surfaces as EPIPE the agent can see (#8110). Kimi's remote install now asks for the posix variant explicitly. Verified on a real Windows host: pre-fix copilot with an abandoning caller never exits; post-fix both exit 0 immediately, and the env-present copilot path still consumes stdin and delivers the POST (paneKey + payload received by a local listener).
…ai#11568) * fix(agent-hooks): exit Windows hooks when Orca env is missing * test(agent-hooks): pin the Windows missing-env exit as a deliberate stdin handoff The Windows-only executable matrix still asserted every managed .cmd drains its writer, which the missing-env fast exit intentionally stops doing. That assertion never runs in CI (vitest is ubuntu-only), so it would only fail on a Windows dev machine. - Accept a broken writer for .cmd hooks on the missing-env path; keep the no-error contract for the PowerShell and Git Bash hooks that still read stdin first. - Correct the drain-epilogue comment: claude-hook.cmd is the remaining in-script jump to it. * docs(agent-hooks): cite stablyai#11549 and the stdin-ownership trade in the guard comment * test(agent-hooks): stop overstating what the live matrix pins runHookProcess always closes stdin, so the executable case cannot reproduce the abandoned-pipe hang; say so and name the guard strings as the real gate. Also record that the Devin skip guard still routes to the drain above these guards, so stablyai#11549 stays reachable for Devin outside an Orca pane. * docs(agent-hooks): record why Windows batch diverges from the POSIX stdin policy The two templates now answer the same question opposite ways and nothing states the rule, so name the constraint (batch has no bounded stdin reader) and the evidence (POSIX callers have not shown the abandon; Windows callers have). * test(agent-hooks): stop the live matrix name and comment from over-claiming The renamed case covers two missing-script launchers that still read to EOF, so 'without stranding a reader' was false for them. Payload size was also the wrong reason for the .cmd exit — the statusline script buffers the same size through more.com; the real constraint is that any read-to-EOF hangs on an abandoned pipe. Also record that the broken-writer relaxation is only sound because hookEnvironment() strips every ORCA_* var, since the branch keys on .cmd. * test(agent-hooks): gate the rule, not the three guards that exist today The revert pin was three exact string denials, so a fourth ORCA_* guard — copied from the nearest in-repo pattern, which still routes to the drain — would have reintroduced stablyai#11549 with the suite green. Assert instead that no ORCA_* guard in a generated .cmd routes to the more.com drain. Verified both directions: reverting the source fails it, and adding a simulated ORCA_TAB_ID guard that gotos the drain fails it too. Does not match the Devin skip, which is not an ORCA_* guard and whose caller is a live Orca pane. * docs(agent-hooks): name the exceptions so the stated rule is not self-contradicting The previous wording set a rule that claude/statusline-script.ts breaks 25 lines away in the same export surface, and said nothing about the Windows .ps1 and Git Bash hooks. State the rule for generated .cmd, then name every hook that still reads first and why — the read is the payload capture, not a drain. Batch is the exception because it streams to curl, so owning stdin buys nothing there. * test(agent-hooks): close the if-not-defined bypass in the drain gate The guard-spelling regex only covered `if "%VAR%"==""`, but `if not defined VAR` is equally house idiom here — every Windows hook opens with `if defined ORCA_AGENT_HOOK_ENDPOINT`. A fourth guard written that way routed to the drain with the suite green. Match the whole line instead of one spelling, which also covers `goto` without its colon. Probed all eight cases: the five bypass spellings are caught, and the Devin skip, the endpoint refresh, and the fixed guard are correctly exempt. * docs(agent-hooks): separate the two reasons a hook is exempt from the .cmd rule The list conflated them. POSIX, copilot .ps1 and kimi .sh read first because the read is the payload capture. claude/statusline-script.ts does route its guard to the drain — it is exempt because its caller closes stdin, which the in-pane capture already proves. Grouping them under 'the read is the capture' would let a future author reach the right conclusion from the wrong premise. * fix(agent-hooks): let the missing-Orca-env exit outrank the Claude/Devin skip claude-hook.cmd checked DEVIN_PROJECT_DIR before the Orca env guards, and that check jumps to the more.com drain. Outside an Orca pane the caller is not Orca's PTY, so it can abandon stdin and leave more.com waiting forever — the stablyai#11549 hang this guard reordering is meant to close. Both branches end the hook, so the only behavior that changes is Devin outside an Orca pane: it now exits 0 instead of parking in more.com. In-pane Devin still reaches the skip and still owns stdin. Depends on stablyai#11568. * refactor(agent-hooks): cut the review additions back to house idiom The three-line guard fix needed a three-line comment, not a thirteen-line taxonomy adjudicating three other files. Swap the hand-rolled drain gate and broken-writer set for the combinators already used repo-wide: not.toMatch (94 uses) and toContain on a literal. --------- Co-authored-by: Brennan Benson <[email protected]>
… unavailable (stablyai#13378) * fix(agent-hooks): refresh existing shared hook scripts when the CLI is no longer detected A CLI that falls off PATH (moved npm prefix, relocated shim) keeps its user-wide config invoking Orca's launcher script under ~/.orca/agent-hooks, but the presence gate skips install() with no removal — freezing the script at whatever Orca generated last. Anyone in that state kept the pre-stablyai#11568 more.com-leaking .cmd forever, because no launcher script is ever deleted and Windows startup deliberately skips shell PATH hydration. Reconcile before gating: every existing shared launcher/statusline script is rewritten to the current template on each install pass. Creating scripts stays behind the presence gate — an existing file is proof of a prior install; a missing one means the gate did its job. Amp and Hermes are deliberately absent: they write provider-native plugin code with its own install lifecycle, not shared launchers. - refreshManagedScriptIfPresent() in installer-utils (no-op unless the file exists) - refreshManagedScripts() on the 11 launcher-writing services (openclaude via the shared Claude class) - reconcile pass in installManagedAgentHooks before presence detection, filtered by the agents option, best-effort per agent - coverage gate: a launcher written to ~/.orca/agent-hooks without a matching refresher entry fails the suite, in both directions * perf(agent-hooks): refresh launchers off the main thread * test(agent-hooks): keep refresh mode assertion POSIX-only
…n stdin (stablyai#13379) Same hang class stablyai#11568 closed for .cmd: copilot-hook.ps1 ran [Console]::In.ReadToEnd() and kimi-hook.sh captured stdin before checking the Orca env, so a user-wide hook fired outside an Orca pane blocked forever when the caller abandoned the pipe — one stranded powershell.exe or bash.exe per hook event. Move the env guard (after the endpoint refresh, which can supply PORT/TOKEN) above the read on the Windows-local variants. The payload is discarded on the missing-env path anyway; the broken writer is the trade stablyai#11568 established. POSIX variants keep capture-first — those callers close stdin, and exiting mid-write there surfaces as EPIPE the agent can see (stablyai#8110). Kimi's remote install now asks for the posix variant explicitly. Verified on a real Windows host: pre-fix copilot with an abandoning caller never exits; post-fix both exit 0 immediately, and the env-present copilot path still consumes stdin and delivers the POST (paneKey + payload received by a local listener).
Description
Stop Windows managed agent hooks (Codex/Claude/etc.) from hanging in
more.comwhen invoked outside an Orca pane withoutORCA_*env.User-wide Codex hooks still run for non-Orca sessions. Missing PORT/TOKEN/PANE_KEY now
exit /b 0immediately instead of routing to the stdin-drain epilogue that can leave visiblecmd.exe+more.comprocesses forever.Focused fix
buildWindowsHookEnvironmentGuardLines()missing-env pathPreserves
Evidence
pnpm exec vitest run --config config/vitest.config.ts src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts src/main/codex/hook-service.test.ts src/main/claude/hook-service.test.ts src/main/agent-hooks/installer-utils.test.ts(92 passed, 10 skipped)exit /b 0and nogotodrain for missing envUser-regression-tradeoffs
cmd.exe /C(Codex launcher); they no longer stick openFixes #11549