agents session list causes an error. #554

Closed
opened 2026-03-04 01:44:23 +00:00 by brent.edwards · 9 comments
Member

Metadata

  • Commit Message: fix(cli): handle missing database in session list command
  • Branch: fix/m3-session-list-error

Background and Context

Running agents session list after a fresh agents init causes an AttributeError: 'DynamicContainer' object has no attribute 'db'. The DI container is not properly wiring the database dependency for the session service when accessed via the CLI.

Current Behavior

Running agents session list produces:

Wrapping unexpected exception: AttributeError: 'DynamicContainer' object has no attribute 'db'
Error [500] INTERNAL: An unexpected error occurred

Expected Behavior

agents session list should return an empty list when no sessions exist, or a list of existing sessions.

Acceptance Criteria

  • agents session list works without error after agents init
  • agents session list returns empty list when no sessions exist
  • agents session list returns sessions when they exist
  • All output formats (rich, json, yaml, plain) work correctly

Definition of Done

This issue is complete when:

  • All subtasks below are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.

Subtasks

  • Code: Investigate DI container wiring for session service database dependency
  • Code: Fix the container.py to properly wire the db attribute for session service
  • Code: Ensure session list handles empty database gracefully
  • Docs: Update any relevant CLI documentation if behavior changes
  • Tests (Behave): Add features/session_list_error.feature covering: empty list, list after create, all output formats
  • Tests (Robot): Add Robot integration scenario in robot/ for session list lifecycle
  • Tests (ASV): Add benchmarks/session_list_bench.py for session list performance
  • Quality: Verify coverage >=97% via nox -s coverage_report. If coverage is <97% then review the current unit test coverage report at build/coverage.xml and use it to write new Behave based unit tests to improve code coverage.
  • Quality: Run nox (all default sessions, including benchmark), fix any errors if needed ensuring nox passes across entire code base.
## Metadata - **Commit Message**: `fix(cli): handle missing database in session list command` - **Branch**: `fix/m3-session-list-error` ## Background and Context Running `agents session list` after a fresh `agents init` causes an `AttributeError: 'DynamicContainer' object has no attribute 'db'`. The DI container is not properly wiring the database dependency for the session service when accessed via the CLI. ## Current Behavior Running `agents session list` produces: ``` Wrapping unexpected exception: AttributeError: 'DynamicContainer' object has no attribute 'db' Error [500] INTERNAL: An unexpected error occurred ``` ## Expected Behavior `agents session list` should return an empty list when no sessions exist, or a list of existing sessions. ## Acceptance Criteria - [ ] `agents session list` works without error after `agents init` - [ ] `agents session list` returns empty list when no sessions exist - [ ] `agents session list` returns sessions when they exist - [ ] All output formats (rich, json, yaml, plain) work correctly ## Definition of Done This issue is complete when: - All subtasks below are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. ## Subtasks - [ ] Code: Investigate DI container wiring for session service database dependency - [ ] Code: Fix the container.py to properly wire the `db` attribute for session service - [ ] Code: Ensure `session list` handles empty database gracefully - [ ] Docs: Update any relevant CLI documentation if behavior changes - [ ] Tests (Behave): Add `features/session_list_error.feature` covering: empty list, list after create, all output formats - [ ] Tests (Robot): Add Robot integration scenario in `robot/` for session list lifecycle - [ ] Tests (ASV): Add `benchmarks/session_list_bench.py` for session list performance - [ ] Quality: Verify coverage >=97% via `nox -s coverage_report`. If coverage is <97% then review the current unit test coverage report at `build/coverage.xml` and use it to write new Behave based unit tests to improve code coverage. - [ ] Quality: Run `nox` (all default sessions, including benchmark), fix any errors if needed ensuring nox passes across **entire** code base.
freemo added this to the v3.2.0 milestone 2026-03-05 00:29:33 +00:00
Author
Member

Root Cause Analysis

_get_session_service() at src/cleveragents/cli/commands/session.py:65-66 calls container.db(), but the Container class in container.py has no db provider. The container defines database_url, unit_of_work, and individual repository builders (e.g., _build_resource_registry_service, _build_namespaced_project_repo), but there is no db provider that returns a session factory.

This means every session CLI command (list, create, show, delete, export, import, tell) fails immediately with:

AttributeError: 'DynamicContainer' object has no attribute 'db'

