BUG-HUNT: [resource] Silent failure in _ensure_template_db can hide test performance issues #2808

Open
opened 2026-04-04 20:32:48 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: fix/resource-ensure-template-db-silent-failure
  • Commit Message: fix(resource): log exception in _ensure_template_db instead of silently passing
  • Milestone: v3.5.0
  • Parent Epic: #1678

Bug Report: [resource] — Silent failure in _ensure_template_db can hide test performance issues

Severity Assessment

  • Impact: Test performance issues are harder to debug because the root cause of slow migrations (failed template DB creation) is hidden.
  • Likelihood: Low, but can happen if there are issues with file permissions, disk space, or the template creation script itself.
  • Priority: Medium

Location

  • File: features/environment.py
  • Function/Class: _ensure_template_db
  • Lines: 421-431

Description

The _ensure_template_db function has a broad except Exception block that catches all exceptions and then silently passes. This could hide errors during the template database creation, leading to a fallback to slower Alembic migrations without any warning or logging. If the create_template script fails for any reason (e.g., file permissions, disk space, or an error in the script itself), the failure will be completely silent. This makes debugging test performance issues difficult.

Evidence

    try:
        # Import the template creation script
        scripts_dir = Path(__file__).parent.parent / "scripts"
        sys.path.insert(0, str(scripts_dir))
        from create_template_db import create_template

        create_template(str(template_path))
        os.environ["CLEVERAGENTS_TEMPLATE_DB"] = str(template_path.resolve())
    except Exception:
        pass  # Fall back to normal Alembic migrations

Expected Behavior

The code should log the exception to provide visibility into why the template DB creation failed.

Actual Behavior

The code silently ignores the exception.

Suggested Fix

Log the exception before passing.

    except Exception as e:
        logging.warning(f"Failed to create template DB: {e}")
        pass  # Fall back to normal Alembic migrations

Category

resource

Subtasks

  • Add import logging (or confirm it is already imported) in features/environment.py
  • Replace bare except Exception: pass with except Exception as e: logging.warning(f"Failed to create template DB: {e}")
  • Verify the warning is emitted in a Behave unit test scenario that simulates a failing create_template call
  • Run nox -e lint and nox -e typecheck to confirm no regressions
  • Run nox -e unit_tests and nox -e coverage_report to confirm coverage ≥ 97%

Definition of Done

  • _ensure_template_db logs a WARNING-level message when create_template raises any exception
  • The fallback to normal Alembic migrations still occurs after logging (no behaviour change, only observability improvement)
  • A Behave scenario covers the exception-logging path
  • All nox stages pass
  • Coverage >= 97%

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

## Metadata - **Branch**: `fix/resource-ensure-template-db-silent-failure` - **Commit Message**: `fix(resource): log exception in _ensure_template_db instead of silently passing` - **Milestone**: v3.5.0 - **Parent Epic**: #1678 ## Bug Report: [resource] — Silent failure in _ensure_template_db can hide test performance issues ### Severity Assessment - **Impact**: Test performance issues are harder to debug because the root cause of slow migrations (failed template DB creation) is hidden. - **Likelihood**: Low, but can happen if there are issues with file permissions, disk space, or the template creation script itself. - **Priority**: Medium ### Location - **File**: `features/environment.py` - **Function/Class**: `_ensure_template_db` - **Lines**: 421-431 ### Description The `_ensure_template_db` function has a broad `except Exception` block that catches all exceptions and then silently passes. This could hide errors during the template database creation, leading to a fallback to slower Alembic migrations without any warning or logging. If the `create_template` script fails for any reason (e.g., file permissions, disk space, or an error in the script itself), the failure will be completely silent. This makes debugging test performance issues difficult. ### Evidence ```python try: # Import the template creation script scripts_dir = Path(__file__).parent.parent / "scripts" sys.path.insert(0, str(scripts_dir)) from create_template_db import create_template create_template(str(template_path)) os.environ["CLEVERAGENTS_TEMPLATE_DB"] = str(template_path.resolve()) except Exception: pass # Fall back to normal Alembic migrations ``` ### Expected Behavior The code should log the exception to provide visibility into why the template DB creation failed. ### Actual Behavior The code silently ignores the exception. ### Suggested Fix Log the exception before passing. ```python except Exception as e: logging.warning(f"Failed to create template DB: {e}") pass # Fall back to normal Alembic migrations ``` ### Category resource ## Subtasks - [ ] Add `import logging` (or confirm it is already imported) in `features/environment.py` - [ ] Replace bare `except Exception: pass` with `except Exception as e: logging.warning(f"Failed to create template DB: {e}")` - [ ] Verify the warning is emitted in a Behave unit test scenario that simulates a failing `create_template` call - [ ] Run `nox -e lint` and `nox -e typecheck` to confirm no regressions - [ ] Run `nox -e unit_tests` and `nox -e coverage_report` to confirm coverage ≥ 97% ## Definition of Done - [ ] `_ensure_template_db` logs a `WARNING`-level message when `create_template` raises any exception - [ ] The fallback to normal Alembic migrations still occurs after logging (no behaviour change, only observability improvement) - [ ] A Behave scenario covers the exception-logging path - [ ] All nox stages pass - [ ] Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: ca-new-issue-creator
freemo added this to the v3.5.0 milestone 2026-04-04 20:32:52 +00:00
Author
Owner

This issue has been moved to the backlog as part of an aggressive grooming of the v3.5.0 milestone. It has been deemed non-critical for the minimal viability of the milestone and will be addressed in a future release.

This issue has been moved to the backlog as part of an aggressive grooming of the v3.5.0 milestone. It has been deemed non-critical for the minimal viability of the milestone and will be addressed in a future release.
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#2808
No description provided.