UAT: agents resource remove blocks on child edges instead of cascade-deleting auto-discovered children as spec requires #3508

Closed
opened 2026-04-05 18:43:08 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: bugfix/backlog-resource-remove-cascade-delete
  • Commit Message: fix(cli): cascade-delete auto-discovered children in resource remove command
  • Milestone: None (Backlog)
  • Parent Epic: #398

Background and Context

The agents resource remove CLI command is implemented in src/cleveragents/cli/commands/resource.py (function resource_remove(), lines 1260–1343). The specification (docs/specification.md, line 10953) explicitly defines the expected behaviour of this command:

"Removes a registered resource and all its auto-discovered child resources. A git-checkout resource can have hundreds of child resources (files, directories). This operation fails if the resource is linked to any project — use agents project unlink-resource first."

The current implementation contradicts this specification: instead of cascade-deleting child resources, it refuses to remove any resource that has DAG edges (child or parent relationships), making the command non-functional for the most common resource types (git-checkout, fs-directory).

Current Behavior

The resource_remove() function at lines 1299–1313 counts all DAG edges referencing the resource and aborts if any exist:

# src/cleveragents/cli/commands/resource.py lines 1299-1313
edge_count = 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 '...': {edge_count} edge(s) still reference it.[/red]")
    raise typer.Abort()

This means any git-checkout resource with auto-discovered children (git, fs-directory, fs-file, etc.) can never be removed via agents resource remove, even though the spec explicitly requires cascade deletion.

Expected Behavior

Per docs/specification.md line 10953:

  1. agents resource remove must cascade-delete all auto-discovered child resources recursively, along with the parent resource.
  2. The command must only fail if the resource is linked to a project (not if it has child edges). Users should be directed to agents project unlink-resource first.
  3. The confirmation prompt should report the number of children: "Remove resource local/api-repo and 395 child resources? [y/N]:"
  4. The success output should include "Children Removed: N" and "Projects Unlinked: 0".

Acceptance Criteria

  • agents resource remove <resource> successfully removes a resource that has auto-discovered child edges (no longer aborts with edge-count error).
  • All auto-discovered child resources are recursively deleted in the same operation.
  • The command fails with a clear error if the resource (or any of its children) is linked to a project, directing the user to agents project unlink-resource.
  • The confirmation prompt displays the count of child resources to be removed.
  • The success output includes "Children Removed: N" reflecting the actual count of deleted children.
  • Removing a resource with no children continues to work correctly.
  • All existing agents resource remove tests continue to pass.

Subtasks

  • Reproduce the bug: attempt agents resource remove on a git-checkout resource with auto-discovered children and confirm the abort error.
  • Write failing Behave scenarios (TDD) covering: cascade-delete of children, project-link guard, confirmation prompt with child count, success output with Children Removed: N.
  • Replace the edge-count abort block (lines 1299–1313) with:
    1. A project-link check (abort if linked to any project).
    2. A recursive collector that gathers all descendant resource IDs via the DAG edges.
  • Implement cascade deletion: delete all collected child ResourceEdgeModel rows, then all child ResourceModel rows, then the parent resource.
  • Update the confirmation prompt to include the child resource count.
  • Update the success output to display "Children Removed: N".
  • Add/update Robot Framework integration tests for agents resource remove with child resources.
  • Run nox -e typecheck and fix any Pyright errors.
  • Run nox -e lint and fix any Ruff errors.
  • Verify coverage >= 97% via nox -s coverage_report.
  • Run nox (all default sessions) and confirm all pass.

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 (fix(cli): cascade-delete auto-discovered children in resource remove command), followed by a blank line, then additional lines describing the implementation.
  • The commit is pushed to the remote on the branch bugfix/backlog-resource-remove-cascade-delete.
  • 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%.

Backlog note: This issue was discovered during autonomous operation
on milestone v3.3.0 (M4). It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.


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

