Repository navigation
id: hosted export production — DO enumeration and R2 blobs into build_export (slice 4b of #2852) - #13212
Conversation
…_export (slice 4b of #2852, #13157) Production half of the §6 export: the hosted data plane now produces the object/blob sets build_export assembles. - hosted-worker/src/export.ts: produceExportSets maps a per-user DO's applied events (BridgeStore.appliedEvents) and the R2 blobs they cite into the §6 sets, in canonical order, with counts and the concatenated-hash digest. A referenced blob R2 cannot produce, or a citation no referenced blob satisfies, fails the export loudly naming the hash. - GET /v1/bridge/export on the DO, ID-key proof like the other bridge HTTPS legs (new "export" auth context). Pure read: available from a read-only, at-cap store. - SignedEvent exposes the envelope signature (parsed already, never surfaced before). Object-model mapping (§6.3 in the spec doc): export bytes are the stored envelope verbatim — never re-encoded, never re-signed; the export hash is SHA-256 of the envelope bytes; signer and signature are the envelope's author and its own signature. hosted_export.rs follows: ExportObject::from_envelope + cited_content_hashes replace the synthetic sign-over-hash constructor, and verify_import step 3 verifies an object by decoding its envelope as chain.rs does. Document citations (BLAKE3, native) resolve to the export's SHA-256 blob names by content. Defect found by the rebind-history acceptance case and fixed at the root: HostedBindingService::verify_key_signature required the ceremony transcript's key to be the record's current key, so no post-rebind record could ever verify. The transcript's key is now required to be the current key or a history key; the current shape stays covered by the service attestation. Cross-language contract: the worker suite seeds a DO from a fixed seed key and pins the produced sets to test/fixtures/hosted-export-sets.json; the Rust suite feeds the same fixture through build_export + verify_import.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 57 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b7cdcf8e1c
ℹ️ 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".
| if hex_encode(event.header.verifying_key.as_bytes()) != object.signer | ||
| || !chain_keys.contains(&object.signer.as_str()) | ||
| || hex_encode(&event.header.signature.to_bytes()) != object.signature |
There was a problem hiding this comment.
Make multi-author bridge exports importable
When a bridge store contains events authored by other users, the new producer exports those events verbatim, but this check rejects the resulting archive with ObjectSignatureInvalid because their authors are not in the exporting user's binding history. This is a supported bridge scenario: hosted-worker/test/bridge-session.test.ts:151–172 authenticates with one bound key while synchronizing Alice's and Bob's separately authored chains. Reconcile the import authorization policy with the producer's complete applied-event set so normal collaborative stores can be exported and restored without discarding other authors' objects.
Useful? React with 👍 / 👎.
| blob_refs: o.blob_refs, | ||
| bytes: [...o.bytes], | ||
| })), | ||
| blobs: sets.blobs.map((b) => ({ hash: b.hash, bytes: [...b.bytes] })), |
There was a problem hiding this comment.
Stream blob bytes instead of expanding the whole export in memory
For stores containing moderately large blobs, this expands every buffered blob into a JavaScript number array before user-do.ts additionally stringifies the entire response. The Worker/DO has a 128 MB isolate memory budget, while blob uploads permit up to 100 MiB and aggregate storage is uncapped by default; even a single blob well below the upload limit can exhaust memory during this conversion. Consequently, valid populated stores cannot export their data, including capped stores for which export is explicitly intended to remain available. Use bounded streaming or chunked export rather than retaining the complete binary, numeric-array, and JSON representations simultaneously.
Useful? React with 👍 / 👎.
| const irohHex = this.requireIroh(req); | ||
| const store = await this.bridgeProof(req, bindingId, irohHex, "export", new Uint8Array(0)); |
There was a problem hiding this comment.
Provide an export production path for users who lost their key
During a lost-key rebind wait, an authenticated account holder cannot satisfy this proof because it requires the unavailable current Iroh private key. However, §6.1 of doc/2026-10-30T22-45-00Z_design_hosted_provisioning_sso_binding.md explicitly promises export in that situation using a service-signed unkeyed_export manifest, which build_export(..., None, ...) already supports. Searching for produceExportSets, appliedEvents, and export routes shows this is the only production path that enumerates the signed objects; the existing /v1/export returns only KV data and blob metadata. Add a separately service-authenticated production path so the binding service can obtain the complete sets without requiring the lost key.
Useful? React with 👍 / 👎.
| const document = mapGet(ext, "document"); | ||
| if (document === undefined) return []; |
There was a problem hiding this comment.
Include blob citations from notes and chat messages
When content is referenced only by a note or a chat attachment, this early return silently treats it as unreferenced and excludes its bytes from the export. The existing native model also carries blob citations in NoteOp::Create and NoteOp::Revise through their content: DocumentRef fields (crates/id-store/src/notes.rs:41–55), and in chat links with ChatLinkKind::Blob (crates/id-store/src/chat.rs:68–95). A read-only reproduction with a signed note.create and its uploaded content produces one object but zero blobs and empty blob_refs, so restoring the archive loses the note's content despite a successful export. Enumerate all supported blob-carrying payload variants in both this helper and the Rust counterpart.
Useful? React with 👍 / 👎.
| * of it, so neither is enumerated here. */ | ||
| appliedEvents(): HeldEvent[] { | ||
| return this.sql | ||
| .exec("SELECT author, seq, id, bytes FROM bridge_events ORDER BY author, seq") |
There was a problem hiding this comment.
Restrict exported events to the applied chain prefix
When a fork is discovered after one branch has already been stored, refreshAuthor() reduces the applied frontier to the fork sequence but retains the branch's rows in bridge_events. This unfiltered query therefore exports events that are no longer applied, while the exporter deliberately omits the competing fork-proof header. In an in-memory reproduction, ingesting e0,a1 followed by conflicting b1 leaves the chain frozen with next_seq: 1, but appliedEvents() returns sequences [0,1]. Restoring that export can reactivate the known-forked branch and its suffix. Filter the enumeration against each author's applied frontier rather than exporting every retained row.
Useful? React with 👍 / 👎.
Conflicts: hosted_export.rs module doc (both slices rewrote the not-here note) — kept the production section, pointing ingest at hosted_ingest. Semantic: #13158's hosted_ingest tests built objects with the synthetic ExportObject::new, which the section 6.3 mapping removes — migrated to ExportObject::from_envelope. Its not-an-event test's premise (a wrapper-valid non-event object) is exactly what 6.3 overturns, so the test now asserts the refusal at verify_import (ObjectSignatureInvalid) instead of at ingest.
Slice 4b (production half) of #2852: produce a real §6 export from a live hosted per-user store. Design + mapping record: the design comment on #13157; the mapping is also recorded in the spec as §6.3.
Data plane (hosted-worker)
src/export.ts:produceExportSetsenumerates the DO's applied events (BridgeStore.appliedEvents()) and fetches the R2 blobs they cite, producing the §6 object/blob sets in canonical (hash) order with counts and the concatenated-hash digest. A referenced blob R2 cannot produce — or a citation no referenced blob satisfies — fails production loudly, naming the hash.GET /v1/bridge/export, ID-key proof like the other bridge HTTPS legs (new"export"auth context). Pure read: available from a read-only, at-cap store.SignedEventnow exposes the envelope signature it already parsed.Object-model mapping (§6.3)
hosted_export.rs:ExportObject::from_envelope+cited_content_hashesreplace the synthetic sign-over-hash constructor;verify_importstep 3 verifies an object by decoding its envelope exactly aschain.rsdoes. Document citations (BLAKE3, native) resolve to the export's SHA-256 blob names by content.Defect found by the rebind-history acceptance case, fixed at the root
HostedBindingService::verify_key_signaturerequired the ceremony transcript's key to be the record's current key, so no post-rebind record could ever verify — a rebind-history export was impossible. The transcript's key must now be the current key or ahistorykey; the record's current shape stays covered by the service attestation (checked alongside in §6.2 step 2).Verification (reference laptop; the dispatch container cannot run this suite — no Node.js and the #13159 nix gaps — so per the dispatch-first fallback the verifying route is local, recorded here)
cargo test -p id --lib— 531 passed, 0 failed (includes 13 hosted_export tests: the reworked 4a set on real envelopes, the fixture contract, the rebind-history export; and all hosted_binding tests).npm test— 121 passed, 0 failed, including 5 new export tests (seeded DO → sets; at-cap availability; both loud-failure legs; proof fail-closed).test/fixtures/hosted-export-sets.json(seed key[7;32]); the Rust suite feeds the same fixture throughbuild_export+verify_import— counts 4/2 and the digest match.cargo fmtclean on the touched Rust files (three test files carry pre-existing fmt drift on main, left untouched). Clippy: no findings in the touched files beyond warn-level pedantic notes; the workspace's clippy run stops earlier on pre-existingexpect()errors incrates/id-store/src/admission.rstest code (untouched here, the id phase-8: P8.8 clippy/lint sweep deferred — ~150 clippy warnings remain with no tracking issue #803-family debt).Acceptance mapping: export from a seeded DO passes
verify_importwith matching counts/digest (fixture contract test); producible at cap (worker test); missing blob fails loudly naming the hash (both legs, worker tests); enumeration mapping covered incl. multiple objects citing multiple blobs, one blob cited twice, and a rebind-history store (Rust test).Closes #13157
Update — reconciled with #13158 (ingest half, landed on main while this PR was open): merged main in (e042850). Doc conflict in
hosted_export.rsresolved by keeping the production section and pointing ingest athosted_ingest. Semantic conflict:hosted_ingest's tests built objects with the removedExportObject::new— migrated toExportObject::from_envelope; its not-an-event test's premise (a wrapper-valid non-event object) is exactly what §6.3 overturns, so it now asserts the refusal atverify_import(ObjectSignatureInvalid). Merged tree re-verified:cargo test -p id --lib— 535 passed, 0 failed.