Skip to content

fault_manager: evict rosbag recordings by retention priority - #844

Draft
bburda wants to merge 1 commit into
feat/rosbag-retention-1afrom
feat/rosbag-retention-1b
Draft

bburda wants to merge 1 commit into
feat/rosbag-retention-1afrom
feat/rosbag-retention-1b

Conversation

@bburda

@bburda bburda commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Pull Request

Summary

This PR is part of configurable rosbag retention. The PR below it parses and validates the rules. This PR makes the store and the start of a recording use them. Without any snapshots.rosbag.retention.* parameter, which recordings are kept or removed does not change.

This PR is the top of a stack of four. Please review the three below it first. The diff of this PR is against the branch of the PR directly below it.

What it adds:

  • Eviction by priority. With valid rules, a new recording evicts only recordings whose priority is less than or equal to its own. Lowest priority goes first, then recordings whose faults are all cleared, then healed, then active, then the oldest. A recording shared by a burst of faults ranks by its highest-priority fault, using each fault's current severity. The whole decision is made before anything is applied.

  • over_quota. A new recording can still not fit after every allowed eviction. With keep (the default), it is stored over the limit with a warning, as happens today with a recording alone over the quota. With drop, it is dropped alone and nothing is deleted. In both cases the removal is logged after the directory is gone.

  • Open-time check. For a fault whose rule says drop, the fault manager predicts whether the recording can fit before it starts it. The prediction counts:

    • the stored bytes,
    • minus what the per-fault cap frees,
    • minus what the fault's priority may evict,
    • plus closed recordings that are not stored yet,
    • plus the buffered bytes and the expected post-fault part.

    A recording predicted not to fit is not started, and the ring buffer stays for the next fault. A recording that grows past the prediction is still dropped when it is stored.

  • Invalid configuration. While the retention configuration is invalid, the quota is a hard stop for new recordings: nothing is evicted for the quota, and a recording that does not fit is dropped. The per-fault cap and auto_cleanup work as without rules.

  • Docs: docs/config/fault-manager.rst, the fault manager README and design doc, and the example parameters file.

What changes for users

  • A failed bag open no longer loses the pre-fault history. Before this PR the buffered messages were moved out before the bag was opened, and an open failure dropped them. They now go back into the ring buffer, and the next fault within duration_sec gets its history. This applies with and without rules.
  • With an invalid retention configuration, a new recording that does not fit is dropped. Before, the oldest recordings were evicted. The fault ROSBAG_RETENTION_CONFIG_INVALID shows the cause.
  • New log lines.
    • A dropped recording logs one WARN naming its path, its size, the quota and the reason.
    • A recording not started by the open-time check logs one INFO line.
    • A recording stored over the limit under keep logs a WARN.

Issue


Type

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

Testing

  • colcon build --packages-up-to ros2_medkit_fault_manager ros2_medkit_integration_tests --cmake-args -DPOSTGRES_SUPPORT=ON, then colcon test --packages-select ros2_medkit_fault_manager ros2_medkit_integration_tests and colcon test-result --verbose.
  • The real-process tests are in src/ros2_medkit_fault_manager/test/integration/test_rosbag_quota.test.py and test_rosbag_quota_pg.test.py. The test through the gateway is src/ros2_medkit_integration_tests/test/features/test_rosbag_retention_priority.test.py: CRITICAL and WARN faults on one app, and GET /api/v1/apps/<app>/bulk-data/rosbags lists the CRITICAL recording but not the evicted one, nor one dropped under over_quota: drop.
  • To try it: give severity.CRITICAL.priority: 900 and defaults.priority: 10 under snapshots.rosbag.retention, and set a small snapshots.rosbag.max_total_storage_mb. Then confirm a few WARN faults and one CRITICAL fault: the CRITICAL recording stays, and the oldest WARN ones are evicted.
  • 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 November 29, 2026 11:27
@bburda
bburda force-pushed the feat/rosbag-retention-1b branch from 7b4eb66 to 5c2e5ab Compare December 1, 2026 15:43
pending.assign(pending_bytes_.begin(), pending_bytes_.end());
}
const double window = config_.duration_sec > 0.0 ? config_.duration_after_sec / config_.duration_sec : 0.0;
const auto reserve = static_cast<size_t>(static_cast<double>(buffered_bytes) * (1.0 + std::max(0.0, window)));

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.

With topics: entity this reserve comes from buffer_bytes_, which covers every buffered topic, while the recording only gets the faulting entity's topics (the caller already has entity_topics resolved at this point). On a busy graph with over_quota: drop, or with an invalid configuration where this check gates every fault, a fault whose filtered bag would fit is refused and gets no recording. Could the estimate sum only the buffered messages that pass the entity filter?

@bburda
bburda force-pushed the feat/rosbag-retention-1b branch from 5c2e5ab to 8e723eb Compare December 2, 2026 12:15
* feat(fault_manager): evict rosbag recordings by priority, honour over_quota, check the quota before a recording starts
* docs(fault_manager): describe priority eviction, over_quota and the open-time quota check
* fix(fault_manager): count closed recordings that are not stored yet in the open-time quota check
* docs(fault_manager): an invalid retention configuration is a hard stop for the quota, pending recordings count in the check
* fix(fault_manager): count a pending recording once in the open-time quota check
* docs(fault_manager): the pending term of the open-time check is a payload estimate
* test(fault_manager): pin the restore order, end the drop test's window by SIGTERM, make the failed open independent of the window
@bburda
bburda force-pushed the feat/rosbag-retention-1b branch from 8e723eb to 77fd4ef 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