The fix should either:

  1. Add a db provider to the Container class that returns a session factory, or
  2. Refactor _get_session_service() to use the existing database_url provider and build the session factory directly (similar to _build_resource_registry_service).

TDD PR

PR #596 adds intentionally-failing TDD tests:

  • 3 Behave BDD scenarios (@wip, @tdd, @bug554)
  • 2 Robot Framework integration smoke tests
  • ASV benchmark with track_list_after_create_count tracker

Tests exercise the real _get_session_service() DI path by resetting _service = None and using a file-based SQLite database.

## Root Cause Analysis `_get_session_service()` at `src/cleveragents/cli/commands/session.py:65-66` calls `container.db()`, but the `Container` class in `container.py` has no `db` provider. The container defines `database_url`, `unit_of_work`, and individual repository builders (e.g., `_build_resource_registry_service`, `_build_namespaced_project_repo`), but there is no `db` provider that returns a session factory. This means every session CLI command (`list`, `create`, `show`, `delete`, `export`, `import`, `tell`) fails immediately with: ``` AttributeError: 'DynamicContainer' object has no attribute 'db' ``` The fix should either: 1. Add a `db` provider to the `Container` class that returns a session factory, or 2. Refactor `_get_session_service()` to use the existing `database_url` provider and build the session factory directly (similar to `_build_resource_registry_service`). ## TDD PR PR #596 adds intentionally-failing TDD tests: - 3 Behave BDD scenarios (`@wip`, `@tdd`, `@bug554`) - 2 Robot Framework integration smoke tests - ASV benchmark with `track_list_after_create_count` tracker Tests exercise the **real** `_get_session_service()` DI path by resetting `_service = None` and using a file-based SQLite database.
Owner

PM Acknowledgment — Day 25 Review

Good root cause analysis, @brent.edwards. The missing db provider in the DI container is confirmed as the blocker for all session CLI commands.

