Skip to content

fix(remote): a missed wake probe no longer closes slow remote connections - #33071

Merged
nwparker merged 1 commit into
mainfrom
nwparker/nonlethal-wake-probe
Oct 24, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/nonlethal-wake-probe

Conversation

@nwparker

@nwparker nwparker commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When your Mac wakes up, or Wi-Fi comes back, Orca checks every connection to a remote server. If a server didn't answer within 8 seconds, Orca hung up and showed "Reconnecting to remote runtime". On a slow or relayed link, such as Tailscale going through a relay right after a wake, the answer often takes longer than that, so Orca dropped connections that were actually fine. Now a slow answer only makes Orca ask again. It hangs up only if the server stays silent for the normal 25 second keepalive window.

What Changed

  • Before: on every macOS wake and every network online event, each remote-runtime client socket got one ping with an 8 s deadline. A miss called onDead and closed the socket, then reconnected, so the banner showed.
  • After:
    • A miss at 8 s marks the socket suspect and sends a second ping, in case the first was lost while the path rerouted.
    • The socket dies only if nothing arrives within 25 s of the probe. That is the same REMOTE_RUNTIME_SOCKET_LIVENESS_TIMEOUT_MS window the regular keepalive uses.
    • The probe also restarts the keepalive window. Without that, an older unanswered keepalive ping could still let the regular tick kill the socket sooner, as little as 11 s after the probe.
    • The probe is skipped when data arrived in the last 3 s, because that link is evidently up.
  • Mechanism: everything is in src/shared/remote-runtime-socket-liveness.ts, which is shared by the shared-control, subscription and passthrough sockets. No caller or wire behaviour changes.

Why

The wake probe from #29444 / #9092 exists so a socket that is really dead after sleep is noticed sooner than the 30–40 s the plain cadence needs. That goal still holds:

Case Before After
Truly dead socket after wake/online closed at 8 s (8–12 s with a stall) closed at 25 s after the probe, deterministic
Live link that answers 8–25 s after wake (relay rerouting) closed and reconnected, banner shown stays connected
Plain cadence without the probe 30–40 s unchanged

Trade-off: a really dead socket after sleep is now noticed about 17 s later than before, but still sooner than the plain keepalive. In exchange, a slow link coming back from a wake or a Wi-Fi change no longer gets a reconnect it didn't need.

Alternatives considered:

SSH, WSL and paired runtimes all use this monitor and get the same behaviour: less aggressive, never slower than the regular keepalive. The SSH host sleep probe (ssh-host-sleep-reconnect.ts) is separate code and is untouched. Mobile has its own decisive 4 s relay resume probe (mobile/src/transport/mobile-relay-rpc-session.ts). This PR doesn't change it; it's a possible follow-up for parity.

Linked Issue

Reported directly by a user whose desktop is paired over Tailscale, with no issue filed. Thanks to that reporter.

Visual Proof

N/A. This is transport timing with no UI change. The visible effect is fewer unnecessary "Reconnecting to remote runtime" banners.

Testing

  • Automated tests added/updated
    • src/shared/remote-runtime-socket-resume-probe.test.ts, run with production defaults:
      • a probe answered 12 s late stays alive;
      • a silent socket dies at exactly 25 s, and not before;
      • a network-change probe with an older keepalive unanswered still gets a full window. This is the case Codex found.
      • the probe is skipped after recent data;
      • after a stall, a fresh probe still ends a silent socket.
    • The new cases fail on origin/main.
  • Ran the full static-analysis job locally, and the test files that import the liveness module and its callers. Six failures in ssh-host-user-disconnect, session-tabs-delta.integration and use-remote-runtime-recovery-triggers also fail on origin/main with this file reverted, so they are unrelated.
  • Ran a paired-remote e2e subset (11 spec files, 15 tests) on a branch that includes this commit (feat(remote): record why each remote-runtime connection closed in app diagnostics #33094). 14 passed. The one failure, paired-remote-terminal-serve-restart-binding.spec.ts › "pending snapshot", fails the same way on origin/main.
  • Not tested:
    • on a real relayed link;
    • the Docker managed-orcad SSH lane, because local Docker is arm64 and that lane needs linux-x64.

…osing it

On macOS wake and network online events every remote-runtime socket was
probed with an 8 s deadline and closed on a miss. Relayed or lossy links
still rerouting after a wake lost connections that would have survived.
A miss now re-pings and leaves the socket until the normal 25 s keepalive
window ends; the probe is skipped when data arrived in the last 3 s.
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The socket liveness monitor now skips resume probes when inbound activity occurred within the previous 3,000 ms. A successful probe resets the liveness window. If the socket remains silent at the probe deadline, the monitor sends another ping; it calls onDead only after a later silent deadline. The tests now cover recent activity, delayed responses, network-change probes, and liveness timeout behavior.

Priority: Normal

Merge Risk: Moderate · up to 7dff2

A recovering remote connection can still close after a network change without receiving a fresh probe. Clear the pending deadline before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: missed wake probes no longer close slow remote connections.
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.
Description check Passed The description is thorough and follows the repository template. It includes a clear ELI5, a before/after account of the change, the mechanism (the liveness module and its shared callers), and the rat…
Full details: Description check

Explanation

The description is thorough and follows the repository template. It includes a clear ELI5, a before/after account of the change, the mechanism (the liveness module and its shared callers), and the rationale with alternatives considered. The Linked Issue section does not link an issue. The author states that the change came from a user report with no issue filed, and the template says outside contributors need a real linked issue. The Visual Proof section is marked N/A with a reason. Testing lists automated test cases and local runs, and leaves real-relay testing unchecked. The Review, Agent skill upstream boundary, Notes, and Checklist sections are not addressed. The AI Disclosure section is blank, and the template asks for it unless the author is a team member. The description covers most of the required content, so it passes. The missing linked issue and AI Disclosure should be addressed before merge.

Finishing Touches: 💡 1
📝 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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


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: a4c6ccc9-1fb6-4712-98f4-2d3f72fb4ece
Commits

Reviewing files that changed from the base of the PR and between 70c4c55 and 7dff2df.

Files selected for processing: 2
  • src/shared/remote-runtime-socket-liveness.ts
  • src/shared/remote-runtime-socket-resume-probe.test.ts

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

armResumeProbeTimer(probedAt, deadlineMs, deadlineMs, () => {
// Why: a missed resume probe is suspect, not dead; a second ping covers a first one lost mid-reroute.
tryPing()
armResumeProbeTimer(now(), deathDelayMs, deadlineMs, () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | Major | ⚡ Quick win

Clear the pending deadline after a late response.

If a socket answers after the first deadline, noteActivity() leaves this second timer armed. A later network-change probe then returns at Line 109 without sending a ping, even after the 3-second recent-activity period ends. For example, a response at 12 seconds followed by a network change at 21 seconds leaves the new path unprobed. An unanswered keepalive can then cause the socket to close without a ping after that network change. Clear the pending resume timer when activity arrives, and test a subsequent resume after a late response.

@nwparker
nwparker merged commit 6a2340b into main Oct 24, 2026
47 checks passed
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