UAT: agents resource remove does not check if resource is linked to a project — allows dangling references #5934

Open
opened 2026-04-09 11:56:42 +00:00 by HAL9000 · 1 comment
Owner

Summary

agents resource remove successfully removes a resource that is currently linked to one or more projects, leaving dangling resource_id references in the project_resource_links table. The spec explicitly states this operation must fail if the resource is linked to any project.

Expected Behavior (from spec)

From docs/specification.md (line 10954):

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). This operation fails if the resource is linked to any project — use agents project unlink-resource first.

Actual Behavior

The resource is deleted even when linked to projects. The project then shows stale ULIDs in its linked resources list that no longer resolve.

Steps to Reproduce

# 1. Add a resource
agents resource add git-checkout local/my-repo --path /tmp/my-repo

# 2. Create a project and link the resource
agents project create local/my-project
agents project link-resource local/my-project local/my-repo

# 3. Remove the resource (should fail, but succeeds)
agents resource remove local/my-repo --yes
# Output: "Removed resource: local/my-repo"

# 4. Show the project — dangling reference remains
agents project show local/my-project
# Output shows: "Linked Resources (1): - <stale-ulid>"

# 5. Trying to show the removed resource fails
agents resource show <stale-ulid>
# Output: "Resource not found: <stale-ulid>"

Root Cause

In src/cleveragents/cli/commands/resource.py, the resource_remove() function (line 1346) only checks for DAG edges (ResourceEdgeModel) before deleting. It does not check the project_resource_links table for active project links.

# Current code only checks DAG edges:
edge_count = session.query(ResourceEdgeModel).filter(
    (ResourceEdgeModel.parent_id == res.resource_id)
    | (ResourceEdgeModel.child_id == res.resource_id)
).count()
if edge_count > 0:
    # blocks removal
    ...

# Missing: check project_resource_links table

Fix Required

Before deleting, query project_resource_links for any rows where resource_id matches. If any exist, print an error listing the linked projects and abort with a non-zero exit code.

Impact

  • Data integrity: Projects accumulate stale resource references that cannot be resolved
  • User confusion: project show displays ULIDs that no longer exist in the registry
  • Spec violation: Core safety guarantee from the spec is not enforced

Environment

  • Tested on: /app (cleveragents-core, master branch)
  • Python 3.13.3
  • Reproduced: 2026-04-09

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

## Summary `agents resource remove` successfully removes a resource that is currently linked to one or more projects, leaving dangling `resource_id` references in the `project_resource_links` table. The spec explicitly states this operation must fail if the resource is linked to any project. ## Expected Behavior (from spec) From `docs/specification.md` (line 10954): > **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). **This operation fails if the resource is linked to any project** — use `agents project unlink-resource` first. ## Actual Behavior The resource is deleted even when linked to projects. The project then shows stale ULIDs in its linked resources list that no longer resolve. ## Steps to Reproduce ```bash # 1. Add a resource agents resource add git-checkout local/my-repo --path /tmp/my-repo # 2. Create a project and link the resource agents project create local/my-project agents project link-resource local/my-project local/my-repo # 3. Remove the resource (should fail, but succeeds) agents resource remove local/my-repo --yes # Output: "Removed resource: local/my-repo" # 4. Show the project — dangling reference remains agents project show local/my-project # Output shows: "Linked Resources (1): - <stale-ulid>" # 5. Trying to show the removed resource fails agents resource show <stale-ulid> # Output: "Resource not found: <stale-ulid>" ``` ## Root Cause In `src/cleveragents/cli/commands/resource.py`, the `resource_remove()` function (line 1346) only checks for DAG edges (`ResourceEdgeModel`) before deleting. It does **not** check the `project_resource_links` table for active project links. ```python # Current code only checks DAG edges: edge_count = session.query(ResourceEdgeModel).filter( (ResourceEdgeModel.parent_id == res.resource_id) | (ResourceEdgeModel.child_id == res.resource_id) ).count() if edge_count > 0: # blocks removal ... # Missing: check project_resource_links table ``` ## Fix Required Before deleting, query `project_resource_links` for any rows where `resource_id` matches. If any exist, print an error listing the linked projects and abort with a non-zero exit code. ## Impact - **Data integrity**: Projects accumulate stale resource references that cannot be resolved - **User confusion**: `project show` displays ULIDs that no longer exist in the registry - **Spec violation**: Core safety guarantee from the spec is not enforced ## Environment - Tested on: `/app` (cleveragents-core, master branch) - Python 3.13.3 - Reproduced: 2026-04-09 --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: uat-tester
HAL9000 added this to the v3.0.0 milestone 2026-04-09 12:02:27 +00:00
HAL9000 modified the milestone from v3.0.0 to v3.2.0 2026-04-09 12:16:37 +00:00
Author
Owner

Label compliance fix applied:

  • Added missing labels and/or milestone to bring issue into compliance with CONTRIBUTING.md

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

Label compliance fix applied: - Added missing labels and/or milestone to bring issue into compliance with CONTRIBUTING.md --- **Automated by CleverAgents Bot** Supervisor: Backlog Grooming | Agent: 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.

Dependencies

No dependencies set.

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