Skip to content

fix(account): a device waiting on its PCs for the move asks them from a PC's page and again on a clock (F9) - #4713

Closed
devswha wants to merge 4 commits into
mainfrom
fix/move-reasks-pcs
Closed

devswha wants to merge 4 commits into
mainfrom
fix/move-reasks-pcs

Conversation

@devswha

@devswha devswha commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Summary

Staging QA (F9): the account was on the migrate switch, but the phone never moved it onto its signed
list. One PC (m3) was up and had let every device in for longer than the scaled day; the other (m4) was
off past its three days. The phone's plan sat at no_witness and it never asked m3 for its witness
answer (GET /api/account/list/witness).

Cause. The device asks its PCs for the move only when something triggers it, and in this state
nothing did:

  • A session's opening asks only if the list status already waits on PCs at that moment. A PC's page
    is a fresh page load: My PCs navigates to it, and a restart loads it directly. The shell opens that
    PC's session before the page's first list round, so nothing is asked.
  • The background asker (askPcs) ran only on the shell's front page (view.active() is frontUp)
    and only when the list view changed. A plan that comes out the same every round (no_witness, or
    too_new on an answer heard earlier) changed no view, so nothing ran it again.
  • On any page, the asker's first run comes from the list's first round. That round runs inside
    refresh() before the directory and the sign-in's key are set, so a PC the device also paired with
    was asked over the pairing. The PC answers that with 403 account_required (the witness is for its
    account's sessions only), and the device then did not ask it again for ten minutes.

Answers are kept in page memory. The one answer QA saw (heard on My PCs) was lost when the app moved on
to m3's page. The rules are not at fault: with one PC that answered and one silent past its three days,
the plan starts (src/lib/account/listMigrate.test.ts, "a PC it knows that has not answered holds the
start back for three days").

Fix (src/lib/relay/accountController.ts):

  • askPcs also runs while a PC's app is open.
  • It runs on a timer while the device waits on its PCs. The timer fires after the re-ask gap, or after
    the too_new wait the plan told where that is longer. It does not run while the page is hidden.
  • Each PC is still asked at most once per gap. The QA twin's factor turns the gap down with its other
    waits, to 30 seconds at the least.
  • It chooses a way to each PC only once this sign-in's directory is read. While that read is under way
    it waits, and refresh() asks once the read ends. With no read under way (a failed one), a saved
    pairing is still used, as before.

Nothing here changes who is carried into a list. The PCs' answers and the plan's rules are untouched.
docs/account-list.md now describes the asking.

No changelog fragment: the move onto the list is not released yet, and this makes it do what
changelog.d/account-list-migrate-app.md already says.

Validation

bun run check fast was not run locally: the PC's heavy queue did not open for over an hour (load above 150); ran the typecheck, the convention tests and the touched test files; CI's Fast checks run the unit suite.

  • bun run typecheck: passes.
  • bun test --timeout 60000 on src/lib/relay/accountController{,.delete,.enrollment,.list,.listLeave,.migrate,.renew,.signOutEverywhere}.test.ts
    plus scripts/conventions.test.ts, src/conventions.test.ts, server/conventions.test.ts: 373 pass, 0 fail.
    src/lib/account/listMigrate{,.session,.review}.test.ts also pass.
  • Red first: the three "F9:" tests in src/lib/relay/accountController.migrate.test.ts (commits 02e5270
    and 27d334e) fail before the fix commits and pass after:
    • the PCs are asked in the background while a PC's app is open;
    • a plan that repeats asks again once its told wait has run out, and no sooner than the gap (fake timers);
    • the first round on a page, which comes before the directory, still asks through the account.
  • Skipped: check integration and the browser batteries (lead's decision).

🤖 Generated with Claude Code

devswha and others added 4 commits November 25, 2026 16:34
…, and a repeating plan never asks again (F9, red)

Staging F9: the phone sat in the app of the PC it paired with; the shell opened that session before the
device waited on its PCs, so onPcSession asked nothing, and the background asker runs only on the shell's
front page and only when the list view changes. The PC was never asked, and the move never started.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n a PC's app too, and again on a clock (F9)

The background asker ran only on the shell's front page (view.active) and only when the list view
changed. A device sitting in the app of the PC it paired with, whose session opened before the device
waited on its PCs, therefore never asked that PC, and a plan that came out the same every round
(`no_witness`, `too_new` on an answer heard earlier) never asked again: the move never started.

It now runs whatever the shell shows, and on a timer while the device waits on its PCs: after the
re-ask gap, or after the wait the plan told where that is longer, and not while the page is hidden.
Each PC is still asked at most once per gap. The QA twin's factor turns the gap down with its other
waits, to 30 seconds at the least.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ng before the directory is read (F9, red)

The list's first round on a page runs inside refresh(), before the directory and the sign-in's key are
set, so a PC the device also paired with is asked over the pairing, which a PC answers 403
account_required, and is then not asked again for the gap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…, and runs when it is read (F9)

The list's first round on a page runs inside refresh(), before the sign-in's directory is read. A
PC the device also paired with was then asked over the pairing, which a PC answers 403
account_required (the witness is for its account's sessions alone), and was not asked again for the
gap. While this sign-in's directory read is under way the ask now waits, and refresh() asks once
the read has ended. With no read under way (it failed) a saved pairing is still the way, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 6 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 8 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b0f20e7 and c23a52e.

Files selected for processing: 3

  • docs/account-list.md
  • src/lib/relay/accountController.migrate.test.ts
  • src/lib/relay/accountController.ts
  • 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

@devswha devswha added the hold Not merged until the owner says so label Nov 25, 2026
@devswha

devswha commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Independent review standing in for CodeRabbit (rate limited on this PR)

A reviewer who was given the code and not the author's conclusions read this branch and tried to break it. Verdict: clear, with three notes that go to a follow-up. The hold is removed.

NOTE M1. CONCERN, not proved. SignedInSessions (server/relay/admissions.ts:27, 61-67) keeps 4 chosen sessions
per device id, and a new one closes that device's oldest. The asker opens through the account with the same sign-in
key the app's own account session uses (or the same saved pairing), and its witness fetch makes it "chosen". So with
4 sessions of this device already at that PC (several tabs), an ask closes the oldest, possibly the page's own app
session. It needs 4 or more, so it is rare. No take-over and no focus: the ask is one GET /api/account/list/witness
over its own transport, closed in finally.

NOTE M2. TRACED. Neither invalidate() (accountController.ts:580) nor sign-out clears shownFor or askTimer.
After a sign-out the timer stops only once the list's round publishes OFF (accountList.ts:1534, 1659; sign-out
pokes it). For that short window an ask can still go to the old account's PCs over saved pairings (openKey is null
because the epoch moved). Fix if wanted: clear askTimer in invalidate() and require
accountView?.kind === "signed-in" in askDuePcs.

NOTE M3. No test for dispose or sign-out stopping the timer, or for the hidden-page re-arm.

Questions checked (#4713)

  • Loop and bounds:
    • one asker at a time: askingPcs is set synchronously before the first await;
    • each PC once per askGap() = max(30 s, 10 min / pageScale) (:440);
    • one timer only: armAsk clears the old one, and its delay is at least the gap;
    • told comes from waitOf, which is at most about a day, so setTimeout cannot overflow;
    • a hidden page re-arms without asking (:409);
    • dispose sets disposed and clears the timer (:564-566);
    • each run reads the current shownFor, lists.view() and listedFor, so no closure is left holding an old sign-in.
  • Directory gate (:431): it returns only while this generation's read is still running. reading is cleared in
    finally whether the read succeeds or fails, and refresh then calls askPcs (:329). So the gate cannot stay
    closed unless the read itself hangs, and a hung read already blocks refresh today. After a failed read the asker
    falls back to saved pairings (openKey null), as before.
  • Who is carried and when: pcsToAsk, asksAgain, the planner and onPcSession are untouched. Only when and how
    often PCs are asked changes (and the account way is now used once the directory is read), so the move can start
    sooner. Who is carried is still the planner's call.
  • Against fix(relay, account): what a PC answers and logs, as the signed-list QA found it #4712: a PC that has not read this key answers the asker held/catching_up; that is caught and silent
    (:473). The ask also spends that PC's once-a-minute refused-sign-in read, at most once per PC per gap.

@devswha devswha removed the hold Not merged until the owner says so label Nov 25, 2026
@devswha

devswha commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Closed in favour of #4723, which merges this branch together with the other fixes the signed-list staging QA asked for. Nothing of this pull request was dropped: #4723 is main with these branches merged in. The reason is CI capacity: twelve separate runs and twelve merges, each waiting for Fast checks on a new base, had filled the self-hosted runners for every session.

The description, the tests and the review of this change stay here; #4723's table links back to it.

@devswha devswha closed this Nov 25, 2026
devswha added a commit that referenced this pull request Nov 25, 2026
…den page (#4713 review M2 red, M3)

M2 (red): a sign-out leaves the asker's clock running, so it can ask the old account's PCs over saved
pairings until the list's view says the sign-in is gone. M3: a dispose stops the clock; a hidden page
asks nothing, and a page shown again asks at once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
devswha added a commit that referenced this pull request Nov 25, 2026
… M2)

invalidate() (sign-out, a removal, another sign-in's read) now stops the asker's clock, and the asker
and its clock act only for a signed-in page: the list may still show the move until it reads that the
sign-in is gone, and meanwhile nothing goes to the old account's PCs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@devswha
devswha deleted the fix/move-reasks-pcs branch November 25, 2026 13:00
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