Skip to content

fix(pairing): a key proof in flight when its code, key or session ends never reaches the waiting list (S13-1) - #4339

Merged
devswha merged 10 commits into
mainfrom
fix/s13-1-proof-in-flight
Nov 20, 2026
Merged

devswha merged 10 commits into
mainfrom
fix/s13-1-proof-in-flight

Conversation

@devswha

@devswha devswha commented Nov 20, 2026

Copy link
Copy Markdown
Owner

A key proof in flight when its code, key or session ends never reaches the waiting list (ledger S13-1)

MUST-CLOSE item before the account-opens-all switch-on (security-triage ranking, lead order 11-21). Not an access fix: a screen approval was still needed. It stops a prompt for a key whose code was already ended (Revoke all, identity reset, expiry), which a hurried owner could approve.

Device table rows: T71, S13-1 (ledger s2-ledger.md).

Cause

PendingRedemptions.prove took the challenge out of #named and then awaited verifyPairProof and pairFingerprint. dropCode / dropKey / forget only looked at #named and #waiting, so a proof between the two landed in the waiting list and on the PC's screen after its code had ended.

Fix (server/account/pending.ts only)

prove() parks the answered challenge in #proving across both awaits. dropCode, dropKey and forget (the session closing, KeyProofPairings.leave) end those entries and give the code use back once. After the awaits, a challenge no longer in #proving returns null without publishing or releasing again.

Relay-hub question (b), identity reset with no reservation: no change needed. The only caller of PendingRedemptions.name is server/account/key-proof.ts:58, which always passes a reservation with codeId. resetIdentity calls services.devices.endPairing() first (server/relay/service.ts:637), which fires every onPairingEnded listener with the code id (server/devices.ts:1724), wired to pendingRedemptions.dropCode (server/index.ts:576).

Tests (red first)

  • f19af50: code ends / key dropped while the proof is verified -> null, nothing waiting, no screen update, use released once (from ledger/s2-13-s13-1@40416d32).
  • de6dc7d: fix.
  • a2b89e8: session closes mid-proof (red). 0e7c80c: fix.

New exports

None.

Reviews

  • security-triage (t13r): YES on access at de6dc7d, closes S13-1.
  • relay-hub (t13t): matches T71; its LOW (a) is taken (session close), and (b) is answered above.
  • dori review + omo gate reviewer: run by relay-hub on this head.

Validation

bun run check fast on 0e7c80c via dori heavy (hosthatch): workflow syntax, generated types/themes, typecheck, build, unit 20812 pass / 0 fail.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • In-progress proof checks are now discarded when the associated code, key, or session ends, preventing stale redemption entries or screen updates.
    • Code reservations are released exactly once when a proof is interrupted.

PendingRedemptions now tracks proofs during asynchronous verification and fingerprinting. Cleanup can end in-progress proofs and release their code reservations. Tests cover code termination, key removal, and session closure during verification.

Changes: Pending proof lifecycle

Layer / File(s) Summary
Track proofs and apply cleanup
server/account/pending.ts, server/account/pending.test.ts
prove tracks in-progress proofs and discards results if cleanup ends them before completion. forget, dropKey, and dropCode also end matching in-progress proofs and release their reservations. Tests verify that the three cleanup cases create no waiting entry or screen notification and release the code use once.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · previous review 0e7c8

This change keeps a key proof that is in flight when its code, key or session ends from reaching the waiting list or the PC screen. The affected logic is limited to the pending-redemption lifecycle and is covered by new tests. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix (in-flight key proof never reaching the waiting list when its code, key or session ends) and matches the changeset, which adds a #proving map in server/account/pending.ts and a…
Description check Passed The description follows the template. It has a Change section that states the problem, cause, and fix. It has a Validation section that lists the checks run (bun run check fast on 0e7c80c) with resu…
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: Title check

Explanation

The title names the fix (in-flight key proof never reaching the waiting list when its code, key or session ends) and matches the changeset, which adds a #proving map in server/account/pending.ts and a test for those cases. The title is specific and accurate.

