Repository navigation
fix(relay): put the daemon in a kill-on-close job so a crash cannot orphan its PTY tree on Windows - #16895
fix(relay): put the daemon in a kill-on-close job so a crash cannot orphan its PTY tree on Windows#16895brennanb2025 wants to merge 2 commits into
Conversation
|
Holding this from merge until Windows verification lands. The unit tests prove the relay attempts assignment and degrades cleanly, but they cannot prove the tree is actually reaped, and this was written on macOS which cannot load Windows prebuilts. Specifically unverified:
A verification run is in flight on a Windows host covering both, plus a baseline arm (hard-kill an owner without the call → does the tree orphan?) and the degrade path. Will post results here. |
|
Warning Review limit reachedNext included review available in 6 minutes. View limit detailsLimit details: You’ve used all 10 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
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 (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe relay daemon now assigns its process to a Windows ConPTY kill-on-close job during startup, before socket ownership and channel setup. The new helper handles successful assignment, unavailable native support, native errors, and non-Windows platforms. Tests cover these outcomes and verify the helper’s startup position. Merge Risk: 🔵 Low · up to On Windows, the relay now attempts process-tree cleanup on crash, but installations where the native operation is unavailable or refused retain the existing orphan-process exposure. This is a bounded deployment/runtime risk requiring owner awareness or follow-up validation; the change is otherwise mergeable. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description is detailed and covers the purpose, implementation, rationale, testing, platform scope, limitations, and linked issue context. It does not use the required template headings or explicitly include the required Visual Proof, AI Disclosure, Review, Agent skill boundary, Notes, and Checklist sections, but the core information is present. ✨ 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 |
Verified on Windows hardware — build 26200All four arms pass on this PR's exact commit ( Arm 0 — the headline risk is clear. This repo's own Windows prebuilt does export the symbol: loaded from the worktree's own patched node-pty ( Arm 1 — baseline reconfirms the bug. Parent 132604 / shell 126320 / marker 48912 all alive; after Arm 2 — the PR's own exported function fixes it. Arm 3 — the degrade path is real, not theoretical. With a loader lacking the export it logged the diagnostic and returned All 12 created PIDs confirmed gone; no production files modified; the run found nothing contradicting the PR description. Taking this out of draft. |
Review — PR #16895Reviewed at head What's rightThe premise is correct and I verified it: the relay does not share Feature detection is also genuinely sound — missing export, load failure, and refused assignment all degrade to a logged outcome and never fail startup. Ablation confirms every branch is pinned:
Main finding: this reimplements something that already exists (P2)
The PR body gives two reasons for the fork. I checked both and neither holds:
Placement contradicts the incumbent's documented guidance (P2)
This PR calls it at the top of Related: the ordering test at Suggested shape: delete Windows observation — worth acting on regardless (residual risk)I reached a real Windows host and probed the ConPTY addon a current worktree actually resolves: None of But it does demonstrate the failure mode is reachable, and that it is shared: when those symbols are absent, this PR logs and no-ops and #16894's Windows branch falls back to Not affectedNo wire-format change (no RPC params, frames, or opcodes); no new |
Review — recommend SUPERSEDE (the gap is real; the implementation is not what we would write)Rebased onto current The earlier round's SUPERSEDE reasoning was wrong, and the gap is realThe prior conclusion was that But the implementation duplicates a tested module for no gain
P1 — the only code path that runs in production is the only one never testedEvery one of the eight tests injects a fake loader ( Note this also removes the main argument for duplicating: the new module has the same resolution fragility as the canonical one, so it did not buy anything. P2 — the startup call site contradicts the documented guidance
The ordering test cements that placement: moving the call after What I would write insteadDelete Gate-level ablation, each arm reverted ALONEAll eight arms are individually pinned — genuinely better test hygiene than #16894 had:
The caveat is that this pins the shape, not the behaviour that matters: the real loader is outside all of it. Composition with #16894They merge cleanly and compose semantically; combined tree is 28/28 on the targeted suites with |
Addendum — P0: this is a no-op on every SSH remote, which changes the recommendationA second pass surfaced something that outranks everything in my comment above. I verified it independently rather than taking it on report.
|
|
Closing on the P0 in the review above, which I verified independently rather than taking on report.
My Windows hardware verification was invalid and I should flag why. The run loaded the addon from Following the recommendation as given:
Also taking the process point: this PR reached 'ready' without an adversarial review loop, which is what caught it. Running that loop on the remaining PRs before treating any of them as ready. |
In plain terms
Same story as the sibling PR, but for a nastier kind of death.
Orca runs a helper program on your remote machine to look after your terminals. Sometimes that helper doesn't get to shut down politely — it's force-killed, runs out of memory, or the machine loses power. In those cases it never runs any cleanup code, so nothing it might have been told to do on the way out will happen.
On Mac and Linux the operating system handles this for us: when the helper dies, your terminal programs get a hang-up signal and shut themselves down. Windows has no equivalent, so the leftovers just keep running — invisible to Orca, holding your project folder, piling up every time it happens.
This tells Windows up front: if I die, take everything I started with me. The operating system then enforces it, no matter how the helper dies.
Measured on a real Windows machine: before this change, a leftover program survived the helper being force-killed. After it, everything was cleaned up within about five seconds.
What you'll notice: on Windows remote machines, no more invisible leftover processes after a crash.
How the three PRs fit together
The original report (STA-5698) was: after the remote helper restarts, Orca might start your AI agent a second time while the first one is still running — two agents editing the same files at once.
That needs two ingredients:
These three PRs remove both ingredients rather than trying to detect the collision afterwards:
Each stands alone and they can land in any order.
Why not just detect the collision? That was the first attempt (#16843, now closed). It tried to work out "has the helper been replaced?" by comparing how long it had been running against when Orca last saw the terminal. It couldn't tell a helper restart apart from the whole machine having rebooted — and after a reboot nothing survives, so there's nothing to protect against. It would have refused to restore your agent in a case that was completely safe. A live reproduction also failed to produce the collision at all on Linux: killing the helper took the agent down with it in 0.3 seconds.
So: prevent the leftovers, fix the names, and the problem doesn't arise instead of being guessed at.
The gap, measured on real hardware
On Windows build 26200, a process that owns a ConPTY and dies without running any handler leaves descendants behind:
taskkill /Fon the parentThe one call is
assignCurrentProcessToJob(), which puts the calling process in a kill-on-close job so the kernel reaps its whole descendant tree when it dies. The addon comment says exactly that: it exists so a crashed host reaps its tree.Why the relay does not already do this
Orca's patched node-pty has two job objects, and only one of them reaps:
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE— with a measured reason in its comment: with that flag, typingexitin a pane also killed whatever the user had backgrounded. Untouched here.assignCurrentProcessToJob.On the desktop side the second one is already wired up (
src/main/windows/windows-pty-job.ts). Nothing insrc/relay/calls it — so the relay, which is the process that owns PTYs on a Windows SSH host, has never been in one. That is a process leak on Windows remote hosts today, independent of any client-side behaviour.The change
One call at relay startup, before any PTY can be created, win32 only.
It feature-detects and degrades, which is not hypothetical: during the hardware experiment one existing checkout's prebuilt addon exported the symbol and another did not. A missing export, a load failure, or a refused assignment is logged through
relayLogLineand returns a distinct outcome — it never fails startup.Why a relay-local module rather than importing the desktop helper
src/main/windows/windows-pty-job.tsfeature-detects onterminateJob/listJobProcessIds, which are the symbols it needs. This path needsassignCurrentProcessToJob, and a prebuilt could carry one set without the other — so it checks the symbol it actually calls, and reports the three cases distinctly. Happy to collapse the two if reviewers prefer a shared loader.Tests
src/relay/relay-windows-pty-job.test.tscovers assignment, the missing-export path, the refused path, load failure, non-win32 no-op, and startup ordering. Red before the change (the module did not exist), 8 green after.Verification
pnpm tc,npx oxlint, the new test file,pnpm oxfmt, andpnpm build:relayall pass. Integrated with the sibling STA-5697 PR the relay suite shows no new failures — the two that fail also fail onorigin/main.Known limit
The unit test proves the relay attempts assignment and degrades cleanly. It cannot prove the tree is actually reaped, and this machine is macOS, so I could not confirm that this repo's own Windows prebuilt exports the symbol — only that the patched source does. If it does not, this degrades to a logged no-op rather than a fix. That check belongs on a Windows host before this is relied on.