Skip to content

fault_manager: max_bags and keep_first per rosbag retention rule - #858

Draft
bburda wants to merge 1 commit into
feat/rosbag-retention-2from
feat/rosbag-retention-3
Draft

bburda wants to merge 1 commit into
feat/rosbag-retention-2from
feat/rosbag-retention-3

Conversation

@bburda

@bburda bburda commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Pull Request

Summary

max_bags_per_fault is one cap for every fault code, and it keeps the newest recordings, so the first occurrence of a fault (often the one with the root cause) is lost. Issue 705 asks for the cap per fault code, pattern or severity, and for a way to keep the first recording. This PR adds the rule fields max_bags and keep_first.

This PR is on top of six PRs in the stack. Please review those first. The diff of this PR is against the branch of the PR directly below it.

What it adds:

  • max_bags (integer >= 0) at every rule level. It replaces max_bags_per_fault for the faults the rule covers. 0 means no cap.
  • keep_first (true/false). With an effective cap of 2 or more, the oldest stored recording of the fault code is kept, plus the max_bags - 1 newest. With a cap of 0 or 1 it is ignored, and each store logs a warning naming the fault code.
  • The clear follows the rule. With auto_cleanup, a clear deletes a fault's recordings when that fault's max_bags is 1, as before, but now from its rule. So a rule max_bags: 3 keeps the history on clear, even with a global max_bags_per_fault: 1.
  • Eviction order. Within one priority and one status class, a recording kept by keep_first is evicted after the others.
  • A fault that cannot be read during a store is not capped in that store and is logged once.
  • The startup warning about snapshots.recapture_cooldown_sec working against the cap also checks the rules' max_bags.
  • Docs: docs/config/fault-manager.rst, docs/tutorials/snapshots.rst, config/snapshots.yaml, the example retention file, the fault manager README and design doc.

What changes for users

  • Without retention parameters nothing changes.
  • New rule fields max_bags and keep_first. An invalid value is reported as ROSBAG_RETENTION_CONFIG_INVALID, and the fault manager runs with the global cap.
  • "First" means the oldest recording of the fault code that is still stored. Once space eviction has removed it, the next oldest is first.
  • Log line change. A cap removal now reads (its max_bags) instead of (max_bags_per_fault).

Issue


Type

  • Bug fix
  • New feature or tests
  • Breaking change
  • Documentation only

Testing

  • colcon build --packages-up-to ros2_medkit_fault_manager --cmake-args -DPOSTGRES_SUPPORT=ON, then colcon test --packages-select ros2_medkit_fault_manager (with ROS2_MEDKIT_TEST_PG_CONN for the PostgreSQL cases) and colcon test-result --verbose.

  • The real-process test is src/ros2_medkit_fault_manager/test/integration/test_rosbag_max_bags.test.py. It covers:

    • the first plus the newest;
    • the cap endpoints 0, 1 and 2;
    • field-by-field resolution, and a severity change;
    • the clear;
    • eviction order with status and with a shared recording;
    • a burst with two codes;
    • an unreadable fault;
    • invalid values.

    test_rosbag_quota_pg.test.py has the PostgreSQL case.

  • The rosbag test helper now waits until the fault manager has taken each published message before it reports the fault. Before, a report could be served between two queued messages and the recording missed one of them.

  • I ran this on Jazzy with PostgreSQL 14. Humble and Lyrical run in CI. clang-tidy on the changed files reports nothing new.


Checklist

  • Breaking changes are clearly described (and announced in docs / changelog if needed)
  • Tests were added or updated if needed
  • Docs were updated if behavior or public API changed

@bburda
bburda added this pull request to stack #836 December 1, 2026 13:21
@bburda
bburda force-pushed the feat/rosbag-retention-3 branch from 8931f64 to 5bc6412 Compare December 1, 2026 15:43
: ResolvedRule{};
facts.priority = rule.priority;
facts.over_quota = rule.over_quota;
facts.cap = rule.max_bags.value_or(limits_.max_bags_per_fault);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

SqliteFaultStorage::get_fault() returns nullopt for any step() failure, not only SQLITE_DONE, so a failed read lands here as an absent fault and resolves the rule with severity 0. With a severity rule like ERROR: max_bags: 4 and a global max_bags_per_fault: 1, that store trims the fault down to one recording, while the docs and the PR say an unreadable fault keeps all its recordings in that store. The new integration test notes this ("fails in sqlite3_step and reads as absent") and steps around it. Making get_fault() throw on anything other than SQLITE_ROW/SQLITE_DONE would route this case into the existing read-failure path.

@bburda
bburda force-pushed the feat/rosbag-retention-3 branch from 5bc6412 to 4e3ee71 Compare December 2, 2026 12:15
* feat(fault_manager): max_bags and keep_first per rosbag retention rule
* fix(fault_manager): one warning per unreadable fault
* fix(fault_manager): one line for an unreadable fault over the quota; cooldown warning counts rule caps
@bburda
bburda force-pushed the feat/rosbag-retention-3 branch from 4e3ee71 to 97fc473 Compare December 2, 2026 18:24

This branch has not been deployed

No deployments
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