Skip to content

fix: move all circuit breaker state to instance storage for consistency#310

Merged
hman38705 merged 1 commit into
solutions-plug:mainfrom
Fidelis900:fix/issue-38-storage-unification
Mar 27, 2026
Merged

fix: move all circuit breaker state to instance storage for consistency#310
hman38705 merged 1 commit into
solutions-plug:mainfrom
Fidelis900:fix/issue-38-storage-unification

Conversation

@Fidelis900

Copy link
Copy Markdown
Contributor

Title: fix: move all circuit breaker state to instance storage for consistency

Body:

Summary

Fixes #38 — Unify Circuit Breaker Storage Layers

CircuitBreakerState lived in persistent storage while OpenedAt (cool-down timer) lived in instance storage, and
ErrorCount/LastObservation also lived in persistent. If instance storage expired while persistent state survived, the
breaker could be Open with OpenedAt = 0, causing the cool-down to immediately resolve to HalfOpen on the next call —
or counters could reset to zero while the breaker stayed Open with no path to re-trigger it correctly.

Root Cause

The inconsistency meant the three components of the circuit breaker had different expiry lifecycles:

Key Before After
CircuitBreakerState persistent instance
OpenedAt instance instance (unchanged)
ErrorCount persistent instance
LastObservation persistent instance

Changes

  • circuit_breaker.rs: _set_state_internal and get_state now use instance storage. Removed the persistent TTL bump
    for CircuitBreakerState — instance storage expires as a unit, so no manual TTL management is needed.
  • monitoring.rs: track_error and reset_monitoring now use instance storage for ErrorCount and LastObservation,
    including the auto-open write to CircuitBreakerState. Inline tests updated accordingly.
  • governance.rs: emergency_pause writes CircuitBreakerState to instance.
  • lib.rs: initialize writes the initial Closed state to instance.

Consistency Guarantee

All safety-related state now shares the same storage layer and expiry lifecycle. If instance storage expires, every
key resets together — get_state returns Closed (the safe default), counters return 0, and the system is in a coherent
state rather than a partially-reset one.

closes #146

- CircuitBreakerState moved from persistent to instance storage in:
  circuit_breaker.rs (_set_state_internal, get_state)
  monitoring.rs (track_error auto-open)
  governance.rs (emergency_pause)
  lib.rs (initialize)
- ErrorCount and LastObservation moved from persistent to instance
  storage in monitoring.rs (track_error, reset_monitoring, tests)
- OpenedAt was already in instance storage (no change needed)
- Removed persistent TTL bump for CircuitBreakerState; instance
  storage expires as a unit so all safety state is always consistent
- All breaker-related state now shares the same storage layer and
  lifecycle — if instance expires, counters and state reset together
  to a safe Closed default rather than leaving a stale Open state
  with zeroed counters

Closes solutions-plug#38
@drips-wave

drips-wave Bot commented Mar 27, 2026

Copy link
Copy Markdown

@Fidelis900 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@hman38705 hman38705 merged commit db9c528 into solutions-plug:main Mar 27, 2026
2 of 13 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.

Unify Circuit Breaker Storage Layers

2 participants