Repository navigation
fix(agent-hooks): guard copilot and kimi Windows hooks before they own stdin - #13379
Conversation
…n stdin 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).
|
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 (4)
📝 WalkthroughWalkthroughWindows-local Copilot and Kimi hooks now validate Orca environment variables before reading stdin. POSIX hooks retain capture-first behavior. Kimi script generation accepts explicit 🚥 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 |
Fallback QA (macOS Electron + CDP) — head
|
| Variant | Required ordering | Result |
|---|---|---|
| Windows-local Copilot | stdout → endpoint refresh → env guard → ReadToEnd |
pass |
| Windows-local Kimi Git Bash | endpoint refresh → env guard → payload capture | pass |
| POSIX-local Copilot/Kimi | capture-first | pass |
| Remote Copilot/Kimi | capture-first | pass |
Electron renderer had no errors related to this change. Opening the PR comments panel exposed an unrelated nested-link hydration warning; it does not touch the hook path.
Explicit gap
This local macOS Electron run is not a substitute for fresh Windows Electron abandoned-pipe execution. The PR's existing real-Windows process evidence and green Windows CI remain the Windows-specific evidence.
Screenshots (not committed)
Generated-script ordering, exact branch context, PR #13379, and green checks
Settings → Agents with Agent status hooks enabled
…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).


Summary
Follow-up to #11568 / #11549 — the same hang class in the two Windows hooks that PR left open.
copilot-hook.ps1ran[Console]::In.ReadToEnd()andkimi-hook.sh(Git Bash) 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 strandedpowershell.exe/bash.exeper hook event.The env guard (after the endpoint refresh, which can supply PORT/TOKEN for restart-surviving PTYs) now runs before 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 requests the posix variant explicitly.
Screenshots
No visual change. Real-Windows-host process evidence in the Testing section.
Testing
pnpm exec oxlinton touched files, cleanpnpm typecheck(node project), cleanpnpm exec vitest runonsrc/main/agent-hooks/+ copilot + kimi suites: 41 files, 613 tests greenpnpm build(not run locally; CI packages)AI Review Report
Reviewed adversarially. Ordering verified against the generated scripts: copilot still emits its required
{}stdout first, then endpoint refresh, then guard, then read; the endpoint file supplies only PORT/TOKEN/ENV/VERSION andORCA_PANE_KEYis launch-context env, so no later step could populate missing context after the early exit — every skipped payload is one Orca could not route or authenticate anyway. Kimi forks guard-first only forlocal+win32; POSIX local, SSH/remote, and the posix lifecycle tests keep capture-first. The accepted risk is the same as #11568's: a parent mid-write sees a broken pipe on the missing-env path while the hook still exits 0; not Copilot/Kimi-specific.Security Audit
No new input handling, command execution, or network surface — the change reorders existing lines in generated scripts. The guard reduces exposure: outside-Orca payloads are no longer read into hook process memory at all on the missing-env path. Token/port handling, curl/Invoke-WebRequest targets, and remote install content are unchanged.
Notes