Repository navigation
Description
Problem or outcome
record_export::export_at (#46) reads every finalized version of the scope with fetch_all and then assembles the ZIP archive in a Vec<u8> before the HTTP handler returns it as one body. For the installation scope this holds the corpus in memory while the export is produced. #46 already releases each version's bytes as they are written (rows are consumed by build_archive), so the peak is roughly one copy of the exported bytes plus one row rather than two copies, but a very large finalized history still costs memory in proportion, and the process can be pressured before the download completes.
The outcome is an installation export whose memory use is bounded by a few units, not by the history: rows are read incrementally and the archive is written to the response as it is produced, with the same documented bytes.
Scope
In scope:
- Stream the query (a cursor over
evaluation_versionin archive order) into a ZIP writer that writes to the response body as it goes, for every scope or for the installation scope alone. - Keep the format byte-identical for a given scope and export instant (
docs/formats/record-export.md): stored entries, fixed entry order and metadata, canonical manifests. Note that a non-seekable writer emits data descriptors, which the format document must either permit explicitly or the implementation must avoid (for example by computing sizes and CRCs first, since stored entries have known lengths). - Decide how a failure part-way through a streamed body is surfaced to the operator (a truncated ZIP does not verify, which is the right failure, but the interface should say what happened).
- Update ADR 0014's cost note once exports stream.
Out of scope:
- Persisting exports under
data/exports/(ADR 0014 records why nothing is retained on disk). - Trainee packets (Milestone 5 design: exports and recovery #44 slice 2) beyond ensuring the streaming path can carry them.
Acceptance criteria
- An installation export with many finalized versions completes with memory bounded by a few units, measured and stated in the PR.
- The streamed archive is byte-identical to the buffered one for the same scope and instant, proven by a test that produces both.
-
export verifyaccepts the streamed archive, and the format document says exactly what changed in the container, if anything. - A mid-stream failure is visible to the operator and never presented as a complete export.
Expected proof
cargo test --workspacewith a test producing a large invented corpus and comparing streamed and buffered bytes.- The usual gates:
cargo fmt --check,cargo clippy --workspace --all-targets -- -D warnings,web/check and build if the interface changes.
Related roadmap, decisions, or issues
- Raised by the Codex review of records(export): structured record exports and the export format #46 (
record_export.rs,collectandbuild_archive). - Refs Milestone 5 design: exports and recovery #44 (Milestone 5 design), Milestone 5 slice 1: structured record exports and the export format #45 (slice 1); ADR 0014 "Costs".
Activity
records(export): require lowercase hashes; release bytes as written
records(export): stream installation exports without buffering them
TusanHomichi commentedon Oct 7, 2026
Review round 3 on PR #69 — plan (2026-10-07)
Scope and source. Finish the open review round on #69 so the maintainer can take a merge decision. Authorized by the owner's 2026-10-07 request ("finish PR #69 review round"), under AGENTS.md / CONTRIBUTING.md / docs/workflow.md at
03cc8c7. In scope:origin/mainmerged intocodex/47-stream-installation-exports(done,c631b6b, clean), the six open review threads on #69, the Rust files the PR already touches, ADR 0014 anddocs/formats/record-export.md, their tests, the full gate sequence, a push, and thread replies. Out of scope: merge, deployment, new issues' work, the unrelated untracked scratch files in the main checkout. No owner effort budget was set; the no-default-cap policy (#73) applies.Triage of the open threads, against the code at
4755731:record_export.rs(outdated)4755731: audit is its own committedwrite_tx, then one reader; 1- and 2-connection pool testsexports_http.rs:2914755731:Completionflag; closure without success fails the body; transport test outlasts both windowsrecord_export.rs:249exports_http.rs:222exports_http.rs:456c1eae2f(own account)4755731; the hold itself never cleared — closed in this roundFixes.
evaluation_version_no_update/_no_delete, migration 0010), so the stored fingerprints — not one long transaction — are what tie the manifest to the payloads. The metadata pass becomes one short read transaction committed before the response starts; each unit is then a point read released before its bytes go to the client, cross-checked against the manifest'scontent_hash/chain_hash/record_schema(a mismatch or missing row ends the transfer incomplete). No connection is held while blocked on the client. This changes the "one snapshot for manifest and payload" wording of the earlier hold review; ADR 0014 says so.export_totakes a cancellation probe checked before the audit write, before and during the metadata pass, and before the response starts; the handler's probe is the body channel'sis_closed(), true the moment the handler returns or is dropped. Cancellation surfaces as a client departure, not a production failure.ChunkSink::writehands on at most 64 KiB per item; the queue holds ≤ 8 × 64 KiB.Acceptance. Each fix has a test that fails against the code it replaces (A:
wal_checkpoint(TRUNCATE)reportsbusy=0while an export is blocked mid-stream; B: norecord_exportedrow and no bytes when cancelled before start, row stands and zero bytes when cancelled after the audit; C:write_all(1 MiB)into an unread queue stalls after exactly 512 KiB). Byte identity and every existing stream test still pass. Both Rust modules stay under 1,000 lines or the ownership boundary is named first. Full gates from CONTRIBUTING.md on the frozen candidate, includingnpm run e2e(the PR touchesweb/src/lib/api.ts). Hostedpr-gateobserved after the push. Threads 1–2 answered and resolved; 3–5 answered with the fix and its negative control.Routes. Primary integration, selection and review: this session with its plan-review advisor. Rust implementation from the fixed spec: the implementer role, owning every
.rsfile. ADR 0014 / format doc: the docs role, owning those two files only. Verification, falsification receipts, gates, push, and GitHub writes: the primary. Roles are recorded, not model identifiers; the host does not expose the serving model and this project's guidance names none.Next action. Implement A–C with their tests in the #47 worktree, then falsify each against the stashed
src/and run the gates.Generated by Claude Code
fix(export): hold no reader or queue slack while a client waits
TusanHomichi commentedon Oct 7, 2026
Round 3 receipt — PR #69 at
732c566(via151fcd6,d4e60f7,88adb09,9bb0cc2,096530e,2870c93)Pushed
151fcd6c78bbdd798fc7748a90a3f11d5fe3caa8(tree4c8d596a) tocodex/47-stream-installation-exports; the branch carriesorigin/main03cc8c7via mergec631b6b. Round summary, thread replies, and the design-change note are on the PR. All five review threads are answered and resolved.Acceptance against the plan above:
busy = 1, log = 385, checkpointed = 384with the payload pass inside a transaction (gated on the first write beyond three payloads' worth of bytes;d4e60f7replaced a write-count gate whose comment misplaced it); B audit count 1 vs 0 and 348,478 bytes vs 0 with the probe forced false; Cwrite_all(1 MiB)succeeds with the whole-entry write. A first A control that pinned the reader after the gate point was invalid and is preserved as such.record_export.rs911 lines,exports_http.rs790./data/dev/src/consolebook-worktrees/47-stream-installation-exports): web check 289 files 0/0 and build on the unchangedweb/tree;cargo fmt --checkclean; clippy-D warningsclean;cargo test --workspace27 binaries, 197 passed, 0 failed, 1 ignored (206 s);cargo build -p consolebook-server;npm run e2e56 passed (7.5 min, system Google Chrome). Gate logs (six candidates), falsification receipts, posted texts and their SHA-256s are archived at/data/dev/home/.codex/tmp/consolebook-pr69-round3-20261007/round3-evidence-v2.tar.gz(SHA-2568dbf695330c383990f6211a902f62f326859eb00a84274053e7a27a4652320f6; the earlierround3-evidence.tar.gzis kept), reopened and read back before this edit; exercised binariesdcf0d9ae37daa527…(151fcd6/d4e60f7),b60aaa21f24d4319…(88adb09),b65b771e9fdfca88…(096530e).d02a8e0(lease per point read) failed the memory proof at 23,484 KiB peak for the 4,000-unit corpus, four runs; the same code measured 15.0–17.7 MiB later, so the peak varies with how many pooled connections the reads land on (one SQLite page cache each).151fcd6held one connection for the pass (steady 14,808 KiB) and was correctly flagged by Codex as a lease starvation vector;88adb09returns to a lease per read, bounds the proof against the pool's page-cache ceiling read at run time (10,000 KiB), and adds a starvation test that fails against the held lease (acquire timeout). ADR 0014 names the term.pr-gate: the151fcd6run was cancelled by the next push and thed4e60f7run superseded; on88adb09it is green — run 37674688625, observed 2026-10-07 ~19:35 UTC. Codex's re-review of88adb09raised one further P1 (concurrent export producers unbounded);9bb0cc2+096530ebound admission at four per server (AppState-owned semaphore; a first process-wide static cut failed the full suite by sharing slots across parallel test servers — preserved as gates4/gates5) with a typed503 export_busyrefusal and a live-socket test that is served200without the bound. Full local gates on096530e: fmt, clippy,cargo test --workspace27 binaries / 199 passed / 0 failed / 1 ignored (157 s), build,npm run e2e56 passed (5.4 min, system Chrome); hostedpr-gateon096530e(run 37678442926): web/format/clippy/Test green, then a 25-minute hang inInstall browser(apt fetch) to the 30-minute job timeout before any browser test ran — runner infrastructure, not this diff;2870c93(test-only: the memory proof now skips, not fails, where no process peak is reported — Codex P2) is the one re-run and is green — run 37682401715 (observed 2026-10-07 ~20:45 UTC).732c566corrects ADR 0014's abandonment wording (Codex P2, docs only; identical binary); all nine review threads are resolved;pr-gateon732c566is green — run 37684726494 (observed 2026-10-07 ~20:58 UTC).Routes: as planned — this session plus its plan-review advisor for selection, review and integration; one implementer-role subagent for the Rust change; one docs-role subagent for the two docs. The memory-proof repair, the lease, starvation and admission fixes, the falsification runs, the gates and the GitHub writes were the primary's. Roles, not model identifiers, are recorded.
Next action: none for this round — hosted gates are green on the head, every thread is resolved, and the merge decision is the maintainer's.
Generated by Claude Code
test(export): gate the WAL proof by position, not write count
fix(export): lease a connection per point read, never across a wait
fix(export): bound concurrent export producers
fix(export): own the export slots on the app state
test(export): skip the memory proof where no peak is reported
docs(adr): say post-audit abandonment leaves its audit event