Repository navigation
records(export): stream installation exports without buffering them - #69
Conversation
Codex Review SummaryThis 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: c1eae2fe25
ℹ️ 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".
TusanHomichi
left a comment
There was a problem hiding this comment.
Merge review at c1eae2f: hold this PR. I inspected the export transaction/audit lifecycle, EntryBuffer, response producer/body, and failure tests, and independently agree with both existing unresolved Codex findings. pr-gate run 34661990490 is green; these are uncovered boundary cases, not a claim that CI failed.
-
Pool ownership:
export_to()holds a pooled read transaction whileaudit_export(pool, ...)waits for another pooled connection. The production pool has five connections. Coordinated exports can occupy all five and then each wait for the audit connection, starving exports and unrelated requests until acquisition timeouts. Repair the reservation/admission/connection lifecycle rather than merely increasing the pool or moving an audit write into a transaction held for the full download. Add a deterministic concurrency regression that holds all competing requests at the relevant boundary; prove unrelated ordinary work still progresses, and exercise a one-connection pool or explicitly prove the supported admission contract. Preserve one snapshot for manifest and payload, the intended authorization boundary, and honest audit semantics. -
Terminal outcome: failure is sent through the same bounded queue that just stalled. If both send windows expire,
signal_failure()only logs, the producer disarms its guard and drops all senders, andExportBodytreats channel closure as successful EOF. A late reader can therefore receive a truncated prefix with a clean HTTP completion. Give success/failure an explicit reliable terminal state independent of queue capacity; only an explicitly successful, finalized producer may permit clean EOF. A channel closing without that success must fail closed. Cover ordinary producer error, panic, full queue, disconnect, and finalization failure.
The decisive new stall regression should leave the data queue full beyond BOTH send deadlines, then resume reading and assert a body/transport error rather than clean EOF. Existing tests that inject a failure while there is queue space, or only test one timed-out send, cannot establish that guarantee. Keep short injectable test deadlines and add a real transport-level check as appropriate; do not weaken timeouts or retry until green.
Keep the existing byte-identity/CRC/header, verifier, snapshot, cancellation, and writer-progress proof. State memory cost precisely: streaming removes whole-corpus payload buffering, but unit metadata, the serialized manifest, and ZIP central-directory state still scale with unit count; browser Blob buffering also remains a documented separate limitation. Do not claim constant memory or end-to-end browser streaming.
Revalidate against current main (now containing #68) and rerun the full gates. No merge or deployment was performed for this PR. This review is source inspection plus GitHub CI/review verification, not an independently executed Rust or browser reproduction.
Export read every finalized version with `fetch_all` and assembled the whole ZIP in memory before the handler answered, so an installation export cost memory in proportion to its history (#47). `record_export::export_to` now writes the container into any seekable sink as it produces it: one read transaction, a metadata-only pass for the manifest (which must be the container's first entry), then a pass that streams each unit's stored bytes and unit manifest. `export_stream::EntryBuffer` holds one entry and applies the `zip` writer's patches to it, so the destination sees an append-only stream and the bytes stay identical to the buffered archive: no data descriptors, real CRC-32 and sizes in the local header, the same central directory. A patch is classified by position — inside the held entry — so the CRC and size patch that seeks backwards and the ZIP64 extra-field update that seeks forwards both land correctly. The export holds one pooled connection at a time, which is what the review's first blocker needed. Its audit event is written in its own short write transaction, committed before the read snapshot that both content passes share, and that snapshot is a reader only (ADR 0019): an export never reserves the writer while it streams, and exports sharing a pool never hold one connection while waiting for another. A scope that holds nothing to export is refused before anything is recorded, so the audit still attests exactly what it says it does. Delivery ends only on an explicit success. Whether a transfer was complete is a flag the producer sets when the archive was produced *and* its tail flushed — not the channel closing, which a client that outlasted the failure signal would otherwise read as a complete download. Every other ending fails the body: a production failure, a producer that panicked (a drop guard covers it), a stalled client, and a client that stayed away past both send windows. Proof: streamed and buffered bytes compared across entry sizes including the patch boundary, and the bytes a live socket delivers compared against the buffered export at the instant the delivered manifest states; the installation's peak memory measured in a fresh process against pre-seeded databases (500 units / 8.7 MB archive at 5.1 MiB, the same units at four times the payload at 7.4 MiB, 4,000 units / 69.7 MB at 14.1 MiB), so the payload volume does not drive it while the unit count does; a whole export on a one-connection pool; two exports overlapping on a two-connection pool with ordinary work still progressing; an export observed mid-stream while the installation's own writer commits; a client that outlasts both stall windows and still cannot receive a complete transfer; and unit tests for each terminal case (success, closed channel without success, failure item, guard on drop, stall, departed client). Each of these was falsified against the design it replaces before it was kept. ADR 0014 and the format document state the connection ownership, the memory terms, and what an interrupted transfer means.
c1eae2f to
4755731
Compare
Repairs at
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4755731cb3
ℹ️ 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".
Address the third review round on #69. - The metadata pass is one short read transaction committed before the response starts. The payload pass holds one pooled connection but no transaction: each unit is one autocommit point read, completed before its bytes reach the client and checked against the manifest's stored fingerprints. Finalized versions are immutable and undeletable (migration 0010), so that check — not a snapshot held for the length of the download — ties payload to manifest, and a paused download pins no WAL reader. - `export_to` takes a cancellation probe checked before the audit, before and during the metadata pass, and before the response starts; the handler's probe is the body channel's closure, so an abandoned request records and reads nothing. - `ChunkSink` hands on at most 64 KiB per queued item, bounding the response queue in bytes (8 × 64 KiB). Each fix has a test that fails against the behaviour it replaces. ADR 0014 and the format document state the new boundary. Refs #47. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Round 3 at
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 151fcd6c78
ℹ️ 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".
The zip writer issues six writes per entry, so the seventh write began the first version's record rather than the fourth version the comment claimed. Hold the first write landing beyond three payloads' worth of bytes instead: at least three versions have then passed through the held connection, whatever an entry costs in writes. Refs #47. Co-Authored-By: Claude Fable 5.1 <[email protected]>
A payload connection held while the client is waited on is a lease the pool cannot give to anyone else: enough slow downloads hold every lease and starve ordinary work. Acquire a pooled connection for each version's point read and return it before the bytes are written, so a stalled download holds no connection and no transaction. The point reads then pass through whichever connections the pool hands out, and their SQLite page caches — at most the pool's size times the per-connection cache limit — count toward the export's memory. The memory proof reads that ceiling from the pool and bounds against it; ADR 0014 names the term. A new test holds two downloads mid-payload on a two-connection pool and requires ordinary work to proceed. Refs #47. Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 88adb0967e
ℹ️ 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".
Each export producer is a blocking thread for the length of its download, and a client reading one chunk per stall window keeps it as long as it likes, so unbounded admission lets one authorized caller grow the blocking pool to its limit and queue closures behind it. Admit at most four exports per process: a slot is taken before any work and held until the producer returns; beyond that a request is refused with a typed `503 export_busy` to retry, never queued. The abandonment probe is also asked before authorization, so a request that is gone does no work at all. Refs #47. Co-Authored-By: Claude Fable 5.1 <[email protected]>
A process-wide semaphore made every server in one process — including the parallel test servers in one test binary — share one set of slots. The slots now live on `AppState`, built by `AppState::new`, so each server bounds its own producers. The abandoned-after-audit test's probe stays present through both checks that precede the audit. Refs #47. Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 096530e258
ℹ️ 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".
`measured` returns `None` on a platform without `/proc/self/status`, meaning to skip; the proof's `expect` turned that skip into a failure. Return early instead, so the workspace suite can pass there. Refs #47. Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2870c93b9c
ℹ️ 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".
The costs note said an abandoned request records nothing; that holds only for abandonment noticed before the audit commits. After it, the `record_exported` event stands as the attested attempt, which the abandoned-after-audit test proves. State both cases. Refs #47. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Primary Issue
Closes #47
Problem And Outcome
An installation export read every finalized version with
fetch_alland assembled the whole ZIP in memory before the handler answered, so its memory cost was proportional to the installation's history. It now streams: the same documented bytes, bounded memory, and an incomplete transfer that can never be mistaken for a complete export.Changes
crates/consolebook-server/src/export_stream.rs—EntryBuffer, aWrite + Seekview of an append-only destination that holds one entry and applies thezipwriter's patches to it. A patch is classified by position (inside the held entry), so the CRC-32/size patch that seeks backwards and the ZIP64 extra-field update that seeks forwards both land correctly. This is what keeps a non-seekable destination byte-identical: no data descriptors, real CRC-32 and sizes in the local header, unchanged central directory.crates/consolebook-server/src/record_export.rs—export_towrites the container into any seekable sink: a metadata-only pass for the manifest (which must be the container's first entry) in one short read transaction committed before the response starts, then a pass that streams each unit's stored bytes and unit manifest — one autocommit point read per unit on a pooled connection acquired for that read and returned before the bytes are written, checked against the manifest's stored fingerprints, so a stalled download holds no connection and no transaction. The audit event is its own committed statement before either pass, so an export reserves no writer while it streams (ADR 0019), pins no WAL reader, and a scope with nothing to export is never audited. An abandoned request stops before authorization, the audit, and the metadata pass, and at most four exports are produced per process — a fifth is refused503 export_busyto retry, never queued.export_atkeeps the buffered API the packet and the tests use.crates/consolebook-server/src/exports_http.rs— the handler produces the archive on a blocking thread into a bounded-channel body: a slow client bounds the producer, a disconnect ends it and releases its connection, and a stall or any production failure after the response starts ends the transfer without its final chunk. The failure sentinel is actually sent (a droppedsendfuture was a silent no-op) and aDropguard covers a producer panic.crates/consolebook-server/tests/export_stream_bytes.rs— byte identity, a real socket, memory, backpressure, stall, and the write-reservation proof; unit tests inexports_http.rsfor the failure signal.docs/decisions/0014-record-export-format.md,docs/formats/record-export.md,docs/development.md,web/src/lib/api.ts.futures-util(stream rows one at a time) andhttp-body(the incremental response body).Cargo.lockchanges only the dependency list.Scope
docs/formats/record-export.mdis unchanged in its normative claims); the browser download helper, which still reads the whole response into a Blob and is documented as such.Verification
Byte identity: streamed bytes equal an independent
ZipWriter<Cursor<Vec<u8>>>reference across eight entry-size shapes (including 0/1/13/14/15/1024/65536/300000), a byte-level walk checks the descriptor flag, the patched CRC-32, the patched sizes, and every local header against the reference, and a live socket response is re-exported at theexported_atits own manifest states and compared withassert_eq!.Memory, peak growth measured in a fresh process against a pre-seeded database with the sink discarding every byte: 500 units / 8.7 MB archive → 5.2 MiB; the same 500 units at 4x payload / 33.3 MB archive → 7.5 MiB; 4,000 units / 69.7 MB archive → 13.6 MiB. The corpus's bytes do not drive the peak; the remaining linear term is the unit metadata and its JSON manifest, which ADR 0014 states.
Reservation: an export observed mid-stream while the installation's own writer commits in well under a second — this fails against the audit-inside-the-transaction design. Failure: a stalled client's transfer carries no terminal chunk and is shorter than the complete archive; a destination that stops accepting ends the export.
export verify, API byte delivery, determinism, packet bytes, and packet pin-history verification are unchanged and green.Review And Merge Notes
EntryBuffer's patch invariant, the audit's new commit point, and the failure path after the response has started.export verifywould reject.