Skip to content

fix: clean up pending_clusters_ when fault cleared before min_count#211

Merged
mfaferek93 merged 2 commits intoselfpatch:mainfrom
eclipse0922:fix/127-cleanup-pending-clusters-on-clear
Feb 15, 2026
Merged

fix: clean up pending_clusters_ when fault cleared before min_count#211
mfaferek93 merged 2 commits intoselfpatch:mainfrom
eclipse0922:fix/127-cleanup-pending-clusters-on-clear

Conversation

@eclipse0922
Copy link
Contributor

Summary

  • Fix phantom references in pending_clusters_ when a fault is cleared before the cluster reaches min_count
  • Remove cleared fault code from pending cluster's fault_codes list
  • Reassign representative based on rule policy (FIRST/MOST_RECENT/HIGHEST_SEVERITY) if the cleared fault was the representative
  • Remove the pending cluster entirely when all its faults are cleared

Test plan

  • ClearFaultRemovesFromPendingCluster — clearing one fault from pending cluster prevents premature activation
  • ClearRepresentativeReassignsPendingCluster — representative is reassigned after clear
  • ClearAllFaultsRemovesPendingCluster — clearing all faults removes the pending cluster
  • All 24 correlation engine tests pass (21 existing + 3 new)
  • clang-format and ament_copyright pass

Closes #127

🤖 Generated with Claude Code

selfpatch#127)

When a fault was cleared before a pending cluster reached min_count,
the cluster retained a phantom reference to the cleared fault code.
This could cause incorrect cluster activation with stale fault data.

- Remove cleared fault from pending cluster's fault_codes list
- Reassign representative if cleared fault was the representative
- Remove pending cluster entirely if all faults are cleared
- Add 3 unit tests covering the fix

Closes selfpatch#127

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes issue #127 by properly cleaning up pending_clusters_ when a fault is cleared before its cluster reaches min_count. The fix ensures that cleared fault codes are removed from pending clusters, representatives are reassigned when necessary, and empty pending clusters are removed entirely.

Changes:

  • Enhanced process_clear() to iterate through pending_clusters_ and remove cleared faults from their respective clusters
  • Implemented representative reassignment logic when the cleared fault was the cluster representative, supporting FIRST, MOST_RECENT, and HIGHEST_SEVERITY policies
  • Added logic to remove pending clusters entirely when all their faults are cleared
  • Added three comprehensive tests covering partial clears, representative reassignment, and complete cluster removal

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/ros2_medkit_fault_manager/src/correlation/correlation_engine.cpp Implements cleanup logic in process_clear() to remove cleared faults from pending clusters, reassign representatives, and remove empty clusters (lines 142-179)
src/ros2_medkit_fault_manager/test/test_correlation_engine.cpp Adds three tests: ClearFaultRemovesFromPendingCluster, ClearRepresentativeReassignsPendingCluster, and ClearAllFaultsRemovesPendingCluster to verify the fix

Address review feedback: convert the HIGHEST_SEVERITY fallback
comment into a tracked TODO referencing issue selfpatch#213.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Collaborator

@mfaferek93 mfaferek93 left a comment

Choose a reason for hiding this comment

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

LGTM!

@mfaferek93 mfaferek93 merged commit 793ccb1 into selfpatch:main Feb 15, 2026
4 checks passed
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.

FaultManager: Clean up pending_clusters_ when fault is cleared before min_count

2 participants

Comments