[MPPI] Destroy the motion model before its loader #6778
All Vouch review confidence checks passed
Residual risk 0.03 = Change Risk (0.18) × (1 − Review Confidence (0.84)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.18 · 4 lines diff across 1 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.78 · 4 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.096
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
7 items
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
| Files with missing lines | Coverage Δ | |
|---|---|---|
| nav2\_mppi\_controller/src/optimizer.cpp | 96.22% <ø> (ø) | |
... and 5 files with indirect coverage changes
<details><summary> :rocket: New features to boost your workflow: </summary>
</details>
Should this happen in shutdown instead?
Also remove the comment
Generally LGTM
I moved this to shutdown.
@SteveMacenski I have addressed your comments.
Approved
Approved these changes.
SteveMacenski
MatthijsBurgh
<!-- Please fill out the following pull request template for non-trivial changes to help us process your PR faster and more efficiently.-->
---
Basic Info
| Info | Please fill out this column |
| ------ | ----------- |
| Ticket(s) this addresses | none (found by reading the code, then confirmed with the existing unit tests) |
| Primary OS tested on | Ubuntu (
ros:rolling-ros-baseDocker image) || Robotic platform tested on | none, unit tests only |
| Does this PR contain AI generated software? | Yes. It was written with Claude Code and checked by building
nav2_mppi_controllerfrom source and running its unit tests before and after the change, plusament_uncrustifyandament_cpplint|| Was this PR description generated by AI software? | Yes, written with Claude Code for me; I have checked the PR and the description myself |
---
Description of contribution in a few bullet points
Bug: since the motion models became plugins (#6076), every
mppi::Optimizerdestruction printsCause:
Optimizerdeclaresmotion_model_(optimizer.hpp) beforemotion_model_loader_, and~Optimizer()only callsshutdown(). Members are destroyed in reverse order, so thepluginlib::ClassLoadergoes while the shared motion model instance still exists (held bymotion_model_and bycritics_data_.motion_model).setMotionModel()has the same problem when it replaces an existing loader, for example on configure after cleanup.Fix: release both references to the motion model in
Optimizer::shutdown(), which the destructor already calls, and beforesetMotionModel()creates a new loader. The header is unchanged, so the patch can be backported.Affected branches:
| Branch | Affected | Patch applies | How checked |
|---|---|---|---|
| main | yes | this PR | reproduced, fix verified |
| lyrical | yes (has the pluginized motion models) | yes, clean cherry-pick | by inspection |
| kilted, jazzy, humble | no | n/a | by inspection: the motion model is not a plugin there |
Could a maintainer add the
backport-lyricallabel?Description of documentation updates required from your changes
None.
Description of how this change was tested
Built
nav2_mppi_controller(Release, tests on) frommaininros:rolling-ros-base, ran these test binaries and counted theSEVERE WARNINGlines:| Test binary |
main|main+ this PR ||---|---|---|
|
controller_state_transition_test(1 test) | 2 | 1 ||
optimizer_unit_tests(22 tests) | 43 | 22 ||
optimizer_smoke_test(3 tests) | 6 | 3 |All tests pass before and after. With gdb I checked the warning that remains in
controller_state_transition_test: it comes fromnav2_costmap_2d::Costmap2DROS::~Costmap2DROS()(the test's costmap is destroyed withouton_cleanup()), not from MPPI. The remaining warnings in the other two binaries come one per test, which matches the same costmap source, but I did not trace each of them.ament_uncrustifyandament_cpplintreport no problems for the changed files.---
Future work that may be required in bullet points
None for this change.
For Maintainers: <!-- DO NOT EDIT OR REMOVE -->
backport-*.🤖 Generated with Claude Code