Full details: Description check

Explanation

The description follows the template. It has a Change section that states the problem, cause, and fix. It has a Validation section that lists the checks run (bun run check fast on 0e7c80c) with results. The template's Validation section also asks for HTTP/WS contract-test coverage, and the description does not state it. This change touches no HTTP or WS code, so the gap is minor. It does not link a maintainer-agreed issue, but the template asks for that only for features, and this is a fix. The description also does not mention the changelog.d entry that CONTRIBUTING.md requires, and it does not say whether the full check or contract tests were skipped.

Finishing Touches

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 40b79ff and 0e7c80c.

Files selected for processing: 2

  • server/account/pending.test.ts
  • server/account/pending.ts

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

@devswha

devswha commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

Gate findings at 0e7c80c: BLOCK (omo gate reviewer; dori CLEAR with 3 LOW; t13r YES on access)

The #proving fix itself holds across both awaits (code end, key drop and session close each refuse and release once), and identity reset and the single caller are confirmed. Two remaining paths still put a prompt on the screen for an ended code. Neither admits a device, but S13-1's point is that the prompt must not appear. One commit, reds first:

  • MEDIUM: src server/account/pending.ts:94-110. The code expires while verification is suspended; activePairing() is already null, but the expiry callback has not run yet, so the entry reaches the waiting list and the PC shows its prompt. Fix: in the same synchronous turn that publishes the entry, re-check this reservation against the device store's deadline (or activePairing). If it has ended, release it once and return null. Red: expire the code between the awaits, before its timer callback runs.
  • MEDIUM: server/relay/session.ts:407-411 and server/account/key-proof.ts:168-174. endPairing() empties the list, then the relay resumes from await prove() and asks for the screen approval; its withdrawal listener is installed after the deletion, so the prompt stays even after the session is refused. Fix: before sending KEY_PENDING or asking for screen approval, check that this exact pending id still waits for this session; keep the listener for later ends. Red: endPairing between prove() resolving and the relay's prompt request.
  • dori's three LOWs (pending.ts:73-74, pending.ts:173-179, key-proof.ts:79): fix them in the same commit if cheap, otherwise answer them in the body.

Verified by the gate reviewer: 44 tests passed, typecheck clean, and the three new regression tests fail on the pre-fix code.

…waiting before the screen is asked, puts no prompt on the screen (S13-1)
…hat leaves mid-proof leaves nothing waiting (S13-1, T71)
…ng before KEY_PENDING or the screen, puts no prompt up; a proof being checked holds its slot (S13-1, T71)
@devswha

devswha commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

Round 2 (gate at 0e7c80c) -> cba7127

Reds first: 77ca7c4, 29e8ffe. Fix: cba7127.

  • MEDIUM (gate): a code that ran out while its proof was checked, before its expiry timer ended it. The reservation now carries live() = devices.codeLive(codeId) (the pending code by id, not over), checked in the same turn that would publish the entry; an ended code releases once and returns null.
  • MEDIUM (gate): endPairing between prove() resolving and the prompt. The relay's KEY_PROVE handler checks isWaiting(entry.id) before KEY_PENDING (refuses auth_failed otherwise), and askScreenForKey checks it before asking the screen; its withdrawal listener stays for later ends.
  • dori LOWs: in-flight proofs count against the per-code and total limits (red); the session-gone branch after prove() was unreachable (leave -> forget ends the proof first) and is removed, with a leave-mid-proof test; #endProving writes no journal line, on purpose: a proof that never reached the waiting list was never shown.
  • New seam: RedeemSeams.codeLive (DeviceStore.codeLive).

Validation: bun run check fast on cba7127 via dori heavy (old-desktop): unit 20811 pass / 0 fail, typecheck, build, generated files, actionlint.

@devswha

devswha commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

Gate findings at cba7127: BLOCK (omo gate reviewer; dori CLEAR with 2 LOW; t13r YES on access)

