Skip to content

fix(runtime): stop a stalled tick from forgiving banked missed probes (STA-3320) - #12841

Merged
Jinwoo-H merged 1 commit into
mainfrom
fix/sta-3320-bounded-pause-pardon
Aug 6, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
fix/sta-3320-bounded-pause-pardon

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Fix-forward on #12790, from its post-merge adversarial review. That review's verdict was SOUND — do not revert, and this addresses the one real defect it demonstrated.

The defect

#12790's resume-from-pause pardon cleared banked misses outright. So a host whose sweep stalls once every three ticks reset the budget forever and a dead socket was never reaped.

Demonstrated by the reviewer: a permanently dead peer, with a > intervalMs * 1.5 gap every third tick, ran 300 sweeps (50 simulated minutes) with zero terminate() calls. Boundary confirmed — a stall every 4th tick still reaps; every 3rd tick never does.

Pre-#12790 this required a stall on every tick to prevent a reap. The consecutive counter widened the pathological window 3×, and the failure mode is permanent non-reaping — exactly the MAX_WS_CONNECTIONS = 128 leak the reaper exists to prevent.

The fix

A stalled tick now charges no miss but forgives nothing.

That is all the original rationale ever needed: a delayed tick cannot infer that clients missed a probe they had no chance to answer, so it must not charge one. Clearing the count as well was over-generous — those earlier misses were banked while the server was running normally, so they are real evidence.

A live client still clears its own count by answering the probe that is still sent on the stalled tick, so a genuine suspend costs a healthy peer nothing.

Verification

The tolerance test's pause case is rewritten to assert the new contract, not weakened — it now pins both halves: the suspend itself costs the socket nothing, and the pre-suspend evidence survives so the next unanswered probe completes the budget. Renamed accordingly (charges no miss for a paused tick but keeps the ones already banked).

A new test pins the leak directly: a host stalling every third tick must still reap a dead socket.

Mutation-proven: forcing stalledTick to false fails the pause test; restored by re-applying the edit, never git checkout.

Suites: src/main/runtime/rpc/ — 124 files, 1220 passing. Includes the pre-existing real-socket half-open reap test (ws-transport.test.ts, kernel-level _socket.pause()), untouched and still green.

Also corrects a stale comment in ws-transport.test.ts that still said "two consecutive ping ticks" — it has been four since #12790.

Not addressed here

The review also noted that elapsedMs < 0 reads a wall clock (Date.now), so a backward NTP or VM-migration step grants a one-off pardon. Harmless in isolation now that a pardon no longer forgives banked misses, but it means the reaper's correctness still depends on a clock a user can change. Moving to a monotonic source is a separate change with its own suspend-semantics questions (CLOCK_MONOTONIC excludes suspend time, CLOCK_BOOTTIME includes it), so it should not ride along with this.

The review's other observation — that a flapping device can now hold 2-3 connection slots instead of 1-2, because the client's own 25s watchdog redials while the server holds the stale socket up to 60s — is by design (hasOtherConnections) and absorbed by the 128-slot budget, but it is worth its own look if slot pressure is ever reported.

@coderabbitai

coderabbitai Bot commented Aug 6, 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: Pro Plus

Run ID: b1b35414-8766-45cc-ab04-e1524ccf1c16

📥 Commits

Reviewing files that changed from the base of the PR and between b70e337 and afd93d9.

📒 Files selected for processing (2)
  • src/main/runtime/rpc/remote-runtime-server-heartbeat-missed-probe-tolerance.test.ts
  • src/main/runtime/rpc/remote-runtime-server-heartbeat.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/runtime/rpc/remote-runtime-server-heartbeat.ts

📝 Walkthrough

Walkthrough

RemoteRuntimeServerHeartbeat now tolerates individual missed probes and reaps sockets after three consecutive unanswered probes. Constructor parameters configure warning-client and missed-probe limits. Delayed timer sweeps no longer change missed-probe counts, while regular sweeps continue probing and reset counts for active sockets. Tests cover preserved misses during pauses and repeated host stalls.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the defect, fix, tests, and follow-up risks, but it omits required template sections for screenshots, AI review, security audit, and checklist results. Add all required template headings, state whether there is visual change, complete the testing checklist, and include AI review, cross-platform, and security audit summaries.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the runtime heartbeat bug and the fix for stalled ticks forgiving missed probes.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 88d7da61-57bb-4b7d-8cf2-e972372a7fb5

📥 Commits

Reviewing files that changed from the base of the PR and between 211b2d1 and 83f2f75cc0f45b09c6af86deaaf6f5df1eddd4cb.

