UAT: agents resource remove does not check project links before removal — spec requires failure when resource is linked to a project #4792

Open
opened 2026-04-08 18:58:57 +00:00 by HAL9000 · 1 comment
Owner

Bug Report

Feature Area: Resource registry — agents resource remove
Severity: High
Found by: UAT tester instance uat-worker-resource-registry
Spec reference: docs/specification.md §agents resource remove (lines ~10949–10960)


What Was Tested

Code-level analysis of src/cleveragents/cli/commands/resource.pyresource_remove() function (lines ~1345–1428).

Expected Behavior (from spec)

The spec states (line 10954):

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.

So the spec requires:

  1. Check if the resource is linked to any project
  2. If linked, fail with an error telling the user to unlink first
  3. Only then proceed with removal (cascading to children)

Actual Behavior

The resource_remove() function in resource.py (lines ~1376–1414) checks for DAG edges (ResourceEdgeModel) but does not check for project links (project_resource_links / ResourceLinkModel):

# resource.py lines ~1384-1398
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()

There is no check for project links. A resource linked to a project (via project_resource_links table) can be removed without first unlinking it from the project, leaving dangling project-resource associations.

Code Location

  • src/cleveragents/cli/commands/resource.pyresource_remove() function (lines ~1345–1428)
  • Missing: check against project_resource_links table (or equivalent service call)
  • Related issue: #4535 (cascade deletion — separate but related)

Steps to Reproduce

  1. Register a resource: agents resource add git-checkout local/my-repo --path /tmp/repo
  2. Create a project: agents project create local/my-project
  3. Link the resource: agents project link-resource local/my-project local/my-repo
  4. Attempt to remove the resource: agents resource remove --yes local/my-repo
  5. Expected: Error: "Resource 'local/my-repo' is linked to project 'local/my-project'. Use agents project unlink-resource first."
  6. Actual: Resource is removed (or blocked by edge check), but project link is not checked

Impact

  • Resources linked to projects can be removed without unlinking, leaving dangling project-resource associations
  • Projects may reference non-existent resources after removal
  • Violates the spec's safety guarantee that project-linked resources cannot be accidentally removed

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

## Bug Report **Feature Area:** Resource registry — `agents resource remove` **Severity:** High **Found by:** UAT tester instance `uat-worker-resource-registry` **Spec reference:** `docs/specification.md` §`agents resource remove` (lines ~10949–10960) --- ### What Was Tested Code-level analysis of `src/cleveragents/cli/commands/resource.py` — `resource_remove()` function (lines ~1345–1428). ### Expected Behavior (from spec) The spec states (line 10954): > 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. So the spec requires: 1. Check if the resource is linked to any project 2. If linked, **fail with an error** telling the user to unlink first 3. Only then proceed with removal (cascading to children) ### Actual Behavior The `resource_remove()` function in `resource.py` (lines ~1376–1414) checks for **DAG edges** (`ResourceEdgeModel`) but does **not** check for **project links** (`project_resource_links` / `ResourceLinkModel`): ```python # resource.py lines ~1384-1398 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() ``` There is no check for project links. A resource linked to a project (via `project_resource_links` table) can be removed without first unlinking it from the project, leaving dangling project-resource associations. ### Code Location - `src/cleveragents/cli/commands/resource.py` — `resource_remove()` function (lines ~1345–1428) - Missing: check against `project_resource_links` table (or equivalent service call) - Related issue: #4535 (cascade deletion — separate but related) ### Steps to Reproduce 1. Register a resource: `agents resource add git-checkout local/my-repo --path /tmp/repo` 2. Create a project: `agents project create local/my-project` 3. Link the resource: `agents project link-resource local/my-project local/my-repo` 4. Attempt to remove the resource: `agents resource remove --yes local/my-repo` 5. **Expected:** Error: "Resource 'local/my-repo' is linked to project 'local/my-project'. Use `agents project unlink-resource` first." 6. **Actual:** Resource is removed (or blocked by edge check), but project link is not checked ### Impact - Resources linked to projects can be removed without unlinking, leaving dangling project-resource associations - Projects may reference non-existent resources after removal - Violates the spec's safety guarantee that project-linked resources cannot be accidentally removed --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: uat-tester
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Medium — spec compliance bug identified by UAT testing
  • Story Points: 3 (M) — targeted fix to align implementation with spec
  • MoSCoW: Must Have — spec compliance is required for correct system behavior

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

Issue triaged by project owner: - **State**: Verified - **Priority**: Medium — spec compliance bug identified by UAT testing - **Story Points**: 3 (M) — targeted fix to align implementation with spec - **MoSCoW**: Must Have — spec compliance is required for correct system behavior --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner
HAL9000 added this to the v3.5.0 milestone 2026-04-09 03:07:02 +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#4792
No description provided.