Repository navigation
fix(relay): stop self-closing the control socket on unknown messages - #18400
Conversation
The desktop control client tore its own relay control WebSocket down with
code 4401 "unknown control message" for any well-formed control frame it
did not recognize. handleMessage() funneled everything that was not
ping / conn-open / drain / a tracked request reply into
failProtocol('unknown control message'), which closes the socket and
orphans the origin.
Three real frames hit that branch:
- A relay reply that arrives after the desktop's 10s request deadline
already deleted the pending entry. Relay control operations run DB
transactions that can exceed 10s under load, so resolveMessage() finds
no waiter and returns false.
- A control-error carrying no reqId (or an unknown one), including the
relay's own 'unknown_control_message' reply to a host command it could
not route.
- A newer relay's opcode that this build predates.
Fleet telemetry shows ~15 of these closes per day across app versions
1.4.175..1.4.197, so it is version-agnostic. The self-close was also far
more costly than the message that caused it: the relay session dropped to
'orphaned' and answered the phone with HOST_OFFLINE (4404) for the orphan
grace window, then the desktop had to re-register through the director's
503 reconnect throttle, stretching a single stray frame into minutes of
mobile downtime.
Per docs/reference/remote-wire-compatibility.md Rule 2, an unknown but
well-formed control frame must be dropped, not treated as fatal. Log and
ignore it; malformed JSON, binary frames, and messages before activation
still close as protocol violations.
Adds unit tests for the unknown-opcode drop, the timed-out-reply drop,
and the preserved malformed-frame teardown.
|
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. 📝 WalkthroughWalkthroughThe relay control client now logs and ignores unknown well-formed control messages. Unknown opcodes and replies for expired requests leave the connection active. Malformed non-JSON frames still close the control and report Merge Risk: ⚪ Minimal · up to Well-formed unknown control messages and late replies now preserve the relay connection, while malformed frames retain teardown behavior. No current merge-blocking risk is identified. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files. Full details: Description checkExplanation The description explains the problem, root cause, fix, tests, verification, and compatibility impact. However, it omits or leaves incomplete several template requirements, including ELI5, What Changed, Why, a Linked Issue with an issue number, Visual Proof or an explicit N/A statement, AI Disclosure, Review, Agent skill upstream boundary, Notes, and the Checklist. Resolution Add the required template sections and complete them. Provide a valid linked issue after “Fixes #”. Add “Visual Proof” with N/A and a reason if no visual or interaction change applies. Complete the Testing checkboxes, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist.
✨ Finishing Touches📝 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.
ℹ️ No critical issues — one doc-comment accuracy nit worth correcting, otherwise this is a clean, well-tested fix.
Reviewed changes
RelayControlClient.handleMessage— an unrecognized-but-well-formed control frame now logs and is dropped instead offailProtocolclosing the socket with4401 BAD_OUTER_CREDENTIAL. Malformed JSON, binary frames, and pre-activation frames still close as genuine protocol violations.- Three new tests: unknown-opcode drop, timed-out-reply drop, and the preserved malformed-JSON teardown guard.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…tion Rule 2 of remote-wire-compatibility governs the SENDER of a new terminal- stream opcode and treats the receiver's silent drop as a hazard, not a mandate. Reframe the comment around the actual justification: the decoder convention of dropping unknown frames, the control channel's lack of an opcode negotiation step, and the incident cost asymmetry.
There was a problem hiding this comment.
ℹ️ No new behavioral issues — the
Rule 2citation was cleaned up in the code comment and PR body, but one stale copy remains in a test comment (flagged inline).
Reviewed changes
- Reworded the drop rationale in
RelayControlClient.handleMessage— removed theremote-wire-compatibility.mdRule 2 citation (which misread Rule 2 as mandating "drop unknown, never fatal") and replaced it with the decoder-convention + no-negotiation-step + cost-asymmetry reasoning. - Updated the PR body to the same effect, noting the dropped citation.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| // A newer relay opcode the desktop schema does not know. Rule 2 of | ||
| // remote-wire-compatibility: an unknown-but-well-formed frame is dropped, | ||
| // never fatal to a live control. |
There was a problem hiding this comment.
This commit drops the Rule 2 misattribution from the code comment and PR body, but this test comment still cites it — and remote-wire-compatibility.md Rule 2 frames the receiver-side silent drop as a hazard to negotiate around, not as authority for "drop unknown, never fatal". Please update this copy so the test rationale matches the reworded code comment.
| // A newer relay opcode the desktop schema does not know. Rule 2 of | |
| // remote-wire-compatibility: an unknown-but-well-formed frame is dropped, | |
| // never fatal to a live control. | |
| // A newer relay opcode the desktop schema does not know. Dropped, never | |
| // fatal to a live control — self-closing is costlier than ignoring (see the | |
| // drop-branch rationale in relay-control-client.ts). |
…tablyai#18400) * fix(relay): stop self-closing the control socket on unknown messages The desktop control client tore its own relay control WebSocket down with code 4401 "unknown control message" for any well-formed control frame it did not recognize. handleMessage() funneled everything that was not ping / conn-open / drain / a tracked request reply into failProtocol('unknown control message'), which closes the socket and orphans the origin. Three real frames hit that branch: - A relay reply that arrives after the desktop's 10s request deadline already deleted the pending entry. Relay control operations run DB transactions that can exceed 10s under load, so resolveMessage() finds no waiter and returns false. - A control-error carrying no reqId (or an unknown one), including the relay's own 'unknown_control_message' reply to a host command it could not route. - A newer relay's opcode that this build predates. Fleet telemetry shows ~15 of these closes per day across app versions 1.4.175..1.4.197, so it is version-agnostic. The self-close was also far more costly than the message that caused it: the relay session dropped to 'orphaned' and answered the phone with HOST_OFFLINE (4404) for the orphan grace window, then the desktop had to re-register through the director's 503 reconnect throttle, stretching a single stray frame into minutes of mobile downtime. Per docs/reference/remote-wire-compatibility.md Rule 2, an unknown but well-formed control frame must be dropped, not treated as fatal. Log and ignore it; malformed JSON, binary frames, and messages before activation still close as protocol violations. Adds unit tests for the unknown-opcode drop, the timed-out-reply drop, and the preserved malformed-frame teardown. * docs(relay): correct the ignore rationale, drop the Rule 2 misattribution Rule 2 of remote-wire-compatibility governs the SENDER of a new terminal- stream opcode and treats the receiver's silent drop as a hazard, not a mandate. Reframe the comment around the actual justification: the decoder convention of dropping unknown frames, the control channel's lack of an opcode negotiation step, and the incident cost asymmetry.

