Skip to content

fix(runtime): never hand a parent the token of a delegated child the save dropped - #35510

Merged
nwparker merged 1 commit into
mainfrom
nwparker/delegated-device-written
Oct 29, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/delegated-device-written

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

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

ELI5

A desktop paired to a host can hand pairing credentials to its phones ("delegated" devices). Since #35483, a registry save drops a device that someone removed from the host's device file. But the function that creates or refreshes these phone devices still returned the dropped phone's token, so the desktop could pass a dead credential to the phone. Now it returns only devices that were actually saved.

What Changed

DeviceRegistry.upsertDelegatedMobileDevices filters its returned entries to the devices present after the save. That leaves out a child whose row was removed on disk, which the merged save dropped. The plan and the save are unchanged.

Why

This is e9's P3 note on #35483. Its only caller, mobile.syncDelegatedDevices in runtime-rpc-mobile-devices.ts, maps the returned entries straight to { phoneKey, deviceId, token } for the parent desktop. A dropped child is simply absent from the result. The next sync mints a fresh child for that phone, because the old row is gone from memory too.

Flag-off: no change with ORCA_INTERNAL_WSL_HOSTS unset either; this is orcad and desktop runtime registry code, independent of the flag.
User-risk: low. It only changes the result in the case where an admin removed the child's row from the file while the parent was syncing. The parent then gets no token for that phone until its next sync, instead of a revoked one.

Linked Issue

Follow-up to #35483 (device registry merge).

Visual Proof

N/A: no UI.

Testing

  • device-registry-external-edit.test.ts: a child removed on disk, then renamed through a later upsert, is not returned. It's absent from the file and its token doesn't validate. Fails on main.
  • The delegated-device integration (13/13) and mobile-desktop relay integration (12/12) tests pass. pnpm tc, typecheck:ci, code-quality, anti-slop and ast-grep pass.
  • Automated tests added/updated

Status

Ready for one reviewer.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A for visuals with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote impact considered (registry is host-side; wire unchanged)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (CI runs the rest)

…save dropped

upsertDelegatedMobileDevices returned every planned entry, including a child whose row was
removed on disk and so dropped by the merged save; the parent would pass that dead token to the
phone. It now returns only entries still in the written registry.
@nwparker

Copy link
Copy Markdown
Contributor Author

STATUS: ready for one reviewer. Head c70c40c.

Checks run: pnpm tc, typecheck:ci, code-quality:changed, anti-slop, oxlint, ast-grep. The new test fails on main, and the external-edit suite passes 9/9. The delegated integration (13/13) and relay integration (12/12) tests pass.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

upsertDelegatedMobileDevices now returns only children that remain in memory after the save.

  • Delegated phone sync returns only children still in the registry.

Reviews (1) · Last reviewed commit: "fix(runtime): never hand a parent the to..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

upsertDelegatedMobileDevices now returns only planned child devices whose IDs remain in the registry after the optional save. A regression test removes a child row from disk, renames the child, and verifies that the update returns no devices, the row remains absent, and the child token no longer validates.

Priority: Low

Severity of issue fixed: Low

Merge Risk: Low · up to c70c4

An externally removed child can remain unavailable until another registry-change event triggers a sync; add retry or error handling before merging.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preventing a parent from receiving a delegated child token that the save removed.
Description check Passed The description is detailed and covers the change, reason, linked issue, visual proof, testing, and checklist. Some template sections are omitted, including Review, Agent skill upstream boundary, and …
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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 is detailed and covers the change, reason, linked issue, visual proof, testing, and checklist. Some template sections are omitted, including Review, Agent skill upstream boundary, and Notes, and the full required validation checklist is not marked complete, but the description is mostly complete.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

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

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4c7b0287-6cb9-48cb-88c0-57e00ce5bec1
Commits

Reviewing files that changed from the base of the PR and between b510cd1 and c70c40c.

Files selected for processing: 2
  • src/main/runtime/device-registry-external-edit.test.ts
  • src/main/runtime/device-registry.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

}
return entries
// A child the file had already lost is dropped by the save: never hand out its token.
return entries.filter((entry) => this.getDevice(entry.deviceId) !== null)

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.

Minor · Data Integrity & Integration · Quick win

Supported by static analysis

Script executed:

#!/bin/bash
rg -n -C 6 --glob '*.ts' --glob '*.tsx' \
  'DELEGATED_MOBILE_DEVICE_SYNC_METHOD|pairing\.delegatedMobileDevice\.sync|DelegatedMobileDeviceSyncResult' .

Repository: stablyai/orca

Length of output: 25867


Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- delegated-phone-grants.ts ---'
nl -ba src/main/runtime/mobile-desktop-relay/delegated-phone-grants.ts | sed -n '1,180p'
printf '%s\n' '--- pairing.ts handler ---'
nl -ba src/main/runtime/rpc/methods/pairing.ts | sed -n '60,105p'
printf '%s\n' '--- all delegated grant callers/usages ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'syncDelegatedMobileDevices' -e 'syncDelegatedPhones' -e 'grantDelegated' -e 'DelegatedMobileDeviceSyncResult' src mobile || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 5620


Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- grant sync consumers ---'
rg -n -F --glob '*.ts' --glob '*.tsx' \
  -e 'syncDelegatedPhoneGrants' \
  -e 'DelegatedPhoneGrants' \
  -e '\.asked' \
  -e 'kind: .ready.' \
  src mobile || test "$?" -eq 1
printf '%s\n' '--- grant-related file outlines ---'
rg --files src/main/runtime/mobile-desktop-relay | sort

Repository: stablyai/orca

Length of output: 2631


Script executed:

#!/bin/bash
set -e
nl -ba src/main/runtime/mobile-desktop-relay/delegated-phone-grant-cache.ts
printf '%s\n' '--- cache callers ---'
rg -n -C 8 --glob '*.ts' --glob '*.tsx' \
  -e 'delegatedPhoneGrantCache' \
  -e 'DelegatedPhoneGrantCache' \
  -e '\.get\(.*phoneKey' \
  src/main/runtime/mobile-desktop-relay src/main/runtime || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 20633


Script executed:

#!/bin/bash
set -e
rg -n -C 12 --glob '*.ts' --glob '*.tsx' \
  -e 'this\.grants\.get' \
  -e 'grants\.get' \
  -e 'grant\.token' \
  -e 'grants\.grants' \
  src/main/runtime/mobile-desktop-relay/mobile-desktop-relay.ts

Repository: stablyai/orca

Length of output: 3501


Retry phones omitted from the delegated sync response.

A successful response can omit a requested phoneKey. The cache still marks that key as answered, so later requests reuse the incomplete result. MobileDesktopRelay.open then rejects the phone without scheduling a retry.

Ensure missing phoneKey values trigger another sync, or return an error that causes the caller to retry.

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