feat: implement HalfOpen timeout and automatic breaker promotion logic#1297
Open
Sendi0011 wants to merge 1 commit into
Open
feat: implement HalfOpen timeout and automatic breaker promotion logic#1297Sendi0011 wants to merge 1 commit into
Sendi0011 wants to merge 1 commit into
Conversation
- Add recovery_window configuration parameter for automatic Open->HalfOpen transition - Implement check_timeout_transitions() for automatic state management - Store opened_at timestamp when circuit transitions to Open - After configurable recovery_window ledgers, allow one probe request (HalfOpen) - On probe success transition to Closed; on failure restart Open timer - Update CircuitBreakerConfig and CircuitBreakerStatus with recovery_window - Add comprehensive timeout transition logic with security checks - Emit cb_timeout events for automatic transitions - Update configure_circuit_breaker API to include recovery_window parameter - Add comprehensive documentation in docs/program-escrow/circuit-breaker.md - Update existing tests to use new API signature - Maintain backward compatibility and security invariants Resolves Jagadeeshftw#1254
|
@Sendi0011 is attempting to deploy a commit to the Jagadeesh B's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@Sendi0011 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement Half-Open Timeout Handling and Automatic Circuit Breaker Promotion
Overview
This PR implements the missing timeout logic for the circuit breaker in
contracts/program-escrow/src/lib.rsas requested in Issue #1254. The circuit breaker now supports automatic transitions from Open to HalfOpen after a configurable recovery window, and from HalfOpen to Closed after successful probe operations.Closes #1254
Changes Made
Core Implementation
1. Enhanced Circuit Breaker Configuration
recovery_windowparameter toCircuitBreakerConfigconfigure_circuit_breakerAPI to accept recovery window (breaking change)2. Automatic Timeout Transitions
check_timeout_transitions(): New function that checks and applies automatic state transitionsrecovery_windowseconds have elapsed sinceopened_atsuccess_thresholdsuccessful operationsopened_attimestamp3. Enhanced State Management
opened_atis stored when circuit transitions to Opencheck_and_allow()now callscheck_timeout_transitions()before state evaluationcb_timeoutevent emitted for automatic transitions4. Updated Status Interface
CircuitBreakerStatusnow includesrecovery_windowfieldget_circuit_breaker_status()returns complete configuration including timeout settingsSecurity & Safety
Invariant Preservation
opened_attimestamp is always set when transitioning to OpenEvent Auditing
cb_timeoutevents for automatic transitions with reason codesAPI Changes
Breaking Changes
New Fields
Files Modified
Core Implementation
contracts/program-escrow/src/error_recovery.rs: Enhanced with timeout logiccontracts/program-escrow/src/lib.rs: Updated API signature and module declarationsTest Updates
contracts/program-escrow/src/test_circuit_breaker_enforcement.rs: Fixed corrupted testcontracts/program-escrow/src/rbac_tests.rs: Updated API callscontracts/program-escrow/src/test_circuit_breaker_audit.rs: Updated API callscontracts/program-escrow/src/test_circuit_breaker_timeout.rs: New comprehensive timeout testsDocumentation
docs/program-escrow/circuit-breaker.md: Complete documentation with examples, best practices, and troubleshootingBehavior Examples
Automatic Recovery Scenario
Configuration Example
Testing Strategy
Comprehensive Test Coverage
Test Categories
Security Considerations
Timestamp Security
opened_atis always set consistently when opening circuitAuthorization Unchanged
Invariant Safety
verify_circuit_invariants()passes for all new statesBackward Compatibility
Breaking Changes
configure_circuit_breakernow requiresrecovery_windowparameterPreserved Functionality
Performance Impact
Minimal Overhead
Storage Impact
Documentation
Complete Documentation Package
Future Enhancements
This implementation provides a solid foundation for future enhancements:
Verification
Manual Testing Checklist
Integration Testing
Deployment Notes
Configuration Migration
Existing deployments will need to update their configuration calls:
Recommended Settings
This implementation fully addresses Issue #1254 requirements:
✅ Store opened_at ledger timestamp when circuit transitions to Open
✅ After configurable recovery_window ledgers, allow one probe request (HalfOpen)
✅ On probe success transition to Closed; on failure restart Open timer
✅ Secure, tested, and documented implementation
✅ Efficient and easy to review code structure