TDD: [Bug Hunt][Cycle 2][Reactive] Memory Leak in ReactiveStreamRouter Observables #7135

Open
opened 2026-04-10 08:07:11 +00:00 by HAL9000 · 2 comments
Owner

Background

This TDD issue captures the failing test for bug #7136 — a memory leak in ReactiveStreamRouter where observables and their subscriptions are stored in dictionaries without any cleanup mechanism. When streams are created but not properly disposed, the observables and their subscriptions remain in memory indefinitely, leading to unbounded memory growth in long-running applications.

The test must be written before the fix is implemented. It uses @tdd_expected_fail to pass CI while the underlying bug is still present, proving the bug exists.

Bug location: src/cleveragents/reactive/stream_router.pyReactiveStreamRouter.__init__() and stream lifecycle management

Current Behavior

ReactiveStreamRouter initialises three dictionaries (streams, observables, agents) and a subscriptions list in __init__() with no corresponding teardown, disposal, or eviction logic. Creating streams without explicit disposal causes all associated observables and subscriptions to accumulate in memory for the lifetime of the router instance.

Expected Behavior

The ReactiveStreamRouter should provide a cleanup/disposal mechanism so that when a stream is removed or the router is shut down, all associated observables and subscriptions are properly disposed and removed from the internal dictionaries, preventing unbounded memory growth.

Acceptance Criteria

  • A Behave scenario exists that creates multiple streams, removes them, and asserts that the internal observables and subscriptions collections are empty after removal
  • The scenario is tagged @tdd_issue, @tdd_issue_7136, and @tdd_expected_fail
  • The test fails (assertion fails) when run against the unfixed code, but CI passes due to @tdd_expected_fail
  • The test is placed in the appropriate feature file under features/

Metadata

  • Branch: tdd/m3.2.0-reactive-stream-router-memory-leak
  • Commit Message: test(reactive): add tdd scenario for ReactiveStreamRouter observable memory leak
  • Milestone: v3.2.0
  • Parent Epic: To be linked — see orphan note below

Subtasks

  • Identify or create the appropriate feature file under features/reactive/
  • Write a Gherkin scenario that creates streams via ReactiveStreamRouter, removes them, and asserts observables and subscriptions are empty
  • Tag the scenario with @tdd_issue, @tdd_issue_7136, and @tdd_expected_fail
  • Implement all step definitions in the corresponding *_steps.py file
  • Verify the test fails on the unfixed code (assertion fails) but CI passes (inverted by @tdd_expected_fail)
  • Open a PR targeting master with title prefixed TDD:
  • Ensure CI passes on the TDD PR

Definition of Done

  • Gherkin scenario written with all three required tags
  • All step definitions implemented (no placeholder steps)
  • Test proves the bug: assertion fails on unfixed code
  • CI passes on TDD branch (due to @tdd_expected_fail)
  • PR reviewed for test quality and correct tagging
  • PR merged to master
  • This TDD issue closed when PR is merged
  • All nox stages pass
  • Coverage >= 97%

Backlog note: This issue was discovered during autonomous operation
on milestone v3.2.0. It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.


Automated by CleverAgents Bot
Supervisor: Bug Hunt | Agent: new-issue-creator

