Repository navigation
Fix classify regressions from batched minimizer lookups - #1065
Merged
Merged
Conversation
ClassifySequence kept its MinimizerLookups in a static thread_local, constructed on a thread's first call with that call's database, hit list, hit counts, taxon counters and options, and never reset or rebound afterwards. That caused three defects. The hit-group count was never reset, so it accumulated across every read a thread classified, and after a thread's first few reads every read passed --minimum-hit-groups, including the wrapper's default of 2. On 72,166,933 dog read pairs at -g 2, master classified 805,969 pairs (1.1%) that 2.18.0-RC1 leaves unclassified. On 20,000 pairs of random sequence each carrying one 36 bp reference fragment, 2.17.2 and RC1 classify 15,002 and master classified 19,827; a read with hit list "0:32 335341:5 0:29 |:| 0:66" is unclassified in RC1 and was classified in master. The database was fixed at the first call. A daemon serves several databases from its index map, so a request against a second database looked its minimizers up in the first database's table. A daemon that served the e2e database and then a database built from half of data/ classified 402 of 440 pairs for the second request, where a direct run against that database classifies 264. The hit list, hit counts and counters were bound by reference to the locals of the ProcessFiles call that first ran on the thread. A later ProcessFiles call, for the next file pair or the next daemon request, has new locals, and the references only worked when those landed at the same addresses. MinimizerLookups is now constructed for each read, so it starts with a zero hit-group count and refers to the current database and outputs. Only its batch buffer is thread_local, so that it is still allocated once per thread. Hit groups are also counted as they were before lookups were batched. The previous minimizer was local to get_batch, so it was forgotten at every batch boundary: after 1,024 positions in a long read, and after every minimizer in quick mode, where the batch size is 1. It was also updated only on a hit, so a hit whose minimizer repeated a minimizer that had missed, or followed a sampled-away minimizer, counted as a repeat rather than a new group. The previous minimizer is now a member, updated by every looked-up minimizer, cleared by a mate or frame border or a sampled-away minimizer, and left alone by an ambiguous span, as the consecutive-minimizer check in RC1 did. classify.min_hit_groups_10.golden classifies tests/data/mhg_*.fq at --minimum-hit-groups 10, where five of the 18 pairs fall short. The simulated reads all clear 5, so classify.min_hit_groups_5.golden could not catch this. The golden files equal RC1's output and report; master fails the check. Verified against RC1 on the e2e database: per-read output identical at -g 2, 10 and 20 on 616,000 pairs built from the fixture reads; output, -F output, --report-zero-counts report and --report-minimizer-data report identical on those and on the 20,000 single-fragment pairs at 8 threads; the two-database daemon request matches the direct run. The end-to-end suite passes.
Quick mode is meant to stop at the first hit that brings a read to --minimum-hit-groups. Since lookups were batched, the early exit compared a local minimizer_hit_groups that nothing increments, so it never fired at the wrapper's default of -g 2 and fired after the first minimizer, hit or not, at -g 0. On 616,000 pairs built from the fixture reads, 2.17.2 and 2.18.0-RC1 classify 588,000 in quick mode at -g 0 while master classified 460,600, and at -g 2 master made the same calls as normal mode, 47,600 of which differ from RC1's quick calls, and ran slower than normal mode. The exit now tests the lookup's hit-group count once the read has a hit. Quick mode resolves each minimizer as it is added, and hits and hit groups change only on a hit, so the condition first holds at the hit that reaches the threshold, as before. The minimizer that triggers the exit is now counted in the total passed to ResolveTree. tests/golden/paired.quick.out and paired.quick.report go back to their contents before afaa1ed and 0903ffd, which were 2.18.0-RC1's output, and the fixed build reproduces them. Verified against 2.18.0-RC1 on the e2e database: quick-mode per-read output and --report-zero-counts report identical at -g 0, 2 and 5, on the 616,000 fixture pairs and on 20,000 pairs of random sequence carrying one reference fragment each. Quick mode at -g 2 now takes 0.35 s single-threaded on the 616,000 pairs, against 1.37 s for RC1's quick mode and 2.1 s for normal mode, since it stops looking minimizers up once the read is decided. The end-to-end suite passes.
A read shorter than k, or one made entirely of ambiguous bases, adds nothing to the hit list. ClassifySequence still compacts the list afterwards, reading taxa[0] and taxa[1] and writing taxa[j] and taxa[j + 1] on an empty vector. When the read is the first a thread classifies, the vector has no storage and classify crashes with a segmentation fault; on a later read it writes into spare capacity, and the following resize happens to leave the output right. Paired reads always carry the mate marker and are not affected, but single-end runs over trimmed reads routinely contain reads under 35 bp. The compaction now runs only when the hit list is not empty, and such a read is written as "0:0" as before. classify.single_short_first_read puts a 20 bp read ahead of the single-end fixture reads and classifies them with one thread. Master exits with SIGSEGV; with this change the short read is unclassified with hit list 0:0 and the rest of the output equals single.out. The end-to-end suite passes.
This was referenced Oct 28, 2026
Closed
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.
Three regressions in
ClassifySequencesince lookups were batched (e041700, 9e1d5c3, 2b94643), reported in #1061. Each commit adds an end-to-end check that fails on master.Construct MinimizerLookups per read. The lookup object was a
static thread_local, constructed on a thread's first call and never reset or rebound:--minimum-hit-groups, including the wrapper's default of 2. On 72,166,933 dog read pairs at-g 2, master classifies 805,969 pairs (1.1%) that 2.18.0-RC1 leaves unclassified.ProcessFilescall on the thread, which only worked while later calls' locals landed at the same addresses.The object is now constructed for each read; only its batch buffer is
thread_local. Hit groups are also counted as they were in RC1 again: the previous minimizer survives batch boundaries and is updated by misses, not only hits.classify.min_hit_groups_10.goldenusestests/data/mhg_*.fq, where five pairs fall short of 10 hit groups (every simulated read clears 5, so the existing check could not catch this).Stop quick mode at the hit that reaches
--minimum-hit-groups. The early exit tested a local counter that is never incremented, so quick mode never stopped early at-g 2and stopped after the first minimizer, hit or not, at-g 0.paired.quick.outandpaired.quick.reportreturn to their RC1 contents, which this reproduces. Quick mode at-g 2now takes 0.35 s on 616,000 pairs single-threaded, against 1.37 s for RC1's quick mode.Skip hit-list compaction for a read with no minimizers. A single-end read shorter than k leaves the hit list empty, and the compaction indexed
taxa[0]andtaxa[1]anyway, so classify segfaulted when such a read was a thread's first.classify.single_short_first_readcovers it.Verified against 2.18.0-RC1 on the e2e database (per-read output,
-Foutput,--report-zero-countsand--report-minimizer-datareports and quick mode, at 1 and 8 threads, on 616,000 fixture-derived pairs and 20,000 single-fragment pairs): identical. On 72 million dog read pairs against a 62.6 GB database, on Graviton5 and AMD EPYC, per-read output is identical to RC1; the--report-zero-countsreport still orders some zero-count sibling taxa differently from RC1, a separate change in master's counter handling that #1066 restores. The end-to-end suite passes, including an AddressSanitizer/UBSan build.