UAT: agents resource remove bypasses service layer and does not cascade-remove child resources as spec requires #4535

Open
opened 2026-04-08 14:20:02 +00:00 by HAL9000 · 0 comments
Owner

Bug Report

Feature Area: Resource management — agents resource remove

Expected Behavior (from spec)

The spec (section agents resource remove, line 10966-10988) shows:

  1. The confirmation prompt should mention child resources:
    Remove resource local/api-repo and 395 child resources? [y/N]: y
    
  2. The output should show the resource name and count of removed children:
    Name: local/api-repo
    ...
    

The spec implies the remove operation should cascade to child resources (auto-discovered children) and inform the user of the count.

Actual Behavior (from code)

In src/cleveragents/cli/commands/resource.py, the resource_remove command:

  1. Directly manipulates the database instead of using the ResourceRegistryService:

    # Lines ~490-520 in resource.py
    session = service._session()
    try:
        from cleveragents.infrastructure.database.models import (
            ResourceEdgeModel,
            ResourceModel,
        )
        # Check for edges
        edge_count = session.query(ResourceEdgeModel).filter(...).count()
        if edge_count > 0:
            console.print(f"[red]Cannot remove resource ... {edge_count} edge(s) still reference it.[/red]")
            raise typer.Abort()
        row = session.query(ResourceModel).filter_by(...).first()
        if row is not None:
            session.delete(row)
            session.commit()
    
  2. Refuses to remove resources with edges instead of cascading:

    • The implementation blocks removal if any edges exist
    • The spec shows removal should cascade to child resources
    • The confirmation prompt does NOT mention child resources
  3. Bypasses the service layer: The CLI directly accesses service._session() (a private method) and manipulates ResourceModel and ResourceEdgeModel directly. This violates the layered architecture and bypasses any business logic in the service layer.

Spec vs Implementation Comparison

Behavior Spec Implementation
Confirmation prompt "Remove resource X and N child resources?" "Remove resource 'X'?"
Child resources Cascade-removed Blocks removal if edges exist
Service layer Uses service Directly manipulates DB
Edge handling Removes edges + children Refuses if edges exist

Code Location

  • src/cleveragents/cli/commands/resource.pyresource_remove() function (lines ~460-530)
  • src/cleveragents/application/services/resource_registry_service.py — Missing remove_resource() method

Impact

  • Users cannot remove resources that have child resources (auto-discovered children), even when they want to
  • The confirmation prompt is misleading — it doesn't warn about child resources
  • The architectural violation (CLI directly accessing DB) makes the code harder to maintain and test
  • Any business logic that should run on resource removal (e.g., UKO index cleanup, project link cleanup) is bypassed

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

## Bug Report **Feature Area:** Resource management — `agents resource remove` ### Expected Behavior (from spec) The spec (section `agents resource remove`, line 10966-10988) shows: 1. The confirmation prompt should mention child resources: ``` Remove resource local/api-repo and 395 child resources? [y/N]: y ``` 2. The output should show the resource name and count of removed children: ``` Name: local/api-repo ... ``` The spec implies the remove operation should cascade to child resources (auto-discovered children) and inform the user of the count. ### Actual Behavior (from code) In `src/cleveragents/cli/commands/resource.py`, the `resource_remove` command: 1. **Directly manipulates the database** instead of using the `ResourceRegistryService`: ```python # Lines ~490-520 in resource.py session = service._session() try: from cleveragents.infrastructure.database.models import ( ResourceEdgeModel, ResourceModel, ) # Check for edges edge_count = session.query(ResourceEdgeModel).filter(...).count() if edge_count > 0: console.print(f"[red]Cannot remove resource ... {edge_count} edge(s) still reference it.[/red]") raise typer.Abort() row = session.query(ResourceModel).filter_by(...).first() if row is not None: session.delete(row) session.commit() ``` 2. **Refuses to remove resources with edges** instead of cascading: - The implementation blocks removal if any edges exist - The spec shows removal should cascade to child resources - The confirmation prompt does NOT mention child resources 3. **Bypasses the service layer**: The CLI directly accesses `service._session()` (a private method) and manipulates `ResourceModel` and `ResourceEdgeModel` directly. This violates the layered architecture and bypasses any business logic in the service layer. ### Spec vs Implementation Comparison | Behavior | Spec | Implementation | |----------|------|----------------| | Confirmation prompt | "Remove resource X and N child resources?" | "Remove resource 'X'?" | | Child resources | Cascade-removed | Blocks removal if edges exist | | Service layer | Uses service | Directly manipulates DB | | Edge handling | Removes edges + children | Refuses if edges exist | ### Code Location - `src/cleveragents/cli/commands/resource.py` — `resource_remove()` function (lines ~460-530) - `src/cleveragents/application/services/resource_registry_service.py` — Missing `remove_resource()` method ### Impact - Users cannot remove resources that have child resources (auto-discovered children), even when they want to - The confirmation prompt is misleading — it doesn't warn about child resources - The architectural violation (CLI directly accessing DB) makes the code harder to maintain and test - Any business logic that should run on resource removal (e.g., UKO index cleanup, project link cleanup) is bypassed --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: uat-tester
HAL9000 added this to the v3.5.0 milestone 2026-04-08 17:41:45 +00:00
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#4535
No description provided.