Problem
Observed 2026-09-03 on a Samsung phone + macOS desktop (v1.4.197-adhoc): the desktop closed its own relay control WebSocket with code
4401 "unknown control message"after ~29 min active, then the phone could not reach the desktop for minutes — every dial ended inreplacement session authentication timed outorrelay_outer_4404(HOST_OFFLINE), even after the director re-assigned the host 5s later.This is not branch-specific: relay telemetry shows ~15 of these
4401 "unknown control message"closes per day across app versions1.4.175..1.4.197.Root cause
RelayControlClient.handleMessage()(src/main/runtime/relay/relay-control-client.ts) routed every control frame that was notping/conn-open/drain/ a tracked request reply intofailProtocol('unknown control message'), which closes the socket (4401) and tears down the origin.Three well-formed frames reach that branch during a healthy
activecontrol:confirmResume,installCredential, …) run DB transactions that can exceed 10s under load, soRelayControlRequests.resolveMessage()finds no waiter and returnsfalse.control-errorwith no/unknownreqId— including the relay's ownsendControlError(session, undefined, 'unknown_control_message')reply to a host command it could not route (orca-cloudhost-session-registry.ts).Why the phone stayed down for minutes
The 4401 self-close is far more costly than the frame that triggers it. On the relay the session drops to
orphanedand, for the 30s orphan-grace window,acceptClientrejects the phone withHOST_OFFLINE (4404). The desktop's recovery (onClose → handleDrain(recovery: 'resolve-director')) then has to re-register through the director's 503 reconnect throttle, so a single stray frame becomes minutes of mobile downtime. Not self-closing removes the orphan window and the re-registration entirely.Fix
A well-formed control frame the desktop does not recognize is now dropped and logged, not treated as fatal — matching how every other Orca decoder already handles an unknown frame. The relay control channel has no opcode-negotiation step, so the frame is either a newer relay message this build predates or a reply whose request already timed out. The justification is the cost asymmetry: self-closing orphaned the relay session and caused minutes of
HOST_OFFLINE, whereas ignoring the frame costs nothing. Malformed JSON, binary frames, and messages before activation still close as genuine protocol violations.(Note: an earlier revision cited
remote-wire-compatibility.mdRule 2 as the mandate here. Rule 2 actually governs the sender of a new terminal-stream opcode and frames the receiver-side silent drop as a hazard, so that citation was dropped — thanks @pullfrog.)Tests
ignores an unrecognized control message without closing the active controlignores a reply whose request already timed out instead of self-closingstill tears down a malformed (non-JSON) control frame(guard preserved)Verification
pnpm test relay-control-client.test.ts— 11/11pnpm test relay-session-broker.test.ts— 8/8 (recovery path)pnpm tc:nodecleanpnpm run check:code-quality:changed— 0 findingsCompatibility
Desktop-only decoder change; nothing on the wire changes. Old relays (which already send these frames) and SSH/remote hosts are unaffected — the desktop simply stops overreacting to them.