Skip to content

fix(mobile): a scope refusal is not a missing method on the Relay pairing probes - #19952

Merged
nwparker merged 4 commits into
mainfrom
nwparker/mobile-pairing-scope-refusal-fallback
Sep 17, 2026
Merged

nwparker merged 4 commits into
mainfrom
nwparker/mobile-pairing-scope-refusal-fallback

Conversation

@nwparker

@nwparker nwparker commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​129 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​129
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​43 $\color{#cf222e}{\Huge{\mathbf{−}}}$​12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​31

The mechanism

runtime-rpc-websocket-dispatch.ts:76 runs the mobile allowlist gate before the RPC dispatcher. So for a mobile-scoped device, method_not_found is reachable only for a method that IS allowlisted but unregistered. A method an older desktop predates is absent from both lists, so the phone is refused with forbidden, never method_not_found.

Both phone-side Relay pairing probes — pairing.getEndpoints and pairing.provisionRelay — keyed their "this desktop is too old for Relay, stay on LAN" fallback on method_not_found alone. That fallback could never fire against the exact desktop it exists for.

What breaks today

Corrected during review. This section originally claimed the break was first-time QR pairing. It is not — see Which site actually reached below. The predicate change is unchanged; only the account of which caller it rescues was wrong.

upgradeDirectMobileRelay re-probes every LAN-only host on every reconnect (MobileRelayDirectUpgradeController fires on each connected transition). Against a desktop too old for Relay, pairing.getEndpoints is refused forbidden, the absence-only predicate let it fall through to interpret, which threw, and the controller's catch {} swallowed it — so the upgrade journal written moments earlier, holding a 32-byte pending resume secret, was never cleared. That journal is write-once, so it was then re-read, never used and never retired, for the life of the pairing. The "too old for Relay, stay on LAN" fallback never fired against the one desktop it exists for.

Which site actually reached

pre-profile-pairing-coordinator.ts cannot hit this against an old desktop, and the earlier claim that it did was wrong. The offer's relay block, both RPC handlers, and both mobile-allowlist entries all landed in the same commit (77b154d5dd7). A desktop old enough to refuse the probe therefore also omits offer.relay, so the coordinator builds no journal and returns a LAN host at its if (!journal) early exit — without ever sending pairing.provisionRelay.

That arm is still worth having, and its test still earns its place: it covers the skew that does remain reachable — a desktop that offers relay but does not allowlist the probe to a phone. That shape is not hypothetical; it is exactly what the Files and Git fallbacks below were written for.

Not a new rule — the pairing probes were the outlier

The phone already reads both codes as absence in two places, with the same mechanism written in the comment:

  • isMobileMethodUnavailableError — mobile/src/files/file-list-fallback.ts
  • isMobileGitUnavailable — mobile/src/source-control/mobile-git-status.ts

Both predate this PR. The Relay pairing probes were simply the pair that never caught up. Those two take (code, message) and also match on the gate's message text; this one takes an RpcResponse and is code-only. Collapsing all three onto one transport-level predicate is a reasonable follow-up and is deliberately not done here — it would touch three unrelated subsystems for a bug fix.

The fix

One shared isPairingRelayRpcUnavailable replaces the two duplicated local isMethodNotFound predicates and accepts either code.

Safe in both directions: a desktop that does serve the probes allowlists them (asserted in the new desktop test), so forbidden on one can only ever mean "this desktop will not expose Relay pairing to a phone" — which is exactly what the caller falls back for. Per docs/reference/remote-wire-compatibility.md: a scope refusal is not a missing method.

The desktop-side test pins the mechanism rather than restating it — a mobile-scoped device gets forbidden for an unregistered method while a runtime-scoped peer gets method_not_found for the same one.

Rollout constraint

The related unreadable-cloud-session fix is 100% desktop-side, and the two cases are byte-identical on the wire. A new phone paired to an old desktop still latches "Desktop signed out — sign in to Orca on your desktop to reconnect" for a transient file error (EPERM/EACCES/EBUSY/EMFILE/ENFILE/EIO) — with no retry armed on that path, cleared only by a successful connect. Desktop rollout must lead or match the phone, never lag.

A phone that predates the close-reason reading ignores it entirely and has no such failure mode, so shipping the phone ahead of the desktop creates this window rather than narrowing it.

Verification

  • mobile: vitest run src/transport → 98 files, 723 passed, 3 skipped, 0 failed (log grepped for FAIL|ELIFECYCLE; exit codes are not trusted in this repo).
  • mobile: tsc --noEmit clean; desktop pnpm tc clean.
  • Mutation-tested, specific regressions only — no survivors:
    • drop the forbidden arm → both new cases fail
    • drop the method_not_found arm → both pre-existing cases fail (confirms the old contract was not widened away)
    • make the desktop gate emit method_not_found → the new desktop case fails

Why this is not waiting behind the SSH remote integration stack

Mobile-side, independent of everything in that stack, and it fixes a first-time pairing flow that currently throws outright. The one sibling commit from the same review depends on a module that only exists on the stack branch and stays there (nwparker/adv2-skew-fixes).

Rebase record (2026-09-11)

Rebased onto main at 5fa62feda7c264c6eda99ba4788ffebab9aae26c.

SHA
old head 3d66c575ca2206be777b62966828639a25b28cf4
new head c831443988c0c19f42afb87dd204acbd5b7c4dea

Conflict in both mobile call sites. main had meanwhile extracted the two hand-rolled helpers (requireSuccess, isMethodNotFound) out of mobile-relay-direct-upgrade.ts and pre-profile-pairing-coordinator.ts into a shared mobile/src/transport/rpc-acceptance-policies.ts as requireRpcResultOrThrowCodedError and isMethodNotFoundRefusal. Resolved by keeping main s shared requireRpcResultOrThrowCodedError at every success site, and keeping this PR s isPairingRelayRpcUnavailable at the two refusal sites it widens — so no local requireSuccess copy came back.

Reviewer note. pairing-relay-rpc-unavailable.ts (added by this PR) and rpc-acceptance-policies.ts (now on main) are two modules in the same directory holding named RpcResponse refusal predicates. The rebase kept them separate rather than relocating this PR s module, because rpc-acceptance-policies.ts explicitly warns "Do not merge two policies without proving every caller of both tolerates the wider or narrower set" and the widened predicate is pairing-specific. Folding isPairingRelayRpcUnavailable into rpc-acceptance-policies.ts as a fourth named policy is a reasonable follow-up; it was left as an author call rather than made during a rebase.

Gates on the rebased head c831443988c0c19f42afb87dd204acbd5b7c4dea

Verified against the pushed head — the tested tree and origin/nwparker/mobile-pairing-scope-refusal-fallback are the same SHA.

Desktop side

  • Root typecheck (run-typecheck-projects-in-parallel.mjs) exit 0. Proven failable first: injected const x: number = "nope" reported TS2322, exit 1.
  • vitest run --config config/vitest.config.ts src/main/runtime/runtime-rpc-mobile-unknown-method-scope-refusal.test.ts — 1 file / 3 tests passed, log grepped for FAIL (0).

Mobile side — previously reported as not run; now run.

mobile/ is a separate pnpm workspace with its own lockfile, so it was installed in isolation inside a throwaway /tmp worktree (pnpm install --frozen-lockfile --ignore-scripts, 1380 packages all reused from the local store, 0 downloaded). A before/after fingerprint of the shared repo — node_modules listing hash and entry count, .modules.yaml, root pnpm-lock.yaml, root package.json, and all native .node binaries — was byte-identical across the install; the only delta anywhere outside mobile/ was mobile/node_modules appearing. No tracked file changed.

  • tsc --noEmit (mobile) — exit 0, 0 errors. Proven failable first: injected a type error into pairing-relay-rpc-unavailable.ts and it reported TS2322, exit 2. That run also surfaced two pre-existing TS2307 errors for *.generated.ts modules, which are products of mobile's own postinstall codegen that --ignore-scripts had skipped; both generator scripts write only under mobile/, so they were run, and the clean result above is with them present.
  • vitest run src/transport (mobile) — 99 files / 760 passed, 3 skipped, log grepped for FAIL (0). Proven failable first: a deliberate expect(1).toBe(2) gave Test Files 1 failed, exit 1.

Mutation-checked, because this PR's fix is exactly what the rebase conflict put at risk. The conflict resolution changed which predicate is called at both refusal sites, so a passing suite alone would not prove the widened predicate is actually wired in. Dropping the 'forbidden' arm from isPairingRelayRpcUnavailable kills precisely the two new cases and nothing else — cleans pending state and leaves direct access unchanged for a scope-refusing old desktop and tolerates an old desktop scope refusal and commits a direct-only host — 2 failed / 14 passed. Restored, suite green again at 99/760. The fix survived the rebase intact and the tests have teeth.


Rebased onto main @ caa465d1da886b2697c85c18bf36f79f2d3b9e68 (2026-09-15).

  • Old head: c831443988c0c19f42afb87dd204acbd5b7c4dea
  • New head: 0d2d23ce3665abc0edda6474447fd41dce143958

Content unchanged apart from one added commit, fix(lint): read the refusal code without casting the reply. The casting gate is changed-lines-only and reads its rule config from the merge base, so this branch's old base skipped it entirely and its previous green did not cover these 4 sites. Verified with git range-diff; prior CI results predate this rebase.


Review round (2026-09-15) — rebased off the merge commit, plus three review fixes

Head b425aca was a merge commit from update-branch, the same mechanism that silently reverted main on this branch once before. Replaced with a real rebase onto origin/main @ 357c9780f8bffa10a21d004449d8d6d9846a9310, so the branch is now linear and its merge base is origin/main.

  • Old head: b425aca9e517b8fbc0972af218d6da8af7b1a5f0 (merge commit)
  • New head: b2da61f0bec173795d6f664ac4f5c21c41fc7390

Revert audit, line by line. git diff origin/main..HEAD is 7 files / +172 / −12, and every one of the 12 removed lines is intended: the two isMethodNotFoundRefusal imports, the three refusal call sites they fed, the three 'method-not-found' sentinel occurrences, and one corrected comment. main's RpcOperation plumbing is untouched at all four sites — no - line removes a relayCredentialProvision.request/.interpret or relayPairingEndpointsRead.request/.interpret, and rpc-acceptance-policies.ts has a zero-byte diff, so its other consumers are unaffected by construction.

Three fixes from adversarial review

  1. The predicate was an unsound type guard. It returned response is RpcFailure, which narrows the false branch to RpcSuccess — but a refusal carrying any other code still reaches that branch. Narrowed to RpcFailure & { error: { code: 'method_not_found' | 'forbidden' } }. Proven both ways: a probe reading provision.error.code after the if compiles under the intersection and fails TS2339: Property 'error' does not exist on type 'never' under the plain guard.
  2. The fallback left no breadcrumb. It now commits a LAN host instead of throwing, so the refusal code was the only record of why a phone has no relay endpoint and nothing wrote it down. Added one log('info', …, provision.error.code) on that path, asserted in the test.
  3. Two comments named a mechanism the desktop cannot produce. The doc claimed method_not_found meant "Relay compiled out, or the provider not wired". Neither is reachable: PAIRING_METHODS is spread unconditionally into ALL_RPC_METHODS, both probes were allowlisted and registered by the same commit (77b154d5dd7), and an unwired provider throws pairing_context_unavailable, which maps to runtime_error. The method_not_found arm is kept — it is the pre-existing contract and it is what keeps the fallback right if the gate ever stops answering first — but the comment now says so instead of inventing a cause. The 'method-not-found' sentinel in the direct-upgrade reader was renamed for the same reason.

The dispatcher claim, proven by mutation

runtime-rpc-websocket-dispatch.ts:76 returns forbidden and returns before dispatchStreaming is ever called, so a mobile-scoped device cannot reach method_not_found for a method the build does not register. Two mutations on the real dispatch path:

  • gate emits method_not_found instead of forbidden → the mobile case fails;
  • gate disabled entirely → the same request comes back method_not_found (AssertionError: expected 'method_not_found' to be 'forbidden'), which is the ordering itself, not a string.

Why forbidden cannot mean a real authorization failure here

Exactly two places in src/main emit the RPC code forbidden: the mobile allowlist gate, and browser.tab.create. The pairing handlers cannot: pairing.ts throws pairing_context_unavailable, which is in no passthrough set and flattens to runtime_error. DeviceRegistry has no scope mutator, so a device cannot be re-scoped mid-life into the gate. A revoked or unknown token answers unauthorized. The relay cell speaks close codes, never RPC envelopes, and the E2EE link throws RelayOuterError. On the only path whose behaviour changes — winner.path === 'direct' — there is no relay in the middle at all. The committed LAN host keeps the same deviceToken and publicKeyB64 and still runs the pinned E2EE handshake; it is less capable, not less authenticated. And it is not terminal: MobileRelayDirectUpgradeController does not unsubscribe on a null upgrade, so it re-probes on every reconnect and foreground.

Gates, measured on the pushed head

The mobile workspace lockfile is written in pnpm 12's flat patchedDependencies format, but pnpm resolves to 10.24.0 inside mobile/ (no packageManager field there), and pnpm 10 reads that format as a config mismatch — that is the whole ERR_PNPM_LOCKFILE_CONFIG_MISMATCH. Invoking pnpm 12 explicitly installs --frozen-lockfile cleanly with no lockfile change.

Gate Result
mobile vitest run (full) 595 files / 5587 passed, 6 skipped, 0 failed
mobile vitest run src/transport 108 files / 860 passed, 3 skipped, 0 failed
ratchet unvalidated-rpc-request-port-boundary 8 passed
desktop runtime-rpc-mobile-unknown-method-scope-refusal 3 passed
mobile tsc --noEmit exit 0 (proven failable: injected TS2322, exit 2)
desktop pnpm tc exit 0
check:code-quality:changed 0 new findings across 7 files, incl. both casting gates
oxlint, oxfmt --check clean on every changed file

Predicate mutations, on the rebased tree: dropping the forbidden arm fails precisely the two new cases (2 failed / 14 passed); dropping the method_not_found arm fails precisely the two pre-existing cases (2 failed / 14 passed); dropping the refusal code from the new log fails only the new log assertion. No survivors.

Confirming round — the doc citation was not true

The predicate comment and the desktop test both ended with "See docs/reference/remote-wire-compatibility.md — a scope refusal is not a missing method", and that page did not say it. The only nearby statement said the opposite, because it describes the runtime-scoped surface, where the dispatcher really does answer method_not_found for an unregistered method. Rather than delete the attribution, the rule is now written down where AGENTS.md sends people to look (Known hazard: on the mobile surface a scope refusal is not a missing method), including the condition under which widening to forbidden is not safe — a probe whose handler can refuse by authorization. The cross-version harness does not run the mobile surface, so that note is the only record.

Final head: ec98c06e8b0, three commits on origin/main @ 357c9780f8bf, linear.

Closing round — the headline claim was wrong and is corrected

A last adversarial pass found that the story this PR told about itself did not hold. "First-time QR pairing threw instead of committing a LAN host" is unreachable: the offer's relay block ships in the same commit as the two RPC handlers and their allowlist entries, so a desktop that refuses the probe never offered relay in the first place and the coordinator exits before probing. The reachable damage was in upgradeDirectMobileRelay — an orphaned direct-upgrade journal, rewritten on every reconnect, against exactly the desktops the fallback was meant to cover.

Two further overclaims went with it. The phone's Files and Git fallbacks have read forbidden as absence since they shipped, so this is settled practice in this codebase rather than a newly found rule; and the reason an allowlisted-but-unregistered method cannot ship is src/main/runtime/mobile-rpc-allowlist.test.ts, which requires every method the phone calls to be both — not a convention about what lands together. Corrected in the two call-site comments, the predicate's doc, the wire-compat note, and this description.

The code is unchanged by this round. Only the claims about it moved. Re-verified after: mobile tsc --noEmit exit 0, vitest run src/transport 108 files / 860 passed, 3 skipped, oxfmt --check clean, check:code-quality:changed 0 new findings.

Final head: 5fd36f1e76d.

@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

  • Shared isPairingRelayRpcUnavailable predicate — a new pairing-relay-rpc-unavailable.ts replaces the two duplicated local isMethodNotFound predicates and accepts either method_not_found or forbidden.
  • Coordinator + direct-upgrade fallback rewired — pre-profile-pairing-coordinator.ts and mobile-relay-direct-upgrade.ts route their "too old for Relay, stay on LAN" fallback through the shared helper, so a scope-refusing desktop now commits a direct-only/LAN host instead of throwing.
  • Regression coverage — two new mobile cases for the forbidden arm, plus a desktop-side test pinning the gate mechanism (mobile-scoped → forbidden, runtime-scoped → method_not_found, allowlist covers both probes).

The fix is sound. forbidden on the two pairing probes can only originate from the mobile allowlist gate (src/main/runtime/runtime-rpc/runtime-rpc-websocket-dispatch.ts:76); handler throws map through mapRuntimeError in src/main/runtime/rpc/errors.ts to a closed passthrough set or runtime_error, never forbidden, so treating it as "this desktop will not expose Relay pairing" is safe in both directions. The tests assert exact values and, per the description, fail without either arm.

ℹ️ Third divergent copy of the "mobile method unavailable" predicate

The new isPairingRelayRpcUnavailable matches method_not_found or forbidden, but the two pre-existing sibling predicates — isMobileMethodUnavailableError (mobile/src/files/file-list-fallback.ts) and isMobileGitUnavailable (mobile/src/source-control/mobile-git-status.ts) — additionally match message.includes('not available to mobile clients'). All three detect the same gate's scope refusal, so this is a mild divergence worth reconciling at some point: either the message arm is redundant and the older helpers can be simplified, or it is load-bearing and this helper should match. Not blocking.

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

@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: 58f37972-fe54-467c-a218-07879a8bf454

📥 Commits

Reviewing files that changed from the base of the PR and between b425aca9e517b8fbc0972af218d6da8af7b1a5f0 and b2da61f.

📒 Files selected for processing (5)
  • mobile/src/transport/mobile-relay-direct-upgrade.ts
  • mobile/src/transport/mobile-relay-pairing-operations.ts
  • mobile/src/transport/pairing-relay-rpc-unavailable.ts
  • mobile/src/transport/pre-profile-pairing-coordinator.test.ts
  • mobile/src/transport/pre-profile-pairing-coordinator.ts

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


📝 Walkthrough

Walkthrough

The change adds a shared predicate for method_not_found and forbidden Relay RPC responses. Direct relay upgrade and pre-profile pairing fallback use this predicate. Tests cover mobile-scoped RPC responses, direct upgrade behavior, and direct-only pairing fallback.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to b2da6

The compatibility fallback correctly handles older desktops without masking current Relay pairing failures. No actionable merge risk remains.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the mechanism, failure mode, fix, rollout constraint, and verification in detail. However, it does not follow the required template and omits the required Linked Issue, Visual… Reformat the description using the repository template. Add a Linked Issue entry with Fixes #..., add Visual Proof or write N/A with a reason, complete the Testing and required checklist items, and address the AI Disclosure, Review, Age…
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely identifies the main change: treating Relay pairing scope refusals separately from missing-method responses.
Full details: Description check

Explanation

The description explains the mechanism, failure mode, fix, rollout constraint, and verification in detail. However, it does not follow the required template and omits the required Linked Issue, Visual Proof or explicit N/A, checklist, notes, review, and agent-skill-boundary sections.

Resolution

Reformat the description using the repository template. Add a Linked Issue entry with Fixes #..., add Visual Proof or write N/A with a reason, complete the Testing and required checklist items, and address the AI Disclosure, Review, Agent skill upstream boundary, and Notes sections.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@nwparker
nwparker force-pushed the nwparker/mobile-pairing-scope-refusal-fallback branch from 3d66c57 to c831443 Compare September 11, 2026 08:41

@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

  • Rebase onto main + conflict resolution — main had since extracted the two hand-rolled helpers out of the call sites into rpc-acceptance-policies.ts as requireRpcResultOrThrowCodedError and isMethodNotFoundRefusal. The rebase kept main's requireRpcResultOrThrowCodedError at every success site and kept this PR's widened isPairingRelayRpcUnavailable at the two refusal sites, so no local requireSuccess copy returned.
  • Narrow-predicate import dropped from the call sites — isMethodNotFoundRefusal is no longer imported by mobile-relay-direct-upgrade.ts or pre-profile-pairing-coordinator.ts; it remains in use by terminal-viewport-refit-state.ts, so rpc-acceptance-policies.ts stays fully populated.

The rebase preserved the fix intact: the refusal sites still widen on forbidden via isPairingRelayRpcUnavailable, and the safety argument holds on the new main — the allowlist gate (runtime-rpc-websocket-dispatch.ts:76) is still the sole forbidden source for the two probes, and MOBILE_RPC_METHOD_ALLOWLIST still lists pairing.getEndpoints / pairing.provisionRelay (asserted by the desktop test). The mutation check in the rebase record (dropping the forbidden arm kills exactly the two new cases) confirms the widened predicate is still wired in.

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

@nwparker
nwparker force-pushed the nwparker/mobile-pairing-scope-refusal-fallback branch 2 times, most recently from 0d2d23c to e8304d1 Compare September 15, 2026 22:16

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

Important

The rebase reverted main's typed pairing operations at all four probe call sites, which fails the mobile raw-RPC ratchet — Mobile Checks / verify is red on this head.

Reviewed changes

Since the prior pullfrog review (c8314439), the branch was rebased onto current main (e7206f62) and one lint commit was added:

  • Rebased onto main @ e7206f62 — the fix commit was replayed onto a newer base.
  • fix(lint) in the desktop test only — runtime-rpc-mobile-unknown-method-scope-refusal.test.ts now reads the refusal code through a typed errorCode helper instead of as casts, satisfying consistent-type-assertions: never. The three cases still pin forbidden vs method_not_found and both probes' allowlist membership; test-only and sound.
  • relayCredentialProvision / relayPairingEndpointsRead dropped at all four pairing call sites — the conflict resolution kept the pre-refactor raw client.sendRequest calls instead of main's typed operations. This is the regression and what turns the ratchet red.

The core fix — treating forbidden as "too old for Relay, stay on LAN" via isPairingRelayRpcUnavailable — is otherwise sound, and the new tests assert exact codes.

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

@nwparker
nwparker force-pushed the nwparker/mobile-pairing-scope-refusal-fallback branch from dfd31b2 to d3ba834 Compare September 15, 2026 23:29

@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

Since the prior pullfrog review (5216409534, on e8304d144b), the branch was rebased/squashed onto current main (b5a99462bc) and its content changed:

  • Typed pairing operations restored — the previous head's raw client.sendRequest fallback at all four probe call sites is gone; mobile-relay-direct-upgrade.ts and pre-profile-pairing-coordinator.ts send both probes through relayCredentialProvision / relayPairingEndpointsRead again. This clears the raw-port regression, and unvalidated-rpc-request-port-boundary.test.ts now passes (verified: mobile transport suite 24/24 green).
  • Widened refusal predicate remains the only behavioral delta — isPairingRelayRpcUnavailable is applied at both refusal sites, with .interpret on the success path. The concern from both open threads on mobile-relay-direct-upgrade.ts:80 and pre-profile-pairing-coordinator.ts:220 is fully addressed, so both were resolved this run.

Also re-verified on this head: desktop runtime-rpc-mobile-unknown-method-scope-refusal.test.ts 3/3, mobile tsc --noEmit clean, and check:code-quality:changed 0 findings. An independent mutation check (dropping the forbidden arm) fails exactly the two new mobile cases and nothing else, so the new tests have teeth.

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

…ring probes

The desktop's mobile allowlist gate runs before its RPC dispatcher, so a method an
older desktop predates is absent from both and the phone is answered `forbidden`,
never `method_not_found`. Keying the "too old for Relay, stay on LAN" fallback on
`method_not_found` alone therefore never fired against the exact desktop it exists
for: first-time pairing threw instead of committing a LAN host.

`isPairingRelayRpcUnavailable` accepts both codes at the three pairing probe sites.
It is pairing-scoped on purpose - `isMethodNotFoundRefusal` has four other consumers
that must keep reading `forbidden` as a refusal, not as absence.

The main-side test pins the claim the fallback rests on: the dispatcher really does
answer `forbidden` to a mobile-scoped device and `method_not_found` to a runtime one,
and this build allowlists both probes, so `forbidden` on either can only mean an
older desktop.
The LAN fallback now commits a host instead of throwing, so the refusal code
was the only record of why a phone ended up without a relay endpoint and
nothing wrote it down. Log it on the path that swallows it.

Narrow `isPairingRelayRpcUnavailable` to the two codes it matches rather than
to `RpcFailure`: a plain failure guard would collapse the *false* branch to
`RpcSuccess`, which a refusal carrying any other code still reaches.

Rename the `'method-not-found'` sentinel in the direct-upgrade reader, which
stopped describing what it covers, and correct two comments that named a
`method_not_found` mechanism the desktop cannot produce for these methods:
both probes have been allowlisted and registered by the same commit since
Relay landed, and an unwired pairing provider answers `runtime_error`.
@nwparker
nwparker force-pushed the nwparker/mobile-pairing-scope-refusal-fallback branch from b425aca to b2da61f Compare September 16, 2026 04:53

@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

Since the prior pullfrog review (5216956525, on d3ba834074), the branch was rebased onto current main (357c9780f8) and three adversarial-review fixes landed:

  • Refusal predicate narrowed to a sound type guard — isPairingRelayRpcUnavailable now returns response is RpcFailure & { error: { code: 'method_not_found' | 'forbidden' } } instead of boolean. A plain RpcFailure guard would have narrowed the false branch to RpcSuccess even though a refusal carrying any other code reaches it.
  • Breadcrumb on the LAN fallback — the coordinator logs Relay: desktop will not serve relay pairing with the refusal code before committing a direct-only host; the new mobile case asserts both the message and the code.
  • Comment corrections — the JSDoc no longer claims method_not_found means "Relay compiled out / provider not wired" (unreachable; an unwired provider answers runtime_error), and the direct-upgrade sentinel was renamed 'method-not-found' → 'relay-pairing-unavailable' to match the widened predicate.

Also verified on this head: mobile pre-profile-pairing-coordinator.test.ts + mobile-relay-direct-upgrade.test.ts 16/16 and desktop runtime-rpc-mobile-unknown-method-scope-refusal.test.ts 3/3. An independent mutation check (dropping the forbidden arm) fails exactly the two new cases (2 failed / 14 passed), then restored — the new tests have teeth.

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

…bsence

Two comments cited this page for "a scope refusal is not a missing method" and
the page did not say it — the only nearby statement says the opposite, because
it describes the runtime-scoped surface, where the dispatcher does answer
`method_not_found`. The allowlist gate makes the mobile surface the exception,
and the harness does not run that surface, so this note is the only record.
The comments and the wire-compat note said this fixed first-time QR pairing.
It cannot: the `relay` block on the pairing offer, both RPC handlers and both
allowlist entries all landed in 77b154d, so a desktop old enough to refuse
the probe also omits the offer block, and that flow commits a LAN host without
ever probing. The site that reached is `upgradeDirectMobileRelay`, which
re-probes every LAN-only host on reconnect: the refusal threw into the
controller's swallowing catch, so the write-once journal it had just written —
and the pending resume secret in it — was never retired.

Also drop two overclaims: the phone's Files and Git fallbacks have read both
codes since they shipped, so this is settled practice rather than a new rule,
and the reason the allowlisted-but-unregistered case cannot ship is
mobile-rpc-allowlist.test.ts, not a convention about what lands together.
@nwparker
nwparker force-pushed the nwparker/mobile-pairing-scope-refusal-fallback branch from 057b29b to 5fd36f1 Compare September 16, 2026 05:31
@nwparker
nwparker merged commit 6c3b97b into main Sep 17, 2026
28 checks passed
@nwparker
nwparker deleted the nwparker/mobile-pairing-scope-refusal-fallback branch September 17, 2026 05:22
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…ring probes (stablyai#19952)

* fix(mobile): a scope refusal is not a missing method on the Relay pairing probes

The desktop's mobile allowlist gate runs before its RPC dispatcher, so a method an
older desktop predates is absent from both and the phone is answered `forbidden`,
never `method_not_found`. Keying the "too old for Relay, stay on LAN" fallback on
`method_not_found` alone therefore never fired against the exact desktop it exists
for: first-time pairing threw instead of committing a LAN host.

`isPairingRelayRpcUnavailable` accepts both codes at the three pairing probe sites.
It is pairing-scoped on purpose - `isMethodNotFoundRefusal` has four other consumers
that must keep reading `forbidden` as a refusal, not as absence.

The main-side test pins the claim the fallback rests on: the dispatcher really does
answer `forbidden` to a mobile-scoped device and `method_not_found` to a runtime one,
and this build allowlists both probes, so `forbidden` on either can only mean an
older desktop.

* fix(mobile): leave a breadcrumb when a desktop refuses relay pairing

The LAN fallback now commits a host instead of throwing, so the refusal code
was the only record of why a phone ended up without a relay endpoint and
nothing wrote it down. Log it on the path that swallows it.

Narrow `isPairingRelayRpcUnavailable` to the two codes it matches rather than
to `RpcFailure`: a plain failure guard would collapse the *false* branch to
`RpcSuccess`, which a refusal carrying any other code still reaches.

Rename the `'method-not-found'` sentinel in the direct-upgrade reader, which
stopped describing what it covers, and correct two comments that named a
`method_not_found` mechanism the desktop cannot produce for these methods:
both probes have been allowlisted and registered by the same commit since
Relay landed, and an unwired pairing provider answers `runtime_error`.

* docs(wire): record that the mobile surface refuses by scope, not by absence

Two comments cited this page for "a scope refusal is not a missing method" and
the page did not say it — the only nearby statement says the opposite, because
it describes the runtime-scoped surface, where the dispatcher does answer
`method_not_found`. The allowlist gate makes the mobile surface the exception,
and the harness does not run that surface, so this note is the only record.

* docs(mobile): name the pairing site the scope refusal actually reached

The comments and the wire-compat note said this fixed first-time QR pairing.
It cannot: the `relay` block on the pairing offer, both RPC handlers and both
allowlist entries all landed in 77b154d, so a desktop old enough to refuse
the probe also omits the offer block, and that flow commits a LAN host without
ever probing. The site that reached is `upgradeDirectMobileRelay`, which
re-probes every LAN-only host on reconnect: the refusal threw into the
controller's swallowing catch, so the write-once journal it had just written —
and the pending resume secret in it — was never retired.

Also drop two overclaims: the phone's Files and Git fallbacks have read both
codes since they shipped, so this is settled practice rather than a new rule,
and the reason the allowlisted-but-unregistered case cannot ship is
mobile-rpc-allowlist.test.ts, not a convention about what lands together.
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