Skip to content

fix(relay): stop an unreadable session file reporting as a sign-out - #20055

Closed
nwparker wants to merge 4 commits into
fix/18211-lan-mode-applies-to-paired-devicesfrom
nwparker/relay-unreadable-session-taxonomy
Closed

nwparker wants to merge 4 commits into
fix/18211-lan-mode-applies-to-paired-devicesfrom
nwparker/relay-unreadable-session-taxonomy

Conversation

@nwparker

@nwparker nwparker commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​66 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​66
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​21 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​18

Stacked on #19870 (fix/18211-lan-mode-applies-to-paired-devices). Review the top commit only.

What breaks

The coordinator's own comment states the contract: readContext "throws on transient failures and returns null solely when the cloud session is gone (absent, or cleared by a 401)". The implementation did not honour it.

readFreshOrcaCloudSession collapsed readOrcaCloudSession's unreadable status into reconnect-required. So readRelayAuthContext returned null, and the coordinator published RELAY_HOST_CLOSE_REASON.SIGNED_OUT, closed the broker with that wire reason, and armed no retry — because a terminal cause arms none.

unreadable fires on EPERM / EACCES / EBUSY / EMFILE / ENFILE / EIO — descriptor exhaustion on a busy machine, a Windows AV file lock. The phone latches setHostSignedOut and shows "Desktop signed out — sign in to Orca on your desktop to reconnect" for a failure the next read would have cleared.

Why unreadable in particular

It is the one status the session store's own doc says "licenses nothing", and clearCloudSessionIfUnchanged already refuses to delete a session because of it — "a session we were denied is not a session we may delete." The relay taxonomy was the single place treating it as evidence the user signed out.

The fix

Give it its own arm on FreshCloudSessionResult and throw for it in readRelayAuthContext, which lands it on the retryable auth_unavailable path the coordinator already has.

Every other caller tests status !== 'found', so their behaviour is unchanged.

The coordinator comment is corrected to say what it actually depends on: null-means-gone is a contract readRelayAuthContext owes it, not something that branch can verify.

Measured before: offlineReason: "signed-out", mint code relay_signed_out. After: auth_unavailable.

Not fixed here, deliberately

decrypt-failed when safeStorage.isEncryptionAvailable() is false — a Linux keyring still locked at login — takes the same route to SIGNED_OUT. Reclassifying it changes sign-in semantics well beyond the relay and needs its own change.

Why this has its own PR

It is the sibling of the fix in #19963 (fix(relay): stop a mid-read profile switch reporting as a sign-out) — the same taxonomy error in the other null exit of the same function. #19963's commit cites this one by SHA and its code comment reads "same argument as the unreadable session above", which only resolves once this lands. #19963 is stacked directly on this branch for that reason.

Until now this commit lived only on the un-PR'd integration branch nwparker/relay-taxonomy-fixes, so a reviewer merging #19963 would have silently missed it.

Verification

tsc --noEmit -p config/tsconfig.node.json clean · src/main/runtime/relay + src/main/startup — 76 files / 661 tests passed, 2 files / 8 tests skipped, 0 failures · oxlint clean.

Rebase record (2026-09-11)