Both stale-prompt races are fixed: a code that expires during verification produces no entry and no prompt, and endPairing before the relay resumes produces neither KEY_PENDING nor a prompt. 170 tests pass and typecheck is clean. One commit, reds first:

  • MEDIUM: removing the session-gone branch reopened a leak. server/account/key-proof.ts:80-85,119-125. If the carrier closes after the pending store publishes the entry but before prove() records its id on the session, the code use is refunded once but the entry stays listed. In the relay fixture, one device stayed waiting after the disconnect, and only 4 of 5 new sessions got in. Fix: restore the ownership check after the await. If the session is gone, decline that exact entry and refuse. Add a deferred test that closes at publication and checks all five slots are reusable.
  • LOW: the relay guard has no relay-level test. All 48 pairing tests passed against the old relay, which still sent KEY_PENDING once in the handoff. Add a test that ends pairing at that handoff and checks the outbound send, the screen request and the refusal.
  • dori's LOWs (server/relay/session.ts:410 and the PR description): fix or answer in the body.

… its slot free; a code ending at the relay's handoff sends no KEY_PENDING and no prompt (S13-1, T71)
…that entry, so its slot is free again (S13-1, T71)
@devswha

devswha commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

Round 3 (gate at cba7127) -> a5e6d12

Red: 63a06ec. Fix: a5e6d12.

  • MEDIUM: the session-gone check after prove() is back (key-proof.ts): a session that ends in the same turn its entry is published declines that entry and refuses, so its slot is free again. Red: the carrier leaves from the publication listener; prove() refuses, nothing waits, and the code still takes all five devices.
  • LOW: a relay-level test of the handoff: the code ends two turns after publication (after KeyProofPairings.prove names and resolves the entry, before the relay session goes on). A spy on MuxEngine.sendSession shows the relay before cba7127 sends KEY_PENDING once there and the head none; the device is refused, no prompt, nothing pending. One turn sooner the prove() check refuses; one turn later KEY_PENDING has gone out legitimately. The timing is counted in turns; the five-run repeat of the contract file was green.
  • dori LOWs: see round 2 notes (journal line on #endProving: none on purpose; double doc comment fixed).

Validation: bun run check fast on a5e6d12 via dori heavy (hosthatch): typecheck, build, generated files, actionlint ok; unit 1 failure, outside this change: scripts/ci-browser-parallel.test.ts "takes a process's name from its executable, never from the argv[0] it sets" read "bun" for a just-spawned sleep (a fork-before-exec race in that test); every other test passed. bun test ./server/account/pending* ./server/account/key-proof*: 57 pass.

…for it; the handoff test asserts no screen ask (S13-1)
@devswha

devswha commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

Test-only fix at 2162497 (hub, after the final round): the bounded wait for KEY_PENDING in provingDevice starts only when a test reads pending (a getter), so a test where it must never come leaves no timer or unhandled rejection; the handoff test asserts askScreenForKey is never called (spy on the services seam; it fails against the old relay). bun test --rerun-each 8 ./server/account/key-proof.contract.test.ts: 168 pass, 0 fail. bun run check fast on 2162497 via dori heavy (hosthatch): unit 20817 pass / 0 fail, typecheck, build, generated files, actionlint.

@devswha
devswha merged commit d51fa32 into main Nov 20, 2026
24 checks passed
@devswha

devswha commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

Merged through pr-merge at head 216249731. Seen before the merge was asked for: required checks green, no unresolved thread, no conflict, no hold, main not red, no release in progress. CodeRabbit said it did not review (a limit or a skip) since this head.

Reviews at 2162497: dori CLEAR (receipt devswha__ovis_4339@216249731); omo gate reviewer (gpt-6.2-astra) final round 3 at a5e6d12: no HIGH, production code verified (publication close, relay handoff, expiry, in-flight limits, single refund); its one MEDIUM (a 10 s test wait leaking an unhandled rejection) fixed test-only in 2162497 and verified by relay-hub: the contract file 8x in one process (--rerun-each 8) 168 pass 0 fail; zero askScreenForKey calls asserted. security-triage (t13r) YES; S13-1 closes. Relay-hub.

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