Skip to content

feat(backup): a full backup's contract part always fits what its import accepts - #2035

Merged
alejoamiras merged 2 commits into
devfrom
worktree-backup-fit-1
Nov 27, 2026
Merged

alejoamiras merged 2 commits into
devfrom
worktree-backup-fit-1

Conversation

@alejoamiras

@alejoamiras alejoamiras commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

The owner's pick of 2026-11-26:

The export never writes a contract part that its own import would refuse. Past the limit it leaves out contract code, the largest app contract first, until the part fits. It never leaves out a saved sender or a contract's entry, and code the wallet itself ships goes last. After a restore, a contract whose code was left out is listed in View errors with the existing "Contract artifact not found", and its app adds it again when it next registers it. … Nothing shows when the backup is made.

Owner sign-off

The owner's word in chat, 2026-11-27: "land 2035". On the restore commit: "Yes, keep the fix in this PR please." On the transaction history, which the fit leaves whole: "ok known issue", filed as #2036 (a full backup with tens of thousands of transactions is too large to create).

Match: head e054777df builds the pick quoted above. Its second commit makes a contract of a class the wallet ships, left without code, restore from the wallet's own copy, which the pick's restore sentence needs. No screen, word or layout changes.

The rule

  • Budget. A written contract part passes three checks. First, the import's cap, measured as the import measures it (JSON.stringify(part).length on the file's form of the part, after the import rewrites each network id to its seeded one). Second, the sealed file's limit. Third, the pretty file's limit. The page fetches the contract part after every other part and passes it what the rest of the file takes, so both file checks see the whole file.
  • Order. When the part is over budget, whole class-table entries go one at a time until it fits: classes an app registered first, then the classes the wallet itself ships (its catalog and its account class). Within each group the largest in the file goes first, and ties go by class id. The kept entries keep their order.
  • What stays. Every contract entry and every saved sender. A part already under budget is written as it is, byte for byte.
  • Where. One function beside the class-table encoder (fitAccountStatePart in account-state/normalize.ts), called once by the export. It sizes each class once and measures the final part once with the import's own measure. If the two disagree, or if the entries alone are over the import's cap, the export stops with an error. If the file still fails a file check with every class out, the page's existing "Backup is too large to create" refuses it.
  • Log. When code is left out, one warn line gives the count, the sizes and up to eight class names (Noir identifiers only), never an address.
  • Restore. A contract of a class the wallet ships, whose code the file leaves out, restores from the wallet's own copy: the restore takes that copy in the wire form a file's artifacts have, so its class-id check reads it. A contract of an app's class whose code was left out reads "Contract artifact not found" in View errors, and registers again when its app next registers it. A registration without a key spends none of the app's registration allowance.

No stored shape changes.

UI impact: none. No screen, word or layout changes.

Tests

  • Unit (normalize-fit.test.ts): a part under budget is returned as the same object; at the budget and one code unit over; the order (app before wallet, largest first, ties by class id, kept entries in table order); entries and senders untouched; the file's form of the code (real Buffer bytecode, real Fr class ids, the production sanitizer); the UTF-8 and pretty budgets; the network-id rewrite; every class must go; idempotent; a bound on the serializations over 2,000 classes; the refusals.
  • Unit: the page passes the contract part's client what the rest of the file takes, and the messaging client forwards it; the file-size helpers.
  • Restore tests: the wallet's own copy of a class, as the PXE client returns it, registers; the artifact schema stand-in refuses a value already parsed, as the real one does.
  • Composition (backup-fit.composition.test.ts): the real export, file assembly, network rewrite and chain-sync tail, then a fresh profile's restore. The largest app code is left out, every entry and sender restores, and the left-out contracts read the existing error. With every class out, the wallet's own contracts restore from its catalog.
  • e2e, proverless, retry 0, the affected specs plus the evidence spec:
    • Chrome: 11 network specs and the evidence spec, 40 of 40 passed (27 min). 7 smoke specs, 29 passed and 7 skipped (toolbar-panel runs on Firefox only).
    • Firefox: 37 passed and 3 skipped (backup-restore-sw-restart runs on Chrome only) (34 min). Smoke, 36 of 36 passed.
    • Network specs: backup-restore-integrity, restore-again, backup-migration-roundtrip, backup-import-stalled-network, backup-edited-local-network, import-handshake-note, import-handshake-note-matrix, account-balance-orphans, same-token-concurrent-sends, backup-restore-sw-restart, profile-reimport-matrix.
    • Smoke specs: backup-roundtrip, backup-imported-account, security-backup, passkey-backup, passkey-retry, legal-acceptance, toolbar-panel.
    • No e2e scenario is added.

