Skip to content

fix(server): announce the boot auth state after the initial session restore - #571

Open
johnthecat wants to merge 4 commits into
mainfrom
fix/announce-boot-auth-state
Open

fix(server): announce the boot auth state after the initial session restore#571
johnthecat wants to merge 4 commits into
mainfrom
fix/announce-boot-auth-state

Conversation

@johnthecat

Copy link
Copy Markdown
Contributor

Problem

A pairing host boots with no answer on the auth callback when there is nothing to restore. The core restores the persisted session on its own at boot, but a signed-out boot is a no-op transition and emits nothing, so a host cannot tell "still restoring" from "signed out". polkadot-desktop worked around it by guessing Disconnected after a timeout, which flashed onboarding at paired users and burned a pairing on every cold start (paritytech/polkadot-desktop#848).

Solution

The boot tick of the session-store sync announces its outcome once it has reconciled, Disconnected included. The auth callback therefore always opens with the real boot state: Connected for a restored session, Disconnected otherwise, with nothing emitted before it. Explicit activateStoredSession keeps its behaviour and never double-emits.

Docs for AuthPresenter, the native HostCallbacks, and the @parity/truapi-host README describe the contract; the codegen golden is regenerated accordingly. Tests cover the signed-out boot, the restored boot, and the invalid-blob boot.

…estore

The session-store sync's boot tick now calls announce_current after
reconciling, so a pairing host receives an opening AuthState
(Disconnected included) without calling activateStoredSession.
@johnthecat
johnthecat requested a review from a team September 2, 2026 08:47
cleared_after_read_error = true;
}
}
pairing_host.auth_state.announce_current();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is right, but the reason it is right is invisible here. The call sits in the loop so it looks like every tick announces; what makes it boot only is that announce_current returns early once announced is set, and transition sets that flag on any real emission.

The old test asserted a tick finding nothing emits nothing, and its comment said a tick that finds nothing must not flash signed out at a signed-in host. That invariant still holds, but the assertion is gone and nothing replaces it. All three new tests cover boot. If someone later moves this line or drops the announced guard, the suite stays green and we get the polkadot-desktop bug back.

Can we add a test that signs in, ticks the notifier with nothing changed, and asserts no extra emission. A one line comment here pointing at the one shot guarantee would help too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and the guard-dependent placement was the real problem. Restructured in f2471e5: the notifier no longer injects a boot tick, the task reconciles once at boot and announces there, and the change loop only reconciles. A change tick can no longer announce, so the one-shot behavior is in the control flow rather than in the announced flag. Added session_store_sync_stays_silent_on_an_unchanged_tick, which signs in through the store, fires a notification against the unchanged blob, and asserts no extra emission.

…store sync task

The notifier no longer injects a synthetic initial tick. The sync task
reconciles once at boot, announces the outcome, and then loops over real
change notifications without announcing, so the one-shot opening state is
visible in the control flow instead of depending on the announced guard.
Adds a test that a change tick against an unchanged store stays silent.
The spawned task upgrades its weak reference when it first runs and bails
if the runtime is already gone, so a pending boot reconcile never keeps a
dropped runtime alive or emits to its platform.
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.

2 participants