R18
What to build¶
ReportStore returns the exact validated bytes whose digest it checked.
Source and evidence¶
Repository scientific/architectural review, snapshot 86c8517, item R18.
Classification: confirmed defect; medium severity.
_read_document() reads and hashes bytes, then calls load_report(path), which
opens the file again. Replacing the file between those reads lets get(digest)
return a different valid report under the requested digest. The store's own
immutable writer does not normally replace an existing document; this requires
external filesystem mutation or repair concurrent with the read. Nevertheless,
the advertised corruption check must validate the bytes actually returned.
MLflow export also relies on this method to associate a report with its digest.
The retained history snapshot probe creates an
isolated temporary store with an original report. A wrapper at the second-read
boundary replaces the file with a valid replacement report, then delegates to
the real loader. get(original_digest) returns replacement, and hashing its
canonical bytes does not match the requested digest. The temporary store is
removed after the experiment; no existing history or remote service is touched.
This controlled interleaving proves the check/use race without a flaky timing test.
Acceptance criteria¶
- [ ] Controlled replacement between read and parse cannot return a different report under the requested digest.
- [ ] Read size is bounded at cap plus one before hashing or decoding.
- [ ] Corrupt/oversized files produce safe store errors; valid get/export/MLflow projection uses the verified snapshot.
- [ ] Concurrent recovery and valid reads preserve content identity without timing-dependent test flakiness.
- [ ] Preserve Consumer-owned meaning, payload-free evidence, disabled optional-import isolation, safe diagnostics and the non-relaxable Safety Floor.
- [ ] Run the narrowest observable contract, then applicable committed Make gates. Record every command and outcome; update specifications/compatibility evidence for changed public or wire contracts. Run native Collector verification for changed Collector assets and build for packaging changes.
Design guidance¶
Read once into a bounded buffer, verify its digest, and pass that buffer to the in-memory decoder. Preserve Repository ownership and immutable writer semantics rather than locking all external filesystem activity.
Keep prefactoring narrow and verifiable in this slice. Reuse established owners and structural interfaces; introduce a pattern only when it clarifies a real responsibility or variation point. Do not add consumer vocabulary or private payloads to platform code or evidence. Mocked/local results must not claim hosted, production, accelerator or release qualification.
Blocked by¶
None (can start immediately). Shared-area coordination is useful, but no other review fix is a genuine prerequisite for this slice.
Verification scope¶
Convert the described counterexample or investigation oracle into an observable test at the lowest suitable public boundary. Prefer bounded operation-count or deterministic interleaving evidence to flaky timing assertions; timing guarantees need a declared tolerance and independently owned cleanup. This ticket authorizes remediation/research, not publication or deployment.