Skip to content

fix(devices): a revoked device's pairing code ends with it, and ovis add finishes its clean-up or says it could not - #3616

Merged
devswha merged 5 commits into
mainfrom
fix/cli-add-qr-cleanup
Nov 10, 2026
Merged

devswha merged 5 commits into
mainfrom
fix/cli-add-qr-cleanup

Conversation

@devswha

@devswha devswha commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to #3586, from the merge pass review of its head 7a9ce2a (note). Security: it is about devices that stay paired, or get paired, after ovis add said they were removed.

What

  1. A revoked device's pairing code ends with it (Opus MEDIUM, reproduced at the store). On a PC in no account any driving device may start a pairing code. A device the QR code let in could start one, be removed, and the code still paired a second device for up to ten minutes, after the command had printed "Removed.". DeviceStore.revoke now ends the pending code when the revoked device holds it, and tells the listeners, so the typed code bound to it goes too.
  2. An unreadable device list during clean-up is an unfinished clean-up (Codex MEDIUM). As a run ends, the list is read up to three times inside the 4 s deadline. When it still cannot be read, the command removes the devices it knew of and says that one may still be paired, and where to revoke it. Before, it removed nothing and said only "Stopped.".
  3. Comments and docs no longer claim a proof of membership (Opus LOW). A first member links itself with its own key and names its account; nothing can check that. docs/account.md lists it under "What this does not protect against".
  4. The last look comes after the DELETE (Opus LOW). After an answer that removed a device, the run ended on the look taken before the removal. It now looks once more before it ends.

How

  • server/devices.ts: the pending code keeps holders, the paired devices that started it or were handed it. revoke(id) calls endPairing() when id is among them. This covers Settings' Revoke, an account remove and a relay identity reset, which all go through revoke.
  • The reviewed path was POST /api/devices/pair/start through the relay. Two more paths start or hand over a code and are covered the same way, because a device paired at the PC's own address (which the QR code's six digits also admit) can use them:
    • pair/start at the PC's own address: the asking device is recorded (by), apart from startedBy, which stays the relay member whose addition the new device is.
    • POST /api/relay/offer and POST /api/relay/code: dispatch.ts passes the asking device to handleRelayRequest, and on to RelayService.offer and RelayPairCodes.mint. An offer that carries a code already pending adds the asker to its holders.
  • A code the PC itself started is held by no device and survives any revoke, so Settings on the PC behaves as before.
  • scripts/plugin-link.ts:
    • clear returns why it cannot tell that none is left: the list was unreadable, or more devices kept pairing than it looks again for. The sweep and the other-account branch say so. Nothing is said before any code was shown.
    • After a removal the loop continues to a fresh look instead of returning. The no-account ending ("Sign in on that device, then run ovis add again") is said by that look, only when the PC is still in no account and nobody is left to ask about.

