Skip to content

Trust + correctness hardening keystone - #24

Merged
logannye merged 8 commits into
mainfrom
rosalind/trust-correctness-keystone
Jun 2, 2026
Merged

Trust + correctness hardening keystone#24
logannye merged 8 commits into
mainfrom
rosalind/trust-correctness-keystone

Conversation

@logannye

@logannye logannye commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Summary

The 6 call/contract-path items from the 2026-06-02 reflection audit — making the shipped memory contract's correctness and trust guarantees actually hold and be tested.

  • Unbiased depth cap — replaces leftmost-arrival truncation with a fixed-seed min-hash bounded reservoir + eviction. Selection is independent of read start position (and thus allele), so a deep het variant carried by reads that start at the variant no longer gets silently dropped. Deterministic and bounded at max_depth. (Reproduced bug: a true 30:30 het → 0 calls under the old biased cap; regression test included.)
  • Canonical obs orderbuild_column emits observations sorted by (allele, base_qual, mapq, reverse), so the order-sensitive f64 QUAL/PL accumulation in germline.rs is order-independent and the VCF stays byte-identical regardless of the active set's internal order (which the reservoir permutes).
  • Surface skip counts — thread SkipCounts out of the streaming + whole-genome callers; print a stderr summary when the cap engages, and record over_max_depth + reads_skipped_total in the receipt.
  • --max-read-len enforcement — under --enforce, a read longer than the declared cap aborts loudly (CoreError::ReadExceedsDeclaredLength) instead of silently voiding the predicted envelope; fixes the contradictory plan.rs comment and the stale --memory-budget-mb / --max-read-len help text.
  • Exit-4 breach test — a post-run-only ROSALIND_FORCE_PEAK_RSS_BYTES seam makes the "never a silent overrun" backstop testable: asserts exit 4 + VIOLATED + output/receipt still written. (Previously zero coverage.)
  • CI memory gatecli-e2e now exercises the bounded variants --index contract: fits (exit 0 + contract: OK) → verify → refuse (exit 3, no VCF). Validated locally against the bundled toy fixtures.

Spec: docs/superpowers/specs/2026-06-02-trust-correctness-hardening-keystone-design.md.
Plan: docs/superpowers/plans/2026-06-02-trust-correctness-hardening-keystone.md.

Deferred to a fast-follow (out of scope here): sort k-way-merge tie-break, @SQ contig-length cross-check, BSD ru_maxrss unit fix + cgroup-awareness, the front-door honesty pass, and merging PR #23.

Test plan

  • cargo test green (incl. new unbiased-cap, obs-order, skip-count accumulate, max-read-len abort, receipt-skip-counts, and exit-4 breach tests)
  • cargo fmt --all -- --check clean; 0 warnings (debug + release)
  • Contract gate validated locally (fits exit 0 / refuse exit 3 / verify OK); now wired into CI

🤖 Generated with Claude Code

logannye and others added 8 commits June 2, 2026 08:19
The 6 call/contract-path items from the 2026-06-02 reflection audit:
unbiased hash-priority depth-cap reservoir, obs-order canonicalization,
surface SkipCounts on --index + receipt, --max-read-len ingest enforcement,
exit-4 breach test, CI memory-envelope gate. Cross-cutting guards deferred
to a fast-follow (sort tie-break, @sq check, BSD/cgroup RSS, honesty pass,
PR #23 merge).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
build_column now sorts observations by (allele, base_qual, mapq, reverse)
before emitting, so the downstream order-sensitive f64 likelihood sum in
germline.rs is order-independent and the VCF stays byte-identical regardless
of the active set's internal order. Prerequisite for the depth-cap reservoir,
which permutes the active set.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… drops)

Replaces leftmost-arrival truncation with a fixed-seed content-hash bounded
reservoir + eviction: keep the max smallest-priority reads covering the cursor,
evicting the greatest-priority resident when a smaller-priority read arrives.
Selection is independent of read start position (and thus allele), so a deep
het variant carried only by reads that start AT the variant survives instead of
being silently dropped. Deterministic and bounded at max_depth. Reproduced-bug
regression test included; the identical-reads cap test (ties -> no eviction)
still holds.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ipt)

Thread SkipCounts out of call_germline_region_streaming and
call_germline_whole_genome (summed per contig via SkipCounts::accumulate).
run_variants_index prints a summary when the cap engages or filters drop reads,
and records over_max_depth + reads_skipped_total in the manifest so the receipt
is honest about whether downsampling was load-bearing for the run.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ath)

Under --enforce, a read whose seq.len() exceeds the declared --max-read-len
aborts loudly (CoreError::ReadExceedsDeclaredLength) instead of silently voiding
the predicted memory envelope. Non-enforced runs are unaffected (max_read_len
None). Fixes the contradictory plan.rs doc comment and the stale
--memory-budget-mb / --max-read-len CLI help text.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds a post-run-only ROSALIND_FORCE_PEAK_RSS_BYTES seam (overrides the realized
peak, never the pre-run baseline) to deterministically force
predicted-fits-yet-realized-overruns, and asserts exit 4 + VIOLATED + VCF and
receipt still written. The contract's most safety-critical branch was previously
untested.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…efuse)

Adds a contract gate to cli-e2e: build index -> sort -> variants --index
--enforce at a generous budget (exit 0 + contract: OK), verify the receipt
without re-running, then a 1 MiB budget (exit 3 refuse, no VCF). Makes 'the
bounded contract is exercised in CI' literally true via deterministic exit
codes (no RSS-noise flakiness; exit-4 is covered deterministically by the
force-seam unit test). Validated locally against the bundled toy fixtures.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@logannye
logannye merged commit 1058f7a into main Jun 2, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant