Skip to content

fix(BrukerTimsFile): off-by-one in MS1 centroid cap (#9230) - #9233

Merged
timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:fix/bruker-tims-cap-off-by-one
Apr 28, 2026
Merged

timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:fix/bruker-tims-cap-off-by-one

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Closes FileConverter (Bruker .d reader) caps MS1 defaultArrayLength at exactly 100001, crashing consumers (e.g. Comet) #9230. The MS1 centroiding cap in FrameCentroider::centroid allowed one extra peak past max_peaks, so capped spectra emitted exactly max_peaks + 1 entries — visible in the wild as defaultArrayLength="100001" on 93% of MS1 spectra in a Bruker timsTOF run, which downstream consumers (Comet via pwiz, MSFragger) trip over.
  • Tightens the loop guard from agg_buff.size() > max_peaks to >= max_peaks and drops the matching + 1 from the buffer reserve. Capped output is now exactly bounded by the configured limit.
  • Adds a regression test (DDA MS1 centroiding cap is exact) that lowers the cap to 10 to force it to fire on every MS1 spectrum, then asserts (a) no spectrum exceeds the cap, (b) the cap actually fires (sanity), and (c) the IM FloatDataArray length stays aligned with the peak count.

Notes for the reviewer

A writer-side audit (MzMLHandler spectrum/binaryDataArray emit path) confirmed the OpenMS-emitted mzML was already internally length-consistent at 100001 — defaultArrayLength, m/z and intensity blob sizes (no per-array arrayLength, fall back to defaultArrayLength), and the IM array's explicit arrayLength="..." all matched. So this fix removes the surprising off-by-one but may not be sufficient to stop the downstream pwiz heap-corruption. Recommend the reporter re-run their pipeline against a build with this patch and confirm whether the Comet/MSFragger crash persists; if it does, the underlying bug is downstream of OpenMS at large array sizes.

Test plan

  • BrukerTimsFile_test — new section DDA MS1 centroiding cap is exact (regression: issue #9230) passes; existing centroid/aggregation/round-trip sections continue to pass.
  • Reporter to confirm patched build no longer emits defaultArrayLength > 100000 and report whether downstream consumers still crash.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Corrected MS1 centroiding peak capping to strictly enforce the configured maximum limit instead of potentially exceeding it by one peak per frame.
  • Tests

    • Added regression test validating peak cap enforcement and data alignment in MS1 centroiding.

The cap check `agg_buff.size() > max_peaks` permitted one extra peak past
the limit, so capped MS1 spectra emitted exactly `max_peaks + 1` entries
(e.g. defaultArrayLength="100001" at the default cap of 100000).
Tighten to `>=` and drop the matching `+ 1` from the reserve.

Adds a regression test that lowers the cap to 10 and asserts no
centroided MS1 spectrum exceeds it, while confirming the cap actually
fires on the fixture and that the IM array length stays aligned with
the peak count.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@timosachsenberg

Copy link
Copy Markdown
Contributor Author

@jonasscheid — couldn't assign you directly (not a collaborator on the repo), so flagging here. This patch fixes the off-by-one cap that produced defaultArrayLength="100001" on your timsTOF run.

Could you re-run your pipeline (FileConverter → Comet/MSFragger) against a build of this branch and confirm:

  1. The patched build no longer emits MS1 spectra with defaultArrayLength > 100000.
  2. Whether the Comet/MSFragger heap-corruption crash on cleanup persists.

If (1) holds but (2) still crashes, the cap was an aggravating factor and the underlying bug is downstream of OpenMS at large array sizes (OpenMS-side mzML emit was already length-consistent at 100001 — see the PR description for the audit notes).

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Corrects an off-by-one peak-capping boundary in MS1 centroiding that caused spectra to exceed the configured max_peaks limit by one element. The fix enforces strict adherence to the peak cap and adds a regression test to prevent recurrence.

Changes

Cohort / File(s) Summary
MS1 Centroiding Peak-Cap Fix
src/openms/source/FORMAT/BrukerTimsFile.cpp
Adjusted buffer capacity reservation and cap-enforcement condition in FrameCentroider::centroid to strictly enforce max_peaks limit instead of allowing max_peaks + 1 elements, fixing the off-by-one boundary condition.
Regression Test
src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp
Added DDA MS1 centroiding test to verify centroided spectra never exceed the configured peak cap and that IM float array length remains synchronized with emitted peak count.

Possibly related PRs

Suggested reviewers

  • jcharkow
  • alhigaylan

Poem

🐰 Off-by-one, oh what a pest!
One too many peaks, put to the test.
Now the cap holds firm at the right bound,
No buffer bloat, just peaks pristine and sound!
mzML files rest easy at last. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main issue: an off-by-one bug in MS1 centroid capping, which matches the core changes in BrukerTimsFile.cpp adjusting the peak cap from max_peaks+1 to max_peaks.
Linked Issues check ✅ Passed The changes directly address issue #9230: the fix tightens the centroiding cap guard from > to >= max_peaks and adjusts buffer reserve, ensuring MS1 spectra respect the configured limit exactly, eliminating the off-by-one that caused defaultArrayLength=100001.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the MS1 centroiding cap in FrameCentroider::centroid and adding a regression test; no unrelated alterations detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp (1)

537-540: Use braces for single-line if statements in this new regression section.

The new block currently uses brace-less single-line if statements (Line 537 and Line 539), which conflicts with repository C++ style rules.

Proposed style-only patch
-    if (spec.getMSLevel() != 1) continue;
+    if (spec.getMSLevel() != 1)
+    {
+      continue;
+    }
     max_observed = std::max(max_observed, spec.size());
-    if (spec.size() == static_cast<Size>(cfg.ms1_centroid_max_peaks)) ++capped_count;
+    if (spec.size() == static_cast<Size>(cfg.ms1_centroid_max_peaks))
+    {
+      ++capped_count;
+    }

As per coding guidelines, "Braces must be on their own lines and aligned; always use braces even for single-line blocks (trivial one-liners may stay single-line)".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp` around lines 537
- 540, The new regression block uses brace-less single-line if statements;
update the two conditionals involving spec.getMSLevel() and spec.size() to use
explicit braces. Locate the lines with "if (spec.getMSLevel() != 1) continue;"
and "if (spec.size() == static_cast<Size>(cfg.ms1_centroid_max_peaks))
++capped_count;" and rewrite each as a proper block with opening and closing
braces on their own lines while preserving the existing logic that updates
max_observed and capped_count and keeps the IM array comment intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp`:
- Around line 537-540: The new regression block uses brace-less single-line if
statements; update the two conditionals involving spec.getMSLevel() and
spec.size() to use explicit braces. Locate the lines with "if (spec.getMSLevel()
!= 1) continue;" and "if (spec.size() ==
static_cast<Size>(cfg.ms1_centroid_max_peaks)) ++capped_count;" and rewrite each
as a proper block with opening and closing braces on their own lines while
preserving the existing logic that updates max_observed and capped_count and
keeps the IM array comment intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4d6d22e5-fe4e-4752-a36e-eca9481547a0

📥 Commits

Reviewing files that changed from the base of the PR and between acf5a12 and 73bba81.

📒 Files selected for processing (2)
  • src/openms/source/FORMAT/BrukerTimsFile.cpp
  • src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp

@timosachsenberg
timosachsenberg merged commit e9c54f1 into OpenMS:develop Apr 28, 2026
41 checks passed
timosachsenberg pushed a commit that referenced this pull request Apr 29, 2026
Added entries for:
- Fix: BrukerTimsFile off-by-one in MS1 centroid cap (#9233)
- Native .idparquet identification format (#9225, #9232):
  - PSMArrowIO new class, FileTypes::IDPARQUET, QPXFile::importFromArrow
  - Tool support: IDMerger, IDFileConverter, PercolatorAdapter,
    CometAdapter, MSGFPlusAdapter, SageAdapter

Co-authored-by: GitHub Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
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.

FileConverter (Bruker .d reader) caps MS1 defaultArrayLength at exactly 100001, crashing consumers (e.g. Comet)

1 participant