Decisions for the merge pass

  • Scope of (1) is wider than the reproduced path: four more server files, about 15 lines, for the direct-address and relay-offer paths. Without them a device paired at the PC's own address keeps the same hole. Say if you want only the startedBy case.
  • In the other-account branch an unreadable list ends the run with the warning; it does not keep looking until the PC answers again.
  • Not changed: variant E, as instructed.
  • Not changed: clean-up removes a device the owner paired another way during the run (Codex's other MEDIUM). It needs pairing provenance on the server.

Validation

  • Ran: bun run check fast on f6bd7fb (main merged in, with fix(access): a pairing code the open LAN started ends with the gate, and so does a relayed socket that holds the bridge token #3613's conflict in server/devices.ts resolved): every step ok, 15471 pass, 0 fail.
  • Ran on f6bd7fb: bun test ./server/relay/ ./server/account/ ./server/relay-pc.contract.test.ts ./server/relay-pc.test.ts ./server/open-access.test.ts ./server/device-access.contract.test.ts, 531 pass, 0 fail.
  • Failing first, on 06836a7:
    • server/devices.test.ts "revoking a device that holds a pairing code" (three tests).
    • server/relay/service.contract.test.ts "ends the relay offer's code, and a typed code, with the paired device that asked for it".
    • scripts/plugin-link.test.ts "says that devices may still be paired when this PC's devices cannot be read as the run ends, after trying again", "ends on a look taken after the removal, not the one before it", and the unreadable cases of "says so when the PC stays in the other account".
  • Failing first, on a70b3ef (second review, comment): the gone-device tests in server/devices.test.ts and server/relay/pair-code.test.ts, the 401 cases in the relay contract test, and the more case of the other-account branch.
  • Not run: bun run check full, the browser regressions (no UI change), a real phone or relay, the Windows and macOS jobs. This PR touches scripts/plugin* and server/, so it waits for GitHub's checks.

Needs a real review: it changes when a pairing code ends (authentication).

🤖 Generated with Claude Code

devswha and others added 3 commits November 11, 2026 06:13
…as handed

On a PC in no account any driving device may start a pairing code. A device
that `ovis add`'s QR code let in could start one, be removed, and the code
still paired a second device for up to ten minutes, after the command had
printed "Removed." (merge pass review of #3586, reproduced at the store).

The pending code now records the paired devices that hold it: the one whose
request started it (`POST /api/devices/pair/start`, through the relay or at the
PC's own address) and one that was handed it (`POST /api/relay/offer`,
`POST /api/relay/code`). `DeviceStore.revoke` ends the code when the revoked
device is among them, and tells the listeners, so the typed code bound to it
goes too. A code the PC itself started is held by no device and is left alone.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…an-up could not read the devices

Follow-up to #3586, from the merge pass review of its head 7a9ce2a.

- After an answer that removed a device the run ended on the look taken
  before the DELETE. A device that linked itself to its own account and
  brought that account's devices in, or one that paired in between, stayed.
  The command now looks once more before it ends, in no account or in the
  account that signed in.
- A device list that could not be read as the run ended left `clear` with
  nothing to remove and nothing said. The read is tried three times inside
  the deadline. When it still fails, or more devices keep pairing than it
  looks again for, the command removes what it knew of and says that one may
  still be paired and where to revoke it. Nothing is said before any code was
  shown. The other-account branch says the same instead of "run ovis add
  again to see".
- The comments and docs said the account's key signed a member's link. A
  first member links itself with its own key and names its account, which
  nothing can check. They now say so, and docs/account.md lists it under
  what this does not protect against.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes

    • Revoking a device now ends any active pairing code it started or received, including its associated typed code.
    • ovis add checks device and account state again after removals, helping catch devices paired during cleanup.
    • If device information remains unavailable or additional devices are detected during cleanup, the command warns that a device may still be paired and explains where to revoke it.
  • Documentation

    • Updated pairing, device revocation, and ovis add guidance, including important limitations and account-membership details.

The change tracks paired devices that start or receive pairing codes and ends those codes when a holder is revoked. ovis add retries device-list reads, rereads state after removal, and reports when cleanup cannot confirm that all devices are gone. Tests and documentation cover these flows.

Changes: Pairing lifecycle

Layer / File(s) Summary
Track pairing-code holders and revoke their codes
server/dispatch.ts, server/relay/*, server/devices.ts, server/devices.test.ts, server/relay/service.contract.test.ts, docs/account.md, changelog.d/revoke-ends-device-code.md
Relay requests pass paired-device identity into pairing operations. The device store records pairing holders and ends a pending code when a holder is revoked. Tests and documentation cover the behavior.
Reread device and account state after removals
scripts/plugin-link.ts, scripts/plugin-link.test.ts, docs/account.md, docs/relay.md
ovis add bases account membership on device rows, asks about other newly paired devices, and checks state again after removal before reporting the no-account state. Tests and docs cover state changes and the limitation on verifying device claims.
Bound cleanup reads and report unresolved devices
scripts/plugin-link.ts, scripts/plugin-link.test.ts, docs/relay.md, changelog.d/cli-add-qr.md
Cleanup retries device-list reads up to three times and reports when devices may remain paired. Tests and docs cover failed reads and repeated arrivals.

Estimated code review effort: 4 (Complex) | ~40 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • devswha/ovis#1977: Adds revoke-all behavior that voids outstanding pairing credentials; this PR also addresses pairing-code invalidation on device revocation.
  • devswha/ovis#3551: Creates relay QR offers and ends their pairing codes when offers are taken down; this PR tracks relay callers as pairing holders.
Merge Risk: Minimal · up to a70b3

Revoking a device now also ends any pairing code it started or received, and ovis add cleanup rereads device state and warns when devices may remain paired. No concrete merge-blocking risk was found. Full checks and real-device testing were not run.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title identifies both main changes: pairing codes end when their holder is revoked, and ovis add reports incomplete cleanup. It is specific, though lengthy.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. 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.
Description check Passed The description explains the problem, changes, security rationale, and known limitations. It lists validation commands and results, skipped checks, and contract-test coverage. Its “What” and “How” sec…
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. 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 3 functions across 9 files. (4 skipped: 4 unsupported.)

Full details: Description check

Explanation

The description explains the problem, changes, security rationale, and known limitations. It lists validation commands and results, skipped checks, and contract-test coverage. Its “What” and “How” sections provide the required change information, even though the headings differ from the template.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5c66921 and a70b3ef.

Files selected for processing: 13

  • changelog.d/cli-add-qr.md
  • changelog.d/revoke-ends-device-code.md
  • docs/account.md
  • docs/relay.md
  • scripts/plugin-link.test.ts
  • scripts/plugin-link.ts
  • server/devices.test.ts
  • server/devices.ts
  • server/dispatch.ts
  • server/relay/pair-code.ts
  • server/relay/routes.ts
  • server/relay/service.contract.test.ts
  • server/relay/service.ts

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

devswha and others added 2 commits November 11, 2026 06:37
…s on its way gets none

Second review of #3616 (Opus and Codex, both CLEAR, same two gaps).

- A device revoked while its `POST /api/relay/code` waited on the relay still
  got a working code: the typed code's mint awaits a relay round trip and
  then started a code held by a device that was already gone, so no later
  revoke ended it. The same held during the look-up of who asks, for
  `pair/start` and `/api/relay/offer`, and for Revoke all with a mint in
  flight. `startPairing` and `holdPairing` now refuse a device the store no
  longer has (`DeviceGoneError`), before anything changes: the code pending
  stays, and the refused start does not count against the window. The routes
  answer `401 unauthorized`.
- `ovis add`, other-account branch: when more devices kept pairing than it
  looks again for and the PC was out of that account again, it said only
  "This PC is in no account again". It now says that one may still be paired
  and where to revoke it, before running the command again.
- docs/account.md: a driving device can have the PC itself start a code
  through loopback from a terminal pane; that code is held by nobody.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@devswha

devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

Second review of a70b3ef (Opus: CLEAR, Codex: CLEAR): the two gaps both found, and how each was resolved

Fixed in 37a7ea2, head f6bd7fb (main merged in). Each has a test that failed first on a70b3ef.

# Gap Resolution
1 A device revoked while its POST /api/relay/code waits on the relay still gets a working code: the mint awaits a relay round trip, then starts a code held by a device that is already gone, so no later revoke ends it. The same during the look-up of who asks, for pair/start and /api/relay/offer, and for Revoke all with a mint in flight. startPairing and holdPairing refuse a device the store no longer has (DeviceGoneError), before anything changes: the code pending stays, and the refused start does not count against the ten codes a window allows. startedBy is checked as well as by. The three routes answer 401 unauthorized, as the device's next request would be. The mint's nameplate is taken off the relay.
2 Other-account branch: clear returns more with a device still paired and the PC back in no account, and the command prints "This PC is in no account again" with no warning. It now says that more devices paired while these were removed, that one may still be paired, and to revoke it in Settings → Devices and PCs before running ovis add again.
3 Docs One sentence under "What this does not protect against": a driving device can have the PC itself start a code through loopback from a terminal pane, and that code is held by no device.

Tests:

  • server/devices.test.ts: "starts no code for a device that is gone by then, and hands it none: no later revoke would end it".
  • server/relay/pair-code.test.ts: "gives no code to a device that was revoked while its code waited on the relay" (a single revoke, and Revoke all, with the mint in flight).
  • server/relay/service.contract.test.ts: /api/relay/offer and /api/relay/code answer 401 for a caller that is gone.
  • scripts/plugin-link.test.ts: "says that a device may still be paired when more keep pairing than it looks again for, also once the PC is out of the other account".

Merging main brought a conflict in server/devices.ts with #3613, which added open to the pending code. Both fields are kept: open ends the code with the gate, holders with its device.

Validation

  • bun run check fast on f6bd7fb: every step ok, 15471 pass, 0 fail.
  • bun test ./server/relay/ ./server/account/ ./server/relay-pc.contract.test.ts ./server/relay-pc.test.ts ./server/open-access.test.ts ./server/device-access.contract.test.ts on f6bd7fb: 531 pass, 0 fail.
  • Not run: bun run check full, the Windows and macOS jobs.

@devswha
devswha merged commit f44653d into main Nov 10, 2026
22 checks passed
@devswha

devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head f6bd7fb45b2a as f44653d9ed0e on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
claude CLEAR
codex CLEAR

Merge pass note (head f6bd7fb, round two). Both reviewers CLEAR. The revoke-during-mint race is closed on every route, Revoke all included; the merge with #3613 kept both the open-access ending of a code and this PR's holder ending; no legitimate start is refused and the new 401 cannot sign a stock client out. Left for one PR after the release:

  • (Codex, MEDIUM, not run) A server lost after a removal leaves ovis add waiting for up to 30 minutes.
  • (Opus, LOW) A device revoked mid-request that asks for a typed code still takes down the typed code already showing before it is refused; the other-account branch does not look at the device list it reads after clean-up; a comment at server/devices.ts:1151 does not hold for a loopback/token caller carrying the revoked cookie.

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