## Metadata - **Branch**: `bugfix/backlog-resource-remove-cascade-delete` - **Commit Message**: `fix(cli): cascade-delete auto-discovered children in resource remove command` - **Milestone**: None (Backlog) - **Parent Epic**: #398 ## Background and Context The `agents resource remove` CLI command is implemented in `src/cleveragents/cli/commands/resource.py` (function `resource_remove()`, lines 1260–1343). The specification (`docs/specification.md`, line 10953) explicitly defines the expected behaviour of this command: > "Removes a registered resource **and all its auto-discovered child resources**. A `git-checkout` resource can have hundreds of child resources (files, directories). This operation fails if the resource is linked to any project — use `agents project unlink-resource` first." The current implementation contradicts this specification: instead of cascade-deleting child resources, it refuses to remove any resource that has DAG edges (child or parent relationships), making the command non-functional for the most common resource types (`git-checkout`, `fs-directory`). ## Current Behavior The `resource_remove()` function at lines 1299–1313 counts all DAG edges referencing the resource and aborts if any exist: ```python # src/cleveragents/cli/commands/resource.py lines 1299-1313 edge_count = 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 '...': {edge_count} edge(s) still reference it.[/red]") raise typer.Abort() ``` This means any `git-checkout` resource with auto-discovered children (git, fs-directory, fs-file, etc.) can **never** be removed via `agents resource remove`, even though the spec explicitly requires cascade deletion. ## Expected Behavior Per `docs/specification.md` line 10953: 1. `agents resource remove` **must** cascade-delete all auto-discovered child resources recursively, along with the parent resource. 2. The command **must only fail** if the resource is linked to a project (not if it has child edges). Users should be directed to `agents project unlink-resource` first. 3. The confirmation prompt should report the number of children: `"Remove resource local/api-repo and 395 child resources? [y/N]:"` 4. The success output should include `"Children Removed: N"` and `"Projects Unlinked: 0"`. ## Acceptance Criteria - [ ] `agents resource remove <resource>` successfully removes a resource that has auto-discovered child edges (no longer aborts with edge-count error). - [ ] All auto-discovered child resources are recursively deleted in the same operation. - [ ] The command fails with a clear error if the resource (or any of its children) is linked to a project, directing the user to `agents project unlink-resource`. - [ ] The confirmation prompt displays the count of child resources to be removed. - [ ] The success output includes `"Children Removed: N"` reflecting the actual count of deleted children. - [ ] Removing a resource with no children continues to work correctly. - [ ] All existing `agents resource remove` tests continue to pass. ## Subtasks - [ ] Reproduce the bug: attempt `agents resource remove` on a `git-checkout` resource with auto-discovered children and confirm the abort error. - [ ] Write failing Behave scenarios (TDD) covering: cascade-delete of children, project-link guard, confirmation prompt with child count, success output with `Children Removed: N`. - [ ] Replace the edge-count abort block (lines 1299–1313) with: 1. A project-link check (abort if linked to any project). 2. A recursive collector that gathers all descendant resource IDs via the DAG edges. - [ ] Implement cascade deletion: delete all collected child `ResourceEdgeModel` rows, then all child `ResourceModel` rows, then the parent resource. - [ ] Update the confirmation prompt to include the child resource count. - [ ] Update the success output to display `"Children Removed: N"`. - [ ] Add/update Robot Framework integration tests for `agents resource remove` with child resources. - [ ] Run `nox -e typecheck` and fix any Pyright errors. - [ ] Run `nox -e lint` and fix any Ruff errors. - [ ] Verify coverage >= 97% via `nox -s coverage_report`. - [ ] Run `nox` (all default sessions) and confirm all pass. ## 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 (`fix(cli): cascade-delete auto-discovered children in resource remove command`), followed by a blank line, then additional lines describing the implementation. - The commit is pushed to the remote on the branch `bugfix/backlog-resource-remove-cascade-delete`. - 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%. > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.3.0 (M4). It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-uat-tester
Author
Owner

Closing as duplicate of #2447.

Both issues describe the same bug: agents resource remove blocks on DAG edges instead of cascade-deleting auto-discovered children as the spec requires. Issue #2447 is the older, more established tracking issue with State/Verified and Priority/Critical labels. Please track this work in #2447.


Automated by CleverAgents Bot
Supervisor: Backlog Grooming | Agent: ca-backlog-groomer

Closing as duplicate of #2447. Both issues describe the same bug: `agents resource remove` blocks on DAG edges instead of cascade-deleting auto-discovered children as the spec requires. Issue #2447 is the older, more established tracking issue with `State/Verified` and `Priority/Critical` labels. Please track this work in #2447. --- **Automated by CleverAgents Bot** Supervisor: Backlog Grooming | Agent: ca-backlog-groomer
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
#398 Epic: Post-MVP Resources
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#3508
No description provided.