_compute_actor_impact() silently swallows all exceptions via three bare except Exception: pass blocks #8434

Open
opened 2026-04-13 18:53:09 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Commit message: Build: Reinforced label enforcement, and ensure implementation workers dont continue work on a mergable PR.
  • Branch: master

Background and Context

The code quality standards explicitly prohibit bare except clauses and error suppression (pass in except). In src/cleveragents/cli/commands/actor.py, the function _compute_actor_impact() contains three separate except Exception: pass blocks that silently swallow all exceptions:

def _compute_actor_impact(actor_name: str) -> tuple[int, int, int]:
    ...
    session_count = 0
    try:
        session_service = container.session_service()
        sessions = session_service.list()
        session_count = sum(1 for s in sessions if s.actor_name == actor_name)
    except Exception:  # pragma: no cover - defensive; DB may be unavailable
        pass           # ← silent failure: session_count stays 0

    active_plan_count = 0
    try:
        uow = container.unit_of_work()
        with uow.transaction() as ctx:
            plans = ctx.lifecycle_plans.list_plans(limit=10000)
        ...
    except Exception:  # pragma: no cover - defensive; DB may be unavailable
        pass           # ← silent failure: active_plan_count stays 0

    action_count = 0
    try:
        lifecycle_service = container.plan_lifecycle_service()
        actions = lifecycle_service.list_actions()
        ...
    except Exception:  # pragma: no cover - defensive; DB may be unavailable
        pass           # ← silent failure: action_count stays 0

    return session_count, active_plan_count, action_count

When any of these three queries fail (e.g., due to a database error, service unavailability, or programming error), the function silently returns (0, 0, 0). The agents actor remove command then displays "0 sessions affected, 0 active plans affected, 0 actions referencing" — which is misleading because the counts are wrong, not zero. The user has no indication that the impact assessment failed.

The # pragma: no cover annotations also hide these paths from coverage, masking the lack of test coverage for error scenarios.

Current Behavior

When any of the three impact queries fail, _compute_actor_impact() silently returns (0, 0, 0). The agents actor remove command displays incorrect impact counts without any warning to the user.

Expected Behavior

Per the code quality standards:

  • Bare except Exception: pass is forbidden.
  • At minimum, each failure should be logged at WARNING level with the exception details so operators can diagnose issues.
  • The function docstring already documents the fallback behavior ("Returns (0, 0, 0) if any query fails"), but the implementation must log the failure rather than silently swallowing it.

Acceptance Criteria

  • All three except Exception: pass blocks in _compute_actor_impact() are replaced with except Exception as exc: blocks that log the exception at WARNING level.
  • The log message includes the exception type and message for diagnostics.
  • The function still returns (0, 0, 0) on failure (graceful degradation is acceptable, but must be visible in logs).
  • # pragma: no cover annotations are removed or justified with proper test coverage.
  • Behave BDD scenarios cover the error paths (DB unavailable → warning logged, counts return 0).
  • nox passes (all sessions).
  • Coverage remains ≥ 97%.

Subtasks

  • Replace all three except Exception: pass blocks with except Exception as exc: + structured log warning
  • Remove or justify # pragma: no cover annotations on these blocks
  • Add Behave BDD scenarios for the error paths
  • Run nox and confirm all sessions pass

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message is fix(error-handling): log exceptions in _compute_actor_impact instead of silently swallowing, followed by a blank line, then additional details, and a footer ISSUES CLOSED: #<this issue number>.
  • The commit is pushed to a branch and submitted as a pull request to master, reviewed, and merged.
  • All nox stages pass and coverage ≥ 97%.

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

