Skip to content

[FIX] Refactor Normalizer instantiation and remove redundant assertions - #10057

Merged
timosachsenberg merged 1 commit into
OpenMS:developfrom
singjc:fix/10049_percolator_normalizer
Sep 4, 2026
Merged

timosachsenberg merged 1 commit into
OpenMS:developfrom
singjc:fix/10049_percolator_normalizer

Conversation

@singjc

@singjc singjc commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

Addresses #10049

Checklist

  • Make sure that you are listed in the AUTHORS file
  • Add relevant changes and new features to the CHANGELOG file
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes
  • Updated or added python bindings for changed or new classes (Tick if no updates were necessary.)

How can I get additional information on failed tests during CI

Click to expand If your PR is failing you can check out

Advanced commands (admins / reviewer only)

Click to expand
  • /reformat (experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.
  • setting the label "NoJenkins" will skip tests for this PR on jenkins (saves resources e.g., on edits that do not affect tests)
  • commenting with rebuild jenkins will retrigger Jenkins-based CI builds

⚠️ Note: Once you opened a PR try to minimize the number of pushes to it as every push will trigger CI (automated builds and test) and is rather heavy on our infrastructure (e.g., if several pushes per day are performed).

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of Percolator-based training and rescoring workflows.
    • Fixed normalization handling to prevent stale state and unexpected failures.
    • Improved compatibility across supported platforms.
  • Maintenance

    • Improved isolation of bundled analysis components to reduce naming conflicts.
    • Removed obsolete internal command-line and validation paths that were not used by supported workflows.

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: df1ac92f-b9cc-484f-822a-3278662332b3

📥 Commits

Reviewing files that changed from the base of the PR and between 25b3b04 and 4989fd8.

📒 Files selected for processing (3)
  • src/openms/source/ANALYSIS/ID/Percolator.cpp
  • src/openms/thirdparty/percolator/Normalizer.cpp
  • src/openms/thirdparty/percolator/patches/01-namespace-wrap.patch
💤 Files with no reviewable changes (1)
  • src/openms/thirdparty/percolator/Normalizer.cpp

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

Changes

Percolator integration

Layer / File(s) Summary
Normalizer lifecycle and callers
src/openms/source/ANALYSIS/ID/Percolator.cpp, src/openms/thirdparty/percolator/patches/01-namespace-wrap.patch
Training and rescoring pass a null normalizer for internal construction. Reset logic deletes the existing normalizer.
Vendored namespace and compile cleanup
src/openms/thirdparty/percolator/patches/01-namespace-wrap.patch
Vendored code is wrapped in the OpenMS internal namespace. Header guards, includes, stream qualification, and logger headers are cleaned up.
Unused vendored paths
src/openms/thirdparty/percolator/patches/01-namespace-wrap.patch
Unused option parsing and SQT sanity handling are removed. Protein-sequence validation is disabled.

Suggested reviewers: cbielow

Poem

A rabbit checks the normalizer with care
Namespaces hop through the Percolator air
Old paths curl up and quietly sleep
Fresh cleanup guards the codebase deep
The build runs lightly, neat and bright
Carrots compile through the night

Merge Risk: ⚪ Minimal · up to 4989f

The normalizer lifecycle cleanup and vendored Percolator updates introduce no identified current-head correctness or runtime risk. The change is ready to merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. (1 skipped: 1 … 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 clearly summarizes the main changes: refactoring Normalizer instantiation and removing redundant assertions.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ 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.

@timosachsenberg timosachsenberg 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.

Reviewed against #10049 and the vendoring tooling. The Percolator.cpp half is correct; the patch-file half is corrupt and blocks merge.

✅ Percolator.cpp — correct fix

SetHandler::normalizeFeatures(Normalizer*& pNorm) assigns pNorm = Normalizer::getNormalizer() unconditionally (SetHandler.cpp:70) before any use, so passing nullptr is right. I checked both call sites: nothing between the declaration (:479, :770) and normalizeFeatures() (:504, :794) dereferences normalizer — only the SanityCheck setup, which either throws out of the function or succeeds without touching it. Every downstream use (preIterationSetup, train, getAvgWeights) runs after the assignment, and resetNormalizer()/setType() still precede the single construction so the subclass is chosen correctly. After this change getNormalizer() has exactly one caller in the whole tree, which is upstream's contract (Caller.cpp).

🔴 Blocking: patches/01-namespace-wrap.patch no longer parses

The new hunk was hand-written instead of regenerated, and it isn't a valid unified diff:

$ git apply --numstat -p0 src/openms/thirdparty/percolator/patches/01-namespace-wrap.patch
error: corrupt patch at line 717

(develop's version of the same file parses fine.) The three defects are in the inline comment below.

This is not a local failure. git apply parses the entire patch before applying anything, so all 65 file sections are lost, not just Normalizer.cpp — every namespace wrap, every std:: qualification, the parseOptions body removal, etc. And sync-from-upstream.sh swallows it:

$ git apply --reject --whitespace=nowarn -p0 .../01-namespace-wrap.patch ; echo "exit=$?"
error: corrupt patch at line 717
exit=128
$ find . -name '*.rej' | wc -l
0

The script runs git apply … || true and then warns only if *.rej files exist. A parse error produces none, so the next ./sync-from-upstream.sh copies raw upstream over the vendored tree, fails to patch it, prints >>> Done. and leaves a tree that doesn't compile. Nothing in CI applies this patch, so it would sit undetected until someone re-syncs.

Fix: regenerate rather than hand-edit — UPSTREAM.md asks for exactly this ("regenerate patches/01-namespace-wrap.patch from the post-adaptation tree rather than hand-editing sources"). The corrected replacement hunks are in the inline comment. I derived them by reconstructing the pinned-SHA upstream Normalizer.cpp (reverse-applying develop's patch section; it round-trips bit-identically) and diffing that against this PR's Normalizer.cpp with the diff -urN --label … invocation from UPSTREAM.md. The result applies cleanly and the full patch parses again.

❓ Does the vendored Normalizer.cpp edit belong in this PR?

#10049 lists it as optional belt-and-braces, and it cuts both ways:

  • With the Percolator.cpp fix in, getNormalizer() has exactly one caller left. The assert(false) can now only fire on a genuine regression — i.e. someone reintroducing the double-instantiation this PR just removed. Deleting it removes the tripwire that caught this bug in the first place, and it's the only thing flagging the related hazard where a second getNormalizer() after a different setType() silently returns a stale singleton of the wrong subclass.
  • Against that, it's a permanent behavioural divergence from upstream that every future syncer has to carry.

My preference would be to land the Percolator.cpp fix alone (the actual root cause) and leave upstream untouched. If you'd rather keep the guard removal, that's defensible — but please then also add a line to the "Patches" section of UPSTREAM.md, since it currently describes 01-namespace-wrap.patch as covering only namespace/compile adaptations, and a silent behavioural change to upstream code is exactly the kind of thing a future re-sync needs to know is deliberate.

Minor

  • CHANGELOG: not updated (checklist item is unticked). Comparable Percolator fixes get entries — e.g. the -percolator_executable abort fix under PercolatorAdapter. A Debug-build abort across 18 tests seems worth a Fix: line.
  • Comment wording: "normalizeFeatures() owns Normalizer construction via its out-parameter" is slightly off — the static singleton owns the object, resetNormalizer() frees it; normalizeFeatures() is just the factory call site. #10049's phrasing plus a cf. upstream Caller.cpp pointer would age better for the next reader.
  • No regression coverage: all five workflows build Release, so NDEBUG hides this entire class of bug. Out of scope here, but a single Debug job (even just Percolator_test) would be what stops the next one.

Generated by Claude Code


@@ -90,3 +93,5 @@

@@ -72,10 +75,7 @@

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.

This hunk is not a valid unified diff, and because git apply parses the whole file before applying anything, it takes down all 65 file sections of the patch (details in the review summary).

Three defects:

  1. Line counts don't match the body. The header claims 10 old / 7 new lines; the body supplies 3 deletions + 4 context = 7 old / 4 new. git apply runs into the next @@ mid-fragment and bails with corrupt patch at line 717.
  2. No leading context. The hunk opens straight on a - line, so the deleted } else { isn't anchored to the } else { theNormalizer = new NoNormalizer(); } block it follows.
  3. The following @@ -90,3 +93,5 @@ hunk was damaged too — both context lines lost one space of indentation ( } → }, out[i] = … → out[i] = …), so they no longer match the file, and its new-side start should now be +90, not +93 (three lines were removed above it).

Replacing both hunks with what diff -urN actually produces for upstream-Normalizer.cpp → this PR's Normalizer.cpp:

@@ -68,9 +71,6 @@
     } else {
      theNormalizer = new NoNormalizer();
     }
-  } else {
-    assert(false);
-    cerr << "Multiple instantiations of Normalizer" << endl;
   }
   return theNormalizer;
 }
