Skip to content

fault_manager: parse and validate rosbag retention rules - #841

Draft
bburda wants to merge 1 commit into
feat/rosbag-retention-0bfrom
feat/rosbag-retention-1a
Draft

bburda wants to merge 1 commit into
feat/rosbag-retention-0bfrom
feat/rosbag-retention-1a

Conversation

@bburda

@bburda bburda commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Pull Request

Summary

Issue 705 adds configurable rosbag retention. This PR adds the rule configuration and its validation; it does not change which recordings are removed yet. The next PR of the stack makes the store use the rules.

This PR is on top of two 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:

  • core::RetentionPolicy, ROS-neutral: it parses the snapshots.rosbag.retention.* parameters and resolves the rule of a fault field by field from four levels: the fault code, the first matching pattern in pattern_order, the fault's severity, the defaults. Two fields exist so far: priority (0-1000, default 0) and over_quota (keep default, or drop).
  • The node reads the retention parameters from the overrides at startup, declares each one read-only with its own value, validates them and logs the policy once.
  • A configuration error does not stop the fault manager. It keeps recording as before, does not use the rules, and reports its own fault ROSBAG_RETENTION_CONFIG_INVALID (CRITICAL, source the fault manager node, description the errors). That fault starts no capture. If it is cleared while the configuration is still wrong, the next confirmed fault reports it again (also a muted confirmation, one inside the capture cooldown, and one confirmed by the tick). A start with a valid configuration, or none, clears it. If the storage is unreachable at start, the report or the clear is retried until the storage accepts it.
  • CaptureHooks gains on_confirmed and on_confirm_candidate, so the node learns about every confirmation without calling into the core under its mutex.
  • An example parameters file, config/rosbag_retention.example.yaml, and the docs (docs/config/fault-manager.rst, the fault manager README and design doc).

Two decisions that differ from the issue text:

  • A fault code with a . is configured through a pattern whose match escapes the dot (GNSS\.FIX_LOST), not as a fault_codes key, because the ROS YAML loader cannot read a dotted key there reliably (next section).
  • Only a key the loader moved stops the fault manager. Every other configuration error keeps it running with its own fault, so one bad retention value does not stop all recording.

What changes for users

  • A stop during startup is a clean stop. A SIGINT or SIGTERM that arrives while the fault manager starts now ends it with exit code 0. Before, a stop during node construction exited with code 1 and the line "Fault manager did not start", and a stop right after construction could abort the process (an uncaught RCLError from creating the executor). An exception while the fault manager runs is now logged as "Fault manager stopped on an error" with exit code 1.
  • Some parameters files now stop the fault manager at startup (exit 1). The ROS YAML loader mishandles a dotted mapping key or an empty mapping inside a block: it moves the keys after it under another prefix, without an error. For example, defaults becomes fault_codes.defaults, or snapshots.rosbag.enabled lands under retention, so rosbag capture is off although the file says enabled: true. At startup the fault manager now reads each parameters file a second time with its own YAML reader. It compares, in every section that rclcpp applies to the node, the names the loader produced with the names the file says. Any difference stops it with a message that names the file, the moved parameters, and the key and line that caused it. This covers the whole fault manager section of the file, not only the retention keys. A file the loader reads correctly is not affected. Flattened top-level keys (snapshots.rosbag.enabled: true directly under ros__parameters) keep working.
  • A -p override under the retention prefix with more key segments than the grammar allows also stops the fault manager with exit code 1.
  • One WARN at startup lists every parameter override that no declaration consumed, so a misspelled key is reported.
  • Retention parameters set while snapshots.rosbag.enabled is false give one WARN and are not validated.

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 and colcon test-result --verbose.
  • The real-process tests are test_retention_config.test.py and test_retention_config_pg.test.py (PostgreSQL behind a TCP proxy that refuses connections until the test opens it) in src/ros2_medkit_fault_manager/test/integration. Run them with ctest -R test_retention. The rule resolution is in RetentionRuleResolution.EachFieldFromFirstLevelThatSetsIt.
  • To try it: start the fault manager with --params-file config/rosbag_retention.example.yaml and rosbag capture on. The log shows the policy line. Change a priority to 1001: the fault list shows ROSBAG_RETENTION_CONFIG_INVALID, and recording goes on as before.
  • I ran this on Jazzy with PostgreSQL 14. Humble and Lyrical run in CI. I ran the ROS YAML loader on the test files in the official Humble, Jazzy and Lyrical images, and its output was identical on all three. 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 November 28, 2026 15:37
@bburda
bburda force-pushed the feat/rosbag-retention-1a branch from 05287b6 to 608d8de Compare December 1, 2026 15:43

// Created cancelled: it runs only while an own-fault action is pending.
retention_timer_ = create_wall_timer(std::chrono::seconds(1), [this]() {
if (!retention_pass()) {

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.

retention_pass() reaches core_->get(), and the core only catches IgnorableConnectionException from storage. Any other storage error, for example a PostgreSQL statement timeout while a maintenance job holds a table lock, or SQLite busy/IOERR, throws out of this timer callback, out of spin(), and the node exits instead of retrying. Could the timer body catch std::exception, log it and keep the timer armed? #862 routes the storage-availability fault through this timer too.

@bburda
bburda force-pushed the feat/rosbag-retention-1a branch from 608d8de to 11e80bd Compare December 2, 2026 12:15
* feat(fault_manager): parse and validate rosbag retention rules
* fix(fault_manager): satisfy clang-tidy in the retention policy and node
* feat(fault_manager): stop on parameters-file keys the loader moves, drive the own fault from events
* feat(fault_manager): compare the loader's reading of parameters files with ours, re-report on every confirmation
* docs(fault_manager): describe the moved-key comparison and the start-up failures
* test(fault_manager): start from a correct section in the second document
* fix(fault_manager): create the retention timer before the started message
* fix(fault_manager): satisfy clang-tidy in the parameters file reading
* feat(fault_manager): apply sections as rclcpp does, compare per section as multisets, verify confirmation candidates
* fix(fault_manager): compare parameters files as rcl merges them, signal confirmations exactly
* fix(fault_manager): treat a stop signal during startup as a clean stop
* fix(fault_manager): keep construction and spinning as separate phases in main
@bburda
bburda force-pushed the feat/rosbag-retention-1a branch from 11e80bd to 2343f85 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