BUG-HUNT: [consistency] Inconsistent exception type in retry_auto_debug #2996

Open
opened 2026-04-05 03:22:44 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: fix/v3.3.0-retry-auto-debug-exception-type
  • Commit Message: fix(core): replace generic Exception with ExecutionError in retry_auto_debug
  • Milestone: v3.3.0
  • Parent Epic: #362

Background and Context

The retry_auto_debug function in core/retry_service_patterns.py violates the project's convention of using specific, typed exceptions from the well-defined exception hierarchy in core/exceptions.py. When the function exhausts all retries and last_error is a string (rather than an Exception instance), it raises a generic Exception(last_error) instead of a typed exception. This makes error handling less precise for consumers of this function and is inconsistent with the fail-fast, typed-exception philosophy enforced throughout the codebase.

Current Behavior (for bugs)

In src/cleveragents/core/retry_service_patterns.py, around line 637, the retry_auto_debug function contains:

            if last_error is not None:
                if isinstance(last_error, Exception):
                    raise last_error
                raise Exception(last_error)  # ← generic Exception used here
            return None

When last_error is a string (e.g., a plain error message captured during retry), the function raises a bare Exception rather than a typed exception from core.exceptions. This is inconsistent with the project's exception hierarchy and makes it harder for callers to handle errors precisely.

  • Impact: Low — the function works, but violates the typed-exception convention.
  • Likelihood: High — this code path is exercised every time the function fails with a string-based error.

Expected Behavior

The function should wrap string-based errors in a specific exception type from cleveragents.core.exceptions (e.g., ExecutionError) to align with the project's error handling strategy and typed exception hierarchy.

from cleveragents.core.exceptions import ExecutionError

# ...

            if last_error is not None:
                if isinstance(last_error, Exception):
                    raise last_error
                raise ExecutionError(last_error)  # ← typed exception
            return None

Acceptance Criteria

  • retry_auto_debug raises ExecutionError (or another appropriate typed exception from core.exceptions) instead of bare Exception when last_error is a string.
  • No bare Exception(...) raise remains in retry_auto_debug for the string-error path.
  • All existing callers of retry_auto_debug that catch Exception continue to work correctly (since ExecutionError is a subclass).
  • Pyright type checking passes with no # type: ignore suppressions.

Subtasks

  • Identify the correct typed exception from core/exceptions.py to use (e.g., ExecutionError).
  • Replace raise Exception(last_error) with raise ExecutionError(last_error) (or equivalent) in retry_auto_debug.
  • Update any imports in retry_service_patterns.py as needed.
  • Tests (Behave): Add/update scenario covering the string-error path in retry_auto_debug to assert ExecutionError is raised.
  • Verify coverage >= 97% via nox -s coverage_report.
  • Run nox (all default sessions), fix any errors.

Supporting Information

  • File: src/cleveragents/core/retry_service_patterns.py
  • Function: retry_auto_debug
  • Lines: ~637
  • Related Epic: #362 Epic: Security & Safety Hardening
  • Category: consistency
  • Severity: Low impact, High likelihood

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 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.
  • All nox stages pass.
  • Coverage >= 97%.

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

## Metadata - **Branch**: `fix/v3.3.0-retry-auto-debug-exception-type` - **Commit Message**: `fix(core): replace generic Exception with ExecutionError in retry_auto_debug` - **Milestone**: v3.3.0 - **Parent Epic**: #362 ## Background and Context The `retry_auto_debug` function in `core/retry_service_patterns.py` violates the project's convention of using specific, typed exceptions from the well-defined exception hierarchy in `core/exceptions.py`. When the function exhausts all retries and `last_error` is a string (rather than an `Exception` instance), it raises a generic `Exception(last_error)` instead of a typed exception. This makes error handling less precise for consumers of this function and is inconsistent with the fail-fast, typed-exception philosophy enforced throughout the codebase. ## Current Behavior (for bugs) In `src/cleveragents/core/retry_service_patterns.py`, around line 637, the `retry_auto_debug` function contains: ```python if last_error is not None: if isinstance(last_error, Exception): raise last_error raise Exception(last_error) # ← generic Exception used here return None ``` When `last_error` is a string (e.g., a plain error message captured during retry), the function raises a bare `Exception` rather than a typed exception from `core.exceptions`. This is inconsistent with the project's exception hierarchy and makes it harder for callers to handle errors precisely. - **Impact**: Low — the function works, but violates the typed-exception convention. - **Likelihood**: High — this code path is exercised every time the function fails with a string-based error. ## Expected Behavior The function should wrap string-based errors in a specific exception type from `cleveragents.core.exceptions` (e.g., `ExecutionError`) to align with the project's error handling strategy and typed exception hierarchy. ```python from cleveragents.core.exceptions import ExecutionError # ... if last_error is not None: if isinstance(last_error, Exception): raise last_error raise ExecutionError(last_error) # ← typed exception return None ``` ## Acceptance Criteria - [ ] `retry_auto_debug` raises `ExecutionError` (or another appropriate typed exception from `core.exceptions`) instead of bare `Exception` when `last_error` is a string. - [ ] No bare `Exception(...)` raise remains in `retry_auto_debug` for the string-error path. - [ ] All existing callers of `retry_auto_debug` that catch `Exception` continue to work correctly (since `ExecutionError` is a subclass). - [ ] Pyright type checking passes with no `# type: ignore` suppressions. ## Subtasks - [ ] Identify the correct typed exception from `core/exceptions.py` to use (e.g., `ExecutionError`). - [ ] Replace `raise Exception(last_error)` with `raise ExecutionError(last_error)` (or equivalent) in `retry_auto_debug`. - [ ] Update any imports in `retry_service_patterns.py` as needed. - [ ] Tests (Behave): Add/update scenario covering the string-error path in `retry_auto_debug` to assert `ExecutionError` is raised. - [ ] Verify coverage >= 97% via `nox -s coverage_report`. - [ ] Run `nox` (all default sessions), fix any errors. ## Supporting Information - **File**: `src/cleveragents/core/retry_service_patterns.py` - **Function**: `retry_auto_debug` - **Lines**: ~637 - **Related Epic**: #362 Epic: Security & Safety Hardening - **Category**: consistency - **Severity**: Low impact, High likelihood ## 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 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. - All nox stages pass. - Coverage >= 97%. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: ca-new-issue-creator
freemo added this to the v3.3.0 milestone 2026-04-05 03:23:43 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Confirmed
  • MoSCoW: Should Have

Valid finding verified during batch triage.


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

Issue triaged by project owner: - **State**: Verified - **Priority**: Confirmed - **MoSCoW**: Should Have Valid finding verified during batch triage. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
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#2996
No description provided.