Triage Notes

  • Shared root cause with #570 — the fix for this issue will resolve both. Both issues remain open per project policy (distinct user-facing symptoms warrant separate tracking).
  • TDD PR #596 assigned to @CoreRasurae for review.
  • Fix ownership: @freemo — this is a DI container wiring fix in container.py. Please add the db provider (Option 1 from Brent's analysis) or refactor _get_session_service() to use existing providers.
  • Priority: Medium — this blocks M3 acceptance gate (PR #559).

Dependencies

  • PR #596 (TDD tests) should merge first so the fix can be verified against Brent's test suite.
  • Once fixed, #570 should also be retested and closed.
## PM Acknowledgment — Day 25 Review Good root cause analysis, @brent.edwards. The missing `db` provider in the DI container is confirmed as the blocker for all session CLI commands. ### Triage Notes - **Shared root cause** with #570 — the fix for this issue will resolve both. Both issues remain open per project policy (distinct user-facing symptoms warrant separate tracking). - **TDD PR #596** assigned to @CoreRasurae for review. - **Fix ownership**: @freemo — this is a DI container wiring fix in `container.py`. Please add the `db` provider (Option 1 from Brent's analysis) or refactor `_get_session_service()` to use existing providers. - **Priority**: Medium — this blocks M3 acceptance gate (PR #559). ### Dependencies - PR #596 (TDD tests) should merge first so the fix can be verified against Brent's test suite. - Once fixed, #570 should also be retested and closed.
Owner

PM Note — Dependency Added

This bug fix is blocked by TDD issue #630 per the mandatory TDD workflow in CONTRIBUTING.md. The failing test scaffolding must be merged before the fix can proceed.

Dependencies:

  • Blocked by: #630 (TDD failing tests for session list)
  • Transitively blocked by: #627 (Behave @tdd_expected_fail tags), #628 (Robot tdd_expected_fail tags)
**PM Note — Dependency Added** This bug fix is **blocked by** TDD issue #630 per the mandatory TDD workflow in CONTRIBUTING.md. The failing test scaffolding must be merged before the fix can proceed. **Dependencies:** - Blocked by: #630 (TDD failing tests for session list) - Transitively blocked by: #627 (Behave `@tdd_expected_fail` tags), #628 (Robot `tdd_expected_fail` tags)
Owner

PM Escalation (Day 31): This bug is STALLED.

Timeline:

  • TDD issue #630 was merged and closed.
  • TDD PRs #596 (Day 30) and #653 (Day 31) both merged by @brent.edwards — failing tests are in develop.
  • No bugfix/ branch exists on remote for the actual fix. 7+ days have passed since TDD tests were available.

Impact: This is Priority/Critical. M3 (v3.2.0) cannot close until this bug, #570, and #647 are all resolved. M3 is currently 16 days past target.

Action required: @brent.edwards — please push a bugfix/ branch with the fix for the DI container error in agents session list. This likely shares root cause with #570 (agents session create) and may be a single fix. If blocked, please comment with the blocker.

Deadline: Fix branch expected by end of Day 32 (2026-03-12).

**PM Escalation (Day 31)**: This bug is **STALLED**. **Timeline**: - TDD issue #630 was merged and closed. - TDD PRs #596 (Day 30) and #653 (Day 31) both merged by @brent.edwards — failing tests are in develop. - **No `bugfix/` branch exists on remote** for the actual fix. 7+ days have passed since TDD tests were available. **Impact**: This is `Priority/Critical`. M3 (v3.2.0) cannot close until this bug, #570, and #647 are all resolved. M3 is currently 16 days past target. **Action required**: @brent.edwards — please push a `bugfix/` branch with the fix for the DI container error in `agents session list`. This likely shares root cause with #570 (`agents session create`) and may be a single fix. If blocked, please comment with the blocker. **Deadline**: Fix branch expected by end of Day 32 (2026-03-12).
Author
Member

Implementation Notes

PR #680 fixes this issue.

Root Cause

_get_session_service() in session.py:66 called container.db() but the DI Container class had no db provider, raising AttributeError.

Fix

  1. Container fix: Added _build_db_session_factory() + db = providers.Singleton(...) to Container class. The factory creates a SQLAlchemy engine, runs Base.metadata.create_all(), and returns a sessionmaker.
  2. Log contamination fix: Added _ensure_cli_logging() to configure structlog to route via stdlib logging to stderr, preventing debug logs from retry decorators from contaminating JSON/YAML CLI output.
  3. Empty list format fix: list_sessions() now outputs valid JSON/YAML for empty session lists.
  4. Commit fix: Added db_session.commit() in SessionRepository.create() so sessions persist across separate queries.

All 30 @tdd_expected_fail test scenarios (both #554 and #570) now pass without the tag. Issue #570 shares the same root cause and is also closed by this PR.

## Implementation Notes PR #680 fixes this issue. ### Root Cause `_get_session_service()` in `session.py:66` called `container.db()` but the DI `Container` class had no `db` provider, raising `AttributeError`. ### Fix 1. **Container fix**: Added `_build_db_session_factory()` + `db = providers.Singleton(...)` to `Container` class. The factory creates a SQLAlchemy engine, runs `Base.metadata.create_all()`, and returns a `sessionmaker`. 2. **Log contamination fix**: Added `_ensure_cli_logging()` to configure structlog to route via stdlib logging to stderr, preventing debug logs from retry decorators from contaminating JSON/YAML CLI output. 3. **Empty list format fix**: `list_sessions()` now outputs valid JSON/YAML for empty session lists. 4. **Commit fix**: Added `db_session.commit()` in `SessionRepository.create()` so sessions persist across separate queries. All 30 `@tdd_expected_fail` test scenarios (both #554 and #570) now pass without the tag. Issue #570 shares the same root cause and is also closed by this PR.
Owner

Escalation: Bug Fix Stalled — 2-Day Deadline

@brent.edwards This bug has had its TDD test merged for 7+ days (PRs #595, #596, #653 all merged) but no bugfix/ branch has been pushed to remote. Per CONTRIBUTING.md, bug fixes are never deferred across milestones and are always top priority.

Current state: TDD tests exist in features/session_list_error.feature (10 scenarios tagged @tdd_expected_fail). These tests are passing CI by inverting assertions, confirming the bug is captured. The next step is straightforward: create a bugfix/ branch, fix the DI container registration for session list, and remove the @tdd_expected_fail tags.

Root cause (previously identified): The session list CLI command fails because the DI container is missing the required db provider registration. Fix involves ensuring the database provider is registered during container bootstrap.

Deadline: Day 33 (2026-03-13). If no bugfix/ branch is pushed to remote by end of Day 33, this bug will be reassigned. M3 closure is blocked on this fix.

Action required:

  1. Create branch bugfix/554-session-list-di
  2. Fix the DI container registration
  3. Remove @tdd_expected_fail tags from features/session_list_error.feature
  4. Push to remote and open PR

This shares root cause with #570 — fixing both together is recommended.

## Escalation: Bug Fix Stalled — 2-Day Deadline @brent.edwards This bug has had its TDD test merged for **7+ days** (PRs #595, #596, #653 all merged) but **no `bugfix/` branch has been pushed to remote**. Per CONTRIBUTING.md, bug fixes are never deferred across milestones and are always top priority. **Current state**: TDD tests exist in `features/session_list_error.feature` (10 scenarios tagged `@tdd_expected_fail`). These tests are passing CI by inverting assertions, confirming the bug is captured. The next step is straightforward: create a `bugfix/` branch, fix the DI container registration for `session list`, and remove the `@tdd_expected_fail` tags. **Root cause** (previously identified): The `session list` CLI command fails because the DI container is missing the required `db` provider registration. Fix involves ensuring the database provider is registered during container bootstrap. **Deadline: Day 33 (2026-03-13)**. If no `bugfix/` branch is pushed to remote by end of Day 33, this bug will be reassigned. M3 closure is blocked on this fix. **Action required**: 1. Create branch `bugfix/554-session-list-di` 2. Fix the DI container registration 3. Remove `@tdd_expected_fail` tags from `features/session_list_error.feature` 4. Push to remote and open PR This shares root cause with #570 — fixing both together is recommended.
Owner

PM De-escalation — Day 31 (2026-03-11)

The escalation posted earlier today is withdrawn. @brent.edwards delivered PR #680 which fixes the db provider registration issue for both session list (#554) and session create (#570).

Current status:

  • PR #680 is open and has passed all quality gates (98% coverage, all TDD tests green)
  • PR #680 has one review from @CoreRasurae with 7 findings — @brent.edwards has addressed all of them
  • The @tdd_expected_fail tags in features/session_list_error.feature should be removed once PR #680 merges

Remaining to close this issue:

  1. PR #680 needs a second review and merge approval
  2. After merge, verify @tdd_expected_fail tags are removed from features/session_list_error.feature
  3. Confirm all 10 TDD scenarios in session_list_error.feature pass without the expected-fail tag

Note: Bug #554 body should reference TDD counterpart #630 for traceability. The TDD→Bug direction (#630→#554) is documented but the reverse is not.

## PM De-escalation — Day 31 (2026-03-11) The escalation posted earlier today is **withdrawn**. @brent.edwards delivered PR #680 which fixes the `db` provider registration issue for both `session list` (#554) and `session create` (#570). **Current status:** - PR #680 is open and has passed all quality gates (98% coverage, all TDD tests green) - PR #680 has one review from @CoreRasurae with 7 findings — @brent.edwards has addressed all of them - The `@tdd_expected_fail` tags in `features/session_list_error.feature` should be removed once PR #680 merges **Remaining to close this issue:** 1. PR #680 needs a second review and merge approval 2. After merge, verify `@tdd_expected_fail` tags are removed from `features/session_list_error.feature` 3. Confirm all 10 TDD scenarios in `session_list_error.feature` pass without the expected-fail tag **Note:** Bug #554 body should reference TDD counterpart #630 for traceability. The TDD→Bug direction (#630→#554) is documented but the reverse is not.
Author
Member

Fix submitted in PR #723 (supersedes PR #680). The root cause was a missing session_service provider in the DI Container — _get_session_service() called container.db() which didn't exist. PR #723 registers a proper session_service Factory provider, adds auto_commit support to repositories, and handles errors gracefully across all session subcommands.

Fix submitted in PR #723 (supersedes PR #680). The root cause was a missing `session_service` provider in the DI Container — `_get_session_service()` called `container.db()` which didn't exist. PR #723 registers a proper `session_service` Factory provider, adds `auto_commit` support to repositories, and handles errors gracefully across all session subcommands.
Owner

PM Acknowledgment — Day 32

Confirmed. PR #723 has been formally APPROVED (Review ID 2167). The DI container root cause fix is correct — all 3 bugs (#554, #570, #680) are addressed in a single clean PR.

PR #723 is mergeable and in the critical merge queue. Awaiting @freemo to merge.

Status: Fix verified. Merge imminent.

**PM Acknowledgment — Day 32** Confirmed. PR #723 has been formally **APPROVED** (Review ID 2167). The DI container root cause fix is correct — all 3 bugs (#554, #570, #680) are addressed in a single clean PR. PR #723 is **mergeable** and in the critical merge queue. Awaiting @freemo to merge. **Status**: Fix verified. Merge imminent.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
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#554
No description provided.