Skip to content

feat(e2ee): checkpoint joins in core (5B) - #3891

Open
zxch3n wants to merge 12 commits into
mainfrom
feat/e2ee-5b-checkpoint-join
Open

zxch3n wants to merge 12 commits into
mainfrom
feat/e2ee-5b-checkpoint-join

Conversation

@zxch3n

@zxch3n zxch3n commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Phase 5B: checkpoint joins in core, the client network and the lab reference gateway (checkpoint joins, formats-v1 §4.7, §6–8). Entry paths are untouched (5C). snapshot/v1 and head-attest/v1 stay until 5C/4G (retirement list below).

Interface for 5C

Anchors (@lody/e2ee-core/protocol, JoinAnchor) — each entry path builds one from what it authenticated out of band:

Entry path Anchor
Remote / same-machine pairing, member link, email over-budget recovery { kind: 'checkpoint', genesis, position: 129·k, checkpointHash } (position 0 joins from genesis)
Account pairing { kind: 'admission', genesis, admissionRecordHash } + admissionPositionHint (untrusted locator)
Email invitation first use { kind: 'first-use', genesis } (server's latest checkpoint, 32 MiB budget; suffix feed ≤ 128 records / 8 MiB)
Recovery device R, audit { kind: 'genesis', genesis } (replays from genesis through the paged feed)

Workflows (@lody/e2ee-core):

  • joinFromAnchor(anchor, { admissionPositionHint? }) returns { origin, view } and requires the LedgerJoinSource port.
    • origin is a LedgerFeedOrigin (genesis or the new checkpoint kind) to keep and pass to LedgerFeed.layer({ origin }) on every open; it is re-verified each time. The feed then catches up from origin.checkpoint.offset in pages.
    • view is at the anchor; for admission it is at the admission record. 5C still checks that this record admits its own key bundle.
  • rejoinFromAnchor(genesis, joinAnchorOf(view)) rebuilds a checkpoint origin from the retained join anchor after a local storage format change, instead of replaying from genesis.

Pure protocol (@lody/e2ee-core/protocol):

  • verifyCheckpointJoin(input) authenticates the checkpoint record by any one of: an out-of-band checkpointHash, a retained anchorState, or nothing (first use). It then decodes the v7 snapshot under the budget with the checkpoint's stateDigest, restores the state at p − 1, and verifies the checkpoint record forward: signature, parent and recomputed digest.
  • authenticateBackwardChain authenticates positions before an anchor. verifyCheckpointJoin's optional preAnchor retains them, including hashes and epoch publications.
  • resolveAdmissionAnchor walks from an admission record back to the nearest checkpoint.
  • joinAnchorOf(view) returns the anchor a view joined from, or null for a full-history view.

Ports and adapters:

  • LedgerJoinSource (@lody/e2ee-core/services):
    • readRecords(fromIndex, limit ≤ 129) → { records, tip, nextOffset }
    • readSnapshot(stateDigest, budget) → bytes
  • The client implementation is network.ledger(credential).join (@lody/client-e2ee/network). Its readSnapshot needs the new snapshotRoutes: { origin, sessionToken, fetch? } option on makePersonalCloudNetwork. 5C must wire it (deployment HTTP origin + session-token getter); without it readSnapshot fails closed.
  • The lab provides labJoinSource.

Changes

  • core:
    • checkpoint-join.ts: join verification, backward chains, admission resolution and join anchors.
    • join.ts: joinFromAnchor / rejoinFromAnchor over the LedgerJoinSource port.
    • LedgerFeed gains a checkpoint origin, verified with verifyCheckpointJoin on every open.
    • Download budgets come from W0's snapshotDownloadBudget ((p + 1) · 4,096 B) and EMAIL_FIRST_USE_SNAPSHOT_BUDGET_BYTES.
    • No change to policy, replay, state-v7 or snapshot-codec (feat(e2ee): cloud-machine registry in the v1 base ledger (tags 14–16) #3859); the join view is built from their existing exports (restore + extendLedger).
  • client-e2ee (network.ts):
    • The account-session fallback after e2ee_device_revoked is removed: a credential read fails with that refusal and is never re-read under the account login (AGENTS.md updated).
    • Every history read uses the new paging mode: limit, then fromIndex or after on the first page, and only cursor + limit on continuations (no checkpoint). Pages carry ≤ 129 records, and the 64-record and 16,384-length caps are lifted. The whole-history helper keeps its 32 MiB in-memory bound.
    • The LedgerJoinSource implementation reads snapshots through W0's streaming snapshot-reader.
  • e2ee-lab reference gateway:
    • The control gateway builds and stores buildSnapshotArchive (SQLite, keyed by genesis and stateDigest) before accepting a tag 13 append; a failure refuses the append.
    • The host serves the cloud-api snapshot routes:
      • raw bytes, exact Content-Length, CORS
      • 404 when absent, JSON { code } refusals
      • recovery devices refused
      • a revoked device served only checkpoints strictly before its invalidating record
    • labJoinSource and a LedgerFeed checkpoint origin in ledger-client.
    • The lab's history is the Durable Streams control stream, so new-mode history paging and its revocation cutoff are not implemented in the lab (the private backend #4610 implements them).
    • @lody/cloud-api is now a lab runtime dependency (lockfile updated for that entry only).

Retirement list (5C per entry path; 4G removes the core APIs)

  • e2ee-client:
    • src/ledger.ts (verifyLedgerSnapshot, snapshotTrustFromView, snapshot feed origin)
    • src/pairing.ts and src/session.ts (signLedgerSnapshot, head signatures in invitations)
    • tests: pairing, host, owned-host, ledger-control, browser host-fixture
  • Electron: e2ee-personal-pairing.mts (signLedgerSnapshot, head signature) and e2ee-runtime-part-2.test.mjs.
  • e2ee-lab:
    • invitation-wire.ts, snapshot-cache.ts, workspace-session.ts and the snapshot feed origin in ledger-client.ts
    • tests: full-session, ledger-client, recovery-vault, snapshot-cache-reopen
  • Tests elsewhere: components e2ee-ledger-verification.test.ts, mobile mobile-host.test.ts, client-e2ee open-content-perf.test.ts.
  • core (4G):
    • the snapshot/v1 / head-attest/v1 APIs: signLedgerSnapshot, verifyLedgerSnapshot, prepareLedgerSnapshot, snapshotTrustFromView, authenticateLedgerSnapshotEvidence, SnapshotTrust / SnapshotFeedOrigin and the snapshot feed origin
    • internal/workspace/invitation.ts
    • their docs

Tests

  • New core tests (test/ledger/checkpoint-join.test.ts, 11), against the independent ledger v2 vector:
    • a join at checkpoint 129 equals full replay in head, length and state digest
    • a wrong anchor, snapshot, position or budget is refused
    • first use, the pre-anchor backward chain and admission resolution
    • a LedgerFeed checkpoint origin open/reopen
    • joinFromAnchor for every anchor kind with its budgets, and rejoinFromAnchor
  • Lab end-to-end test/checkpoint-join.test.ts:
    • the host stores the archive before the 129 checkpoint, and a failed store refuses the append
    • a new device joins at 129 over the lab routes and its feed catches up to 133
    • R is refused, a pre-checkpoint revoked device gets e2ee_device_revoked, a tampered chunk is refused, and an absent snapshot is 404
  • The mobile revoked-phone test now serves the revoked credential its history up to the revocation and asserts no account-session read.
  • After merging main (including feat(e2ee): cloud-machine registry in the v1 base ledger (tags 14–16) #3859):
    • e2ee-core 875 (+1 skipped)
    • e2ee-lab 145
    • client-e2ee 195
    • e2ee-client 105 (browser 85 before the merge)
    • mobile-capacitor e2ee 142
  • Before the merge:
    • Electron run-tests.mjs 668/0
    • CLI e2ee/rpc/session-execution-service/roost 1088 (+2 skipped)
    • components e2ee 402
  • Typecheck clean in every affected package; comment ratchet, oxfmt and boundary checks pass. The CLI's two acp-extension module errors are the temp worktree's missing submodule builds.

🤖 Generated with Claude Code

@zxch3n
zxch3n marked this pull request as ready for review December 5, 2026 11:06
zxch3n and others added 4 commits December 5, 2026 11:15
- P0 lab: truncate control-stream reads at the revoked device's first invalidating
  record on the gateway side (stream-read.ts)
- P0 lab: require workspace-bound credential (genesis !== null) on snapshot routes
- P1 client: raise personal refresh and admission page-size caps from 64 to 129
- P1 core: rebuild checkpoint-origin feeds from the checkpoint anchor offset instead
  of genesis (-1), and preserve verified admission suffix in CheckpointFeedOrigin
- P1 core: verify anchorState head/stateDigest/parentPosition before downloading snapshot
- P1 client-e2ee: reuse SnapshotDownload across retries so consumed budget is never refunded
- P1 core: propagate email first-use suffix limit (128 records / 8 MiB) into LedgerFeed
  and enforce it before copying/verifying records
- P1 client-e2ee: retain nextCursor on feed catch-up and send cursor alone on continuations
- P1 core: allow retained-state v7 CBOR codec to scale to the authenticated snapshot budget
  above 64 MiB (aligned with formats-v1 §8.1 unbounded ledger CBOR subset)

Model: Gemini 4 Neon
…nd paging

Address Astra's round-2 review findings on #3891:
- Verify and truncate prior control stream responses against the verified readable prefix on mid-flight revocation; stream chunk-by-chunk up to cutoff without buffering > 16 MiB
- Enforce feed/state byte and record budgets before allocating or copying in CBOR, state-v7, and LedgerFeed; replace MAX_SAFE_INTEGER export cap
- Align LedgerFeed, SQLite, and IndexedDB origin caps to persist and reopen > 64 MiB snapshots across restart
- Align personal client ingestLedgerRecords paging to 129 records/page and drop legacy 16384 checkpoint length cap
- Preserve caller checkpoint anchor on corrupt-suffix rebuild and preserve verified genesis admission suffix in joinFromAnchor
- Coalesce concurrent snapshot downloads per digest and free buffered chunks on budget exhaustion
- Tighten network readAfter limit by remaining maxRecords, stream join-source windows without retaining full history, and preserve continuation cursor on retry

Model: Gemini 4 Neon

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant