Prevent interval endpoint overflow and remove stray adjust-mods stderr output - #706
Open
SuhasSrinivasan wants to merge 2 commits into
Open
Conversation
This was referenced Aug 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Review status: Author-reviewed and ready for ONT review.
Fixes #671.
Summary
dbg!call fromadjust-modsso successful commands no longer print internal source state to stderr.ReferenceIntervalBatchesFeederendpoint arithmetic from overflowing nearu32::MAX.Severity
Severity: Low — diagnostics and extreme-coordinate reliability
Rationale: The stderr leak is routine but does not change the output BAM. The interval defect can panic, wrap coverage backwards, or fail to terminate, but it requires an uncommon accepted-input coordinate and interval-size combination near the
u32limit. Neither defect is known to change routine biological calls or statistics.Root cause
Adjust::runexecutesdbg!(&self.cpg)unconditionally before motif parsing. Separately,ReferenceIntervalBatchesFeeder::next_batchevaluatesstart + self.interval_sizeinu32before clipping the result to the contig end. The addition therefore panics in debug builds and wraps in release builds beforemincan constrain it.Implementation
The two fixes remain separate commits:
dbg!expression without changing intended logging.start.saturating_add(self.interval_size), then retain the existing clip to the contig end.The saturating addition is local to the faulty endpoint expression and avoids a coordinate-type or scheduling refactor.
Preserved behavior
Non-goals
u32coordinates, broad arithmetic audit, interval-size policy change, or scheduler refactor.Behavior before and after
adjust-mods --ignore h&self.cpg = falseand a Rust source location to stderr&self.cpgormodbam_util/subcommands.rssignature in stderr[u32::MAX-9, u32::MAX)with interval size 8[MAX-9, MAX-1),[MAX-1, MAX); exactly nine covered basesTesting
Test environment
8eb4867b309a3f0eac4317d16652780ea3cec506477b0986db3b77a24d2d19363c8a3dbbac4f2329; clean after testingCargo.lockSHA-256f9d3389f8fc63c9ad653dad3fbf43a1c26cc54008f0a39e06e71ff6455a1e9b5;rust-htslib0.46.0,hts-sys2.2.0,tempfile3.27.05cecc3fb3a9336068d9e3c68d5c08d678153dd2c; issue reproducer foradjust-mods, plus replay oftest_reference_interval_batches_near_u32_maxdbg!signature; debug overflow panics, and release behavior violates the bounded exact-coverage oracleTMPDIR=/private/tmp/modkit-pr-small-output-test-tmp cargo test -p mod_kit interval_chunks::interval_chunks_tests::test_reference_interval_batches_near_u32_max -- --exact --nocapture --test-threads=1TMPDIR=/private/tmp/modkit-pr-small-output-test-tmp cargo test -p modkit --test test_adjust_mods test_adjust_mods_does_not_dump_cpg_to_stderr -- --exact --nocapture --test-threads=1usingtests/resources/bc_anchored_10_reads.sorted.bamTMPDIR=/private/tmp/modkit-pr-small-output-test-tmp cargo test --workspace --all-targets --no-fail-fast -- --test-threads=1test_adjust_modstarget contributed 15 passedrustfmt --edition 2021 --check modkit-core/src/interval_chunks.rs modkit-core/src/modbam_util/subcommands.rs modkit/tests/test_adjust_mods.rs;git diff --check upstream/master...HEADTests not performed
Scientific validation
Output and compatibility
adjust-modsinputs.Reviewer guide
adjust-modsleaks debug state to stderr and interval batching can overflow atu32endpoints #671.modbam_util/subcommands.rsand the one-line saturating addition ininterval_chunks.rs.Checklist