Repository navigation
Persist byte-exact canonical audit bundles - #173
Conversation
Rows written before the immutable canonical artifact API advertise an audit_bundle_sha256 with nothing canonical behind it. Add a standalone, idempotent, resumable backfill that walks qbit_pool_audit_bundles in primary-key order and recovers the exact advertised bytes for each row: * a pre-v2 literal external body is promoted verbatim, never parsed and re-emitted, because those bytes are the serialization the digest was computed over; * a compact/v2 external body is reconstructed through the artifact store, with an absent on-disk share segment reloaded from the append-only ledger, canonicalized with the store's segment encoder, and checked against the segment digest the bundle embeds; * an inline JSONB body is canonicalized with the repository's existing canonicalizer. Every candidate is verified against the advertised digest before anything reaches the filesystem, and the ledger's pre-publication preflight (writer-lease refresh plus row identity confirmation) runs immediately before each write. A row that fails verification is reported on stderr with its block, digest, and reason, left untouched, and turned into a nonzero exit status once the requested range has been processed; the advertised digest is never rewritten. The phase-2 canonical artifact API and the ledger preflight are bound by name in two small adapters that report what they resolved in the run summary, so reconciling a final signature difference is a local edit. Co-Authored-By: Claude Opus 5 <[email protected]>
The public digest of an audit publication is the SHA-256 of the canonical JSON bundle, but only a compact pointer body reached the disk. Answering for that digest meant reconstructing the bundle from share segments and trusting the reconstruction, and a segment that had since been pruned made the identity unanswerable. Persist the exact bytes instead. `prepare_external_audit_body` already holds the canonical bytes it just digest-checked, so it publishes them as a first-class artifact kind before deriving the compact body -- reusing the bytes rather than reserializing, and running after the writer-lease preflight so the copy stays behind the same fence as every other audit side effect. The store gains the artifact kind and its APIs: a content-addressed path, a writer that verifies the uncompressed digest before publication and again after reopening the published file, and a reader that separates a clean miss from damage so a caller can log the loss before falling back. Compression is stdlib gzip level 9 at mtime=0, which is reproducible, so republishing identical bytes is a durable no-op and a conflicting artifact fails loudly. For the historical backfill, the resolvers now accept a missing-range callback and a helper reconstructs a bundle from an already published body. Recovered ranges are canonicalized and checked against the digest the body itself commits to, then the assembled bundle against the advertised digest, so database fallback bytes are never trusted on their own. Pre-v2 bodies that already are the canonical bundle are taken verbatim. A ledger preflight refreshes the writer lease and confirms the block/digest row identity immediately before each backfill publication. Canonical bundles are classified as their own kind, counted in metrics, and never touched by retention.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a5bdf874f9
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3c11e8a1fb
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5c1bdb2bf6
ℹ️ 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".
…2026-08-24 have no canonical sidecar The guide said 2.x wrote a sidecar beside every v2 body. It writes one beside each new body only since #173 was deployed. On union, the bodies from before 2026-08-24, about 9,500 of them, have none, so most legacy v2 rows reach the parts-digest check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Storage decision
Measured representative canonical bundles compressed from 7.97 MB to 696 KB and from 35.85 MB to 3.159 MB with gzip-9. Because zstd level 3 was only 7.8% smaller on the larger sample, this keeps the existing gzip-based store format and retains all canonical bundles. Estimated centralized growth is 5.6–9.2 GB per month.
No PostgreSQL schema, dependency, or hash-definition changes are included.
Verification
Fixes #158
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.