[events/ReactiveEventBus] TDD: ReactiveEventBus._audit_log grows unboundedly with default max_audit_log_size=None #10321

Open
opened 2026-04-18 08:42:31 +00:00 by HAL9000 · 0 comments
Owner

Metadata

  • Commit: fix(events): bound ReactiveEventBus audit log by default to prevent memory exhaustion
  • Branch: fix/reactive-event-bus-unbounded-audit-log

Background and Context

ReactiveEventBus in src/cleveragents/infrastructure/events/reactive.py defaults to max_audit_log_size=None, creating an unbounded deque. Every emit() call appends a deep copy of the event. In long-running processes, this causes unbounded memory growth. The DI container registers ReactiveEventBus as a Singleton, so it lives for the entire process lifetime.

This TDD issue captures the failing test that must be written before the fix is applied, following the project's test-driven development workflow.

Expected Behavior

A ReactiveEventBus created with default parameters should either:

  1. Have a bounded audit log (e.g., max_audit_log_size=10_000 as default), OR
  2. Emit a warning when max_audit_log_size=None to alert operators of the unbounded configuration

Acceptance Criteria

  • Test is written and tagged with @tdd_issue, @tdd_issue_N, @tdd_expected_fail
  • Test fails before the fix is applied
  • Test passes after the fix is applied
  • Either a default max size is set OR a warning is emitted for unbounded configuration

Subtasks

  • Write failing test tagged @tdd_issue, @tdd_issue_N, @tdd_expected_fail for bounded default audit log
  • Write failing test tagged @tdd_issue, @tdd_issue_N, @tdd_expected_fail for warning on unbounded config
  • Confirm tests fail before fix
  • Confirm tests pass after fix is applied (see parent bug issue)

Definition of Done

This issue is closed when:

  1. The tagged TDD tests exist in the test suite
  2. The tests fail before the fix is applied
  3. The tests pass after the fix described in the parent bug issue is merged

Test Specification

Write a failing test (tagged @tdd_issue, @tdd_issue_N, @tdd_expected_fail) that verifies the default ReactiveEventBus configuration has a bounded audit log.

Scenario

@tdd_issue @tdd_issue_N @tdd_expected_fail
Scenario: ReactiveEventBus default configuration has a bounded audit log
  Given a ReactiveEventBus instance created with default parameters
  When 10000 events are emitted
  Then the audit_log length does not exceed a reasonable default maximum
  And memory usage does not grow proportionally with the number of events emitted

@tdd_issue @tdd_issue_N @tdd_expected_fail
Scenario: ReactiveEventBus warns when no max_audit_log_size is configured
  Given a ReactiveEventBus instance created with default parameters (max_audit_log_size=None)
  Then a warning is logged indicating the audit log is unbounded
  Or the default max_audit_log_size is set to a reasonable value (e.g., 10000)

Expected Failure Reason

The test will fail because ReactiveEventBus() (default) creates deque(maxlen=None), which has no size limit. After emitting 10,000 events, len(bus.audit_log) will be 10,000, not bounded by any default maximum.

Fix Path

Option A: Set a sensible default for max_audit_log_size:

def __init__(self, max_audit_log_size: int | None = 10_000) -> None:

Option B: Log a warning when max_audit_log_size=None:

if max_audit_log_size is None:
    _logger.warning(
        "reactive_event_bus_unbounded_audit_log",
        message="max_audit_log_size is None — audit log will grow unboundedly. "
                "Consider setting a max_audit_log_size to prevent memory exhaustion.",
    )

Option C: Both A and B.

References

  • src/cleveragents/infrastructure/events/reactive.pyReactiveEventBus.__init__() and emit()

Automated by CleverAgents Bot
Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor

## Metadata - **Commit**: `fix(events): bound ReactiveEventBus audit log by default to prevent memory exhaustion` - **Branch**: `fix/reactive-event-bus-unbounded-audit-log` ## Background and Context `ReactiveEventBus` in `src/cleveragents/infrastructure/events/reactive.py` defaults to `max_audit_log_size=None`, creating an unbounded `deque`. Every `emit()` call appends a deep copy of the event. In long-running processes, this causes unbounded memory growth. The DI container registers `ReactiveEventBus` as a Singleton, so it lives for the entire process lifetime. This TDD issue captures the failing test that must be written before the fix is applied, following the project's test-driven development workflow. ## Expected Behavior A `ReactiveEventBus` created with default parameters should either: 1. Have a bounded audit log (e.g., `max_audit_log_size=10_000` as default), OR 2. Emit a warning when `max_audit_log_size=None` to alert operators of the unbounded configuration ## Acceptance Criteria - [ ] Test is written and tagged with `@tdd_issue`, `@tdd_issue_N`, `@tdd_expected_fail` - [ ] Test fails before the fix is applied - [ ] Test passes after the fix is applied - [ ] Either a default max size is set OR a warning is emitted for unbounded configuration ## Subtasks - [ ] Write failing test tagged `@tdd_issue`, `@tdd_issue_N`, `@tdd_expected_fail` for bounded default audit log - [ ] Write failing test tagged `@tdd_issue`, `@tdd_issue_N`, `@tdd_expected_fail` for warning on unbounded config - [ ] Confirm tests fail before fix - [ ] Confirm tests pass after fix is applied (see parent bug issue) ## Definition of Done This issue is closed when: 1. The tagged TDD tests exist in the test suite 2. The tests fail before the fix is applied 3. The tests pass after the fix described in the parent bug issue is merged --- ## Test Specification Write a failing test (tagged `@tdd_issue`, `@tdd_issue_N`, `@tdd_expected_fail`) that verifies the default `ReactiveEventBus` configuration has a bounded audit log. ### Scenario ```gherkin @tdd_issue @tdd_issue_N @tdd_expected_fail Scenario: ReactiveEventBus default configuration has a bounded audit log Given a ReactiveEventBus instance created with default parameters When 10000 events are emitted Then the audit_log length does not exceed a reasonable default maximum And memory usage does not grow proportionally with the number of events emitted @tdd_issue @tdd_issue_N @tdd_expected_fail Scenario: ReactiveEventBus warns when no max_audit_log_size is configured Given a ReactiveEventBus instance created with default parameters (max_audit_log_size=None) Then a warning is logged indicating the audit log is unbounded Or the default max_audit_log_size is set to a reasonable value (e.g., 10000) ``` ### Expected Failure Reason The test will fail because `ReactiveEventBus()` (default) creates `deque(maxlen=None)`, which has no size limit. After emitting 10,000 events, `len(bus.audit_log)` will be 10,000, not bounded by any default maximum. ### Fix Path Option A: Set a sensible default for `max_audit_log_size`: ```python def __init__(self, max_audit_log_size: int | None = 10_000) -> None: ``` Option B: Log a warning when `max_audit_log_size=None`: ```python if max_audit_log_size is None: _logger.warning( "reactive_event_bus_unbounded_audit_log", message="max_audit_log_size is None — audit log will grow unboundedly. " "Consider setting a max_audit_log_size to prevent memory exhaustion.", ) ``` Option C: Both A and B. ## References - `src/cleveragents/infrastructure/events/reactive.py` — `ReactiveEventBus.__init__()` and `emit()` --- **Automated by CleverAgents Bot** Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor
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#10321
No description provided.