Skip to content

fix(Feature): eliminate cache-invalidation side effect in getConvexHulls() - #9404

Closed
timosachsenberg wants to merge 4 commits into
developfrom
claude/side-effect-investigation-qJtr9
Closed

timosachsenberg wants to merge 4 commits into
developfrom
claude/side-effect-investigation-qJtr9

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented May 25, 2026 •

Copy link
Copy Markdown
Contributor

The non-const getConvexHulls() unconditionally set convex_hulls_modified_
= true, causing unnecessary recomputation of the overall convex hull on
every subsequent getConvexHull() call — even when callers only read. Due
to C++ overload resolution, ~20 read-only call sites in hot paths
(feature finding, scoring, ID mapping) triggered this side effect simply
because they held a non-const Feature reference.

Replace the non-const overload with explicit mutation methods:

  • addConvexHull(): for push_back use cases
  • clearConvexHulls(): for clear use cases
  • getMutableConvexHulls(): for complex direct-access mutation

Read-only callers now automatically resolve to the const overload,
which does not touch the dirty flag.

https://claude.ai/code/session_01YadC62yRF8dsQHHF8kebe2

Summary by CodeRabbit

  • Refactor
    • Improved convex-hull management for features: new dedicated operations to add/clear hulls and a single consistent method to obtain the overall hull. Internal handling updated across feature processing and IO for more predictable geometry behavior.
  • New Features
    • Python bindings added for managing per-feature convex hulls (add and clear) for easier scripting.

Review Change Stack

claude added 3 commits May 25, 2026 08:46
…lls()

The non-const getConvexHulls() unconditionally set convex_hulls_modified_
= true, causing unnecessary recomputation of the overall convex hull on
every subsequent getConvexHull() call — even when callers only read. Due
to C++ overload resolution, ~20 read-only call sites in hot paths
(feature finding, scoring, ID mapping) triggered this side effect simply
because they held a non-const Feature reference.

Replace the non-const overload with explicit mutation methods:
- addConvexHull(): for push_back use cases
- clearConvexHulls(): for clear use cases
- getMutableConvexHulls(): for complex direct-access mutation

Read-only callers now automatically resolve to the const overload,
which does not touch the dirty flag.

https://claude.ai/code/session_01YadC62yRF8dsQHHF8kebe2
After removing the non-const getConvexHulls() overload,
vector<ConvexHull2D>::iterator no longer compiles because the const
overload returns const_iterator from begin()/end(). Both loop bodies
were already read-only.

https://claude.ai/code/session_01YadC62yRF8dsQHHF8kebe2
Register the new methods in the test000 Feature docstring and add
a small round-trip test exercising addConvexHull and clearConvexHulls
through the nanobind binding.

https://claude.ai/code/session_01YadC62yRF8dsQHHF8kebe2
@github-actions

Copy link
Copy Markdown
Contributor

@timosachsenberg The following names might be missing from the AUTHORS file:

  • Claude

Please consider applying the following patch:

--- AUTHORS	2026-05-25 10:15:30.094870070 +0000
+++ AUTHORS.new	2026-05-25 10:15:35.109830403 +0000
@@ -23,6 +23,7 @@
  - Chris Bauer
  - Chris Bielow
  - Christian Ehrlich
+ - Claude
  - Clemens Groepl
  - Cornelia Friedle
  - Daniel Jameson

@coderabbitai

coderabbitai Bot commented May 25, 2026 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1f856293-a502-4e32-b835-df3770068fb0

📥 Commits

Reviewing files that changed from the base of the PR and between 9b7475b and ef22b7b.

📒 Files selected for processing (5)
  • src/openms/include/OpenMS/KERNEL/Feature.h
  • src/openms/source/KERNEL/Feature.cpp
  • src/pyOpenMS/bindings/bind_kernel.cpp
  • src/tests/class_tests/openms/source/Feature_test.cpp
  • src/topp/FeatureFinderCentroided.cpp
💤 Files with no reviewable changes (1)
  • src/topp/FeatureFinderCentroided.cpp

📝 Walkthrough

Walkthrough

The PR refactors the Feature class convex hull API to use named mutators (addConvexHull, clearConvexHulls, getMutableConvexHulls) instead of direct vector manipulation. All call sites throughout feature-finder algorithms, serialization handlers, and tools are updated consistently, with Python bindings and tests added.

Changes

Feature convex hull API refactoring

