Skip to content

fix(relay): carry the signed-out reason when the broker's own renewal notices the session loss - #21562

Merged
Jinwoo-H merged 1 commit into
mainfrom
relay-signed-out-reason
Sep 19, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
relay-signed-out-reason

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​71 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​65
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​32 $\color{#cf222e}{\Huge{\mathbf{−}}}$​21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​11

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:

  • Report a sign-out whenever the refresh is empty. Rejected: it mislabels the still-signed-in cases above.
  • Have the broker hand the close back to the coordinator via a callback. Rejected: it re-reads the session just to re-derive an answer the caller already had, leaves the socket open across that gap, and the socket leaks if the coordinator is already shutting down.
  • Chosen: the refusal returned by the refresh carries the reason. One small function decides "is this a sign-out?" and both close paths read it, so the rule cannot drift apart in two places, and no new state is introduced.

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.

npx vitest run src/main/runtime/relay     # 21 files, 187 tests, all passing
pnpm tc                                   # clean
pnpm run check:code-quality:changed       # 0 new findings across 6 changed files
pnpm format

New tests in src/main/runtime/relay/relay-session-broker.test.ts, under RelaySessionBroker 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 carried undefined) 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.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Backwards compatibility: no wire change. signed-out is 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.
  • Security: no change to what is trusted. The reason is still derived on the desktop from its own session read, and the phone side already validates it against an exact allow-list.
  • Cross-platform / SSH / mobile: platform-neutral desktop logic; nothing here touches paths, shells, or process spawning.
  • Performance: no added reads or timers. The refusal is a small object on a path that was already returning a value.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

… 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.
@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 0a0e49c4-cc2a-4b49-83df-076f70ce932a

📥 Commits

Reviewing files that changed from the base of the PR and between ac4dc65 and f2e6262.

📒 Files selected for processing (5)
  • src/main/runtime/relay/relay-auth-coordinator.test.ts
  • src/main/runtime/relay/relay-auth-coordinator.ts
  • src/main/runtime/relay/relay-session-broker-contract.ts
  • src/main/runtime/relay/relay-session-broker.test.ts
  • src/main/runtime/relay/relay-session-broker.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The relay refresh contract now returns an object containing an access token and an optional host close reason. RelayAuthCoordinator sets SIGNED_OUT when the authentication context is missing. RelaySessionBroker passes the returned reason to closeNow. Tests cover signed-out, unentitled, identity-mismatch, and invalid refresh results.

Priority: ➖ Normal

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the user impact, mechanism, rationale, alternatives, testing, compatibility, security, and performance. However, the required Linked Issue field is incomplete and contains onl… Replace Fixes # with the actual linked issue number or URL. Confirm the final description retains the required issue reference before merging.
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 5 files. 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 and concisely describes the main change: preserving the signed-out reason when relay renewal detects session loss.
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.
Full details: Description check

Explanation

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 Fixes #.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Renewal refusal carries the cause — refreshAccessToken now returns RelayAccessTokenRefresh, a discriminated union that pairs a null token with an optional hostCloseReason (relay-session-broker-contract.ts:18).
  • One owner for the "why" — the null-only sign-out rule is extracted to authLossCloseReason and shared by reconcileEpoch and the renewal path, so the two close paths cannot drift (relay-auth-coordinator.ts:51).
  • Broker forwards the reason — refreshAuthorization closes with refresh.hostCloseReason rather 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 reason suite wires a real RelayAuthCoordinator + RelaySessionBroker so the renewal tick is genuinely the first reader of the lost session, and asserts both null → signed-out and 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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

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