📒 Files selected for processing (11)
  • src/main/runtime/rpc/remote-runtime-server-heartbeat-missed-probe-tolerance.test.ts
  • src/main/runtime/rpc/remote-runtime-server-heartbeat.test.ts
  • src/main/runtime/rpc/remote-runtime-server-heartbeat.ts
  • src/main/runtime/rpc/ws-transport-accept-order.test.ts
  • src/main/runtime/rpc/ws-transport-transient-packet-loss.test.ts
  • src/main/runtime/rpc/ws-transport.ts
  • src/renderer/src/web/web-runtime-client.test.ts
  • src/renderer/src/web/web-runtime-client.ts
  • src/shared/reconnect-jitter.test.ts
  • src/shared/reconnect-jitter.ts
  • src/shared/remote-runtime-shared-control-state.ts

@@ -21,7 +21,7 @@ type WebSocketMessageHandler = {
): void
}['bivarianceHack']

// Why: mobile clients background-suspend sockets with no TCP FIN, leaving half-opens that otherwise only the OS keepalive (~2h) reaps; a 15s ping/pong sweep bounds that to ~30s (clients auto-pong per RFC 6455).
// Why: mobile clients background-suspend sockets with no TCP FIN, leaving half-opens that otherwise only the OS keepalive (~2h) reaps; a 15s ping/pong sweep bounds that to ~60s (clients auto-pong per RFC 6455), since a reap needs consecutive unanswered probes rather than one (STA-3320).

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Correct the heartbeat timing bound.

The socket is terminated on the third missed check at approximately 45 seconds after the last successful sweep. The ~60s value adds one interval that the implementation does not wait.

Proposed fix
-// Why: mobile clients background-suspend sockets with no TCP FIN, leaving half-opens that otherwise only the OS keepalive (~2h) reaps; a 15s ping/pong sweep bounds that to ~60s (clients auto-pong per RFC 6455), since a reap needs consecutive unanswered probes rather than one (STA-3320).
+// Why: mobile clients background-suspend sockets with no TCP FIN, leaving half-opens that otherwise only the OS keepalive (~2h) reaps; three consecutive missed 15s ping/pong checks bound reaping to ~45s (STA-3320).
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Why: mobile clients background-suspend sockets with no TCP FIN, leaving half-opens that otherwise only the OS keepalive (~2h) reaps; a 15s ping/pong sweep bounds that to ~60s (clients auto-pong per RFC 6455), since a reap needs consecutive unanswered probes rather than one (STA-3320).
// Why: mobile clients background-suspend sockets with no TCP FIN, leaving half-opens that otherwise only the OS keepalive (~2h) reaps; three consecutive missed 15s ping/pong checks bound reaping to ~45s (STA-3320).

Post-merge review of #12790 demonstrated a real leak: the resume-from-pause
pardon cleared banked misses outright, so a host whose sweep stalls once every
three ticks reset the budget forever and a dead socket was never reaped. The
reviewer ran 300 sweeps against a permanently dead peer with a >1.5x gap every
third tick and observed zero terminate() calls.

Pre-#12790 that required a stall on *every* tick; the counter widened the
pathological window 3x, and the failure mode is permanent non-reaping — the
MAX_WS_CONNECTIONS leak the reaper exists to prevent.

A stalled tick now charges no miss, which is all the original rationale needed
(the client had no chance to answer that probe), but no longer forgives the
misses already banked. A live client still clears its own count by answering
the probe that is still sent on the stalled tick.

The tolerance test's pause case is rewritten to assert the new contract rather
than the old forgive-everything one, and a new test pins the leak directly: a
host stalling every third tick must still reap a dead socket.
@Jinwoo-H
Jinwoo-H force-pushed the fix/sta-3320-bounded-pause-pardon branch from 83f2f75 to afd93d9 Compare August 6, 2026 02:43
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@Jinwoo-H
Jinwoo-H merged commit ff01fad into main Aug 6, 2026
43 checks passed
@Jinwoo-H
Jinwoo-H deleted the fix/sta-3320-bounded-pause-pardon branch August 6, 2026 03:28
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…stablyai#12841)

Post-merge review of stablyai#12790 demonstrated a real leak: the resume-from-pause
pardon cleared banked misses outright, so a host whose sweep stalls once every
three ticks reset the budget forever and a dead socket was never reaped. The
reviewer ran 300 sweeps against a permanently dead peer with a >1.5x gap every
third tick and observed zero terminate() calls.

Pre-stablyai#12790 that required a stall on *every* tick; the counter widened the
pathological window 3x, and the failure mode is permanent non-reaping — the
MAX_WS_CONNECTIONS leak the reaper exists to prevent.

A stalled tick now charges no miss, which is all the original rationale needed
(the client had no chance to answer that probe), but no longer forgives the
misses already banked. A live client still clears its own count by answering
the probe that is still sent on the stalled tick.

The tolerance test's pause case is rewritten to assert the new contract rather
than the old forgive-everything one, and a new test pins the leak directly: a
host stalling every third tick must still reap a dead socket.

Co-authored-by: Jinwoo-H <[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