R16
What to build¶
Invalid batch output cardinality cannot cause arbitrary full-sequence materialization.
Source and evidence¶
Repository scientific/architectural review, snapshot 86c8517, item R16.
Classification: confirmed defect; medium severity.
The splitter returns a Sequence, but evaluate_batches() copies all of it to a
tuple before checking that its length matches the actual batch. An invalid
output sequence can impose arbitrary traversal and retained memory despite a
small validated batch size. The retained batch cardinality probe
supplies a valid Sequence implementation with 100,000 outputs for a two-case
batch. It records all 100,000 element reads before the batch is classified failed.
This is a bounded operation-count experiment; it does not claim a measured memory
peak or run an endless source. The existing bad-cardinality test uses one output
for two cases and therefore does not test excess-output work.
Acceptance criteria¶
- [ ] A lazy 100000-output Sequence for a two-case batch fails without reading all outputs.
- [ ] If iterable support remains, consumption stops at expected cardinality plus one.
- [ ] Too few, too many, split exceptions and padding mismatches fail the whole batch with original-index alignment.
- [ ] Valid partial final batches preserve latency and cases/request throughput semantics.
- [ ] 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¶
Check Sequence length before copying and retain a bounded fallback for permitted iterables. Keep validation inside the batching owner so consumers cannot bypass count conservation.
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.