UAT: UnitOfWork imports broken ResourceRepository from new_repositories.py instead of correct implementation in repositories.py #3958

Open
opened 2026-04-06 07:52:16 +00:00 by freemo · 0 comments
Owner

Bug Report

Feature Area: Infrastructure and Database Layer
Severity: Critical — all resource persistence operations via UnitOfWork.resources will fail at runtime
Found by: UAT tester (code analysis)


What Was Tested

Code analysis of src/cleveragents/infrastructure/database/unit_of_work.py import resolution for ResourceRepository.

Expected Behavior

UnitOfWork.resources should provide a fully functional ResourceRepository that correctly maps to the resources table using the spec-aligned ResourceModel from models.py.

A correct, complete ResourceRepository already exists in repositories.py (line 2068) with:

  • Proper field mapping (resource_id, namespaced_name, type_name, resource_kind, etc.)
  • Type validation (checks ResourceTypeModel exists before insert)
  • Duplicate detection
  • Full CRUD: create, get, get_by_name, list, update, delete, link_child, unlink_child, get_children, get_parents

Actual Behavior

unit_of_work.py imports ResourceRepository from new_repositories.py (the broken implementation) instead of repositories.py (the correct implementation):

# unit_of_work.py lines 16-31 — imports DecisionRepository from repositories.py (correct)
from cleveragents.infrastructure.database.repositories import (
    ActionRepository,
    ActorRepository,
    ChangeRepository,
    CheckpointRepository,
    ContextRepository,
    CorrectionAttemptRepository,
    DebugAttemptRepository,
    DecisionRepository,       # ✓ correct — from repositories.py
    LifecyclePlanRepository,
    PlanRepository,
    ProjectRepository,
)

# unit_of_work.py lines 29-31 — imports ResourceRepository from new_repositories.py (BROKEN)
from cleveragents.infrastructure.database.new_repositories import (
    ResourceRepository,       # ❌ broken — uses wrong field names
)

The ResourceRepository in new_repositories.py uses wrong field names (id, name, resource_type, config) that don't exist on the ResourceModel in models.py. Any call to uow.resources.create() or uow.resources.get() will raise AttributeError.

Impact

Every code path that uses UnitOfWork.resources is broken:

  • agents resource add — cannot persist new resources
  • agents resource list — cannot query resources
  • Any plan execution that creates or reads resources

Code Location

  • Broken import: src/cleveragents/infrastructure/database/unit_of_work.py (lines 29-31)
  • Broken implementation: src/cleveragents/infrastructure/database/new_repositories.py (lines 20-59)
  • Correct implementation: src/cleveragents/infrastructure/database/repositories.py (lines 2068-2500+)

Fix Required

Change unit_of_work.py to import ResourceRepository from repositories.py instead of new_repositories.py:

# Fix: import from repositories.py
from cleveragents.infrastructure.database.repositories import (
    ActionRepository,
    ActorRepository,
    ChangeRepository,
    CheckpointRepository,
    ContextRepository,
    CorrectionAttemptRepository,
    DebugAttemptRepository,
    DecisionRepository,
    LifecyclePlanRepository,
    PlanRepository,
    ProjectRepository,
    ResourceRepository,    # ← add this
)
# Remove the import from new_repositories entirely

Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-uat-tester

## Bug Report **Feature Area:** Infrastructure and Database Layer **Severity:** Critical — all resource persistence operations via `UnitOfWork.resources` will fail at runtime **Found by:** UAT tester (code analysis) --- ## What Was Tested Code analysis of `src/cleveragents/infrastructure/database/unit_of_work.py` import resolution for `ResourceRepository`. ## Expected Behavior `UnitOfWork.resources` should provide a fully functional `ResourceRepository` that correctly maps to the `resources` table using the spec-aligned `ResourceModel` from `models.py`. A correct, complete `ResourceRepository` already exists in `repositories.py` (line 2068) with: - Proper field mapping (`resource_id`, `namespaced_name`, `type_name`, `resource_kind`, etc.) - Type validation (checks `ResourceTypeModel` exists before insert) - Duplicate detection - Full CRUD: `create`, `get`, `get_by_name`, `list`, `update`, `delete`, `link_child`, `unlink_child`, `get_children`, `get_parents` ## Actual Behavior `unit_of_work.py` imports `ResourceRepository` from `new_repositories.py` (the broken implementation) instead of `repositories.py` (the correct implementation): ```python # unit_of_work.py lines 16-31 — imports DecisionRepository from repositories.py (correct) from cleveragents.infrastructure.database.repositories import ( ActionRepository, ActorRepository, ChangeRepository, CheckpointRepository, ContextRepository, CorrectionAttemptRepository, DebugAttemptRepository, DecisionRepository, # ✓ correct — from repositories.py LifecyclePlanRepository, PlanRepository, ProjectRepository, ) # unit_of_work.py lines 29-31 — imports ResourceRepository from new_repositories.py (BROKEN) from cleveragents.infrastructure.database.new_repositories import ( ResourceRepository, # ❌ broken — uses wrong field names ) ``` The `ResourceRepository` in `new_repositories.py` uses wrong field names (`id`, `name`, `resource_type`, `config`) that don't exist on the `ResourceModel` in `models.py`. Any call to `uow.resources.create()` or `uow.resources.get()` will raise `AttributeError`. ## Impact Every code path that uses `UnitOfWork.resources` is broken: - `agents resource add` — cannot persist new resources - `agents resource list` — cannot query resources - Any plan execution that creates or reads resources ## Code Location - **Broken import:** `src/cleveragents/infrastructure/database/unit_of_work.py` (lines 29-31) - **Broken implementation:** `src/cleveragents/infrastructure/database/new_repositories.py` (lines 20-59) - **Correct implementation:** `src/cleveragents/infrastructure/database/repositories.py` (lines 2068-2500+) ## Fix Required Change `unit_of_work.py` to import `ResourceRepository` from `repositories.py` instead of `new_repositories.py`: ```python # Fix: import from repositories.py from cleveragents.infrastructure.database.repositories import ( ActionRepository, ActorRepository, ChangeRepository, CheckpointRepository, ContextRepository, CorrectionAttemptRepository, DebugAttemptRepository, DecisionRepository, LifecyclePlanRepository, PlanRepository, ProjectRepository, ResourceRepository, # ← add this ) # Remove the import from new_repositories entirely ``` --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-uat-tester
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#3958
No description provided.