Skip to content

Keep and publish the agent profile when a drive is hosted on a node - #2575

Open
joepio wants to merge 3 commits into
developfrom
fix/profile-missing-after-restore
Open

joepio wants to merge 3 commits into
developfrom
fix/profile-missing-after-restore

Conversation

@joepio

@joepio joepio commented Nov 17, 2026

Copy link
Copy Markdown
Member

Requested by Joep · project thread

What was wrong

Found while walking real flows on a local stack (portal, managed node, Cloud Vault, mock billing).

  1. Device 1: sign up, type your name at "How your colleagues see you", turn on Cloud Server for the drive.
  2. Device 2: sign in, restore with the recovery code. The drive and its documents arrive and edits sync, but the account row says "Signed in" instead of the name.
  3. Later, device 1 lost the name as well: the Share dialog asked "How your colleagues see you" again, activity showed the raw agent id, and an invited collaborator saw no name either.

What the devices held: the node had an agent document with encryptionKey, publicKey, read, and no name (written by device 2's EncryptionKeyPublisher). Device 1 still had isLocalOnlySubject(agent) === true after its drive was hosted, so it never pushed its profile. Its local row ended up as a bare stub (isA, publicKey, read).

Causes and fixes (browser/lib/src/store.ts)

  1. A full snapshot from a node replaced the local document. Store.applyIncoming swapped the local Loro document for any full snapshot (WS GET, or UPDATE with the snapshot flag) whenever there were no unsaved changes. That includes the bare agent a node creates by itself, so a node holding a stub could replace a real profile and its history. Now a document with real history is merged into; only a placeholder or a history-less rebuild is replaced, the rule replayOnLocalBase already uses.
  2. Nothing carried the profile to a hosting node. Promoting a drive only lifted the drive's local-only registration; the agent stayed local-only for good. New Store.publishAgentProfile(): when the agent is still registered local-only while its personal drive is hosted, it unregisters the agent, fetches the node's copy so the histories merge, and saves the whole document. It runs on connect and from syncDriveToServerAndVerify, so accounts already in this state heal on their next session; on failure the agent is registered local-only again and it retries later.

Test coverage

No test connected a profile made on one device to a node-hosted drive and a second device, which is why this was invisible. Added integration tests (real Store, wasm database, real atomic-server):

  • agent-profile-publish.integration.test.ts: the profile is published when the drive is hosted on the node; a node that holds a name-less agent from another device is healed (both documents merge, key and name survive); a profile with history is kept when a full snapshot of a bare agent arrives. The first and third failed before the change.
  • vault-profile-restore.integration.test.ts and one test in wasm/tests/vault.rs: guard tests showing the Cloud Vault path does carry the profile (it did already; these pin it).

Results: browser/lib vitest 188 files / 1788 tests passed; the three integration files 13 passed; pnpm typecheck clean.

Verified by hand (Chromium, local stack with a managed node)

New account "Flow Five", Cloud Server turned on with mock billing: the node's agent resource has name: Flow Five. A fresh second device restoring with the recovery code shows "Flow Five" in the account row, and the first device still has the name in its local database.

Not covered

  • Devices whose local profile was already replaced by a stub cannot get the name back from this change alone; the person types it again once (it then publishes).
  • What exactly emptied device 1's row in the original run was not reproduced as a visible name loss in a test, only as history loss through the replace path.
  • One pre-existing failure in wasm/tests/vault.rs (a_current_state_checkpoint_is_smaller_and_restores) was seen before these changes and not looked into.
  • The comment in helpers/managed/cloudSync.ts saying managed nodes refuse a standalone agent profile looks out of date (the live managed node accepted it) and is left as is.

No UI changed, so no screenshots. The first commit on the branch is superseded by the second; please squash.

Checklist

  • Changelog entry (browser/CHANGELOG.md)
  • Tests added

A Cloud Vault restore writes the agent profile to the local database behind
the page's back. When the encryption-key publisher had already set a key on
the empty agent resource, reloading it skipped the stored copy because of the
unsaved edit, so the restored device never showed the person's name.

Adds integration tests for profile restore and a wasm export/import test.
A full snapshot from a node replaced a local resource that had history of its
own. For an agent the node made itself that wiped the name and picture and
left two documents that could no longer merge. Replace only placeholders and
docs rebuilt without history.

Also publish the agent profile that onboarding kept local-only once the
personal drive is hosted on a node: merge the node's copy, then push the whole
document. Runs on connect, so accounts already in that state heal.

Reverts the speculative hydrate merge for unsaved edits.
@joepio joepio self-assigned this Nov 17, 2026
@joepio
joepio marked this pull request as ready for review November 17, 2026 22:06
publishAgentProfile lifted the agent's local-only registration before it knew
the push would happen. When the profile was not loaded yet, or the identity
changed meanwhile, it returned with the registration gone, so nothing ever
tried again. Register it again unless the push succeeded.
@joepio

joepio commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

Self-review, read critically. Do not merge on the green checks alone: the checks that ran on this PR are the Flutter package jobs only. The browser suite does not run on PRs, so I dispatched main.yml on this branch: https://github.com/ontola/atomic-server/actions/runs/44200834345 (a later push needs a new dispatch).

Fixed in a follow-up commit (a79503e)

  • publishAgentProfile lifted the agent's local-only registration before it knew the push would happen. If the profile was not loaded yet, or the identity changed meanwhile, it returned with the registration gone and nothing ever retried. It is now registered again unless the push went through.

Open risk a reviewer should weigh

  • The applyIncoming change applies to every resource, not only agents. A full snapshot from a node used to replace the local Loro document whenever there were no unsaved changes; now it only replaces a placeholder or a history-less rebuild, and merges otherwise. The original comment gives the reason for replacing: merging a full snapshot into a doc that was seeded with partial state "can surface only the seed's props" (the class-less, "deeply broken drive" case). snapshot-replace.test.ts still passes, but in that test the seeded doc is still loading, so it does not prove the case where a partially seeded doc already has renderable content and is not marked history-less. If such a doc exists in practice, this change turns a replace into a merge for it. For documents that share history with the server a merge is equivalent; for two independently created documents with text or lists, a merge could duplicate content where a replace would not. I could not construct that case in a test, and I could not rule it out either. The full e2e run above is the evidence to wait for.
  • The visible name loss on the first device was observed on the live stack but only reproduced in a test as history loss through this replace path, not as the name disappearing. So this is the most likely cause, not a proven one.

Smaller notes

  • publishAgentProfile runs on every connect. It returns early unless the agent is registered local-only while its personal drive is hosted, so the cost is one map lookup plus one drive-subject derivation.
  • The profile is only pushed to the server that hosts the person's own personal drive, which is the same rule linkPrivateDrive follows for an agent that is not local-only.
  • The comment in helpers/managed/cloudSync.ts about managed nodes refusing a standalone agent profile is now wrong (the managed node accepts it) and should be updated by someone who knows why it was written.

This branch has not been deployed

No deployments
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