Missing validation for cooldown_seconds parameter in CircuitBreaker.__init__ #10580

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

Metadata

Commit: Latest commit in current branch
Branch: main

Background and Context

The CircuitBreaker class in src/cleveragents/core/circuit_breaker.py does not validate the cooldown_seconds parameter in its __init__ method. This parameter controls the minimum time between successive half-open probe windows to prevent rapid flickering between states.

Code Evidence:

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

Expected Behavior

The CircuitBreaker.init method should validate that cooldown_seconds is a non-negative number and raise a ValueError if it is not. This ensures that the circuit breaker operates correctly and prevents unexpected behavior from invalid parameter values.

Actual Behavior

No validation is performed on the cooldown_seconds parameter, allowing negative values to be set. When cooldown_seconds is negative, the time comparison logic behaves unexpectedly:

  • The condition now - self._last_half_open_time < self.cooldown_seconds will always be false for negative values
  • This causes the circuit breaker to immediately attempt recovery without respecting the intended cooldown period
  • The circuit breaker transitions to HALF_OPEN state prematurely

Acceptance Criteria

  • CircuitBreaker.init validates that cooldown_seconds is a non-negative number (>= 0)
  • A ValueError is raised with a descriptive message if cooldown_seconds is negative
  • Existing validation for half_open_max_successes remains intact
  • Unit tests verify that negative cooldown_seconds values are rejected
  • Unit tests verify that valid non-negative values are accepted

Subtasks

  • Add validation logic to CircuitBreaker.init for cooldown_seconds parameter
  • Add unit tests for negative cooldown_seconds values
  • Add unit tests for boundary cases (0, very large values)
  • Update docstring if necessary to document the validation requirement
  • Verify no other parameters need similar validation

Definition of Done

This issue is complete when:

  1. The cooldown_seconds parameter is validated in CircuitBreaker.init
  2. A ValueError is raised for negative values with a clear error message
  3. All new unit tests pass
  4. Existing tests continue to pass
  5. Code review is approved
  6. Changes are merged to main branch

Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata **Commit:** Latest commit in current branch **Branch:** main ## Background and Context The CircuitBreaker class in `src/cleveragents/core/circuit_breaker.py` does not validate the `cooldown_seconds` parameter in its `__init__` method. This parameter controls the minimum time between successive half-open probe windows to prevent rapid flickering between states. **Code Evidence:** - File: `src/cleveragents/core/circuit_breaker.py` - Lines 87-90: The `__init__` method validates `half_open_max_successes` but does not validate `cooldown_seconds` - Line 206: The `cooldown_seconds` is used in time calculations: `now - self._last_half_open_time < self.cooldown_seconds` ## Expected Behavior The CircuitBreaker.__init__ method should validate that `cooldown_seconds` is a non-negative number and raise a `ValueError` if it is not. This ensures that the circuit breaker operates correctly and prevents unexpected behavior from invalid parameter values. ## Actual Behavior No validation is performed on the `cooldown_seconds` parameter, allowing negative values to be set. When `cooldown_seconds` is negative, the time comparison logic behaves unexpectedly: - The condition `now - self._last_half_open_time < self.cooldown_seconds` will always be false for negative values - This causes the circuit breaker to immediately attempt recovery without respecting the intended cooldown period - The circuit breaker transitions to HALF_OPEN state prematurely ## Acceptance Criteria - [ ] CircuitBreaker.__init__ validates that `cooldown_seconds` is a non-negative number (>= 0) - [ ] A `ValueError` is raised with a descriptive message if `cooldown_seconds` is negative - [ ] Existing validation for `half_open_max_successes` remains intact - [ ] Unit tests verify that negative `cooldown_seconds` values are rejected - [ ] Unit tests verify that valid non-negative values are accepted ## Subtasks - [ ] Add validation logic to CircuitBreaker.__init__ for cooldown_seconds parameter - [ ] Add unit tests for negative cooldown_seconds values - [ ] Add unit tests for boundary cases (0, very large values) - [ ] Update docstring if necessary to document the validation requirement - [ ] Verify no other parameters need similar validation ## Definition of Done This issue is complete when: 1. The `cooldown_seconds` parameter is validated in CircuitBreaker.__init__ 2. A `ValueError` is raised for negative values with a clear error message 3. All new unit tests pass 4. Existing tests continue to pass 5. Code review is approved 6. Changes are merged to main branch --- **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#10580
No description provided.