Stack preserved: base stays fix/18211-lan-mode-applies-to-paired-devices (#19870), which was rebased onto main at 5fa62feda7c264c6eda99ba4788ffebab9aae26c first. This branch was replayed with git rebase --onto 13eee7eacf8a6fcd4bb77ff680d18f727fca1171 9ce190247edbdb508b452e8c62a63c4c2cdd0089.

SHA
old head aff7b40fff5112e9806a0a7f9c297f01cef77936
new head 0dc273fd9090210d41ea50af66c7edfdca32a57c
new base (#19870) 13eee7eacf8a6fcd4bb77ff680d18f727fca1171

No conflicts. The PR is still the single top commit above its base.

@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 critical issues — minor suggestions inline.

Reviewed changes

  • FreshCloudSessionResult gains an unreadable arm — readFreshOrcaCloudSession now surfaces the session store's unreadable status instead of collapsing it into reconnect-required.
  • readRelayAuthContext throws on unreadable — landing it on the coordinator's retryable auth_unavailable path rather than the terminal SIGNED_OUT branch.
  • Coordinator comment corrected — documents that null-means-gone is a contract readRelayAuthContext owes the branch, not something it verifies.
  • Tests — a new suite pins the throw, the reconnect-required → null behavior, and the auth_unavailable classification.

The core fix is correct and well-scoped. I traced the throw through shouldRetryRelayConnectionError (a plain Error is retryable) and relayOfflineReasonForOpenFailure (reachedRelay === undefined → 'auth_unavailable'), so the unreadable session now arms a retry instead of publishing SIGNED_OUT. Other consumers (runWithFreshOrcaCloudSession) test status !== 'found', so their behavior is unchanged as claimed.

ℹ️ Nitpicks

  • readFreshOrcaCloudSession's new unreadable branch (profile-cloud-session-refresh.ts:235-237) is only exercised indirectly — the relay test mocks readFreshOrcaCloudSession, so the propagation from readOrcaCloudSession's unreadable to the new result arm has no direct unit coverage. A one-line assertion in profile-cloud-session-refresh.test.ts would pin the load-bearing mapping.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

expect(result).toEqual({ broker: null, offlineReason: 'auth_unavailable' })
expect(result.broker).toBeNull()
// The wire close reason is what the phone latches on; it must not be spent here.
expect(broker.closeNow).not.toHaveBeenCalledWith(RELAY_HOST_CLOSE_REASON.SIGNED_OUT)

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.

This assertion is vacuous: readContext throws before openBroker runs, so broker is never opened and closeNow is never invoked regardless of whether the fix is present. The comment "must not be spent here" describes a scenario (an existing paired broker) this test doesn't construct. The offlineReason: 'auth_unavailable' assertion is what actually pins the regression — and that classification is already covered by relay-auth-coordinator-offline-reason.test.ts:72. If the goal is to prove SIGNED_OUT is never spent on a live broker, establish a registered broker first, then reconcile with readFreshOrcaCloudSession returning unreadable and assert closeNow wasn't called with SIGNED_OUT.

@nwparker
nwparker force-pushed the fix/18211-lan-mode-applies-to-paired-devices branch from 9ce1902 to 13eee7e Compare September 11, 2026 08:10
The coordinator's own comment states the contract: readContext "throws on
transient failures and returns null solely when the cloud session is gone
(absent, or cleared by a 401)". The implementation did not honour it.

readFreshOrcaCloudSession collapsed readOrcaCloudSession's `unreadable`
status into `reconnect-required`, so readRelayAuthContext returned null and
the coordinator published RELAY_HOST_CLOSE_REASON.SIGNED_OUT, closed the
broker with that wire reason, and armed no retry because a terminal cause
arms none. `unreadable` fires on EPERM/EACCES/EBUSY/EMFILE/ENFILE/EIO —
descriptor exhaustion on a busy machine, a Windows AV file lock. The phone
latches setHostSignedOut and shows "Desktop signed out — sign in to Orca on
your desktop to reconnect" for a failure the next read would have cleared.

The contrast is the argument: `unreadable` is the one status the session
store's own doc says "licenses nothing", and clearCloudSessionIfUnchanged
already refuses to delete a session because of it — "a session we were
denied is not a session we may delete". The relay taxonomy was the single
place treating it as evidence the user signed out.

Give it its own arm on FreshCloudSessionResult and throw for it in
readRelayAuthContext, which lands it on the retryable auth_unavailable path
the coordinator already has. Every other caller tests `status !== 'found'`,
so their behaviour is unchanged. Correct the coordinator comment to say what
it actually depends on: null-means-gone is a contract readRelayAuthContext
owes it, not something that branch can verify.

Measured before the fix: offlineReason "signed-out", mint code
relay_signed_out. After: auth_unavailable.

Not fixed here, and worth a separate look: `decrypt-failed` when
safeStorage.isEncryptionAvailable() is false (a Linux keyring still locked at
login) takes the same route to SIGNED_OUT, but reclassifying it changes
sign-in semantics well beyond the relay.
@nwparker
nwparker force-pushed the nwparker/relay-unreadable-session-taxonomy branch from aff7b40 to 0dc273f Compare September 11, 2026 08:10
Clean auto-merge; the result differs from the base only in this branch's files.
Four of the eleven findings were removable rather than suppressible: annotate
the variable instead of asserting the literal. The rest carry a line-specific
SAFETY rationale on the line that opens the cast expression, which is where the
diagnostic points -- not the `} as Foo` that closes it.

Measured: gate exit 0, tc exit 0, relay 32 files / 251 tests passed.
@OrcaWin

OrcaWin commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Closing as superseded by #22122, which explicitly replaces this PR and carries its unreadable-session fix forward. I compared the complete four-file patch here with replacement head e0124c3e5aab5910851caddd03ac199e801cc88c: it throws orca_cloud_session_unreadable directly from readFreshOrcaCloudSession, so relay reads still reach retryable auth_unavailable rather than the null/signed-out branch, and organization-session readers get the same correction. It preserves absent-session behavior, the coordinator contract, and regression coverage; it also adds direct coverage of the session-store unreadable mapping requested in review.

#22122 is still open, so this is consolidation onto the replacement, not a claim that the fix has merged. The decrypt-failed case remains outside this PR’s scope.

@OrcaWin OrcaWin closed this Oct 26, 2026
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.

2 participants