Repository navigation
Conversation
…ign stdin The generated Windows batch hooks are installed user-wide, so agents launched outside Orca run them too. Each guard for a missing Orca environment variable jumped to the shared drain epilogue, which blocks in more.com until stdin hits EOF. A caller that is not Orca never closes that pipe, so the cmd.exe/more.com pair and its console window persist forever, and a fresh pair leaks on every hook event. Missing Orca env means the caller is not Orca, so Orca owes it no drain: exit immediately instead. The EPIPE contract from stablyai#8430 only covers hooks Orca itself invokes, which do get a payload written with stdin then closed, and those still take the drain. Claude's statusline script carried the same guard and is the worst offender because Claude re-invokes it several times a second while streaming; it gets the same treatment. Fixes stablyai#11549 Co-authored-by: Orca <help@stably.ai>
📝 WalkthroughWalkthroughWindows managed hooks now exit directly when required Orca environment variables are missing. The Windows statusline script now exits directly when 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 process-leak bug on Windows where hook scripts installed for an entire user account would hang indefinitely when invoked by non-Orca callers (e.g. Claude running outside Orca). The root cause was that all three Orca-env guards routed to
Confidence Score: 5/5Safe to merge — the change is narrowly scoped to Windows batch script generation, is gated by The fix is a one-word substitution ( Files Needing Attention: No files require special attention. The remaining unreachable drain epilogue in
|
| Filename | Overview |
|---|---|
| src/main/agent-hooks/hook-stdin-contract.ts | Core change: guard lines now emit exit /b 0 instead of goto :drain; drain epilogue builder preserved and still exported for callers that have a surviving jump. |
| src/main/claude/hook-service.ts | Reorders endpoint-refresh and Devin-skip relative to env guards so the drain epilogue is only reachable when Orca launched the hook; conditional epilogue emission is correctly gated on skipsDevinImport. |
| src/main/claude/statusline-script.ts | Pane-key guard changed from goto :drain to exit /b 0; drain epilogue removed; the epilogue is now unreachable dead code (acknowledged residual in PR description). |
| src/main/antigravity/hook-service.ts | Drain epilogue removed from main hook; wrapper scripts gain env guards before the drain command so stale wrappers exit cleanly on non-Orca invocations. |
| src/main/command-code/command-code-managed-script.ts | Drain epilogue removed; subroutine labels :sourceEndpointByPort / :maybeSourceEndpoint are call-only and unaffected. |
| src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts | Test suite extended with structural assertions for exit-vs-drain, reachability of epilogue, wrapper ordering, and a loopback HTTP server for verifying the Orca-env positive path still drains correctly. |
| src/main/claude/statusline-script.test.ts | Updated to assert exit /b 0 on missing pane key and absence of the drain label; assertions correctly match the new script shape. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Hook script invoked] --> B{ORCA_AGENT_HOOK_ENDPOINT\ndefined & exists?}
B -- Yes --> C[call endpoint file\nrefresh env vars]
B -- No --> D
C --> D{Env guards:\nPORT / TOKEN / PANE_KEY set?}
D -- Any missing --> E[exit /b 0\nno drain, no hang]
D -- All present --> F{skipsDevinImport\nand DEVIN_PROJECT_DIR set?}
F -- Yes --> G[goto :orca_agent_hook_drain_stdin\ndrain stdin then exit]
F -- No --> H[curl POST to Orca hook endpoint]
H --> I[exit /b 0]
G --> I
subgraph Antigravity wrapper - core missing
J[Env guards\nPORT / TOKEN / PANE_KEY] -- Any missing --> K[exit /b 0]
J -- All present --> L[more.com drain\nstdin then exit]
end
style E fill:#f96,color:#000
style K fill:#f96,color:#000
style G fill:#9cf,color:#000
style L fill:#9cf,color:#000
Reviews (2): Last reviewed commit: "fix(agent-hooks): close remaining Window..." | Re-trigger Greptile
…reachability Order the Orca-env guards ahead of Claude's Devin skip so that skip's drain is reachable only when Orca invoked the hook, guard the Antigravity event wrappers before their standalone drain, and stop emitting the epilogue where nothing can jump to it. Correct the stablyai#8430 rationale: it did cover Orca-less callers, but assumed every caller closes stdin. Co-authored-by: Orca <help@stably.ai>
|
Closing as superseded after checking current The immediate-exit Windows hook guards shipped through merged #11568, with broader guard coverage added by #13379 and #19415. Current main exits when the Orca hook environment is absent instead of draining foreign stdin, including the relevant Windows shell variants. Closing this PR only; its branch is being retained. |
Fixes #11549
ELI5
On Windows, Orca installs little script files that AI coding tools run whenever something happens. Because those scripts are installed for the whole user account, tools launched outside Orca run them too.
Each script started by checking "did Orca launch me?" — and when the answer was no, instead of just quitting, it jumped to a cleanup step that waits for the caller to finish sending data. A caller that isn't Orca never signals it's done, so that wait never ended: the script and a helper program sat there forever, along with a black console window. A new pair piled up on every event. The worst offender was Claude's status line script, which gets re-run several times a second while Claude is typing.
The fix is: when the Orca environment is missing, exit immediately instead of waiting. The waiting step is kept only where something can still reach it and Orca really did send data — one script, plus the wrappers that take over when the shared script is missing.
Root cause
buildWindowsHookEnvironmentGuardLines()emitted all three missing-env guards asgoto :orca_agent_hook_drain_stdin:The epilogue at that label is
"%SystemRoot%\System32\more.com" >nul 2>nul+exit /b 0.more.comblocks until stdin reaches EOF.The drain exists to honor the EPIPE contract from #8430 (
c3ab805d12). That contract explicitly covered ordinary launches with no Orca environment — but it assumed every caller eventually closes stdin, and where that failed it relied on "the existing config-level timeout terminates the hook". A caller that is not Orca has no Orca timeout and need not ever close the pipe, so the hook wedges forever, leaking acmd.exe/more.compair and a visible console window per hook event.statusline-script.tscarried the identicalORCA_PANE_KEYguard. It is the highest-frequency leak because Claude re-invokes the statusline several times a second while streaming a response.Two further paths reproduced the same leak class and were not addressed by simply changing the shared guard:
claude-hook.cmdemitted itsDEVIN_PROJECT_DIRskip as agototo the drain before any Orca-env validation, so a Windows Devin process outside Orca reachedmore.comfirst.antigravity-hook.cmdis missing, so a stale or partially-removed install invoked outside Orca kept the same hang primitive.Fix
exit /b 0) in the shared guard builder and the statusline script.exit /b 0→ epilogue. The Devin skip is therefore reachable only when Orca invoked the hook — exactly when a payload was written and stdin will be closed — which makes its drain legitimate rather than a hang. Moving the endpoint refresh ahead of the skip is asetlocal-scoped no-op. OpenClaude uses the same template without the Devin skip, so it gets no epilogue.echo {}protocol reply so Antigravity never stalls parsing stdout. A stale wrapper invoked outside Orca now exits; an Orca-invoked one still drains.claude-hook.cmd.WINDOWS_HOOK_STDIN_DRAIN_COMMAND,installer-utils.tsandwrapWindowsGitBashHookCommandare untouched.hook-stdin-contract.ts, is that fix(agent-hooks): drain stdin before hook script early exits so agents never hit EPIPE #8430's assumption — every caller eventually closes stdin — does not hold for a foreign caller, and a transient broken pipe is the cheaper of the two failures.Proof
Each fix verified by reverting only that production change.
Antigravity wrapper guards:
Devin-guard reorder:
Dead epilogue (restored in grok only):
Dead epilogue in statusline:
Original missing-env guards, against
main:The structural tests now assert reachability, not text presence —
expect(labelIndex > -1).toBe(jumpIndex > -1)per script, plus guard ordering — and the loop covers the Antigravity event wrappers instead of excluding them.After — this branch:
The other touched agents (devin, droid, cursor, gemini, openclaude, copilot, kimi, agent-hooks): 40 files passed, 576 passed | 6 skipped.
pnpm tcandpnpm lintpass on this branch.The Windows-gated runtime test is skipped on the macOS host used here — it is not proof. See Residual risk.
Release-readiness
runHookProcessrejects after 10s rather than resolving, so a hungmore.comfails the test — that is the #11549 regression gate.target === 'local' && process.platform === 'win32'. POSIX scriptscatthe payload before any exit, so their semantics are untouched — confirmed by the unchanged, still-passing POSIX suites.installRemote()/writeManagedScriptRemote()with target'posix', which never reaches the win32 branch.~/.orca/agent-hooks. Provider-neutral. All test paths usepath.join..cmdfiles are content-compared and atomically rewritten bywriteManagedScript(), so an existing leaked-shape script self-refreshes at the next install/reconcile. Downgrading rewrites the old shape back. No schema or settings format changed.Residual risk
cmd.exe/more.compair and a console window on every hook event. The no-env test accordingly allows only broken-pipe errnos (EPIPE/ECONNRESET/ERR_STREAM_DESTROYED/EOF) — any other errno fails, meaning the script itself broke.copilot-hook.ps1andkimi-hook.shcapture stdin before any guard and are still held to the old zero-writer-errors bar.it.skipIf(process.platform !== 'win32')and skipped on this host; its new with-Orca-env block (a real loopback HTTP reader running all 12 scripts asserting zerostdinErrors, plus aclaude-hook.cmd+DEVIN_PROJECT_DIRcase that only passes if the surviving epilogue actually consumes the 1MB payload) will execute for the first time on a Windows machine. PR CI will not catch it either —.github/workflows/pr.ymlruns Vitest on Ubuntu only; the Windows job builds and packages without running Vitest. Coverage here is structural plus a Windows-only runtime gate that no CI lane executes.hooks.jsonentries:installer-utils.ts([Console]::In.ReadToEnd()missing-script launcher) andwrapWindowsGitBashHookCommand. This narrows the leak; it does not remove the primitive.docs/reference/agent-hook-stdin-lifecycle.mddocumented this contract but was deleted in Add native chat skill picker with host-aware discovery #9480 as no longer maintained. The contract now lives in thehook-stdin-contract.tscomment. Restoring a maintained doc is a reasonable follow-up.cmd.exewindow flash fromcmd.exe /C hook.cmdis unchanged.Made with Orca 🐋