## Metadata - **Commit message**: `Build: Reinforced label enforcement, and ensure implementation workers dont continue work on a mergable PR.` - **Branch**: `master` ## Background and Context The code quality standards explicitly prohibit bare `except` clauses and error suppression (`pass` in `except`). In `src/cleveragents/cli/commands/actor.py`, the function `_compute_actor_impact()` contains three separate `except Exception: pass` blocks that silently swallow all exceptions: ```python def _compute_actor_impact(actor_name: str) -> tuple[int, int, int]: ... session_count = 0 try: session_service = container.session_service() sessions = session_service.list() session_count = sum(1 for s in sessions if s.actor_name == actor_name) except Exception: # pragma: no cover - defensive; DB may be unavailable pass # ← silent failure: session_count stays 0 active_plan_count = 0 try: uow = container.unit_of_work() with uow.transaction() as ctx: plans = ctx.lifecycle_plans.list_plans(limit=10000) ... except Exception: # pragma: no cover - defensive; DB may be unavailable pass # ← silent failure: active_plan_count stays 0 action_count = 0 try: lifecycle_service = container.plan_lifecycle_service() actions = lifecycle_service.list_actions() ... except Exception: # pragma: no cover - defensive; DB may be unavailable pass # ← silent failure: action_count stays 0 return session_count, active_plan_count, action_count ``` When any of these three queries fail (e.g., due to a database error, service unavailability, or programming error), the function silently returns `(0, 0, 0)`. The `agents actor remove` command then displays "0 sessions affected, 0 active plans affected, 0 actions referencing" — which is misleading because the counts are wrong, not zero. The user has no indication that the impact assessment failed. The `# pragma: no cover` annotations also hide these paths from coverage, masking the lack of test coverage for error scenarios. ## Current Behavior When any of the three impact queries fail, `_compute_actor_impact()` silently returns `(0, 0, 0)`. The `agents actor remove` command displays incorrect impact counts without any warning to the user. ## Expected Behavior Per the code quality standards: - Bare `except Exception: pass` is forbidden. - At minimum, each failure should be logged at WARNING level with the exception details so operators can diagnose issues. - The function docstring already documents the fallback behavior ("Returns `(0, 0, 0)` if any query fails"), but the implementation must log the failure rather than silently swallowing it. ## Acceptance Criteria - [ ] All three `except Exception: pass` blocks in `_compute_actor_impact()` are replaced with `except Exception as exc:` blocks that log the exception at WARNING level. - [ ] The log message includes the exception type and message for diagnostics. - [ ] The function still returns `(0, 0, 0)` on failure (graceful degradation is acceptable, but must be visible in logs). - [ ] `# pragma: no cover` annotations are removed or justified with proper test coverage. - [ ] Behave BDD scenarios cover the error paths (DB unavailable → warning logged, counts return 0). - [ ] `nox` passes (all sessions). - [ ] Coverage remains ≥ 97%. ## Subtasks - [ ] Replace all three `except Exception: pass` blocks with `except Exception as exc:` + structured log warning - [ ] Remove or justify `# pragma: no cover` annotations on these blocks - [ ] Add Behave BDD scenarios for the error paths - [ ] Run `nox` and confirm all sessions pass ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message is `fix(error-handling): log exceptions in _compute_actor_impact instead of silently swallowing`, followed by a blank line, then additional details, and a footer `ISSUES CLOSED: #<this issue number>`. - The commit is pushed to a branch and submitted as a pull request to `master`, reviewed, and merged. - All nox stages pass and coverage ≥ 97%. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor
HAL9000 added this to the v3.6.0 milestone 2026-04-13 19:14:32 +00:00
Author
Owner

[AUTO-OWNR-5] Triage Decision

Status: Verified

MoSCoW: Should Have
Priority: Medium

Rationale: _compute_actor_impact() contains three bare except Exception: pass blocks that silently swallow all exceptions, returning (0, 0, 0) without any indication of failure. This directly violates the project's code quality standards which explicitly prohibit bare except clauses and error suppression. The practical impact is that the agents actor remove command can display misleading impact counts (showing zero when the queries actually failed), giving operators false confidence. The # pragma: no cover annotations further mask the lack of test coverage for these error paths. Classified as Should Have because this is a code quality and debuggability issue — the graceful degradation is acceptable, but silent failure is not.

Next Steps: Replace all three except Exception: pass blocks with except Exception as exc: blocks that log the exception at WARNING level with the exception type and message. Remove or justify # pragma: no cover annotations. Add Behave BDD scenarios for the error paths (DB unavailable → warning logged, counts return 0). Run nox and confirm all sessions pass with coverage ≥ 97%.


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

## [AUTO-OWNR-5] Triage Decision **Status**: ✅ Verified **MoSCoW**: Should Have **Priority**: Medium **Rationale**: `_compute_actor_impact()` contains three bare `except Exception: pass` blocks that silently swallow all exceptions, returning `(0, 0, 0)` without any indication of failure. This directly violates the project's code quality standards which explicitly prohibit bare `except` clauses and error suppression. The practical impact is that the `agents actor remove` command can display misleading impact counts (showing zero when the queries actually failed), giving operators false confidence. The `# pragma: no cover` annotations further mask the lack of test coverage for these error paths. Classified as **Should Have** because this is a code quality and debuggability issue — the graceful degradation is acceptable, but silent failure is not. **Next Steps**: Replace all three `except Exception: pass` blocks with `except Exception as exc:` blocks that log the exception at WARNING level with the exception type and message. Remove or justify `# pragma: no cover` annotations. Add Behave BDD scenarios for the error paths (DB unavailable → warning logged, counts return 0). Run `nox` and confirm all sessions pass with coverage ≥ 97%. --- **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.

Dependencies

No dependencies set.

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