Repository navigation
fix(relay): carry the signed-out reason when the broker's own renewal notices the session loss - #21562
Conversation
… notices the session loss The relay control socket closes with the reason `signed-out` so the cell can tell paired phones to sign in rather than reporting a bare "host offline". Only the auth coordinator computed that reason. The broker's renewal tick called `closeNow()` with no reason when its token refresh came back empty, and `closeNow` is idempotent, so whenever that tick observed the lost session first — the common case for a session revoked or expired while Orca runs — the coordinator's later `closeNow(SIGNED_OUT)` was a no-op and the cause never left the desktop. `refreshAccessToken` now returns a refusal that carries the reason the coordinator already derives, and both close paths read it from one place. A refusal for any other cause still names nothing: a present-but-unentitled desktop is signed in, and a superseded refresh leaves the close to whoever superseded it.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe relay refresh contract now returns an object containing an access token and an optional host close reason. Priority: ➖ Normal 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the user impact, mechanism, rationale, alternatives, testing, compatibility, security, and performance. However, the required Linked Issue field is incomplete and contains only the placeholder
✨ 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.
✅ No new issues found.
Reviewed changes
- Renewal refusal carries the cause —
refreshAccessTokennow returnsRelayAccessTokenRefresh, a discriminated union that pairs a null token with an optionalhostCloseReason(relay-session-broker-contract.ts:18). - One owner for the "why" — the null-only sign-out rule is extracted to
authLossCloseReasonand shared byreconcileEpochand the renewal path, so the two close paths cannot drift (relay-auth-coordinator.ts:51). - Broker forwards the reason —
refreshAuthorizationcloses withrefresh.hostCloseReasonrather than an unnamed close, which is the fix for the race the coordinator's own reconcile could not win (relay-session-broker.ts:275). - Race-reproducing coverage — the new
RelaySessionBroker renewal close reasonsuite wires a realRelayAuthCoordinator+RelaySessionBrokerso the renewal tick is genuinely the first reader of the lost session, and asserts bothnull→signed-outand unentitled-but-alive → silent.
Verified locally: npx vitest run src/main/runtime/relay (21 files, 187 tests) and pnpm tc:node both pass. The split preserves the prior semantics for every non-null refusal (superseded, unentitled, identity switch), and no wire shape changes.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
When you sign out of Orca on your computer (or your sign-in quietly expires), your phone should say "sign-in required". Sometimes it said "host is offline" instead, which made it look like your computer had gone to sleep. This makes the phone hear the real reason every time.
What Changed
Before: a desktop whose Orca Cloud session disappeared while the app was running usually dropped its phones with no explanation. The phone showed "Host is offline", so people went looking for a network or sleep problem instead of signing back in. Whether the phone got the right message was a coin flip decided by which part of the desktop noticed the lost session first.
After: the phone is told "sign-in required" in that case, consistently.
Mechanism: the desktop's relay control socket can close with a named reason,
signed-out, which the relay passes on to paired phones. Two different parts of the desktop can notice a lost session, but only one of them knew how to name it. The relay session broker refreshes its own credentials on a timer; when that refresh came back empty it closed the socket with no reason at all. Closing is one-way, so the part that did know the reason then had nothing left to close, and its message was silently dropped. The refresh call now hands back the reason along with its refusal, so whichever part closes the socket first still names the cause.Why
A session that is revoked or expires while Orca is running is the ordinary way people end up signed out, and it is exactly the path where the timer usually wins the race. So the feature that tells phones "sign-in required" was mostly not working for the case it was built for.
The tricky part is that an empty refresh is not always a sign-out. It also happens when the desktop is still signed in but no longer entitled to the relay, when the identity changed, and when the refresh was already superseded by a newer one. Reporting "sign-in required" for those would be wrong advice, because the user has nothing to sign in to fix.
Alternatives considered:
Linked Issue
Fixes #
Visual Proof
N/A— this is desktop-side plumbing with no UI; the phone-facing copy it unblocks ships separately.Testing
Ran on macOS. The relay code here is platform-neutral (no paths, shells, or child processes), and the suites run on CI's Linux runners too.
New tests in
src/main/runtime/relay/relay-session-broker.test.ts, underRelaySessionBroker renewal close reason. They drive a real broker from a real auth coordinator with an already-spent lease, so the broker's renewal tick is genuinely the first thing to read the lost session:names the sign-out when its renewal reads the lost session first— reproduces the race. Confirmed it fails on the old code (the close carriedundefined) and passes with the fix.stays silent when its renewal finds the entitlement gone but the session alive— guards the case that must not claim a sign-out.The existing close-reason suite (
relay-auth-host-close-reason.test.ts) still covers the coordinator's own paths: explicit sign-out, quit, stop, lost entitlement, linger, and identity switch.AI Disclosure
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
signed-outis an existing close reason on an existing slot; this only makes it reach the cell on a path where it was being dropped. Relays and phones that do not read it are unaffected, and no other close gains a reason.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)