Evidence (scratch spec, not committed; proverless, retry 0)

The base build is dev at 8a90f146f with the same e2e flags. The e2e and evidence ran on these two commits on top of 8a90f146f. The rebase onto 6d722c105 adds only #2033 (where the PXE route snapshot schema lives), and every local gate (lint, typecheck:all, test, audit:vue, test:ci-gating, Storybook) passed after it. In E2 this build's export runs right after an in-place update and an unlock, so its time includes that cold start. Fitting a 6.36M part that already fits takes 0.35 to 0.6 s in a unit run.

Row What it shows Chrome Firefox
E1 A build with the import's cap lowered to 5,500,000 code units. Its export leaves out the app's Crowdfunding code, then the wallet's 3.6M Token code, and writes a 2.54M part. A fresh profile on that build imports the file. Every sender comes back, and every entry but the Crowdfunding contract registers again. The wallet's Token contract restores from its own copy. The Crowdfunding contract reads "Contract artifact not found", the playground registers it again, and its delegated sendTx returns a tx hash. pass. Export 4.2 s, import 13.9 s, call 13.2 s pass. Export 7.6 s, import 21.8 s, call 20.7 s
E2 One profile, the base build then this build swapped in place: both write the same contract part, byte for byte (6,364,903 code units). pass. Base export 4.6 s, this build 7.7 s pass. Base export 7.1 s, this build 15.0 s
E3 The base build's file imports on this build with no errors and every registration back. pass. 14.5 s pass. 21.1 s

🤖 Generated with Claude Code

alejoamiras and others added 2 commits November 26, 2026 22:39
…rt accepts

The export writes the account-state part so that the import's part cap
and both file checks (the sealed text and the pretty text) accept it.
Past that size it leaves out whole class-table entries: app classes
first, then the wallet's own, each largest in the file first, ties by
class id. Every network item, contract entry and saved sender stays, and
a part that already fits is written unchanged.

- `fitAccountStatePart` sits beside `encodeAccountState` and is called
  once by `AccountStateService.backup()`. It sizes each class once in
  the wire form the file carries, and measures the final part once with
  `accountStatePartCodeUnits`, the measure the import's cap reads.
- The page fetches the account-state part last and passes what the rest
  of the file takes (`BackupFileRest`); `MAX_SEALABLE_TEXT_BYTES` is the
  compact text a sealed file can hold. `ServiceClient.backup` forwards
  its arguments as `restore` does.
- One warn line names the classes left out and their sizes, never an
  address.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…own copy of its class

The restore takes the wallet's own copy of a class in the wire form a file's artifacts have, so its
class-id check parses it once and a contract of a class the wallet ships registers from that copy.
The restore tests' artifact schema now refuses a value already parsed, as the real one does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Extension preview build — e054777

Version 1.3.0-pr.2035 · workflow run · artifacts expire after 7 days.

Load it
  1. Download and unzip (GitHub wraps the dist/ folder in a zip).
  2. Chrome: chrome://extensions → Developer mode → Load unpacked → pick the unzipped folder.
    Firefox: about:debugging#/runtime/this-firefox → Load Temporary Add-on… → pick manifest.json.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
nulo-landing e054777 Commit Preview URL

Branch Preview URL
Nov 26 2026, 10:51 PM

@alejoamiras
alejoamiras merged commit 7571c77 into dev Nov 27, 2026
66 checks passed
@alejoamiras
alejoamiras deleted the worktree-backup-fit-1 branch November 27, 2026 14:32
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