@@ -90,3 +90,5 @@
   }
   out[i] = (in[i] - subScore) / scale; // update the intercept m0
 }
+
+}}}  // namespace OpenMS::Internal::Percolator

Also drop the blank lines the hand-edit inserted between hunks — diff -urN doesn't emit them, so they'd reappear as noise on the next regeneration.


Generated by Claude Code

Copy link
Copy Markdown
Contributor

Verified both halves of my review locally. Summary: the Percolator.cpp fix works and is sufficient on its own; the patch file is confirmed broken. A corrected branch is pushed — see the end.

1. The fix works — reproduced the abort, then watched it go away

The vendored subtree is a standalone CMake target with no libOpenMS dependency, so it builds on its own in Debug (-UNDEBUG -O0, asserts live). I drove it with the real SetHandler/DataSet/Normalizer sources through the exact sequence of Percolator::train() (:428-504), varying only the one line this PR changes:

vendored tree Percolator.cpp sequence result
develop (assert present) getNormalizer() — pre-PR SIGABRT: Normalizer.cpp:75: Assertion 'false' failed
develop (assert still present) nullptr — this PR clean; normalizer assigned, features normalized
this PR (assert removed) getNormalizer() — pre-PR clean
this PR (assert removed) nullptr — this PR clean

The abort message matches #10049 exactly. Row 2 is the interesting one: the Percolator.cpp change alone fixes it with the assert still in place, which is the empirical basis for my question about whether the vendored edit needs to be in this PR at all.

