Repository navigation
fix(web): declare a socket dead even when its probe cannot be sent - #17838
Conversation
Greptile SummaryThe PR fixes WebSocket heartbeat teardown when a probe cannot be sent and introduces a tested shared transport-liveness decision policy.
Confidence Score: 4/5The PR appears safe to merge, with the non-blocking concern that its new shared policy is not actually adopted by production heartbeat code. The heartbeat fix handles unsendable probes correctly, but the policy and production implementation can drift because they remain disconnected. Files Needing Attention: src/shared/transport-liveness-policy.ts and src/renderer/src/web/web-runtime-connection-heartbeat.ts
|
| Filename | Overview |
|---|---|
| src/renderer/src/web/web-runtime-connection-heartbeat.ts | Correctly arms the existing deadline before attempting a probe, while retaining the handwritten policy instead of adopting the new shared function. |
| src/renderer/src/web/web-runtime-connection-heartbeat-unsendable-probe.test.ts | Covers the reported false-return regression and verifies eventual dead-socket handling. |
| src/shared/transport-liveness-policy.ts | Adds a clear pure decision policy, but it currently has no production importer. |
| src/shared/transport-liveness-policy.test.ts | Exercises probing, timeout, pause, backward-clock, idle, and inbound-traffic decisions, though only against the otherwise-unused policy. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
T[Heartbeat tick] --> P{Long local pause?}
P -->|Yes| R[Rebaseline timestamps]
P -->|No| D{Probe deadline expired?}
D -->|Yes| L[Close socket and reconnect]
D -->|No| I{Idle and no probe outstanding?}
I -->|Yes| A[Arm deadline unconditionally]
A --> S[Attempt probe send]
I -->|No| W[Wait]
Reviews (1): Last reviewed commit: "fix(web): declare a socket dead even whe..." | Re-trigger Greptile
| export function decideTransportLiveness( | ||
| config: TransportLivenessConfig, | ||
| input: TransportLivenessInput | ||
| ): TransportLivenessDecision { |
There was a problem hiding this comment.
The production WebSocket heartbeat still implements these decisions independently instead of calling decideTransportLiveness, so the new policy's tests can pass while production behavior drifts from the invariants it is intended to centralize.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthrough
Merge Risk: 🔵 Low · up to The change correctly reconnects sockets whose probes cannot be sent, but the heartbeat still uses a pause threshold that may close a healthy connection after a moderate event-loop stall; the PR is mergeable with explicit owner awareness and follow-up for that bounded reconnect risk. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description clearly explains the bug, fix, scope, regression test, issue references, and verification results. However, it omits several required template sections and checklist items, including the required Resolution Update the description to follow the repository template. Add the required linked issue using
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 3457e3f7-9750-4d7a-8e8f-d2107594fbe1
📒 Files selected for processing (4)
src/renderer/src/web/web-runtime-connection-heartbeat-unsendable-probe.test.tssrc/renderer/src/web/web-runtime-connection-heartbeat.tssrc/shared/transport-liveness-policy.test.tssrc/shared/transport-liveness-policy.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.
| // Why the deadline is armed before the send and regardless of its result: a probe that could | ||
| // not be written is the strongest evidence the link is gone, not a reason to stop watching. | ||
| // Gating this on a successful send disarms the only branch above that can declare the socket | ||
| // dead, so a saturated or half-open socket would never be judged at all -- the same wedge | ||
| // fixed on the SSH transport in #17817. See src/shared/transport-liveness-policy.ts (#17823). | ||
| this.heartbeatProbeSentAt = now | ||
| this.options.sendProbe() |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Use the shared pause decision in runTick.
This code still uses the local 20-second pause threshold at Line 52. With a 10-second interval and a 20-second probe grace, the shared policy rebases after a 10-second pause.
For example, a probe armed at 30 seconds, followed by a normal tick at 40 seconds and a 15-second pause, reaches Line 64 with a 25-second-old probe. The current code closes the socket before queued inbound traffic can update lastInboundFrameAt. Use decideTransportLiveness here so the WebSocket path applies the same pause rebasing policy.
| * migration, or the local event loop stalling. | ||
| */ | ||
| export function transportLivenessPauseGapMs(config: TransportLivenessConfig): number { | ||
| return config.deadWindowMs - config.probeIntervalMs |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect every policy configuration and policy call site.
rg -n -C 4 --type ts \
'deadWindowMs\s*:|probeIntervalMs\s*:|decideTransportLiveness\s*\(|transportLivenessPauseGapMs\s*\(' \
srcRepository: stablyai/orca
Length of output: 9770
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- applicable repository conventions ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -type f -name '*.md' -print
printf '%s\n' '--- policy source ---'
cat -n src/shared/transport-liveness-policy.ts
printf '%s\n' '--- all tracked references to the policy and configuration fields ---'
rg -n -C 3 \
'transportLivenessPauseGapMs|decideTransportLiveness|probeIntervalMs|probeAfterIdleMs|deadWindowMs' \
$(git ls-files)Repository: stablyai/orca
Length of output: 18367
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- repository-wide review conventions ---'
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions/repo-wide.md
printf '%s\n' '--- source-scope review learnings ---'
cat /tmp/coderabbit-repo-knowledge/stablyai/orca-89dc44e4/learnings/src.md 2>/dev/null || true
cat /tmp/coderabbit-repo-knowledge/stablyai-*/learnings/src.md 2>/dev/null || true
printf '%s\n' '--- change for the reviewed file ---'
git diff -- src/shared/transport-liveness-policy.ts src/shared/transport-liveness-policy.test.tsRepository: stablyai/orca
Length of output: 2275
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- repository-wide review conventions ---'
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions/repo-wide.md
printf '%s\n' '--- source-scope review learnings ---'
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings/src.md 2>/dev/null || true
printf '%s\n' '--- change for the reviewed file ---'
git diff -- src/shared/transport-liveness-policy.ts src/shared/transport-liveness-policy.test.tsRepository: stablyai/orca
Length of output: 2275
Reject configurations where deadWindowMs <= probeIntervalMs. TransportLivenessConfig accepts independent number values. For an invalid configuration, transportLivenessPauseGapMs is non-positive, so decideTransportLiveness returns 'rebase-after-pause' for every non-negative tick gap and never reaches the probe or dead-link decisions. Enforce this invariant and add a test.
There was a problem hiding this comment.
Important
The heartbeat fix itself is correct, but the shared liveness policy this PR introduces has no production adopter — the description's "one adopter" claim doesn't match the diff.
Reviewed changes
- Arm the probe deadline before sending —
web-runtime-connection-heartbeat.tsnow recordsheartbeatProbeSentAtunconditionally, so a probe that cannot be written still starts the dead-socket clock. - Introduce a shared transport-liveness policy — a pure decision function plus a derived pause gap and a
trueconstant, meant to be the single source of truth for liveness decisions. - Add tests — one regression test for the unsendable-probe case and six tests for the policy module.
⚠️ The shared liveness policy has no production adopter
decideTransportLiveness and transportLivenessPauseGapMs are imported only by their own test file. The heartbeat fix is inline and never calls the module, so the module, the exported TRANSPORT_LIVENESS_ARM_PROBE_UNCONDITIONALLY constant, and its 108-line test file all ship unreferenced. Combined with the SOCKET_LIKE fixture mismatch below, nothing yet validates that the shared logic faithfully expresses the code it is meant to unify.
Technical details
# Shared liveness policy is unreferenced
## Affected sites
- src/shared/transport-liveness-policy.ts — no production importers
- src/shared/transport-liveness-policy.test.ts — the only consumer of the module
- src/renderer/src/web/web-runtime-connection-heartbeat.ts:76 — comment references the module, but the class never imports it
## Required outcome
- Either make the heartbeat a real adopter (route its tick through `decideTransportLiveness` and reconcile the pause threshold, currently `HEARTBEAT_INTERVAL_MS * 2`), or defer the module and its test to the #17823 migration that actually adopts it.
## Open questions for the human
- Is the module meant to be adopted within this PR, or is it documentation-as-code to be wired up later?DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No critical issues — one minor nit inline.
Reviewed changes
- Removed the shared liveness-policy module and its test —
src/shared/transport-liveness-policy.tsand its 108-line test are deleted, resolving the prior review's "no production adopter" finding by deferring the policy to #17823. - Heartbeat fix and regression test unchanged — the unconditional probe-deadline arming in
web-runtime-connection-heartbeat.tsand its regression test carry over from the prior review.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…tablyai#17838) * fix(web): declare a socket dead even when its probe cannot be sent * chore: land the shared liveness policy with its first real adopter instead * docs: drop the reference to a file this PR no longer adds

First step of #17823, and it carries a real latent bug fix.
The bug
web-runtime-connection-heartbeat.tsarmed its dead-socket deadline only if the probe was successfully sent:The dead-socket branch above requires
heartbeatProbeSentAt !== null. So afalsereturn silently disarms the only thing that can declare the link dead, and a socket that cannot be written to is watched forever.This is the same wedge fixed on the SSH transport in #17817, where a saturated writer suppressed the dead-link check without bound and the mux never disposed, never fired
onRelayLost, and never reconnected.It is currently unreachable only by luck.
sendProbeissendEncrypted, which returnsfalsesolely for!socket || readyState !== OPEN || !sharedKey— and the first two are already excluded by the guard immediately above. BrowserWebSocket.send()buffers intobufferedAmountrather than refusing, so saturation returnstrue. Make that predicate backpressure-aware, which is the natural thing to do next, and the bug appears immediately.Fix: arm the deadline before the send and regardless of its result. A probe that could not be written is the strongest evidence available that the link is gone — never a reason to stop watching.
The shared policy
src/shared/transport-liveness-policy.tsis a pure decision function —probe/rebase-after-pause/declare-lost/wait— plus the two invariants each hand-written copy re-derived and got wrong at least once:deadWindowMs - probeIntervalMspushes silence past the dead window on its own; a threshold set atdeadWindowMs— the intuitive choice — leaves a dead band where every healthy peer is declared lost after a host suspend, a VM migration, or the local event loop stalling. I reintroduced exactly this while writing the relay reaper in fix(ssh): declare a wedged relay link lost, and stop reading silence as a verdict #17817; it was caught in review only because someone compared the two files.Six tests cover both shapes in the codebase (probe-every-tick like the SSH mux, probe-after-idle like the WebSocket), the dead band, a backwards clock, and "any inbound traffic counts, not just a reply".
Scope, deliberately
The module is introduced with one adopter. I also tried aligning
remote-runtime-socket-liveness.ts's pause threshold onto the derived form and reverted it: that path has no bug — it armsprobeSentAtbefore callingtryPing(), andtryPingswallows throws, so it is structurally immune — and with custom configspingIntervalMs * 1.5is not equal tolivenessTimeoutMs - pingIntervalMs, which broke two tests that encode the existing value on purpose. Taking regression risk on a path with no defect is not worth it. Aligning it, and the SSH mux and relay reaper once #17817 lands, is mechanical follow-up under #17823.Verification
One file (
remote-runtime-shared-control-connection.test.ts) failed in a combined run and passes in isolation; this diff does not touch it.Refs #17823, #17817
ELI5
The web client checked whether its connection was alive by sending a ping — but only started the 'are you dead' timer if the ping was successfully sent. A connection too broken to send was therefore never declared dead.
User-facing regression risk
remote-runtime-socket-liveness.tswas attempted and reverted — it has no bug, and with custom configs the thresholds are not equivalent.Scoped down after review: the shared policy module has been removed
A reviewer pointed out that
src/shared/transport-liveness-policy.tshad zero production importers —decideTransportLivenesswas called only by its own test. That is a fair criticism: the PR delivered less than its description implied, and shipping a module nothing imports is not consolidation, it is documentation with a test suite attached.I considered adopting it here, in the heartbeat this PR already fixes, and decided against it. Mapping the heartbeat onto the policy would move its pause-rebase threshold from 20s to 10s — a real behaviour change on a path with no bug motivating it. I made exactly that mistake earlier in this batch (aligning
remote-runtime-socket-liveness.tsonto the derived threshold, which broke two tests because with custom configsping × 1.5 ≠ timeout − ping) and reverted it for the same reason. Taking regression risk on a healthy path to justify a module is the wrong trade twice over.So this PR is now exactly what it is: the 6-line fix plus its regression test, scoped to the web path.
The policy module will land under #17823 with its first real adopters — the SSH multiplexer and the relay reaper — once #17817 merges and they can actually import it. That is where it has teeth, because those are the two sites that have already had this bug.
What the module was documenting remains true and is worth restating for whoever picks up #17823:
deadWindowMs - probeIntervalMspushes silence past the window on its own; a threshold set atdeadWindowMsleaves a dead band. I reintroduced exactly this while writing the relay reaper.