Repository navigation
fix(terminal): warn about remote work when closing the window or quitting - #18593
Conversation
…ting The native window-close warning was built from a local-only pty set: any worktree with a connectionId was dropped whole, and any remote runtime pty was filtered out. A build, test run, or agent on an SSH or Orca Remote host was therefore structurally invisible to it, on every platform. The quit path skipped the check entirely (stablyai#524), so remote work got no prompt at all. Route both paths through the same probe the tab-close guard uses, so the two cannot drift, and keep the verdict vocabulary of the SSH execution boundary: only a host that answers "no children" suppresses the warning. An unreachable host is `unverifiable`, never `exited`, so it warns rather than quitting silently — with its own copy, because "could not reach the host" is a different claim than "processes are running". Quit still ignores local ptys, preserving stablyai#524: quitting is an unambiguous instruction to end this machine's processes, but not to end execution on someone else's, which a bounded relay grace period will SIGKILL once the countdown expires. The probe budget is 1.5s (vs the tab guard's 4s) because quit is time sensitive; expiry raises the prompt, so an unreachable host costs a click rather than the 15s RPC timeout or a silently orphaned build.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (17)
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe change adds shared PTY probing with timeout and unverifiable-result handling. Terminal and window close flows now use this probe to detect running work across local and remote PTYs. The close dialog receives a running or unverifiable kind and renders the matching message. Tests cover remote hosts, timeouts, duplicate PTYs, layouts, failures, and native-close fallback behavior. Localized running-process messages no longer specify local terminals. Merge Risk: ⚪ Minimal · up to The close warnings cover running and unverifiable remote work while preserving local quit behavior. No actionable merge risk remains. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 64.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 10 files. (7 skipped: 7 unsupported.) Full details: Description checkExplanation The description provides detailed defect, fix, behavior, timeout, hardware verification, tests, and known follow-up information. However, it omits required template sections, including the linked issue, visual proof, checklist, review, notes, and agent-skill boundary declaration. Resolution Restructure the description using the repository template. Add the required issue reference after "Fixes #", attach before-and-after visual proof or provide the required N/A explanation, complete the Testing checkboxes with platforms and commands, complete AI Disclosure if applicable, and complete Review, Agent skill upstream boundary, Notes, and Checklist sections.
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 |
…ting (stablyai#18593) The native window-close warning was built from a local-only pty set: any worktree with a connectionId was dropped whole, and any remote runtime pty was filtered out. A build, test run, or agent on an SSH or Orca Remote host was therefore structurally invisible to it, on every platform. The quit path skipped the check entirely (stablyai#524), so remote work got no prompt at all. Route both paths through the same probe the tab-close guard uses, so the two cannot drift, and keep the verdict vocabulary of the SSH execution boundary: only a host that answers "no children" suppresses the warning. An unreachable host is `unverifiable`, never `exited`, so it warns rather than quitting silently — with its own copy, because "could not reach the host" is a different claim than "processes are running". Quit still ignores local ptys, preserving stablyai#524: quitting is an unambiguous instruction to end this machine's processes, but not to end execution on someone else's, which a bounded relay grace period will SIGKILL once the countdown expires. The probe budget is 1.5s (vs the tab guard's 4s) because quit is time sensitive; expiry raises the prompt, so an unreachable host costs a click rather than the 15s RPC timeout or a silently orphaned build.
…ork confirmations are off With "Closing a running chat or terminal" turned off, window close now treats local PTYs and chats as consented, the same way quit does (stablyai#524). It still probes SSH relay PTYs, so live or unverifiable remote work keeps prompting (stablyai#18593). Nothing is probed when there are no SSH PTYs. Fixes stablyai#49921 Co-authored-by: sasha <[email protected]>
…ork confirmations are off (#49922) With "Closing a running chat or terminal" turned off, window close now treats local PTYs and chats as consented, the same way quit does (#524). It still probes SSH relay PTYs, so live or unverifiable remote work keeps prompting (#18593). Nothing is probed when there are no SSH PTYs. Fixes #49921 Co-authored-by: Neil <[email protected]>

The defect (F15)
proceedToNativeWindowClosebuilt its "is anything running?" evidence from a local-only pty set:…and probed it with
window.api.pty.hasChildProcesses, a local boolean API with nounverifiableverdict. A build, test run, or long-running agent on an SSH or Orca Remote host was structurally invisible to the confirmation, on macOS, Linux and Windows alike.Verified against real hardware (an SSH worktree on
openclaw):getConnectionIdreturned"ssh-1788504734116-vt0bfg", so the old code dropped a live remote terminal before it could ever be probed.Two findings beyond the report:
if (!isQuitting)— so Cmd+Q warned about nothing at all, local or remote. That was deliberate in Fix manual quit terminal preservation #524 ("intent to quit is unambiguous"), reasoned about local PTYs that die with the app, before remote execution existed.Promise.allhad no.catch. A single rejected probe left the window neither closing nor prompting.The fix
Both close paths now run through the same probe the tab-close guard uses (
pty-running-work-probe.ts, extracted fromrunning-terminal-close-guard.ts), so the two cannot drift apart — the failure mode behind F7/F8. The guard keeps its own policy; only the measurement is shared.Verdicts follow
docs/reference/ssh-execution-boundary.mdexactly: only a host that answers "no children" suppresses the warning. A rejection, a closed transport, or a deadline that expires first isunverifiable, neverexited.Quit still ignores local ptys: quitting is an unambiguous instruction to end this machine's processes, but not to end execution on someone else's — and a target with a bounded relay grace period SIGKILLs that work once the countdown expires. Purely-local quits are therefore exactly as fast as before (no probe at all).
The dialog gets separate copy for the two claims. Telling a user "processes are running" when the truth is "a host went quiet" is the fabricated certainty this workstream exists to prevent.
Timeout: 1.5s
Shorter than the tab guard's 4s because quit is time-sensitive — the user has already asked to leave. A healthy local inspect answers in single-digit ms; a healthy remote one is a single RPC round-trip on an already-open mux channel. 1.5s leaves ~3x headroom over a slow-but-live transcontinental host while capping the worst case at ~1.5s instead of the 15s RPC timeout the probe would otherwise inherit. Expiry raises the prompt, so an unreachable host costs a click, not a silently orphaned build.
Measured on hardware: 1502ms with the host frozen.
The prompt is safe on the quit path — preload acks
window:close-request-receivedsynchronously on delivery, clearing main's 10s quit-ack timer before the dialog appears.Hardware verification
Real SSH host (
openclaw, Ubuntu), real relay, realsleep 900running remotely (PID 4146685 on pts/11):assessWindowCloseRunningWork({isQuitting:true})→{kind:'running'}in 31ms; the dialog rendered.SIGSTOPped (work still running underneath):{kind:'unverifiable'}in 1502ms, bounded by the budget. The app's own banner confirmed "Relay channel lost. Reconnecting…" while the dialog offered the unverifiable copy.Tests
window-close-running-work.test.ts(16) +use-terminal-editor-close-foundation.window-close.test.tsx(4). Both picked up byconfig/vitest.config.ts(src/**/*.test.ts{,x}— note.spec.tsis not collected).Every test was revert-tested. 11 targeted mutations of the production fix; each is caught, and 15/16 policy tests are pinned by at least one:
unverifiable→ not-warningunverifiabletooThe 4 wiring tests were revert-tested against the true pre-fix file (
git show origin/main:…): 3 of 4 fail. The 4th ("falls through when the assessment throws") passes on the original too — it is a negative control, not a fix-specific assertion. Likewise "closes without probing when no workspace owns a pty" is a negative control killed by no mutation.Verification
tscclean on all three projects (node, cli, web)oxlintclean on all changed files — positive-controlled: a 1200-line probe file did triggermax-lines, so the clean exit is meaningful. Nomax-linesdisable added;running-terminal-close-guard.tsshrank 155 → 143.check:code-quality:changed: 0 new findings (code quality, type-aware, React Doctor)oxfmtappliedAgentMapWorkspaceContextMenu.test.tsx, unrelated, passes in isolation (load flake)src/maintouched by this diff. Confirmed flaky on a cleanorigin/mainbaseline worktree: the same files fail there too, and the specific failing test differs run to run.Two existing guard test files needed their
settleProbe()helper widened from 3 fixed microtask ticks to a drain loop, and anawaitafteradvanceTimersByTime: the deadline now resolves a promise instead of firing the prompt inside the timer callback, so the policy runs one microtask later. Not user-observable. All 29 + 16 of their assertions still pass unchanged.Unrelated issue found
While driving the app,
PortsStatusSegmentcrashed itsoverlay.status-barerror boundary withgetSnapshot should be cached to avoid an infinite loopfollowed byMaximum update depth exceeded(stack:forceStoreRerender/updateStoreInstance— theuseSyncExternalStorepath).It reproduced at renderer startup on a fresh, empty user-data dir with zero SSH targets and zero repos — 251s before this session's first SSH activity, and it did not recur when a target later connected. Not touched by this PR; handed to the agent working the ports-panel CI failure. Untested against a clean
main, so "pre-existing" is inference from the diff having nouseSyncExternalStore, no store selectors and no subscriptions, not a measurement.Not done deliberately
skipCloseTerminalWithRunningProcessConfirmis still not honored on the window/quit path (matching today's behavior). There is a real tension to resolve: a user off VPN with a disconnected SSH worktree now gets anunverifiableprompt on every quit. Honoring that setting would give them an opt-out, but it would also disarm a just-added safety warning through a setting that predates it and was written for a different surface (one tab, not the whole app). That is a product decision, not a rider on this PR — filed here so it is not lost.