Deferring construction doesn't disturb anything else:

  • setType() still selects the subclass — stdv → StdvNormalizer (sub=[3.5 35 0.5], div=[1.70783 …]), uni → UniNormalizer (sub=[1 10 -2], div=[5 50 5]), none → NoNormalizer (sub=[0 0 0], div=[1 1 1]).
  • Normalized feature values are byte-identical across every passing run, matching Percolator: normalizer singleton instantiated twice, aborting every Debug run since #9218 #10049's "Release is numerically correct".
  • Two consecutive train()-style calls in one process each get a freshly allocated instance, so resetNormalizer() still does its job and no stale state survives.

2. The patch file — confirmed against a real upstream checkout

I cloned percolator/percolator at the pinned eb157f7 and replayed sync-from-upstream.sh (copy the 65 whitelisted files → git apply --reject -p0 → CRLF→LF → diff against the committed tree):

vendored tree patch git apply result
develop develop's patch exit 0, 0 rejects bit-identical — harness is faithful, and UPSTREAM.md's re-sync claim holds
this PR this PR's patch exit 128, corrupt patch at line 717, 0 rejects all 65 files left as raw upstream — no namespace wrap; the tree does not compile
this PR regenerated patch exit 0, 0 rejects bit-identical to this PR's intended tree

The zero reject count on the failing run is the operationally nasty part: sync-from-upstream.sh runs git apply … || true and warns only when *.rej files exist. A parse error produces none, so the script prints >>> Done. over a tree it never patched.

Also confirmed that real upstream Normalizer.cpp@eb157f7 is byte-for-byte what the regenerated hunk was produced against, so the diff in my inline comment is exactly what a proper regeneration yields.

Corrected branch

Pushed to claude/openms-pr-10057-review-bxd0ol (commit 5821859) — your two source changes verbatim on current develop, with only the patch file regenerated. Cherry-pick it, or just take the patch-file hunk; whichever is easier.

Two things I deliberately left out, since they're yours to decide: the CHANGELOG entry, and — if the vendored getNormalizer() edit stays — a line in UPSTREAM.md's "Patches" section recording that the vendored tree now diverges behaviourally from upstream, not just for namespace/compile reasons.


Generated by Claude Code

