Skip to content

fix(terminal): warn about remote work when closing the window or quitting - #18593

Merged
nwparker merged 1 commit into
stablyai:mainfrom
nwparker:nwparker/quit-warn-remote-work
Sep 4, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
nwparker:nwparker/quit-warn-remote-work

Conversation

@nwparker

@nwparker nwparker commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

The defect (F15)

proceedToNativeWindowClose built its "is anything running?" evidence from a local-only pty set:

const connectionId = getConnectionId(worktreeId)
if (connectionId !== null) return []          // drops every SSH/remote worktree, whole
...filter((ptyId) => !isRemoteRuntimePtyId(ptyId))   // drops every remote runtime pty

…and probed it with window.api.pty.hasChildProcesses, a local boolean API with no unverifiable verdict. 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): getConnectionId returned "ssh-1788504734116-vt0bfg", so the old code dropped a live remote terminal before it could ever be probed.

Two findings beyond the report:

  1. The quit path skipped the check entirely — 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.
  2. The old Promise.all had 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 from running-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.md exactly: only a host that answers "no children" suppresses the warning. A rejection, a closed transport, or a deadline that expires first is unverifiable, never exited.

local pty remote pty
window close live → warn; unverifiable → no live → warn; unverifiable → warn
quit not probed (preserves #524) live → warn; unverifiable → warn

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-received synchronously on delivery, clearing main's 10s quit-ack timer before the dialog appears.

Hardware verification

Real SSH host (openclaw, Ubuntu), real relay, real sleep 900 running remotely (PID 4146685 on pts/11):

  • Live remote process → warning on quit. assessWindowCloseRunningWork({isQuitting:true}) → {kind:'running'} in 31ms; the dialog rendered.
  • Unreachable host → warning, not a hang. With the relay 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 by config/vitest.config.ts (src/**/*.test.ts{,x} — note .spec.ts is 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:

mutation tests killed
restore the F15 local-only filter 11
collapse unverifiable → not-warning 3
drop the quit carve-out 1
narrow the remote predicate to owner-ful ids 1
remove the deadline 1 (hangs to the 30s test timeout — the quit-hang bug itself)
warn on local unverifiable too 1
ignore layout-bound panes 1
treat an unanswered probe as idle 1
never probe local on window close 1
warn unconditionally 5
collect no ptys 12

The 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

  • tsc clean on all three projects (node, cli, web)
  • oxlint clean on all changed files — positive-controlled: a 1200-line probe file did trigger max-lines, so the clean exit is meaningful. No max-lines disable added; running-terminal-close-guard.ts shrank 155 → 143.
  • check:code-quality:changed: 0 new findings (code quality, type-aware, React Doctor)
  • oxfmt applied
  • Renderer + shared: 36178 passed, 1 failed — AgentMapWorkspaceContextMenu.test.tsx, unrelated, passes in isolation (load flake)
  • Main + shared: 38095 passed, 5 failed — all real-binary/integration timing tests, none under src/main touched by this diff. Confirmed flaky on a clean origin/main baseline 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 an await after advanceTimersByTime: 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, PortsStatusSegment crashed its overlay.status-bar error boundary with getSnapshot should be cached to avoid an infinite loop followed by Maximum update depth exceeded (stack: forceStoreRerender / updateStoreInstance — the useSyncExternalStore path).

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 no useSyncExternalStore, no store selectors and no subscriptions, not a measurement.

Not done deliberately

  • The local-work-on-quit gap (Fix manual quit terminal preservation #524) is left as-is; F15 is scoped to remote, and changing it affects every local user.
  • Known follow-up: skipCloseTerminalWithRunningProcessConfirm is 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 an unverifiable prompt 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.

…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.
@pullfrog

pullfrog Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Pullfrog  | View workflow run | via Pullfrog | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 4, 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: Team

Run ID: 32fd6661-2191-4bfc-9a63-0c76b186636e

📥 Commits

Reviewing files that changed from the base of the PR and between b378101 and e7a7982.

📒 Files selected for processing (17)
  • config/scripts/locale-ko-key-overrides.json
  • src/renderer/src/components/TerminalWorkspaceDialogs.tsx
  • src/renderer/src/components/terminal/pty-running-work-probe.ts
  • src/renderer/src/components/terminal/running-terminal-close-guard.test.ts
  • src/renderer/src/components/terminal/running-terminal-close-guard.ts
  • src/renderer/src/components/terminal/terminal-tab-close-running-confirm.test.ts
  • src/renderer/src/components/terminal/window-close-running-work.test.ts
  • src/renderer/src/components/terminal/window-close-running-work.ts
  • src/renderer/src/components/use-terminal-editor-close-foundation.ts
  • src/renderer/src/components/use-terminal-editor-close-foundation.window-close.test.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/fr.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/shared/remote-execution-host-pty-id.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The 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 e7a79

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning 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:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning 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 issu… 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 co…
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the main change: warning about remote work during window close or quit.
Full details: Docstring Coverage

Explanation

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 check

Explanation

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.

  • Fix all pre-merge checks with AI

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.

@nwparker
nwparker merged commit b85510f into stablyai:main Sep 4, 2026
28 of 29 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
nwparker added a commit to UADominator/orca that referenced this pull request Nov 26, 2026
…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]>
nwparker added a commit that referenced this pull request Nov 26, 2026
…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]>
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