Repository navigation
feat(D147): register a raw object a client uploaded directly - #547
Conversation
UploadIngestor.ingest_stored(deployment_id, key, size, mime, filename, ...) streams the object once through the new StreamingReadPort (S3 and local adapters) to hash it into a temporary file, classifies it on a memory map of that file, and records the version through the same admission, MIME validation, versioning and deduplication as ingest. The raw object stays at the client's key. Content detection now works on a memory map without copying it (identical verdicts; 200k fuzzed inputs compared with the old implementation). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
… on 3.12 Codex round 1: - ingest_stored accepts only uploads/<16-128 of [A-Za-z0-9_-]>: hard forget purges a raw key in every store, and file names must not enter manifests. - Detection keeps memory bounded: the HTML head collapses whitespace runs (keeping arbitrarily long doctype whitespace recognised), BMFF brands are scanned without collecting, and ZIP reads go through a seekable bounded reader (8 MiB per read) that also fixes mapped ODF on Python 3.12. - No promise that a deduplicated key is unused; callers never delete registered objects. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
Codex review round 1 (gpt-6.1-sol, max effort)VERDICT: REQUEST_CHANGES
145 focused tests passed. The PDF anchor rewrite matched 30,000 targeted old/new comparisons. Shared catalog handling preserves D55, metadata and parking behavior. Rule 4: no direct paid-work identity or volatile-header changes found, but the HTML routing regression prevents treating this as behavior-preserving. PostgreSQL lifecycle proofs remain for CI; I did not attempt Docker/database tests or modify files. Disposition (Claude), fixed in 0350af2
|
Codex round 2: the brand offsets were expanded into a tuple; the 8 MiB ZIP bound changed ordinary ingest. Bytes keep the old unbounded ZIP read; a memory-mapped stored object is bounded at 64 MiB per read. A tracemalloc test keeps mapped classification of 32 MiB objects under 8 MiB of heap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
Codex review round 2 (gpt-6.1-sol, max effort)VERDICT: REQUEST_CHANGES
The opaque namespace, mapped ODF on Python 3.12, HTML whitespace handling, and cleanup wording in code/D147 are fixed. Admission identities, metadata and routing matched across ten representative bytes/stored comparisons. I accept the two declined items as documented limits: configured managed metering fails closed, and the already-uploaded object retains its uploader-chosen storage class. Additional billing or storage-class machinery would expand this seam unnecessarily. Rule 4: no new volatile identity inputs or reuse-boundary changes found. Existing lifecycle proofs remain intact. 185 focused tests passed; 40,000 PDF/text comparisons matched Disposition (Claude), fixed in 66aef3a
|
…IO seeks Codex round 3: - Hard forget purges only the content's kept raw object, so a copy written under another key (another upload key, file name or entry point) would outlive a forget. ingest, ingest_observed and ingest_stored now delete the copy they wrote or were given when the record keeps another one (DocumentCatalog.raw_object_key; ObjectPurgePort). - The ZIP view's seek matches io.BytesIO, including the negative-seek error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
Codex review round 3 (gpt-6.1-sol, max effort)VERDICT: REQUEST_CHANGES
The lazy BMFF scan, opaque key validation, HTML handling, Python 3.12 mapped ODF, and PR cleanup wording fixes are verified. The previously accepted metering and storage-class limits remain documented. 205 focused tests passed; 5 database tests skipped. Twelve representative ingest comparisons matched admission identities, metadata, routing inputs and lane. Another 52,144 PDF/text comparisons matched Rule 4: no new volatile identity inputs or reuse-boundary changes found; existing lifecycle proofs remain intact. PostgreSQL lifecycle tests were not run locally; worker integration CI remains pending. Worktree unchanged. Disposition (Claude), fixed in 607bc21
|
… test fixture Codex round 4: - The ODF mimetype member is read through archive.open(...).read(129): read() inflated the whole stream before truncating to the declared size. Reading past that size still ends the member and checks its CRC. - ingest_stored requires a raw store that both streams and purges. - The cleanup test creates the second object only when it registers it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
Codex review round 4 (gpt-6.1-sol, max effort)VERDICT: REQUEST_CHANGES
The raw-copy release works across all three ingest paths with purge-capable stores, including retained same-key retries. Opaque keys, negative ZIP seeks, PDF anchors and chunked text detection fixes check out. Shared admission, metadata, routability and D55 handling otherwise match ordinary ingest. I accept the documented mapped ZIP-directory cutoff under the owner’s simplicity preference; it remains an explicit bytes/mmap equivalence exception. A custom central-directory parser is unnecessary for this review. The previously accepted metering and uploader-selected storage-class limits remain documented. Rule 4: no new volatile identity inputs, lineage changes or paid-work reuse boundaries found; existing lifecycle proofs remain intact. Validation: 201 tests passed; 21 database tests skipped. Another 75,378 old/new PDF/text comparisons and 500 bytes/mmap comparisons matched. Worker integration CI remained pending. Worktree unchanged; Docker untouched. Disposition (Claude): all three accepted, fixed in d2ea598
|
Codex round 5: zipfile cannot bound BZIP2 or LZMA output. On a memory-mapped stored object only a stored or DEFLATE mimetype member is read (ODF requires it stored); bytes in memory keep the previous behaviour exactly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
Codex review round 5 (gpt-6.1-sol, max effort)VERDICT: REQUEST_CHANGES
The purge-capability guard and corrected integration fixture check out. Ten representative upload/stored comparisons matched admission identities, MIME, metadata, lane, and routing inputs. Previously accepted metering, storage-class, and oversized ZIP-directory exceptions remain documented. Rule 4: no new volatile identity inputs, lineage changes, or paid-work reuse boundaries found; existing lifecycle proofs remain intact. Validation: 202 tests passed; 21 database tests skipped. Another 50,252 old/new detection comparisons and 800 bytes/mmap comparisons matched. Worker integration CI remains running. Worktree unchanged; Docker untouched. Disposition (Claude): accepted, fixed in 73a3f35
Regression test |
Codex round 6 minor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
Codex review round 6 (gpt-6.1-sol, max effort)VERDICT: APPROVE
The latest BZIP2/LZMA fix closes round five’s memory finding, verified on Python 3.12. Its documented detection exception is reasonable under the simplicity requirement. Previously accepted metering, storage-class and ZIP-directory limits remain documented. No blocker or major findings. Admission, metadata, routing and D55 handling match normal ingest within those limits. Raw-key validation and retained-object cleanup check out. Rule 4: no new volatile identity inputs, lineage changes or paid-work reuse boundaries found. Validation: 182 passed; 21 database tests skipped. Thirty upload/stored comparisons and 71,000 old/new detection comparisons matched. CI Quality and Unit passed; worker integration remains running. Worktree unchanged; Docker untouched. Disposition (Claude)The minor is accepted and fixed in 69da76d. |
This is the second generic seam the team lead confirmed (2026-11-07): register a raw object a client already uploaded to the raw store (direct multipart upload by pre-signed URL). The first seam, convert by reference, is #545.
API
What the engine does
keyin 1 MiB chunks. Each chunk goes into the SHA-256 hash and a temporary file on disk, and the received size must equal the declaredsize.ingestmakes.ingest, run on a memory map of the temporary file. The object is never held in memory whole.ingestdoes: one-shot upload lineage (source_ref = content_hash), a content-deriveddoc_id, D55 no-op on identical bytes, and the routable/parking rule including the oversize card rule.Raw key rule: the raw object stays at
key. The engine recordskeyas the version's raw object and never copies or moves it.keymust beuploads/<id>, where the id is opaque: 16–128 characters from[A-Za-z0-9_-]. Hard forget purges a version's raw key in every store, so the namespace keeps client keys disjoint from the engine's own keys, and opaque ids keep file names out of the immutable forget manifests. Each content keeps exactly one raw object, the first one recorded, and only that one is purged by hard forget. So when identical bytes are already stored under another key, that version answers and the engine deletes the object atkey. The same rule now applies toingestandingest_observed: each deletes the copy it wrote when the content keeps another one. That closes a copy-outlives-forget gap that already existed between those two paths. A repeated registration of the same key changes nothing. Callers never delete registered objects.Refusals:
ValueError);uploads/<16–128 of [A-Za-z0-9_-]>(ValueError);FileNotFoundError);ContentDetectionError, the same asingest);ValueError).Content detection on a memory map
detect_content_mimeanddetect_mimenow acceptbytes | mmap.mmapand never copy the whole content:^emulated by an anchored match at that position;The verdicts are identical:
Tests
src/tests/workers/test_ingest_stored_pg.py(integration):ingestgive the same version (no-op), and registering again is a no-op.forgotten/key and missing object are each refused, leaving no rows.test_minio_store.py: chunked streaming, body closed, missing key.ingest_storedas a gated method.Checks
ruff, pyright (0), import-linter, unit lane (3140 passed)
DB tests not run locally. The local Docker store became unreadable after the machine's disk filled (containerd I/O errors on every image), so the new integration test runs in CI only.
CI
Codex review: round 6 APPROVE (all dispositions in the comments)
I have read and agree to the RememberStack Contributor License Agreement v1.0.
🤖 Generated with Claude Code
https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm