UAT: agents tool remove for a Validation raises ToolInUseError instead of auto-detaching attachments as required by spec #2069

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

Metadata

  • Branch: fix/tool-remove-validation-auto-detach
  • Commit Message: fix(cli): auto-detach validation attachments on tool remove instead of raising ToolInUseError
  • Milestone: v3.7.0
  • Parent Epic: #392

Background

The specification (docs/specification.md) defines the following behaviour for agents tool remove:

"Remove a registered tool. Because Validations are a subtype of Tool and share the same registry, this command also removes validations. When removing a Validation, all attachments are automatically detached before the entry is removed from the registry."

During UAT testing, agents tool remove was exercised against a Validation that had active attachments. Instead of auto-detaching those attachments and then removing the validation, the command raised ToolInUseError and aborted — forcing the user to manually detach every attachment before the remove could succeed.

What Was Tested

  • agents tool remove <NAME> CLI command (end-to-end)
  • ToolRegistryRepository.delete() in src/cleveragents/infrastructure/database/repositories.py

Steps to Reproduce

  1. Register a validation: agents validation add --config my-validation.yaml
  2. Attach it to a resource: agents validation attach my-resource local/my-validation
  3. Attempt removal: agents tool remove --yes local/my-validation
  4. Observe: ToolInUseError is raised; the validation is NOT removed.

Expected Behaviour (per spec)

When agents tool remove is called on a Validation that has active attachments, the command must:

  1. Automatically detach all validation attachments (equivalent to running agents validation detach for each one).
  2. Then remove the validation entry from the tool registry.

No error should be raised; the operation should be atomic and transparent to the caller.

Actual Behaviour

ToolRegistryRepository.delete() (around line 3517–3555 of repositories.py) queries for active ValidationAttachmentModel rows and raises ToolInUseError if any exist:

# Check for validation attachments
attachment_count: int = (
    session.query(ValidationAttachmentModel)
    .filter(ValidationAttachmentModel.validation_name == name)
    .count()
)
if attachment_count > 0:
    raise ToolInUseError(name, attachment_count)

This guard was presumably added to prevent orphaned attachments, but it contradicts the spec's "automatically detached" guarantee.

Affected Code

Location Detail
src/cleveragents/infrastructure/database/repositories.py ~L3517–3555 ToolRegistryRepository.delete() — raises instead of auto-detaching
src/cleveragents/infrastructure/database/repositories.py ~L3300 ToolInUseError exception class definition

Severity

High — users cannot remove a validation that has any attachments without first manually detaching each one, directly violating the spec's "automatically detached" guarantee.

Subtasks

  • Update ToolRegistryRepository.delete() to query all ValidationAttachmentModel rows for the target validation name and delete them within the same transaction before deleting the registry entry
  • Remove (or guard) the ToolInUseError raise that currently blocks the delete when attachments exist
  • Ensure the auto-detach + delete is wrapped in a single Unit-of-Work transaction so it is atomic
  • Add/update Behave BDD scenarios in features/ covering: (a) remove validation with no attachments, (b) remove validation with one attachment, (c) remove validation with multiple attachments
  • Add/update Robot Framework integration test in robot/ exercising the full agents tool remove CLI flow against a validation with active attachments
  • Verify nox (all default sessions) passes after the fix
  • Confirm test coverage remains ≥ 97 %

Definition of Done

  • ToolRegistryRepository.delete() auto-detaches all ValidationAttachmentModel rows before removing the registry entry — no ToolInUseError is raised for validations
  • The auto-detach + delete is atomic (single transaction / Unit of Work)
  • All Behave BDD scenarios for the affected behaviour pass
  • Robot Framework integration test for agents tool remove on a validation with attachments passes
  • All nox stages pass
  • Coverage >= 97%

Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-new-issue-creator

## Metadata - **Branch**: `fix/tool-remove-validation-auto-detach` - **Commit Message**: `fix(cli): auto-detach validation attachments on tool remove instead of raising ToolInUseError` - **Milestone**: v3.7.0 - **Parent Epic**: #392 ## Background The specification (`docs/specification.md`) defines the following behaviour for `agents tool remove`: > "Remove a registered tool. Because Validations are a subtype of Tool and share the same registry, this command also removes validations. When removing a Validation, all attachments are automatically detached before the entry is removed from the registry." During UAT testing, `agents tool remove` was exercised against a Validation that had active attachments. Instead of auto-detaching those attachments and then removing the validation, the command raised `ToolInUseError` and aborted — forcing the user to manually detach every attachment before the remove could succeed. ## What Was Tested - `agents tool remove <NAME>` CLI command (end-to-end) - `ToolRegistryRepository.delete()` in `src/cleveragents/infrastructure/database/repositories.py` ## Steps to Reproduce 1. Register a validation: `agents validation add --config my-validation.yaml` 2. Attach it to a resource: `agents validation attach my-resource local/my-validation` 3. Attempt removal: `agents tool remove --yes local/my-validation` 4. **Observe**: `ToolInUseError` is raised; the validation is NOT removed. ## Expected Behaviour (per spec) When `agents tool remove` is called on a Validation that has active attachments, the command must: 1. Automatically detach **all** validation attachments (equivalent to running `agents validation detach` for each one). 2. Then remove the validation entry from the tool registry. No error should be raised; the operation should be atomic and transparent to the caller. ## Actual Behaviour `ToolRegistryRepository.delete()` (around line 3517–3555 of `repositories.py`) queries for active `ValidationAttachmentModel` rows and raises `ToolInUseError` if any exist: ```python # Check for validation attachments attachment_count: int = ( session.query(ValidationAttachmentModel) .filter(ValidationAttachmentModel.validation_name == name) .count() ) if attachment_count > 0: raise ToolInUseError(name, attachment_count) ``` This guard was presumably added to prevent orphaned attachments, but it contradicts the spec's "automatically detached" guarantee. ## Affected Code | Location | Detail | |---|---| | `src/cleveragents/infrastructure/database/repositories.py` ~L3517–3555 | `ToolRegistryRepository.delete()` — raises instead of auto-detaching | | `src/cleveragents/infrastructure/database/repositories.py` ~L3300 | `ToolInUseError` exception class definition | ## Severity **High** — users cannot remove a validation that has any attachments without first manually detaching each one, directly violating the spec's "automatically detached" guarantee. ## Subtasks - [ ] Update `ToolRegistryRepository.delete()` to query all `ValidationAttachmentModel` rows for the target validation name and delete them within the same transaction before deleting the registry entry - [ ] Remove (or guard) the `ToolInUseError` raise that currently blocks the delete when attachments exist - [ ] Ensure the auto-detach + delete is wrapped in a single Unit-of-Work transaction so it is atomic - [ ] Add/update Behave BDD scenarios in `features/` covering: (a) remove validation with no attachments, (b) remove validation with one attachment, (c) remove validation with multiple attachments - [ ] Add/update Robot Framework integration test in `robot/` exercising the full `agents tool remove` CLI flow against a validation with active attachments - [ ] Verify `nox` (all default sessions) passes after the fix - [ ] Confirm test coverage remains ≥ 97 % ## Definition of Done - [ ] `ToolRegistryRepository.delete()` auto-detaches all `ValidationAttachmentModel` rows before removing the registry entry — no `ToolInUseError` is raised for validations - [ ] The auto-detach + delete is atomic (single transaction / Unit of Work) - [ ] All Behave BDD scenarios for the affected behaviour pass - [ ] Robot Framework integration test for `agents tool remove` on a validation with attachments passes - [ ] All nox stages pass - [ ] Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
freemo added this to the v3.7.0 milestone 2026-04-03 03:48:07 +00:00
freemo self-assigned this 2026-04-03 16:58:11 +00:00
Author
Owner

MoSCoW classification: Should Have

Rationale: This issue addresses a spec requirement or important quality improvement. It should be included in the milestone if possible.


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

MoSCoW classification: **Should Have** Rationale: This issue addresses a spec requirement or important quality improvement. It should be included in the milestone if possible. --- **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.

Blocks
#392 Epic: Actor YAML & Compiler
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#2069
No description provided.