Layer / File(s) Summary
Feature class API declaration and implementation
src/openms/include/OpenMS/KERNEL/Feature.h, src/openms/source/KERNEL/Feature.cpp, src/pyOpenMS/bindings/bind_kernel.cpp
Feature adds getMutableConvexHulls(), addConvexHull(), and clearConvexHulls(); getConvexHull() now returns by-value; internal cached modified/cached hull members removed; Python bindings expose new methods and change convex-hull exposure semantics.
Hull addition across feature creation and serialization
src/openms/include/OpenMS/ANALYSIS/OPENSWATH/MRMTransitionGroupPicker.h, src/openms/source/FEATUREFINDER/Biosaur2Algorithm.cpp, src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmMetaboIdent.cpp, src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp, src/openms/source/FEATUREFINDER/FeatureFinderIdentificationAlgorithm.cpp, src/openms/source/FEATUREFINDER/FeatureFinderMultiplexAlgorithm.cpp, src/openms/source/FORMAT/FeatureMapArrowIO.cpp, src/openms/source/FORMAT/HANDLERS/FeatureXMLHandler.cpp, src/topp/MassTraceExtractor.cpp
Feature construction and deserialization now call addConvexHull() instead of mutating the hull vector directly.
Hull clearing, mutable access, and read-only iteration
src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmMetaboIdent.cpp, src/openms/source/FEATUREFINDER/FeatureFinderIdentificationAlgorithm.cpp, src/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp, src/openms/source/ANALYSIS/MAPMATCHING/MapAlignmentTransformer.cpp, src/openms/source/FORMAT/OMSFileLoad.cpp, src/topp/FeatureFinderCentroided.cpp, src/openms/source/ANALYSIS/ID/IDMapper.cpp, src/topp/FileFilter.cpp, src/topp/FeatureLinkerBase.cpp, src/topp/MRMTransitionGroupPicker.cpp
Calls that cleared hulls now use clearConvexHulls(); code that needs mutable hull data uses getMutableConvexHulls(); IDMapper iteration uses const_iterator.
Test additions for new Feature API methods
src/tests/class_tests/openms/source/Feature_test.cpp, src/pyOpenMS/tests/unittests/test000.py, src/pyOpenMS/tests/unittests/test_IDMapper.py, src/tests/class_tests/openms/source/OpenSwathTestHelper.h, src/tests/class_tests/openms/source/FeatureMapArrowIO_test.cpp, src/tests/class_tests/openms/source/OpenSwathMRMFeatureAccessOpenMS_test.cpp
C++ and Python unit tests updated and extended to exercise getMutableConvexHulls(), addConvexHull(), and clearConvexHulls(); test helpers and fixtures updated accordingly.

Possibly related PRs

  • OpenMS/OpenMS#8385: Both PRs touch Biosaur2Algorithm feature-conversion code and convex-hull handling.

Suggested labels

Review effort [1-5]: 3

Suggested reviewers

  • cbielow
  • jpfeuffer
  • pjones

"I hop and stitch each convex line,
add and clear with methods fine,
tests and bindings all in tow,
geometry neat — now off I go! 🐇"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.22% 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 clearly and concisely describes the main change: eliminating a cache-invalidation side effect in the getConvexHulls() method, which is the core objective of this refactoring PR.
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.

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

✨ 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 claude/side-effect-investigation-qJtr9

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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/tests/class_tests/openms/source/Feature_test.cpp (1)

101-113: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Exercise getMutableConvexHulls() in this test section.

This section is named for getMutableConvexHulls(), but it only reads through getConvexHulls(). As written, it does not test the mutable accessor path at all.

Suggested test adjustment
 START_SECTION((vector<ConvexHull2D>& getMutableConvexHulls()))
   Feature tmp;
   tmp.setConvexHulls(hulls);
