fix(cli): handle unhandled exceptions in _get_plan_executor DI container wiring #3697

Open
opened 2026-04-05 22:13:36 +00:00 by freemo · 0 comments
Owner

Metadata

  • Branch: fix/error-handling-get-plan-executor
  • Commit Message: fix(cli): handle unhandled exceptions in _get_plan_executor DI container wiring
  • Milestone: N/A (Backlog — see note below)
  • Parent Epic: #362

Bug Report

Severity Assessment

  • Impact: The CLI could crash with an unhandled exception.
  • Likelihood: Medium — depends on DI container configuration.
  • Priority: High

Location

  • File: src/cleveragents/cli/commands/plan.py
  • Function: _get_plan_executor
  • Lines: 1347–1395

Description

The _get_plan_executor function builds a PlanExecutor wired with real LLM actors by retrieving services from the DI container. It does not guard against the case where a service is unavailable or misconfigured, which can cause an unhandled exception to propagate and crash the CLI.

Evidence

def _get_plan_executor(lifecycle_service: PlanLifecycleService | None = None) -> Any:
    from cleveragents.application.container import get_container
    ...
    container = get_container()
    registry = container.provider_registry()          # may raise
    ...
    context_assembler = ACMSExecutePhaseContextAssembler(
        context_tier_service=container.context_tier_service(),   # may raise
        project_repository=container.namespaced_project_repo(),  # may raise
        hot_max_tokens=container.settings().context_max_tokens_hot,
    )
    ...

Any of the container.*() calls can raise if the service is not registered or the configuration is invalid. No try/except block is present.

Expected Behaviour

_get_plan_executor should catch exceptions raised during DI container resolution and re-raise them as a CleverAgentsError with a clear, actionable message so the CLI can surface a user-friendly error instead of an unhandled traceback.

Suggested Fix

Wrap the DI resolution and actor construction in a try/except block:

try:
    container = get_container()
    registry = container.provider_registry()
    ...
except Exception as exc:
    raise CleverAgentsError(
        f"Failed to initialise plan executor — DI container error: {exc}"
    ) from exc

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

Subtasks

  • Add argument validation / pre-condition checks at the top of _get_plan_executor
  • Wrap DI container resolution calls in a try/except block and raise CleverAgentsError on failure
  • Write BDD unit test scenarios (Behave/Gherkin) covering: missing service, misconfigured service, and happy path
  • Ensure static typing remains valid — no # type: ignore suppressions
  • Update any relevant docstrings

Definition of Done

  • _get_plan_executor raises CleverAgentsError (not a raw exception) when DI container resolution fails
  • All new code paths are covered by Behave unit tests in features/
  • nox -e lint passes
  • nox -e typecheck passes (Pyright — zero errors)
  • nox -e unit_tests passes
  • nox -e coverage_report passes (coverage ≥ 97%)
  • All nox stages pass
  • Coverage >= 97%
  • PR is merged and linked issue is closed

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

## Metadata - **Branch**: `fix/error-handling-get-plan-executor` - **Commit Message**: `fix(cli): handle unhandled exceptions in _get_plan_executor DI container wiring` - **Milestone**: N/A (Backlog — see note below) - **Parent Epic**: #362 ## Bug Report ### Severity Assessment - **Impact**: The CLI could crash with an unhandled exception. - **Likelihood**: Medium — depends on DI container configuration. - **Priority**: High ### Location - **File**: `src/cleveragents/cli/commands/plan.py` - **Function**: `_get_plan_executor` - **Lines**: 1347–1395 ### Description The `_get_plan_executor` function builds a `PlanExecutor` wired with real LLM actors by retrieving services from the DI container. It does not guard against the case where a service is unavailable or misconfigured, which can cause an unhandled exception to propagate and crash the CLI. ### Evidence ```python def _get_plan_executor(lifecycle_service: PlanLifecycleService | None = None) -> Any: from cleveragents.application.container import get_container ... container = get_container() registry = container.provider_registry() # may raise ... context_assembler = ACMSExecutePhaseContextAssembler( context_tier_service=container.context_tier_service(), # may raise project_repository=container.namespaced_project_repo(), # may raise hot_max_tokens=container.settings().context_max_tokens_hot, ) ... ``` Any of the `container.*()` calls can raise if the service is not registered or the configuration is invalid. No `try/except` block is present. ### Expected Behaviour `_get_plan_executor` should catch exceptions raised during DI container resolution and re-raise them as a `CleverAgentsError` with a clear, actionable message so the CLI can surface a user-friendly error instead of an unhandled traceback. ### Suggested Fix Wrap the DI resolution and actor construction in a `try/except` block: ```python try: container = get_container() registry = container.provider_registry() ... except Exception as exc: raise CleverAgentsError( f"Failed to initialise plan executor — DI container error: {exc}" ) from exc ``` --- > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.7.0. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. ## Subtasks - [ ] Add argument validation / pre-condition checks at the top of `_get_plan_executor` - [ ] Wrap DI container resolution calls in a `try/except` block and raise `CleverAgentsError` on failure - [ ] Write BDD unit test scenarios (Behave/Gherkin) covering: missing service, misconfigured service, and happy path - [ ] Ensure static typing remains valid — no `# type: ignore` suppressions - [ ] Update any relevant docstrings ## Definition of Done - [ ] `_get_plan_executor` raises `CleverAgentsError` (not a raw exception) when DI container resolution fails - [ ] All new code paths are covered by Behave unit tests in `features/` - [ ] `nox -e lint` passes - [ ] `nox -e typecheck` passes (Pyright — zero errors) - [ ] `nox -e unit_tests` passes - [ ] `nox -e coverage_report` passes (coverage ≥ 97%) - [ ] All nox stages pass - [ ] Coverage >= 97% - [ ] PR is merged and linked issue is closed --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: ca-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.

Blocks
#362 Epic: Security & Safety Hardening
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#3697
No description provided.