@timosachsenberg
timosachsenberg merged commit 5420e54 into OpenMS:develop Sep 4, 2026
35 checks passed
timosachsenberg added a commit that referenced this pull request Sep 5, 2026
…coring single-transition fixes (#10065)

Two recently merged fixes landed without their own CHANGELOG entry:
- #10057 (fixes #10049) - Percolator::train()/rescore() called Normalizer::getNormalizer()
  themselves even though SetHandler::normalizeFeatures() already does so via its
  out-parameter, tripping the vendored Normalizer's "Multiple instantiations" assert in
  Debug builds.
- #10055 (fixes #10050) - MRMScoring's cross-correlation/mutual-information scoring
  functions required a matrix of at least 2x2, rejecting single-transition compounds.


Claude-Session: https://claude.ai/code/session_01CHEsujKnJFTTChdC6Q8qGu

Co-authored-by: Claude <[email protected]>
okohlbacher added a commit that referenced this pull request Oct 11, 2026
…ch 01, repair patch 01, make the sync fail on unapplied patches (#10485)

* [DOC] Percolator: keep the later patches out of a regenerated patch 01 (UPSTREAM.md)

The documented regeneration of patches/01-namespace-wrap.patch diffed the
upstream files against the current vendored tree. Since #10474 the tree also
holds patch 02 (std::atomic includeNegativesInResult), so a regenerated patch 01
would contain that change too; sync-from-upstream.sh then applies 01 before 02,
and 02 is rejected (PosteriorEstimator.{h,cpp}.rej). Reported by CodeRabbit on
#10474.

The flow now reverse-applies the later patches (02-*.patch, ...) on a staged
copy of the tree and diffs against that copy. It also:
- runs from src/openms/thirdparty/percolator/ throughout; it read whitelist.txt
  and UPSTREAM_COMMIT from there but diffed against
  src/openms/thirdparty/percolator/<file>, which does not exist from there, so
  patch 01 came out as a deletion of every file;
- sorts with LC_ALL=C, the order of the committed patch; under en_US.UTF-8 the
  file sections came out in a different order.

Checked in a scratch copy: the regenerated patch 01 contains no patch-02 line,
and upstream eb157f7 + the regenerated 01 + 02 (sync-from-upstream.sh, which
applies 01 and then 02) reproduces every vendored source file, with no *.rej.
The regenerated 01 differs from the committed one only in the Normalizer.cpp
hunks; the next commit replaces the committed 01 with it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FIX] Percolator: regenerate patches/01-namespace-wrap.patch, which git apply rejected

A hand edit of the Normalizer.cpp hunks in #10057 left the patch malformed: the
added hunk declares 10 old lines but carries 7, and several context lines lost
their leading space. git apply stops with "corrupt patch at line 717" and
applies none of the patch, so sync-from-upstream.sh, even at the pinned SHA,
left all 65 vendored files as plain upstream copies (and rejected a hunk of
patch 02).

The new patch 01 is the output of the regeneration flow in UPSTREAM.md, run on
this tree. It differs from the old one only in the Normalizer.cpp hunks.
upstream eb157f7 + 01 + 02 through sync-from-upstream.sh now reproduces every
vendored source file again, with no *.rej. No source file changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [DOC] Percolator: stop the patch-01 regeneration at the first error (UPSTREAM.md)

The snippet ignored failed downloads, failed reverse-applies of the later
patches and diff errors, and truncated patch 01 before generating the new
one; a failed step silently produced a wrong patch 01. It now runs under
set -euo pipefail in a subshell, downloads into a fresh temp directory,
iterates the whitelist (a stale non-whitelisted file such as an upstream
ssl.cpp no longer gets a section), detects git-format later patches (-p1)
as sync-from-upstream.sh does, and replaces patch 01 only at the end.
Also correct the wording: patch 01 no longer covers the later patches, and
the re-sync check was last verified on 2026-10-09.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FIX] Percolator: sync-from-upstream.sh fails when a patch does not apply

git apply errors were ignored, so a patch that does not parse (patch 01
since #10057) left no .rej, and the script recorded the upstream commit and
printed "Done" with exit code 0. Collect the failing patches, report them and
exit 1 before recording the upstream commit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [DOC] Percolator: patch-01 regeneration also stops when listing or writing the patch fails (UPSTREAM.md)

A failing command substitution in a for list does not trigger set -e, so
when patches/ could not be listed the later patches were not reverse-applied
and patch 01 absorbed them, with exit code 0. The list is now assigned to a
variable first, so a failed listing stops the snippet. Patch 01 is written
to a temporary file in patches/ and renamed over the old one, so a failed
write no longer leaves a truncated patch 01.

The check after regenerating now passes the SHA from UPSTREAM_COMMIT to
sync-from-upstream.sh: without an argument the script syncs to its built-in
default, which a sync to another ref does not update.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [DOC] Percolator: patch-01 regeneration writes through a per-run temporary directory (UPSTREAM.md)

The temporary file for the new patch 01 had a fixed name, so two
regenerations at the same time could write the same file. Use a directory
from mktemp -d inside patches/ instead (same file system, so the final mv is
still a rename), and remove it on exit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FIX] Percolator: sync-from-upstream.sh patches a staging tree, vendored files change only if every patch applies

`git apply --reject` applied the hunks that fit before a patch failed and left
*.rej files next to partially patched vendored sources. The upstream files are
now copied into a temporary staging tree, the whole patch series is applied and
line endings are normalized there, and the result is copied into the vendored
directory only after every patch succeeded. A failing patch exits non-zero and
leaves the vendored files untouched.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Timo Sachsenberg <[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.

Percolator: normalizer singleton instantiated twice, aborting every Debug run since #9218

2 participants