-  TEST_EQUAL(tmp.getConvexHulls().size(),2)
-  TEST_REAL_SIMILAR(tmp.getConvexHulls()[0].getHullPoints()[0][0],1.0)
-  TEST_REAL_SIMILAR(tmp.getConvexHulls()[0].getHullPoints()[0][1],2.0)
-  TEST_REAL_SIMILAR(tmp.getConvexHulls()[0].getHullPoints()[1][0],3.0)
-  TEST_REAL_SIMILAR(tmp.getConvexHulls()[0].getHullPoints()[1][1],4.0)
-  TEST_REAL_SIMILAR(tmp.getConvexHulls()[1].getHullPoints()[0][0],0.5)
-  TEST_REAL_SIMILAR(tmp.getConvexHulls()[1].getHullPoints()[0][1],0.0)
-  TEST_REAL_SIMILAR(tmp.getConvexHulls()[1].getHullPoints()[1][0],1.0)
-  TEST_REAL_SIMILAR(tmp.getConvexHulls()[1].getHullPoints()[1][1],1.0)
+  auto& mutable_hulls = tmp.getMutableConvexHulls();
+  TEST_EQUAL(mutable_hulls.size(),2)
+  TEST_REAL_SIMILAR(mutable_hulls[0].getHullPoints()[0][0],1.0)
+  TEST_REAL_SIMILAR(mutable_hulls[0].getHullPoints()[0][1],2.0)
+  TEST_REAL_SIMILAR(mutable_hulls[0].getHullPoints()[1][0],3.0)
+  TEST_REAL_SIMILAR(mutable_hulls[0].getHullPoints()[1][1],4.0)
+  TEST_REAL_SIMILAR(mutable_hulls[1].getHullPoints()[0][0],0.5)
+  TEST_REAL_SIMILAR(mutable_hulls[1].getHullPoints()[0][1],0.0)
+  TEST_REAL_SIMILAR(mutable_hulls[1].getHullPoints()[1][0],1.0)
+  TEST_REAL_SIMILAR(mutable_hulls[1].getHullPoints()[1][1],1.0)
 END_SECTION
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/tests/class_tests/openms/source/Feature_test.cpp` around lines 101 - 113,
The test is supposed to exercise getMutableConvexHulls() but only calls
getConvexHulls(); change the test to call tmp.getMutableConvexHulls(), mutate
one of the hull points (for example modify hull 0 point 0 x/y), then assert the
mutation is visible through tmp.getConvexHulls() (or a subsequent
getMutableConvexHulls() call); keep the existing setConvexHulls(hulls) and other
value checks but add a mutation via getMutableConvexHulls() on the Feature
instance to verify the mutable accessor works.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/openms/include/OpenMS/KERNEL/Feature.h`:
- Around line 89-96: Replace the short "///" comments for the four new public
methods with full Doxygen blocks: add a /** */ comment for
getMutableConvexHulls() that includes `@brief`, `@return` (reference to vector of
ConvexHull2D) and `@note` that it marks the cache dirty; for setConvexHulls(const
std::vector<ConvexHull2D>& hulls) include `@brief` and `@param` [in] hulls; for
addConvexHull(const ConvexHull2D& hull) include `@brief` and `@param` [in] hull; for
clearConvexHulls() include `@brief` and `@note` if it invalidates cached data;
include `@throws` only if the method can throw, otherwise omit, following the
project's documentation conventions and using the exact symbol names
getMutableConvexHulls, setConvexHulls, addConvexHull, clearConvexHulls.

---

Outside diff comments:
In `@src/tests/class_tests/openms/source/Feature_test.cpp`:
- Around line 101-113: The test is supposed to exercise getMutableConvexHulls()
but only calls getConvexHulls(); change the test to call
tmp.getMutableConvexHulls(), mutate one of the hull points (for example modify
hull 0 point 0 x/y), then assert the mutation is visible through
tmp.getConvexHulls() (or a subsequent getMutableConvexHulls() call); keep the
existing setConvexHulls(hulls) and other value checks but add a mutation via
getMutableConvexHulls() on the Feature instance to verify the mutable accessor
works.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5bb22e8c-92c4-4d47-80cb-306fcf717a9b

📥 Commits

Reviewing files that changed from the base of the PR and between 49d558c and 9b7475b.

📒 Files selected for processing (26)
  • src/openms/include/OpenMS/ANALYSIS/OPENSWATH/MRMTransitionGroupPicker.h
  • src/openms/include/OpenMS/KERNEL/Feature.h
  • src/openms/source/ANALYSIS/ID/IDMapper.cpp
  • src/openms/source/ANALYSIS/MAPMATCHING/MapAlignmentTransformer.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp
  • src/openms/source/FEATUREFINDER/Biosaur2Algorithm.cpp
  • src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmMetaboIdent.cpp
  • src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp
  • src/openms/source/FEATUREFINDER/FeatureFinderIdentificationAlgorithm.cpp
  • src/openms/source/FEATUREFINDER/FeatureFinderMultiplexAlgorithm.cpp
  • src/openms/source/FORMAT/FeatureMapArrowIO.cpp
  • src/openms/source/FORMAT/HANDLERS/FeatureXMLHandler.cpp
  • src/openms/source/FORMAT/OMSFileLoad.cpp
  • src/openms/source/KERNEL/Feature.cpp
  • src/pyOpenMS/bindings/bind_kernel.cpp
  • src/pyOpenMS/tests/unittests/test000.py
  • src/pyOpenMS/tests/unittests/test_IDMapper.py
  • src/tests/class_tests/openms/source/FeatureMapArrowIO_test.cpp
  • src/tests/class_tests/openms/source/Feature_test.cpp
  • src/tests/class_tests/openms/source/OpenSwathMRMFeatureAccessOpenMS_test.cpp
  • src/tests/class_tests/openms/source/OpenSwathTestHelper.h
  • src/topp/FeatureFinderCentroided.cpp
  • src/topp/FeatureLinkerBase.cpp
  • src/topp/FileFilter.cpp
  • src/topp/MRMTransitionGroupPicker.cpp
  • src/topp/MassTraceExtractor.cpp