## Background This TDD issue captures the failing test for bug #7136 — a memory leak in `ReactiveStreamRouter` where observables and their subscriptions are stored in dictionaries without any cleanup mechanism. When streams are created but not properly disposed, the observables and their subscriptions remain in memory indefinitely, leading to unbounded memory growth in long-running applications. The test must be written **before** the fix is implemented. It uses `@tdd_expected_fail` to pass CI while the underlying bug is still present, proving the bug exists. **Bug location**: `src/cleveragents/reactive/stream_router.py` — `ReactiveStreamRouter.__init__()` and stream lifecycle management ## Current Behavior `ReactiveStreamRouter` initialises three dictionaries (`streams`, `observables`, `agents`) and a `subscriptions` list in `__init__()` with no corresponding teardown, disposal, or eviction logic. Creating streams without explicit disposal causes all associated observables and subscriptions to accumulate in memory for the lifetime of the router instance. ## Expected Behavior The `ReactiveStreamRouter` should provide a cleanup/disposal mechanism so that when a stream is removed or the router is shut down, all associated observables and subscriptions are properly disposed and removed from the internal dictionaries, preventing unbounded memory growth. ## Acceptance Criteria - A Behave scenario exists that creates multiple streams, removes them, and asserts that the internal `observables` and `subscriptions` collections are empty after removal - The scenario is tagged `@tdd_issue`, `@tdd_issue_7136`, and `@tdd_expected_fail` - The test fails (assertion fails) when run against the unfixed code, but CI passes due to `@tdd_expected_fail` - The test is placed in the appropriate feature file under `features/` ## Metadata - **Branch**: `tdd/m3.2.0-reactive-stream-router-memory-leak` - **Commit Message**: `test(reactive): add tdd scenario for ReactiveStreamRouter observable memory leak` - **Milestone**: v3.2.0 - **Parent Epic**: _To be linked — see orphan note below_ ## Subtasks - [ ] Identify or create the appropriate feature file under `features/reactive/` - [ ] Write a Gherkin scenario that creates streams via `ReactiveStreamRouter`, removes them, and asserts `observables` and `subscriptions` are empty - [ ] Tag the scenario with `@tdd_issue`, `@tdd_issue_7136`, and `@tdd_expected_fail` - [ ] Implement all step definitions in the corresponding `*_steps.py` file - [ ] Verify the test fails on the unfixed code (assertion fails) but CI passes (inverted by `@tdd_expected_fail`) - [ ] Open a PR targeting `master` with title prefixed `TDD:` - [ ] Ensure CI passes on the TDD PR ## Definition of Done - [ ] Gherkin scenario written with all three required tags - [ ] All step definitions implemented (no placeholder steps) - [ ] Test proves the bug: assertion fails on unfixed code - [ ] CI passes on TDD branch (due to `@tdd_expected_fail`) - [ ] PR reviewed for test quality and correct tagging - [ ] PR merged to `master` - [ ] This TDD issue closed when PR is merged - [ ] All nox stages pass - [ ] Coverage >= 97% > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.2.0. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunt | Agent: new-issue-creator
HAL9000 added this to the v3.2.0 milestone 2026-04-10 08:09:36 +00:00
Author
Owner

⚠️ Orphan Issue — Needs Manual Parent Epic Linking

This TDD issue was created during autonomous Bug Hunt Cycle 2 operation. No parent Epic for the Bug Hunt Cycle 2 Reactive module was found in the issue tracker at creation time.

A maintainer must link this issue to the appropriate parent Epic using Forgejo's dependency system:

  • This issue should block the parent Epic
  • The parent Epic should depend on this issue

Suggested parent: the Bug Hunt Cycle 2 Reactive Epic (if one exists), or the v3.2.0 reactive subsystem Epic.


Automated by CleverAgents Bot
Supervisor: Bug Hunt | Agent: new-issue-creator

⚠️ **Orphan Issue — Needs Manual Parent Epic Linking** This TDD issue was created during autonomous Bug Hunt Cycle 2 operation. No parent Epic for the Bug Hunt Cycle 2 Reactive module was found in the issue tracker at creation time. A maintainer must link this issue to the appropriate parent Epic using Forgejo's dependency system: - This issue should **block** the parent Epic - The parent Epic should **depend on** this issue Suggested parent: the Bug Hunt Cycle 2 Reactive Epic (if one exists), or the v3.2.0 reactive subsystem Epic. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunt | Agent: new-issue-creator
Author
Owner

Verified — TDD test for critical resource bug: ReactiveStreamRouter memory leak. MoSCoW: Must-have. Priority: Critical.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Verified** — TDD test for critical resource bug: ReactiveStreamRouter memory leak. MoSCoW: Must-have. Priority: Critical. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-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.

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