Skip to content

Test that a notepad started over in NOTE never costs a file - #4

Merged
kualta merged 1 commit into
mainfrom
replaced-vault
Nov 23, 2026
Merged

kualta merged 1 commit into
mainfrom
replaced-vault

Conversation

@kualta

@kualta kualta commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Summary

NOTE is gaining "Start a new notepad": a signed-in owner whose passkey can't open the current notepad publishes a brand-new vault (new vault id, new key, epoch 1, only that passkey listed, a signed create) over the existing vault record, compare-and-swap against the record it read, removes the old notepad's blobs and revokes every device token. A linked Obsidian vault must survive that without losing a file. These tests prove it does, with no code change needed.

Test-only: tests/e2e.test.ts gains a a notepad started over in NOTE block, driving the real device client and SyncController against seal's in-memory Flow ID. tests/start-over.ts builds the replacement from seal's internal/* modules, the way the kit's own adminBrowser builds the first vault (the kit can only create a vault where none exists), so no seal release is needed.

What the tests show

For each order, start over alone, revoke alone, start over, then revoke and revoke, then start over, with the vault both syncing and closed (14 files, more than the mass-deletion threshold, plus an edit and a new file made after the start-over):

  • The vault stops in the removed phase with the notice This vault was removed from your NOTE notepad's access. Link it again to keep syncing. when only the record changed, or Flow ID unlinked this vault. Link it again to keep syncing. once the token is revoked. A restart afterwards finds no link (unlinked).
  • Every file stays byte for byte, nothing is trashed, and no mass-deletion prompt is ever raised.
  • The seed and tokens are wiped and the pin kept; the device writes nothing to the PDS after the start-over (the record is the one NOTE left, no Flow ID rule violations), and the new notepad stays empty.
  • The old notepad's blobs disappearing before the record is replaced only pauses syncing (the status leaves Synced); nothing is deleted, and the later replacement stops it as above.
  • Linking the same vault again to the new notepad pushes every file into it and deletes nothing locally, and a second vault linked to the new notepad receives every file, the attachment included.

Why it is safe

  • A running device verifies the root with the key it holds before reading any entry. The new root doesn't decrypt under it, so the transport stops with VaultAccessError and the runtime locks (SYNC_LOCKED). The controller closes the engine before the session's key is wiped and reopens, and the reopen finds no access slot for this seed (or a refused token) and calls onRemoved, which wipes keys, the device database and every sync index, never a file.
  • The sync session only applies entries a verified root carries, and the new notepad has none, so it never sees deletions.
  • The sync index is per device and per vault id, and a new link deletes them all first, so a relink plans against an empty base. A plan with no entries can only push files; delete-local needs an entry.
  • Mutation check: keying the index by account only and keeping indexes across a link makes the relink test fail with every file trashed.

Testing

  • bun run lint, bun run lint:obsidian (no errors; the 13 warnings predate this change), bun run typecheck, bun test (105 pass), bun run build, bun run smoke
  • The new block ran 3 more times in a row, 10/10 each

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T16:56:20.096579Z 7ab32af PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7ab32af854

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/e2e.test.ts
Comment on lines +571 to +572
fresh = await startOver(note);
dropBlobs();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Capture old blob refs before replacing the record

In every apply-based start-over scenario, startOver(note) replaces the record before dropBlobs() examines note.record(). Because the replacement is an empty notepad, the old attachment CIDs are no longer available to add to gone, so these cases do not simulate the specified replacement-then-blob-deletion sequence and could miss a device attempting to download an old attachment during that window. Capture the old record's blob refs before replacement, then mark those refs unavailable afterward.

Useful? React with 👍 / 👎.

@kualta
kualta merged commit 62b9d52 into main Nov 23, 2026
1 check passed
@kualta
kualta deleted the replaced-vault branch November 23, 2026 17:59
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