Skip to content

refactor(network): the route snapshot schema has one home, in a leaf entry - #2033

Merged
alejoamiras merged 1 commit into
devfrom
quality-lows-c-a2
Nov 26, 2026
Merged

alejoamiras merged 1 commit into
devfrom
quality-lows-c-a2

Conversation

@alejoamiras

Copy link
Copy Markdown
Contributor

What changed

The route snapshot half of #1976; the proving-backend half shipped in #1989.

RouteSnapshotSchema existed twice, in packages/aztec-runtime/src/pxe/schemas.ts (the PXE client's parse) and in apps/extension/src/wallet/services/network/spec.ts (the network service's RPC result). Each value list was tied to its type by as const satisfies readonly T[], which accepts a narrower list, so widening EndpointState or TransportFailure compiled while both copies refused the new value. #1989 could not import the schema from the @nulo/aztec-runtime/pxe barrel: the popup reaches network/spec.ts, and that import put the PXE and its kernel artifacts in the popup's graph.

  • One home in a leaf entry. packages/aztec-runtime/src/pxe/route-snapshot.ts, exported as @nulo/aztec-runtime/pxe/route-snapshot, holds the lists and the schema and imports only zod and types. pxe/schemas.ts re-exports it, so the client and its test keep their import. network/spec.ts imports it from the leaf, and its copy goes. Nothing imported the schema from network/spec.ts.
  • The schema is unannotated, so its inferred type is exact. route-snapshot.test.ts pins z.output<typeof RouteSnapshotSchema> to RouteSnapshot | null with expectTypeOf. A state or failure that only one side lists is now a compile error in bun run typecheck:all.
  • The comment at network/spec.ts's type-only barrel import now says why values come from leaf entries. packages/aztec-runtime/README.md names the entry.

Proofs

  • Premise, at base 93394e1e7. With EndpointState widened by "stale", tsc --noEmit in packages/aztec-runtime and vue-tsc --noEmit in apps/extension both exit 0, and both schemas refuse state: "stale" while accepting "ready".

  • Fix, at this head. Widening EndpointState ("stale") or TransportFailure ("throttled") makes aztec-runtime's tsc --noEmit fail at route-snapshot.test.ts (TS2344). Unwidened, it passes. At run time, pxe/schemas.ts's export and NetworkMethodSchemas.getRouteSnapshot.result are the leaf's schema object.

  • The popup's graph does not grow. Measured on the Chrome build: the module scripts in dist/chrome/src/popup/index.html, and the bytes of their files.

    module scripts bytes
    base 93394e1e7 177 4,017,361
    head 177 4,017,559

    The chunk names are the same, content hashes aside, except for one shared chunk, now named route-snapshot instead of rpc-url.

  • Stored shapes. The route snapshot is not a stored shape. stored-shapes/snapshot.test.ts passes with no new stamp.

  • Layering. Extension → aztec-runtime is allowed by biome.json's noRestrictedImports. The leaf imports nothing from another workspace.

  • Review. One Codex pass (gpt-6.1-sol, high, read-only) over the diff. It was asked whether the popup's graph grows, whether a schema accepts or refuses anything new, whether a layer is crossed and whether the type test can pass vacuously. Verdict: approve, no findings. It compared both base schemas with the head schema on 27 boundary cases, and they agreed on every one.

Validation

At this head, 81556e22a (rebased on dev after #2032), retry 0, one at a time: bun run lint, bun run typecheck:all, bun run test (1067 files passed), bun run test:ci-gating (784 pass). Before the rebase, at the same change: both Chrome builds above and bun run --cwd apps/extension build-storybook, all exit 0. No local e2e, since no behaviour changes. The e2e lanes in CI are the gate of record.

No visible change.

Closes #1976

🤖 Generated with Claude Code

…entry

`RouteSnapshotSchema` lived twice, in `pxe/schemas.ts` and in the network
spec, each value list tied to its type by a `satisfies` that accepts a
narrower list. Widening `EndpointState` or `TransportFailure` compiled
while both copies refused the new value. The schema now lives in
`@nulo/aztec-runtime/pxe/route-snapshot`, an entry that imports only zod
and types, so the popup's network spec reads it without the `pxe` barrel.
It is unannotated, and a type test pins its output to
`RouteSnapshot | null`, so a value only one side lists no longer compiles.

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

Copy link
Copy Markdown

Extension preview build — 81556e2

Version 1.3.0-pr.2033 · 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.

@alejoamiras
alejoamiras merged commit 6d722c1 into dev Nov 26, 2026
65 checks passed
@alejoamiras
alejoamiras deleted the quality-lows-c-a2 branch November 26, 2026 20:41
alejoamiras added a commit that referenced this pull request Nov 27, 2026
…rt accepts (#2035)

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](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

Value lists are copied beside their owning type, so a new value compiles and fails at run time

1 participant