Skip to content

fix(agent-hooks): guard copilot and kimi Windows hooks before they own stdin - #13379

Merged
brennanb2025 merged 1 commit into
mainfrom
followup/copilot-kimi-hook-stdin-guard
Aug 12, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
followup/copilot-kimi-hook-stdin-guard

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #11568 / #11549 — the same hang class in the two Windows hooks that PR left open. copilot-hook.ps1 ran [Console]::In.ReadToEnd() and kimi-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 stranded powershell.exe/bash.exe per 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 oxlint on touched files, clean
  • pnpm typecheck (node project), clean
  • pnpm exec vitest run on src/main/agent-hooks/ + copilot + kimi suites: 41 files, 613 tests green
  • Structural assertions flipped to pin guard-before-read for both scripts; revert-check confirms reverting the source fails the suite
  • Validated on a real Windows host (PowerShell child processes with redirected pipes, ORCA_* stripped):
    • pre-fix copilot + abandoning caller: never exits (the bug)
    • post-fix copilot and kimi + abandoning caller: exit 0 immediately
    • post-fix copilot with full Orca env: consumes stdin (no writer error) and its POST arrives at a local listener with paneKey + payload
    • control: trivial exit-0 scripts under both hosts exit fine with an abandoned pipe, ruling out host-level stdin confounds
  • pnpm 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 and ORCA_PANE_KEY is 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 for local + 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

  • Windows-only behavior change; POSIX and SSH/remote script content is byte-identical.
  • With this, every Windows-local managed hook (.cmd, .ps1, Git Bash .sh) follows the same rule: missing Orca env never owns stdin. The statusline script's drain remains intentionally different — its caller demonstrably closes stdin, and its read is the payload capture.

…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).
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2ed01b51-0601-4593-86d2-6f3ac8d38243

📥 Commits

Reviewing files that changed from the base of the PR and between 427f178 and f2727c3.

📒 Files selected for processing (4)
  • src/main/agent-hooks/hook-stdin-contract.ts
  • src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts
  • src/main/copilot/hook-service.ts
  • src/main/kimi/hook-service.ts

📝 Walkthrough

Walkthrough

Windows-local Copilot and Kimi hooks now validate Orca environment variables before reading stdin. POSIX hooks retain capture-first behavior. Kimi script generation accepts explicit local and posix targets, and remote installation selects the POSIX variant. Windows lifecycle tests verify early stdin release and accept EPIPE or ECONNRESET for all local hook types.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Windows-local Copilot and Kimi hook stdin guard, which is the primary change.
Description check ✅ Passed The description covers all template sections, explains behavior and risks, and documents extensive testing, including the unrun local build.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@brennanb2025

brennanb2025 commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Fallback QA (macOS Electron + CDP) — head f2727c3f71

Windows low-spec runtime disconnected twice before dispatch; this is the local fallback QA only.

Identity and focused validation

window.api.app.getIdentity() was checked before interaction and identified:

  • pr-11568-review @ followup/copilot-kimi-hook-stdin-guard
  • HEAD f2727c3f71cdc08ded324d3049a96c6fa6344480

Focused lifecycle/Copilot/Kimi tests: 5 files, 42 passed, 1 skipped (the Windows-live process matrix is expected to skip on macOS).

Generated-script ordering:

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

ordering and PR checks

Settings → Agents with Agent status hooks enabled

agent status hooks setting

@brennanb2025
brennanb2025 merged commit 23cbe6d into main Aug 12, 2026
45 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant