UAT: agents resource remove blocks on DAG edges instead of cascading to auto-discovered children — spec requires cascade deletion #2447

Open
opened 2026-04-03 18:24:00 +00:00 by freemo · 1 comment
Owner

Metadata

  • Commit Message: fix(resource): cascade-delete auto-discovered children on resource remove
  • Branch: bugfix/resource-remove-cascade-children

Background and Context

The specification (line 10952–10953) states:

Cascading Deletion: Removes a registered resource and all its auto-discovered child resources. A git-checkout resource can have hundreds of child resources (files, directories).

The spec output example (lines 10969–10976) shows:

╭─ Resource Removed ──────────────────────────────────╮
│ Name: local/api-repo                                │
│ Type: git-checkout                                  │
│ Children Removed: 395                               │
│ Projects Unlinked: 0                                │
╰─────────────────────────────────────────────────────╯
✓ OK Resource removed

The current implementation in src/cleveragents/cli/commands/resource.py (lines 1299–1313) does the opposite: it blocks deletion when DAG edges exist, printing an error like:

Cannot remove resource 'local/api-repo': N edge(s) still reference it.

This makes it impossible to remove any resource that has auto-discovered children (which is the normal case for git-checkout and fs-directory resources), because auto-discovery creates child resources linked via DAG edges.

Current Behavior

# Lines 1299-1313 in resource.py
edge_count: int = (
    session.query(ResourceEdgeModel)
    .filter(
        (ResourceEdgeModel.parent_id == res.resource_id)
        | (ResourceEdgeModel.child_id == res.resource_id)
    )
    .count()
)
if edge_count > 0:
    console.print(
        f"[red]Cannot remove resource '{res.name or res.resource_id}': "
        f"{edge_count} edge(s) still reference it.[/red]"
    )
    raise typer.Abort()

This blocks deletion of any resource with children, making agents resource remove unusable for the primary use case (removing a git-checkout resource with auto-discovered children).

Expected Behavior

agents resource remove should:

  1. Collect all auto-discovered child resources recursively (BFS/DFS traversal of the DAG)
  2. Show a confirmation prompt: Remove resource local/api-repo and 395 child resources? [y/N]:
  3. Delete all child resources and their DAG edges in dependency order (leaves first)
  4. Delete the root resource
  5. Report the count of children removed and projects unlinked

The JSON output format should be:

{
  "command": "resource remove",
  "status": "ok",
  "data": {
    "name": "local/api-repo",
    "type": "git-checkout",
    "children_removed": 395,
    "projects_unlinked": 0
  }
}

Steps to Reproduce (Code Analysis)

  1. Register a git-checkout resource: agents resource add git-checkout local/api-repo --path /some/path
  2. Auto-discovery creates child resources (git objects, directories, files)
  3. Run agents resource remove local/api-repo
  4. Actual: Error "N edge(s) still reference it" — cannot remove
  5. Expected: Confirmation prompt showing child count, then cascade deletion

Code Location

  • File: src/cleveragents/cli/commands/resource.py
  • Function: resource_remove() (line ~1270)
  • Bug: Lines 1299–1313 block on edges instead of cascading

Subtasks

  • Replace edge-blocking check with recursive child collection in resource_remove()
  • Implement BFS traversal to collect all descendant resource IDs
  • Update confirmation prompt to include child count: Remove resource X and N child resources?
  • Delete children in reverse topological order (leaves first) to avoid FK violations
  • Delete all associated DAG edges
  • Report children_removed count in output (rich, plain, JSON, YAML formats)
  • Add unit tests for cascade deletion
  • Add integration test verifying child count reporting

Definition of Done

  • All subtasks completed
  • agents resource remove local/api-repo successfully removes the resource and all auto-discovered children
  • Output includes Children Removed: N count
  • Confirmation prompt shows child count
  • Tests pass
  • Commit pushed to bugfix/resource-remove-cascade-children with the specified commit message
  • PR merged

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

## Metadata - **Commit Message**: `fix(resource): cascade-delete auto-discovered children on resource remove` - **Branch**: `bugfix/resource-remove-cascade-children` ## Background and Context The specification (line 10952–10953) states: > **Cascading Deletion**: Removes a registered resource **and all its auto-discovered child resources**. A `git-checkout` resource can have hundreds of child resources (files, directories). The spec output example (lines 10969–10976) shows: ``` ╭─ Resource Removed ──────────────────────────────────╮ │ Name: local/api-repo │ │ Type: git-checkout │ │ Children Removed: 395 │ │ Projects Unlinked: 0 │ ╰─────────────────────────────────────────────────────╯ ✓ OK Resource removed ``` The current implementation in `src/cleveragents/cli/commands/resource.py` (lines 1299–1313) does the **opposite**: it **blocks** deletion when DAG edges exist, printing an error like: ``` Cannot remove resource 'local/api-repo': N edge(s) still reference it. ``` This makes it impossible to remove any resource that has auto-discovered children (which is the normal case for `git-checkout` and `fs-directory` resources), because auto-discovery creates child resources linked via DAG edges. ## Current Behavior ```python # Lines 1299-1313 in resource.py edge_count: int = ( session.query(ResourceEdgeModel) .filter( (ResourceEdgeModel.parent_id == res.resource_id) | (ResourceEdgeModel.child_id == res.resource_id) ) .count() ) if edge_count > 0: console.print( f"[red]Cannot remove resource '{res.name or res.resource_id}': " f"{edge_count} edge(s) still reference it.[/red]" ) raise typer.Abort() ``` This blocks deletion of any resource with children, making `agents resource remove` unusable for the primary use case (removing a `git-checkout` resource with auto-discovered children). ## Expected Behavior `agents resource remove` should: 1. Collect all auto-discovered child resources recursively (BFS/DFS traversal of the DAG) 2. Show a confirmation prompt: `Remove resource local/api-repo and 395 child resources? [y/N]:` 3. Delete all child resources and their DAG edges in dependency order (leaves first) 4. Delete the root resource 5. Report the count of children removed and projects unlinked The JSON output format should be: ```json { "command": "resource remove", "status": "ok", "data": { "name": "local/api-repo", "type": "git-checkout", "children_removed": 395, "projects_unlinked": 0 } } ``` ## Steps to Reproduce (Code Analysis) 1. Register a `git-checkout` resource: `agents resource add git-checkout local/api-repo --path /some/path` 2. Auto-discovery creates child resources (git objects, directories, files) 3. Run `agents resource remove local/api-repo` 4. **Actual**: Error "N edge(s) still reference it" — cannot remove 5. **Expected**: Confirmation prompt showing child count, then cascade deletion ## Code Location - **File**: `src/cleveragents/cli/commands/resource.py` - **Function**: `resource_remove()` (line ~1270) - **Bug**: Lines 1299–1313 block on edges instead of cascading ## Subtasks - [ ] Replace edge-blocking check with recursive child collection in `resource_remove()` - [ ] Implement BFS traversal to collect all descendant resource IDs - [ ] Update confirmation prompt to include child count: `Remove resource X and N child resources?` - [ ] Delete children in reverse topological order (leaves first) to avoid FK violations - [ ] Delete all associated DAG edges - [ ] Report `children_removed` count in output (rich, plain, JSON, YAML formats) - [ ] Add unit tests for cascade deletion - [ ] Add integration test verifying child count reporting ## Definition of Done - [ ] All subtasks completed - [ ] `agents resource remove local/api-repo` successfully removes the resource and all auto-discovered children - [ ] Output includes `Children Removed: N` count - [ ] Confirmation prompt shows child count - [ ] Tests pass - [ ] Commit pushed to `bugfix/resource-remove-cascade-children` with the specified commit message - [ ] PR merged --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-uat-tester
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Critical — agents resource remove blocks on DAG edges instead of cascading to auto-discovered children. This makes resource cleanup impossible for hierarchical resources.
  • MoSCoW: Must Have — Resource management is a core feature. Blocking on DAG edges with no cascade option makes the resource lifecycle incomplete.

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

Issue triaged by project owner: - **State**: Verified - **Priority**: Critical — `agents resource remove` blocks on DAG edges instead of cascading to auto-discovered children. This makes resource cleanup impossible for hierarchical resources. - **MoSCoW**: Must Have — Resource management is a core feature. Blocking on DAG edges with no cascade option makes the resource lifecycle incomplete. --- **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.

Dependencies

No dependencies set.

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