Skip to content

fix(vm-recipes): stop dialing a sleeping workspace VM, and resume one whose host is gone - #40105

Merged
nwparker merged 1 commit into
mainfrom
nwparker/vm-dead-host-and-suspend-reconnect
Nov 9, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/vm-dead-host-and-suspend-reconnect

Conversation

@nwparker

@nwparker nwparker commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When you put a VM workspace to sleep, Orca kept knocking on its door. Some providers wake the VM whenever someone knocks, so it never actually slept. Orca now stays quiet until you open the workspace. Also, if the VM died on its own, opening the workspace now restarts it instead of doing nothing.

Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​501 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​501
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​265 $\color{#cf222e}{\Huge{\mathbf{−}}}$​15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​250

What Changed

Suspended VMs get no background dials (#36363). A VM is held while its record is suspended (or resume_failed) and no wake is under way. The hold is applied at the lowest dial points, so every caller above them is covered:

  • SSH: SshConnectionManager.connect and the SSH reconnect ladder refuse that VM's Orca-owned SSH host. This covers managed tunnels, managed-server checks, terminal census, the browser bridge and pairing repair. A user's connection test (probe) is still allowed, as with Disconnect.
  • Shared control socket: it does not retry after a close and does not open while held. That includes a retry timer armed before the sleep, OS-wake retryNow, and every wait for ready. Waiting requests are rejected with the existing runtime_environment_asleep code.
  • Health probe: the status owner answers asleep without dialing. Tunnelled servers were already refused by request preparation. Paired servers were not.
  • Request and subscription traffic (git and GitHub polling, terminal reattach, listings) was already refused by prepareRecipeVm.

A wake (opening the workspace, Resume, a phone or CLI open) is marked pending before it dials, so its own connect passes. After the wake, Orca reopens the server's control socket and refreshes its status. A suspend that is still running does not hold anything, so a suspend that fails or is skipped never strands reconnects.

A VM whose host is gone can be resumed (#34089). Before, opening a workspace whose VM is recorded running (or suspend_failed) returned the record unchanged, even when the VM was gone. Now, if Orca's SSH reconnect ladder for that VM has used every attempt (reconnection-failed, minutes of failures), opening the workspace runs the recipe's resume and reconnects. If the resume or reconnect fails, the record is left as it was, so it never lands in an asleep state and normal reconnects go on. A blip, a reconnect still under way, a host the user disconnected, or one not dialed this session does not trigger it.

Why

Issue #36363 shows a provider whose paused box resumed about 25 s after suspend, from Orca's own reconnects. Holding dials at the transport layer gives one predicate (isRecipeVmEnvironmentAsleep / isRecipeVmSshTargetAsleep in src/main/ephemeral-vm/recipe-vm-asleep.ts) instead of patching each poller.

For #34089, Orca only resumes on strong evidence (an exhausted reconnect ladder) and never on a single failed probe. The default of refusing to sleep a host whose terminals can't be confirmed stopped is unchanged. A "Sleep anyway" action or a recipe status hook would need UI or recipe-schema decisions and is left out.

Linked Issue

Fixes #36363
Refs #34089. This covers the SSH-mode recovery path. Paired-mode VMs have no equivalent reliable "gone" signal yet.

Visual Proof

N/A. No UI change; the behaviour is in main-process transports. Test evidence:

Scenario Before After
Socket drops while VM asleep, 10 min of fake time retries every 0.25 s to 5 min 0 new connections (remote-runtime-shared-control-asleep.test.ts, real ws server)
Retry armed before the sleep fires dials 0 new connections
Background SSH connect to an asleep VM host SSH login refused with ssh_host_asleep, no session created
Reconnect ladder / network-return retry while asleep redials 0 attempts
Status probe of asleep paired VM dials answers asleep, sendRemoteRuntimeRequest not called
Open workspace, VM running, SSH ladder exhausted no-op recipe resume + reconnect, then socket and status reopened
Same, but SSH connected / reconnecting / never dialed / user-disconnected no-op no-op (unchanged)

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below
  • Every added test fails without this change and avoids the test anti-patterns

New tests: ssh-host-sleep-hold.test.ts, remote-runtime-shared-control-asleep.test.ts, runtime-environment-status-owner-asleep.test.ts, recipe-vm-asleep.test.ts, workspace-resume-lost-contact.test.ts. I confirmed that disabling the hold makes the shared-control and SSH tests fail. pnpm check:changed passes. The only failures were load timeouts in existing SSH and shared-control suites, which pass 3/3 when run alone. I did not run this against a real VM provider (macOS only).

Risk

Level: Low

  • Users without recipe VMs: no change. Both predicates return early unless the environment or SSH host belongs to a recipe VM (Orca-owned runtime-ssh- target ids). The environment check is one cached store read per socket open or close. The predicates never throw; an unreadable record means "not asleep".
  • A VM recorded suspended that the user resumed from the provider console: Orca no longer auto-reconnects to it. Opening the workspace runs Resume as before.
  • Non-sidebar opens of an asleep SSH-mode VM (notifications and similar) now get a clear ssh_host_asleep instead of an SSH login that would wake the VM behind Orca's back. Requests to such a VM were already refused with runtime_environment_asleep.
  • Lost-contact resume runs only after the reconnect ladder is exhausted. A failure leaves the record unchanged.
  • Persisted data: no schema change. A plain revert backs this out.

@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 49b11813-8588-4aba-9e8f-1ad81b394daa
Commits

Reviewing files that changed from the base of the PR and between 7cc8b28 and 12d6b1b.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The changes add recipe-VM asleep detection and apply it to shared-control connections, SSH connections, reconnect attempts, and runtime status requests. They also add recovery for eligible SSH VMs whose target reports reconnection-failed. Recovery resumes the recipe, reconnects SSH, and schedules shared-control reconnection and environment status refresh. Tests cover sleep-state checks, connection and status behavior while asleep, and lost-contact recovery.

Severity of issue fixed: Medium

Merge Risk: Minimal · previous review 7cc8b

No merge-blocking issue was established for the VM sleep and recovery changes. The change is mergeable after normal checks.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title names the two main changes: holding dials to a sleeping recipe VM workspace, and resuming a VM whose host is gone. Both match the changeset and the PR objectives. The title is 88 characters,…
Description check Passed The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue (Fixes #36363, Refs #34089), Visual Proof (N/A with a reason and test evidence table), Testing wit…
Linked Issues check Passed Directly linked issue #36363 requires that, once suspend succeeds, Orca stops reconnecting to the workspace environment until the user wakes it and Orca calls resume. The PR implements this hold at th…
Out of Scope Changes check Passed The changed files serve the #36363 hold or its related lost-contact case. The hold covers recipe-vm-asleep.ts, ssh-host-sleep-hold.ts, the SSH connection manager guard, the reconnector mayRedial guard…
Docstring Coverage Passed Docstring coverage is 81.82% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
Full details: Title check

Explanation

The title names the two main changes: holding dials to a sleeping recipe VM workspace, and resuming a VM whose host is gone. Both match the changeset and the PR objectives. The title is 88 characters, slightly above the usual short-title length, but it stays specific and readable.

Full details: Description check

Explanation

The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue (Fixes #36363, Refs #34089), Visual Proof (N/A with a reason and test evidence table), Testing with checkboxes and new test files, and Risk with a level and rollback note. It explains the mechanism and the alternatives considered. Gaps: the Testing checkboxes are partly unchecked, the AI Disclosure section is left blank, the Review and Agent skill upstream boundary sections are not addressed, and the Checklist is not included. These are non-critical for the overall assessment.

Full details: Linked Issues check

Explanation

Directly linked issue #36363 requires that, once suspend succeeds, Orca stops reconnecting to the workspace environment until the user wakes it and Orca calls resume. The PR implements this hold at the transport layer. (1) src/main/ephemeral-vm/recipe-vm-asleep.ts: isVmAsleep returns true when the VM record is suspended or resume_failed and no wake is in state 'waking'. Read at head, this is the shared predicate. (2) Per the PR summary, SshConnectionManager.openSession refuses non-probe connections to an asleep runtime-owned SSH host with ssh_host_asleep. The SSH reconnect ladder is also gated. (3) Per the summary, the shared control connection (openRefusal, isAsleep option) does not retry or open while held, and waiting requests reject with runtime_environment_asleep. (4) Per the summary, the status owner answers asleep without dialing. A wake is marked pending before it dials (waker state 'waking'), and workspace-resume.ts reopens the control socket and status after the wake. The issue's failure path (control-socket-close retries that open a fresh SSH login after suspend) is covered by items 2 and 3. Tests are listed in the PR (ssh-host-sleep-hold.test.ts, remote-runtime-shared-control-asleep.test.ts, runtime-environment-status-owner-asleep.test.ts, recipe-vm-asleep.test.ts). I did not run them. The issue's related case (a provider pauses a VM on its own, and Orca should call resume when reconnects keep failing, or offer Wake) is addressed for SSH-mode VMs only. workspace-resume.ts (read at head) calls resumeEphemeralVmRuntime when isRecipeVmLostContact is true, which requires the ladder to report reconnection-failed. No Wake action and no paired-mode recovery are added. The issue text for that case is advisory ('it would help'), and the PR objectives present it as a separate case, so it is not counted as an unmet primary requirement. Residual uncertainty: the SSH reconnector and shared-control hold files were not read directly. An attempted read of src/main/ssh/connection/ssh-connection-reconnect.ts failed because that path does not exist at head. Their behavior rests on the PR summary and the author's test list.

Full details: Out of Scope Changes check

Explanation

The changed files serve the #36363 hold or its related lost-contact case. The hold covers recipe-vm-asleep.ts, ssh-host-sleep-hold.ts, the SSH connection manager guard, the reconnector mayRedial guard, the shared-control hold and types, the status owner guard, the environment policy, and startup wiring in main-process-runtime-service.ts. The lost-contact resume covers recipe-vm-lost-contact.ts and the workspace-resume.ts change. Its tests are workspace-resume-lost-contact.test.ts and the matching test cases. The PR body cites #34089 with 'Refs'. #34089 is not among the supplied linked issues. Its lost-contact recovery is assessed here through the related-case text in #36363, which asks for resume when reconnecting keeps failing. That text connects the change to the linked issue, so it is not demonstrated unrelated. Test and documentation changes support the listed behavior. I found no change that lacks a connection to the linked issue. The PR body notes that it is not a complete solution for paired-mode VMs. That gap is an unmet scope item, not an out-of-scope change.

Full details: Docstring Coverage

Explanation

Docstring coverage is 81.82% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 11 functions across 17 files.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: daebc7bd-148a-4f58-a27e-81af9bb06e93
Commits

Reviewing files that changed from the base of the PR and between 72e5893 and 7cc8b28.

Files selected for processing: 17

  • src/main/ephemeral-vm/recipe-vm-asleep.test.ts
  • src/main/ephemeral-vm/recipe-vm-asleep.ts
  • src/main/ephemeral-vm/recipe-vm-lost-contact.ts
  • src/main/ephemeral-vm/workspace-resume-lost-contact.test.ts
  • src/main/ephemeral-vm/workspace-resume.ts
  • src/main/ipc/runtime-environments/runtime-environment-shared-control-policy.ts
  • src/main/ipc/runtime-environments/runtime-environment-status-owner-asleep.test.ts
  • src/main/ipc/runtime-environments/runtime-environment-status-owner.ts
  • src/main/ssh/connection/reconnect/ssh-connection-reconnect.ts
  • src/main/ssh/connection/ssh-connection-manager.ts
  • src/main/ssh/connection/ssh-host-sleep-hold.test.ts
  • src/main/ssh/connection/ssh-host-sleep-hold.ts
  • src/main/startup/main-process-runtime-service.ts
  • src/shared/remote-runtime/control/remote-runtime-shared-control-asleep.test.ts
  • src/shared/remote-runtime/control/remote-runtime-shared-control-connection.ts
  • src/shared/remote-runtime/control/remote-runtime-shared-control-hold.ts
  • src/shared/remote-runtime/control/remote-runtime-shared-control-types.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

… whose host is gone

A suspended recipe VM kept getting reconnect attempts: shared-control
socket retries, health probes and SSH logins. Providers that resume a VM
on a new SSH login or connection woke it again, so suspend saved nothing
(#36363).

While a VM's record is suspended (or its resume failed) and no wake is
under way, Orca now makes no background dial to it:
- SSH: connect and the reconnect ladder refuse that VM's own SSH host,
  which covers tunnels, managed-server checks, census and browser bridge.
- Shared control: no retry after close, and no socket open, including a
  retry timer armed before the sleep.
- Status probe: answers asleep without dialing.
A wake (opening the workspace, Resume) is pending before it dials, so the
wake's own connect passes. Afterwards the server's control socket and
status are reopened.

A VM recorded as up whose SSH host Orca gave up reaching (the reconnect
ladder used every attempt) may have been stopped or reclaimed by its
provider. Before, opening the workspace did nothing for it (#34089). Now
it runs the recipe's resume and reconnects. If that fails, the record is
left as it was, so normal reconnects go on.

Fixes #36363
Refs #34089
@nwparker
nwparker force-pushed the nwparker/vm-dead-host-and-suspend-reconnect branch from 7cc8b28 to 12d6b1b Compare November 9, 2026 04:15
@nwparker
nwparker merged commit 4652a35 into main Nov 9, 2026
76 checks passed
@nwparker
nwparker deleted the nwparker/vm-dead-host-and-suspend-reconnect branch November 9, 2026 04:40
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.

[Bug]: VM recipe suspend: Orca keeps reconnecting to a suspended workspace, which wakes providers that resume on SSH login

1 participant