Comment on lines +89 to +96
/// Mutable access to the convex hulls (marks cache as dirty)
std::vector<ConvexHull2D>& getMutableConvexHulls();
/// Set the convex hulls of single mass traces
void setConvexHulls(const std::vector<ConvexHull2D>& hulls);
/// Add a single convex hull
void addConvexHull(const ConvexHull2D& hull);
/// Remove all convex hulls
void clearConvexHulls();

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add full Doxygen blocks for the new public convex-hull methods.

The new declarations currently use short /// comments only. For this header path, new public methods should include full /** */ docs with @brief, parameter direction tags (for hull), @return (for getMutableConvexHulls()), and @throws/@note where relevant.

📘 Proposed documentation update
-    /// Mutable access to the convex hulls (marks cache as dirty)
-    std::vector<ConvexHull2D>& getMutableConvexHulls();
+    /**
+      `@brief` Mutable access to mass-trace convex hulls
+      `@return` Reference to the internal convex hull container
+      `@note` Marks the overall convex hull cache as dirty.
+    */
+    std::vector<ConvexHull2D>& getMutableConvexHulls();
@@
-    /// Add a single convex hull
-    void addConvexHull(const ConvexHull2D& hull);
+    /**
+      `@brief` Add one mass-trace convex hull
+      `@param`[in] hull Convex hull to append
+      `@note` Marks the overall convex hull cache as dirty.
+    */
+    void addConvexHull(const ConvexHull2D& hull);
@@
-    /// Remove all convex hulls
-    void clearConvexHulls();
+    /**
+      `@brief` Remove all mass-trace convex hulls
+      `@note` Marks the overall convex hull cache as dirty.
+    */
+    void clearConvexHulls();

As per coding guidelines: “src/openms/include/OpenMS/**/*.h: Method documentation must include @brief, parameter documentation with [in], [out], or [in,out], @return, @throws, and @note/@warning.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openms/include/OpenMS/KERNEL/Feature.h` around lines 89 - 96, Replace the
short "///" comments for the four new public methods with full Doxygen blocks:
add a /** */ comment for getMutableConvexHulls() that includes `@brief`, `@return`
(reference to vector of ConvexHull2D) and `@note` that it marks the cache dirty;
for setConvexHulls(const std::vector<ConvexHull2D>& hulls) include `@brief` and
`@param` [in] hulls; for addConvexHull(const ConvexHull2D& hull) include `@brief`
and `@param` [in] hull; for clearConvexHulls() include `@brief` and `@note` if it
invalidates cached data; include `@throws` only if the method can throw, otherwise
omit, following the project's documentation conventions and using the exact
symbol names getMutableConvexHulls, setConvexHulls, addConvexHull,
clearConvexHulls.

The cached overall convex hull (convex_hull_, convex_hulls_modified_)
existed to avoid recomputing a bounding box from mass trace hulls.
The computation is trivial — iterate ~1-5 hulls and enlarge a
DBoundingBox — so the cache added complexity for near-zero benefit.

Changes:
- Remove mutable members convex_hull_ and convex_hulls_modified_
- getConvexHull() now computes and returns by value each time
- Simplify constructors, copy/move operators, and mutators
- Remove no-op expandToBoundingBox() on overall hull in
  FeatureFinderCentroided (the overall hull is already a bounding box)
- Update pyOpenMS binding to return by value

This eliminates all mutable state from Feature related to convex hulls,
making the class simpler and thread-safer.

https://claude.ai/code/session_01YadC62yRF8dsQHHF8kebe2
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.

2 participants