Missing validation for recovery_timeout parameter in CircuitBreaker.__init__ #10569

Open
opened 2026-04-18 17:22:01 +00:00 by HAL9000 · 0 comments
Owner

Metadata

Commit: Latest commit in repository
Branch: main

Background and Context

The CircuitBreaker class in src/cleveragents/core/circuit_breaker.py does not validate the recovery_timeout parameter in its __init__ method. This parameter is critical for determining how long the circuit breaker waits in the OPEN state before attempting a half-open probe.

Currently, the __init__ method validates half_open_max_successes but skips validation of recovery_timeout, allowing invalid values to be set.

Expected Behavior

The CircuitBreaker.init method should validate that recovery_timeout is a non-negative number and raise a ValueError with a descriptive message if it is not. This ensures the circuit breaker operates as intended and prevents rapid cycling between OPEN and HALF_OPEN states.

Actual Behavior

No validation is performed on recovery_timeout, allowing negative timeout values. When recovery_timeout is set to a negative value (e.g., -1), the circuit breaker immediately transitions to HALF_OPEN state, bypassing the intended recovery period and defeating the circuit breaker's purpose of protecting against cascading failures.

Code Evidence

  • File: src/cleveragents/core/circuit_breaker.py
  • Lines 87-90: The __init__ method validates half_open_max_successes but does not validate recovery_timeout
  • Line 206: The recovery_timeout is used in time calculations: now - self.last_failure_time >= self.recovery_timeout

Steps to Reproduce

  1. Create a CircuitBreaker instance with recovery_timeout=-1
  2. Trigger the circuit breaker to open (e.g., by calling record_failure())
  3. Observe that the circuit breaker immediately transitions to HALF_OPEN state instead of waiting for the recovery period

Acceptance Criteria

  • CircuitBreaker.init validates that recovery_timeout is a non-negative number
  • A ValueError is raised with a clear message if recovery_timeout is negative
  • Existing unit tests pass with the new validation in place
  • New unit tests verify the validation behavior for negative values
  • Documentation is updated to reflect the validation requirement

Subtasks

  • Add validation logic to CircuitBreaker.init for recovery_timeout parameter
  • Write unit tests for negative recovery_timeout values
  • Write unit tests for zero recovery_timeout (edge case)
  • Write unit tests for positive recovery_timeout values
  • Update docstring to document the validation requirement
  • Run full test suite to ensure no regressions

Definition of Done

This issue is complete when:

  1. The recovery_timeout parameter is validated in CircuitBreaker.init
  2. A ValueError is raised for negative values with a descriptive error message
  3. All new unit tests pass
  4. All existing tests continue to pass
  5. Code coverage remains >= 97%
  6. The change is documented in the docstring

Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata **Commit:** Latest commit in repository **Branch:** main ## Background and Context The CircuitBreaker class in `src/cleveragents/core/circuit_breaker.py` does not validate the `recovery_timeout` parameter in its `__init__` method. This parameter is critical for determining how long the circuit breaker waits in the OPEN state before attempting a half-open probe. Currently, the `__init__` method validates `half_open_max_successes` but skips validation of `recovery_timeout`, allowing invalid values to be set. ## Expected Behavior The CircuitBreaker.__init__ method should validate that `recovery_timeout` is a non-negative number and raise a `ValueError` with a descriptive message if it is not. This ensures the circuit breaker operates as intended and prevents rapid cycling between OPEN and HALF_OPEN states. ## Actual Behavior No validation is performed on `recovery_timeout`, allowing negative timeout values. When `recovery_timeout` is set to a negative value (e.g., -1), the circuit breaker immediately transitions to HALF_OPEN state, bypassing the intended recovery period and defeating the circuit breaker's purpose of protecting against cascading failures. ## Code Evidence - **File:** `src/cleveragents/core/circuit_breaker.py` - **Lines 87-90:** The `__init__` method validates `half_open_max_successes` but does not validate `recovery_timeout` - **Line 206:** The `recovery_timeout` is used in time calculations: `now - self.last_failure_time >= self.recovery_timeout` ## Steps to Reproduce 1. Create a CircuitBreaker instance with `recovery_timeout=-1` 2. Trigger the circuit breaker to open (e.g., by calling `record_failure()`) 3. Observe that the circuit breaker immediately transitions to HALF_OPEN state instead of waiting for the recovery period ## Acceptance Criteria - [ ] CircuitBreaker.__init__ validates that `recovery_timeout` is a non-negative number - [ ] A `ValueError` is raised with a clear message if `recovery_timeout` is negative - [ ] Existing unit tests pass with the new validation in place - [ ] New unit tests verify the validation behavior for negative values - [ ] Documentation is updated to reflect the validation requirement ## Subtasks - [ ] Add validation logic to CircuitBreaker.__init__ for recovery_timeout parameter - [ ] Write unit tests for negative recovery_timeout values - [ ] Write unit tests for zero recovery_timeout (edge case) - [ ] Write unit tests for positive recovery_timeout values - [ ] Update docstring to document the validation requirement - [ ] Run full test suite to ensure no regressions ## Definition of Done This issue is complete when: 1. The `recovery_timeout` parameter is validated in CircuitBreaker.__init__ 2. A `ValueError` is raised for negative values with a descriptive error message 3. All new unit tests pass 4. All existing tests continue to pass 5. Code coverage remains >= 97% 6. The change is documented in the docstring --- **Automated by CleverAgents Bot** Agent: new-issue-creator
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#10569
No description provided.