You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(relay): probe on an overdue keepalive ack; 60s retry cap for a newly named failing cell - #41992
When a relay connection silently stops working, the desktop now notices about 17 seconds sooner. When the director names a cell the desktop hasn't just failed to reach, and that cell also fails, the desktop retries within a minute instead of backing off to five. If the director itself is failing, or keeps naming the same dead cell, the desktop backs off fully as before so it doesn't pile onto the director.
What Changed
Implements fixes#4 and #6 from the client-resilience audit (relay-edge research, client-resilience.md §2 and §4).
The edge answers the client keepalive immediately. If no inbound frame has arrived 10 s after a keepalive was sent, the desktop starts the existing 3 × 8 s WebSocket ping probe. Any inbound frame or pong cancels the probe. A single lost frame still never tears the control down (STA-3320).
The keepalive interval is unchanged. The watch only runs on relays that offered keepalive.
New log line: [relay] control keepalive overdue cell=… sinceInboundMs=… probe=armed.
Simulated silent-stall detection (p50/p90/max) goes from 68/81/90 s to about 51/64/69 s. Worst case is keepalive interval + 10 s + 24 s.
#4: lower cap when only a newly named cell failed (relay-retry-schedule.ts, relay-origin-pool.ts)
RelayRetrySchedule.schedule(retryAfterMs, retry, maxMs?) takes an optional per-attempt ceiling.
In resolveDrainTarget, the retry is capped at 60 s only when the director's assign succeeded and the rebind or connect failed on a cell that did not just fail.
The pool keeps the set of cells that failed since the last success. If the director names any of them again, including alternating A, B, A, B, the retry uses the full 1 s·2ⁿ → 300 s schedule. Every drain retry re-asks the director, so a short cap on dead cells would raise director load for every host on them.
The set clears after a success.
Director errors keep the full schedule, Retry-After is still honoured, and the per-host 5 s assign gate is unchanged.
Why
The audit lists 45–90 s stall detection and the 300 s cap as too slow on lossy networks when the director is answering and only the cell is unreachable. On its own, the 60 s cap helps only a little. It matters more once the avoid-cell hint (#2) lands. That hint needs a director change first, so it is not in this PR.
User-visible effect
A desktop whose relay path blackholes recovers about 17 s sooner on average.
When the director moves the host to a cell that then also fails, the next retry comes within 60 s instead of up to 5 minutes. A cell that keeps failing gets exactly today's schedule.
Healthy connections are unchanged: acks arrive well inside 10 s, so no probe is sent and no retry runs.
Testing
Fake-timer unit tests:
relay-control-liveness.test.ts:
answered keepalives never probe over 10 minutes;
a blackhole probes at interval + 10 s and tears down 24 s later, before the 75 s silence bound;
one lost ack followed by a pong keeps the control;
relays without the keepalive offer are untouched.
relay-origin-pool-retry.test.ts drives RelayOriginPool with a mocked origin and director over a 30-minute outage:
when the director keeps naming the same dead cell, it is asked no more often than under the director-503 baseline, and the backoff reaches the 300 s cap;
when it alternates between two failing cells, asks are at most the dead-cell baseline + 2 (each cell gets one short retry), and the backoff reaches 300 s;
when it names a different failing cell each time, retries stay ≤ 60 s apart;
pnpm lint: all 46 steps pass, including the changed-lines gate.
pnpm typecheck:node: passes.
Not tested manually against a live relay.
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. The "healthy/no-offer unchanged" cases are regression guards.
Visual Proof
N/A: desktop main-process relay liveness and backoff only, no UI change.
Risk
Level: Low
Blast radius: ships with the next desktop release. No protocol or server change.
Riskiest part: a false overdue signal. That only sends WS pings, and teardown still needs three unanswered pings across 24 s.
Herding: the 60 s cap applies only to the first failure on each newly named cell in an episode. For cells that keep failing, alternating or not, director ask rates are unchanged.
…cell failed
Start the existing 3 x 8 s ping probe once a keepalive reply is 10 s overdue,
cutting silent-stall detection without shortening the keepalive interval or
tearing down on a single lost frame.
When the director answered and only the cell connect failed, cap the drain
retry at 60 s instead of 300 s. Director failures keep the full schedule.
RelayControlLiveness checks for an inbound frame 10 seconds after it sends a keepalive. If no frame arrives and the control remains live, it arms the existing probe mechanism. RelayRetrySchedule accepts an optional maximum for exponential backoff. RelayOriginPool applies a 60,000 ms maximum to failures connecting to newly named cells. Director request failures and repeated failures for the same cell use the default retry schedule.
Merge Risk: Low · up to 630bd
In a narrow sequence, a relay cell that fails again after earlier recovering, with director errors in between, can wait up to 5 minutes before the next retry instead of 60 seconds. This is the behavior before this PR and does not break connectivity. It is worth fixing before or soon after merge.
Pre-merge checks: 3 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Description check
The description follows the template and covers most required sections: ELI5, What Changed, Why, User-visible effect, Testing, and Risk. It fails the template because the Linked Issue section is not v…
1. Replace the Linked Issue line "Fixes #" with a real issue number that this PR resolves. Confirm whether #4 refers to the audit item or the unrelated Ctrl+Click issue. Remove the audit reference from What Changed if it is not a tracked is…
Passed checks: 3 passed
Check name
Status
Explanation
Title check
The title names the two main changes: an overdue keepalive ack probe for relay liveness, and a 60s retry cap for a newly named failing cell. Both match the changed files (relay-control-liveness.ts and…
Linked Issues check
The only linked issue is #4, "Add Ctrl+Click to open links in terminal". Its state is closed, and it is marked as historical context only. No active directly linked target remains, so no linked-issue …
Out of Scope Changes check
No active linked issue defines coding requirements. The changes are checked against the PR's stated scope: relay liveness detection and retry timing. relay-control-liveness.ts adds a 10 s keepalive-ac…
Full details: Title check
Explanation
The title names the two main changes: an overdue keepalive ack probe for relay liveness, and a 60s retry cap for a newly named failing cell. Both match the changed files (relay-control-liveness.ts and relay-origin-pool.ts / relay-retry-schedule.ts). It is a single line, though it packs two changes into one title.
Full details: Linked Issues check
Explanation
The only linked issue is #4, "Add Ctrl+Click to open links in terminal". Its state is closed, and it is marked as historical context only. No active directly linked target remains, so no linked-issue coding requirements apply. The PR description's "#4" refers to an item in a client-resilience audit, not GitHub issue #4. The PR changes relay liveness and retry code under src/main/runtime/mobile-cloud-relay. It does not change terminal link handling. That absence is not a requirement failure.
Full details: Out of Scope Changes check
Explanation
No active linked issue defines coding requirements. The changes are checked against the PR's stated scope: relay liveness detection and retry timing. relay-control-liveness.ts adds a 10 s keepalive-ack overdue timer that arms the existing WebSocket ping probe. stop() clears the timer. relay-retry-schedule.ts adds an optional maxMs argument to schedule(). relay-origin-pool.ts applies a 60 s cap only after a director assign succeeds and the cell step fails on a newly named cell. Director failures and repeat failures on the same cell keep the full backoff. The test files cover these paths. Each change maps to the stated PR behavior. No unrelated change is demonstrated. The assessment used the summary and the previous assessment; no additional source inspection was needed to reach this result.
Full details: Description check
Explanation
The description follows the template and covers most required sections: ELI5, What Changed, Why, User-visible effect, Testing, and Risk. It fails the template because the Linked Issue section is not valid. It reads "Fixes #" with no issue number. It cites "Implements fixes #4 and #6 from the client-resilience audit", which points to an audit document, not a linked issue. The objectives state that issue #4 is an unrelated closed issue about Ctrl+Click terminal links, so the description cites the wrong issue number. The Visual Proof section is N/A with a reason, which is valid. The Testing checkboxes are inconsistent: the manual-testing box is unchecked, and the description says the change was not tested manually against a live relay. The AI Disclosure section is left as the template placeholder, the Review and Agent skill upstream boundary checkboxes are unaddressed, and the Risk level is stated as Low.
Resolution
Replace the Linked Issue line "Fixes #" with a real issue number that this PR resolves. Confirm whether #4 refers to the audit item or the unrelated Ctrl+Click issue. Remove the audit reference from What Changed if it is not a tracked issue. 2. Complete the AI Disclosure section. State whether an AI model was used, and if so, which model. If the author is a StablyAI team member, state that the section does not apply. 3. Complete the Review section. Mark the Agent skill upstream boundary checkbox, or state that it is not applicable. 4. Clarify the Testing checklist. The manual-testing box is unchecked, so either check it with the steps used or explain that only automated tests and no live-relay test were run. 5. Fill the Checklist items for cross-platform, SSH/remote, and pnpm test, or state why they are N/A. Note the test count discrepancy: the description reports 845 passing tests, and the objectives report 844.
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.
Every drain retry re-asks the director, so capping retries at 60 s for a cell
that keeps failing would raise director load for every host on that cell. The
short cap now applies only when the director names a cell that has not just
failed; the same cell failing again falls back to the full 300 s schedule.
nwparker
changed the title
fix(relay): probe on an overdue keepalive ack; cap retry at 60s when only the cell failed
fix(relay): probe on an overdue keepalive ack; 60s retry cap for a newly named failing cell
Nov 13, 2026
A director alternating between failing cells (A, B, A, B) kept the 60 s cap
forever because only the previous cell was compared. Track every cell that
failed since the last success; a repeat of any of them uses the full backoff.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Major · Functional Correctness · Quick win
Clear failed-cell history when recovery succeeds.
If director failures start the next failure episode, drainRetry.attempts becomes nonzero before isNewCellFailure runs. This condition then preserves the previous episode's failedCells.
For example, let cell A fail and then recover successfully. After enough director failures to reach the 300-second backoff, let A fail again. The retained entry classifies A as a repeated failure, so its first failure in the new episode misses the 60-second cap.
Clear failedCells alongside drainRetry.reset() on successful recovery at Line 220. Add a regression case with director failures between successful recovery and the next cell failure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
When a relay connection silently stops working, the desktop now notices about 17 seconds sooner. When the director names a cell the desktop hasn't just failed to reach, and that cell also fails, the desktop retries within a minute instead of backing off to five. If the director itself is failing, or keeps naming the same dead cell, the desktop backs off fully as before so it doesn't pile onto the director.
What Changed
Implements fixes #4 and #6 from the client-resilience audit (relay-edge research,
client-resilience.md§2 and §4).#6: overdue-ack probe (
relay-control-liveness.ts)[relay] control keepalive overdue cell=… sinceInboundMs=… probe=armed.#4: lower cap when only a newly named cell failed (
relay-retry-schedule.ts,relay-origin-pool.ts)RelayRetrySchedule.schedule(retryAfterMs, retry, maxMs?)takes an optional per-attempt ceiling.resolveDrainTarget, the retry is capped at 60 s only when the director's assign succeeded and the rebind or connect failed on a cell that did not just fail.Why
The audit lists 45–90 s stall detection and the 300 s cap as too slow on lossy networks when the director is answering and only the cell is unreachable. On its own, the 60 s cap helps only a little. It matters more once the avoid-cell hint (#2) lands. That hint needs a director change first, so it is not in this PR.
User-visible effect
Testing
Fake-timer unit tests:
relay-control-liveness.test.ts:relay-origin-pool-retry.test.tsdrivesRelayOriginPoolwith a mocked origin and director over a 30-minute outage:Results:
vitest run src/main/runtime/mobile-cloud-relay src/main/runtime/rpc src/shared/remote-runtime/relay: 240 files passed, 2 skipped; 845 tests passed, 4 skipped.pnpm lint: all 46 steps pass, including the changed-lines gate.pnpm typecheck:node: passes.Not tested manually against a live relay.
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. The "healthy/no-offer unchanged" cases are regression guards.
Visual Proof
N/A: desktop main-process relay liveness and backoff only, no UI change.
Risk
Level: Low