Bug: agents resource remove does not check project links before removal — spec requires failure if resource is linked to any project #3513

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

Metadata

  • Branch: fix/resource-remove-project-link-check
  • Commit Message: fix(cli): fail resource remove when resource is linked to a project
  • Milestone: None (Backlog)
  • Parent Epic: #398

Background

The agents resource remove command in src/cleveragents/cli/commands/resource.py (lines 1260–1343) does not check whether the resource is linked to any project before attempting removal. The specification explicitly states:

"This operation fails if the resource is linked to any project — use agents project unlink-resource first." (spec line 10953)

This is a spec-compliance bug: the current implementation silently removes resources that are still linked to projects, leaving dangling project-resource links in the database and violating the data integrity guarantee described in the specification.

Current Behavior

The resource_remove() function only checks for DAG edges (parent/child relationships). It does not query the project_resource_links table to check if the resource is linked to any project. A resource linked to one or more projects can be removed without warning, leaving dangling project-resource links in the database.

Expected Behavior

Before removing a resource, the command should:

  1. Query the project-resource link table to check if the resource is linked to any projects.
  2. If linked to any projects, fail with a clear error message, e.g.:

    "Resource 'local/api-repo' is linked to 1 project(s): local/api-service. Use 'agents project unlink-resource' first."

  3. Only proceed with removal if the resource has no project links.

Code Location

  • File: src/cleveragents/cli/commands/resource.py
  • Function: resource_remove(), lines 1260–1343
  • Model: ResourceLinkModel in src/cleveragents/infrastructure/database/models.py
  • The project link check should be added before the edge count check (or replacing it, since the spec states edges should be cascade-deleted, not blocked).

Impact

Resources linked to projects can be silently removed, leaving orphaned project-resource links in the database. This violates the spec's data integrity guarantee and can cause unexpected behavior when plans try to access the removed resource through the project.

Subtasks

  • Add a query against ResourceLinkModel (or equivalent project-resource link table) inside resource_remove() to detect any linked projects
  • If linked projects are found, raise a user-facing error listing the linked project(s) and instructing the user to run agents project unlink-resource first
  • Add/update BDD scenario in features/ covering the "resource linked to project → remove fails" case
  • Add/update BDD scenario covering the "resource not linked to any project → remove succeeds" case
  • Ensure all nox quality gates pass (lint, typecheck, unit_tests, integration_tests, coverage_report)

Definition of Done

  • resource_remove() queries the project-resource link table before proceeding with removal
  • Attempting to remove a resource linked to ≥1 project exits with a non-zero status and a descriptive error message naming the linked project(s)
  • Removing a resource with no project links continues to work correctly
  • New BDD scenarios cover both the failure and success paths
  • All nox stages pass
  • Coverage >= 97%

Backlog note: This issue was discovered during autonomous operation
on milestone v3.6.0. 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**: `fix/resource-remove-project-link-check` - **Commit Message**: `fix(cli): fail resource remove when resource is linked to a project` - **Milestone**: None (Backlog) - **Parent Epic**: #398 ## Background The `agents resource remove` command in `src/cleveragents/cli/commands/resource.py` (lines 1260–1343) does not check whether the resource is linked to any project before attempting removal. The specification explicitly states: > "This operation fails if the resource is linked to any project — use `agents project unlink-resource` first." (spec line 10953) This is a spec-compliance bug: the current implementation silently removes resources that are still linked to projects, leaving dangling project-resource links in the database and violating the data integrity guarantee described in the specification. ## Current Behavior The `resource_remove()` function only checks for DAG edges (parent/child relationships). It does **not** query the `project_resource_links` table to check if the resource is linked to any project. A resource linked to one or more projects can be removed without warning, leaving dangling project-resource links in the database. ## Expected Behavior Before removing a resource, the command should: 1. Query the project-resource link table to check if the resource is linked to any projects. 2. If linked to any projects, fail with a clear error message, e.g.: > `"Resource 'local/api-repo' is linked to 1 project(s): local/api-service. Use 'agents project unlink-resource' first."` 3. Only proceed with removal if the resource has no project links. ## Code Location - **File**: `src/cleveragents/cli/commands/resource.py` - **Function**: `resource_remove()`, lines 1260–1343 - **Model**: `ResourceLinkModel` in `src/cleveragents/infrastructure/database/models.py` - The project link check should be added before the edge count check (or replacing it, since the spec states edges should be cascade-deleted, not blocked). ## Impact Resources linked to projects can be silently removed, leaving orphaned project-resource links in the database. This violates the spec's data integrity guarantee and can cause unexpected behavior when plans try to access the removed resource through the project. ## Subtasks - [ ] Add a query against `ResourceLinkModel` (or equivalent project-resource link table) inside `resource_remove()` to detect any linked projects - [ ] If linked projects are found, raise a user-facing error listing the linked project(s) and instructing the user to run `agents project unlink-resource` first - [ ] Add/update BDD scenario in `features/` covering the "resource linked to project → remove fails" case - [ ] Add/update BDD scenario covering the "resource not linked to any project → remove succeeds" case - [ ] Ensure all `nox` quality gates pass (lint, typecheck, unit_tests, integration_tests, coverage_report) ## Definition of Done - [ ] `resource_remove()` queries the project-resource link table before proceeding with removal - [ ] Attempting to remove a resource linked to ≥1 project exits with a non-zero status and a descriptive error message naming the linked project(s) - [ ] Removing a resource with no project links continues to work correctly - [ ] New BDD scenarios cover both the failure and success paths - [ ] All nox stages pass - [ ] Coverage >= 97% > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.6.0. 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 #2446 and #3406.

All three issues describe the same bug: agents resource remove does not check project links before deletion. Issue #3406 (v3.6.0 milestone, Priority/Critical, State/Verified) is the active tracking issue for this work. Issue #2446 is the older backlog version. Please track this work in #3406.


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

Closing as duplicate of #2446 and #3406. All three issues describe the same bug: `agents resource remove` does not check project links before deletion. Issue #3406 (v3.6.0 milestone, `Priority/Critical`, `State/Verified`) is the active tracking issue for this work. Issue #2446 is the older backlog version. Please track this work in #3406. --- **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#3513
No description provided.