Skip to content

test(consensus): pin that the per-base error count stays exact on deep pileups - #613

Merged
nh13 merged 1 commit into
mainfrom
nh/investigate-ce
Jul 22, 2026
Merged

nh13 merged 1 commit into
mainfrom
nh/investigate-ce

Conversation

@nh13

@nh13 nh13 commented Jul 21, 2026 •

Copy link
Copy Markdown
Member

This was carried on the port list as a suspected cE collapse on deep mixed pileups — the concern being that the per-base error count subtracts two operands that are already saturated at the Short ceiling, so on a deep enough pileup the difference would collapse toward zero and understate cE.

I investigated and it is not a bug. No behavior change here; this is the test that pins why.

Why it does not happen

The error count is computed as:

let error_count = depth - self.consensus_builder.observations_for_base(base);

Both operands are unsaturated u32 counters — observations is [u32; 4] and contributions() sums it. The clamp to fgbio's Short ceiling is applied to the result, when the value is pushed into the errors array, which is exactly what fgbio does (it stores per-base depths and errors as Short). So the subtraction is exact and only the stored value is clamped.

Why it is still worth a test

The correctness of cE on deep families depends entirely on those two operands staying wide, and nothing pinned that. Narrowing observations to a saturating u16 — a plausible "memory optimization" — would silently collapse the difference toward zero on exactly the deepest families, where the metric matters most, with no test failing.

The test builds a pileup where both the matching and mismatching counts individually exceed the Short ceiling (70,534 contributions total) and asserts the error count comes back exact at 36,767, rather than the 0 a saturated-operand subtraction would produce.

Wave 1 separately verified that per-base aD/bD/ae/be clamp correctly via clamp_per_base_to_fgbio_short with i64 intermediates, so this closes out the last open question in that area.

cargo ci-test (5535 tests), cargo ci-fmt, cargo ci-lint, RUSTDOCFLAGS="-D warnings" cargo ci-doc pass.

Summary by CodeRabbit

  • Bug Fixes

    • Improved accuracy when processing extremely deep sequencing pileups.
    • Error counts now remain exact beyond the previous observation-count ceiling, preventing mismatches from being incorrectly reported as zero.
  • Tests

    • Added regression coverage for deep pileups with a dominant base and mismatching observations.

…p pileups

The per-base error count is `contributions() - observations_for_base(base)`, and
the callers clamp only the *stored* cD/cE values to fgbio's `Short` ceiling. That
is correct, but it is load-bearing and currently implicit: if either operand were
narrowed to a saturating `u16`/`i16` counter, the difference would collapse
toward zero on a pileup deep enough for both to saturate, silently understating
cE on exactly the deepest families.

This was raised as a suspected cE-collapse bug. It is not one -- `observations`
is `[u32; 4]` and `contributions()` sums it, so neither operand saturates -- but
nothing pinned that. This adds a test over a pileup where both the matching and
mismatching counts exceed the ceiling and asserts the difference is exact rather
than collapsed.

No behavior change.
@nh13
nh13 temporarily deployed to github-actions July 21, 2026 01:31 — with GitHub Actions Inactive
@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4c87ee97-f90a-460d-b14d-5ae842a5b37d

📥 Commits

Reviewing files that changed from the base of the PR and between 3da9945 and d46c6ef.

📒 Files selected for processing (1)
  • crates/fgumi-consensus/src/base_builder.rs

Walkthrough

Adds a regression test covering deep pileups beyond i16::MAX, verifying that consensus selection remains correct and mismatch-derived error counts do not collapse due to operand saturation.

Changes

Deep pileup regression

Layer / File(s) Summary
Deep pileup error-count validation
crates/fgumi-consensus/src/base_builder.rs
Adds a test for unsaturated depth, correct consensus selection, and exact mismatch counts beyond the fgbio Short ceiling.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the added regression test for exact per-base error counts on deep pileups.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch nh/investigate-ce

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.39%. Comparing base (f3b0c78) to head (d46c6ef).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #613      +/-   ##
==========================================
- Coverage   93.42%   93.39%   -0.04%     
==========================================
  Files         175      175              
  Lines      104807   104817      +10     
==========================================
- Hits        97919    97896      -23     
- Misses       6888     6921      +33     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nh13

nh13 commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13
nh13 merged commit d302dcc into main Jul 22, 2026
14 checks passed
@nh13
nh13 deleted the nh/investigate-ce branch July 22, 2026 08:19
@nh13 nh13 mentioned this pull request Jul 22, 2026

This branch was previously deployed

1 inactive deployment
github-actions — d46c6efc Deployed Jul 21, 2026 by nh13 via coverage #2820
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