UAT: agents plan correct does not validate that the target decision ID exists in the plan's decision tree #3271

Open
opened 2026-04-05 08:54:36 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: bugfix/m3-plan-correct-validate-decision-id
  • Commit Message: fix(cli): validate target decision ID exists before executing plan correct
  • Milestone: v3.2.0
  • Parent Epic: #357

Bug Report

Feature Area: agents plan correct CLI Command — decision ID validation (v3.2.0)

Background and Context

The agents plan correct command accepts either a plan ID or a decision ID as its positional <DECISION_ID> argument. The specification (lines 14911–14926) requires that the command validates the target decision ID exists before proceeding with correction. The spec states that both revert and append modes must validate the target decision ID exists (spec section 6: "Both modes validate the target decision ID exists").

Current (Incorrect) Behavior

When a decision ID (not a plan ID) is provided as the identifier, the code in src/cleveragents/cli/commands/plan.py (lines 3030–3044) does not validate that the decision ID exists in the plan's decision tree:

else:
    # Not a plan_id - treat as decision_id (backward compat)
    target_decision_id = identifier
    resolved_plan_id = plan_id or _resolve_active_plan_id()

# Build structural tree adjacency list (parent -> children)
decisions = decision_svc.list_decisions(resolved_plan_id)

decision_tree: dict[str, list[str]] = {}
for d in decisions:
    if d.parent_decision_id is not None:
        decision_tree.setdefault(d.parent_decision_id, []).append(d.decision_id)

# Fetch influence DAG edges
influence_edges = decision_svc.get_influence_edges(resolved_plan_id)

svc = container.correction_service()

# Create the correction request
request = svc.request_correction(
    plan_id=resolved_plan_id,
    target_decision_id=target_decision_id,  # Never validated!
    ...
)

The target_decision_id is used directly without checking whether it exists in the decisions list. This means:

  1. A completely invalid/nonexistent decision ID will be silently accepted
  2. The correction will be created and "executed" against a nonexistent decision
  3. The BFS traversal will simply return only the target ID (since it has no children in the tree), producing a misleading "success" result

Steps to Reproduce

  1. Create a plan with at least one decision
  2. Run: agents plan correct --mode=revert --guidance "Fix this" --yes NONEXISTENT-DECISION-ID
  3. Observe: The command proceeds without error, creates a correction for the nonexistent decision ID, and reports success

Expected Behavior

The command should validate that the provided decision ID exists in the plan's decision tree. If the decision ID does not exist, it should raise a ResourceNotFoundError and display an error message such as:

[red]Not found:[/red] Decision 'NONEXISTENT-DECISION-ID' not found in plan '{plan_id}'.

The DecisionService.get_decision() method already exists and raises DecisionNotFoundError (a subclass of ResourceNotFoundError) when a decision is not found. The CLI should call this method to validate the decision ID before proceeding.

Code Location

src/cleveragents/cli/commands/plan.py, lines 3030–3054. The fix should add a validation step after line 3033:

# Validate that the decision_id exists in the plan
decision_ids_in_plan = {d.decision_id for d in decisions}
if target_decision_id not in decision_ids_in_plan:
    console.print(
        f"[red]Not found:[/red] Decision '{target_decision_id}' "
        f"not found in plan '{resolved_plan_id}'."
    )
    raise typer.Abort()

Impact

This is a critical spec violation for v3.2.0. The spec explicitly requires that both modes validate the target decision ID exists (spec section 6: "Both modes validate the target decision ID exists"). Allowing corrections against nonexistent decisions corrupts the correction audit trail and produces misleading success output.

Subtasks

  • Add validation step in src/cleveragents/cli/commands/plan.py after resolving target_decision_id to check it exists in the plan's decision list
  • Use DecisionService.get_decision() or set-membership check against decision_svc.list_decisions() results to validate existence
  • Display a [red]Not found:[/red] error message and abort if the decision ID is not found
  • Tests (Behave): Add scenario — agents plan correct with nonexistent decision ID raises ResourceNotFoundError / aborts with error message
  • Tests (Behave): Add scenario — agents plan correct with valid decision ID proceeds normally (regression guard)
  • Tests (Robot): Add integration test for invalid decision ID rejection in both --mode=revert and --mode=append
  • Verify coverage >= 97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

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): validate target decision ID exists before executing plan correct), followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly (bugfix/m3-plan-correct-validate-decision-id).
  • 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%.

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

## Metadata - **Branch**: `bugfix/m3-plan-correct-validate-decision-id` - **Commit Message**: `fix(cli): validate target decision ID exists before executing plan correct` - **Milestone**: v3.2.0 - **Parent Epic**: #357 ## Bug Report **Feature Area**: `agents plan correct` CLI Command — decision ID validation (v3.2.0) ### Background and Context The `agents plan correct` command accepts either a plan ID or a decision ID as its positional `<DECISION_ID>` argument. The specification (lines 14911–14926) requires that the command validates the target decision ID exists before proceeding with correction. The spec states that both revert and append modes must validate the target decision ID exists (spec section 6: "Both modes validate the target decision ID exists"). ### Current (Incorrect) Behavior When a decision ID (not a plan ID) is provided as the identifier, the code in `src/cleveragents/cli/commands/plan.py` (lines 3030–3044) does **not** validate that the decision ID exists in the plan's decision tree: ```python else: # Not a plan_id - treat as decision_id (backward compat) target_decision_id = identifier resolved_plan_id = plan_id or _resolve_active_plan_id() # Build structural tree adjacency list (parent -> children) decisions = decision_svc.list_decisions(resolved_plan_id) decision_tree: dict[str, list[str]] = {} for d in decisions: if d.parent_decision_id is not None: decision_tree.setdefault(d.parent_decision_id, []).append(d.decision_id) # Fetch influence DAG edges influence_edges = decision_svc.get_influence_edges(resolved_plan_id) svc = container.correction_service() # Create the correction request request = svc.request_correction( plan_id=resolved_plan_id, target_decision_id=target_decision_id, # Never validated! ... ) ``` The `target_decision_id` is used directly without checking whether it exists in the `decisions` list. This means: 1. A completely invalid/nonexistent decision ID will be silently accepted 2. The correction will be created and "executed" against a nonexistent decision 3. The BFS traversal will simply return only the target ID (since it has no children in the tree), producing a misleading "success" result ### Steps to Reproduce 1. Create a plan with at least one decision 2. Run: `agents plan correct --mode=revert --guidance "Fix this" --yes NONEXISTENT-DECISION-ID` 3. Observe: The command proceeds without error, creates a correction for the nonexistent decision ID, and reports success ### Expected Behavior The command should validate that the provided decision ID exists in the plan's decision tree. If the decision ID does not exist, it should raise a `ResourceNotFoundError` and display an error message such as: ``` [red]Not found:[/red] Decision 'NONEXISTENT-DECISION-ID' not found in plan '{plan_id}'. ``` The `DecisionService.get_decision()` method already exists and raises `DecisionNotFoundError` (a subclass of `ResourceNotFoundError`) when a decision is not found. The CLI should call this method to validate the decision ID before proceeding. ### Code Location `src/cleveragents/cli/commands/plan.py`, lines 3030–3054. The fix should add a validation step after line 3033: ```python # Validate that the decision_id exists in the plan decision_ids_in_plan = {d.decision_id for d in decisions} if target_decision_id not in decision_ids_in_plan: console.print( f"[red]Not found:[/red] Decision '{target_decision_id}' " f"not found in plan '{resolved_plan_id}'." ) raise typer.Abort() ``` ### Impact This is a critical spec violation for v3.2.0. The spec explicitly requires that both modes validate the target decision ID exists (spec section 6: "Both modes validate the target decision ID exists"). Allowing corrections against nonexistent decisions corrupts the correction audit trail and produces misleading success output. ## Subtasks - [ ] Add validation step in `src/cleveragents/cli/commands/plan.py` after resolving `target_decision_id` to check it exists in the plan's decision list - [ ] Use `DecisionService.get_decision()` or set-membership check against `decision_svc.list_decisions()` results to validate existence - [ ] Display a `[red]Not found:[/red]` error message and abort if the decision ID is not found - [ ] Tests (Behave): Add scenario — `agents plan correct` with nonexistent decision ID raises `ResourceNotFoundError` / aborts with error message - [ ] Tests (Behave): Add scenario — `agents plan correct` with valid decision ID proceeds normally (regression guard) - [ ] Tests (Robot): Add integration test for invalid decision ID rejection in both `--mode=revert` and `--mode=append` - [ ] Verify coverage >= 97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## 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): validate target decision ID exists before executing plan correct`), followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly (`bugfix/m3-plan-correct-validate-decision-id`). - 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%. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
freemo added this to the v3.2.0 milestone 2026-04-05 08:56:37 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Critical — agents plan correct does not validate that the target decision ID exists in the plan's decision tree. This means users can attempt to correct non-existent decisions, leading to undefined behavior.
  • Milestone: v3.2.0 (already assigned — milestone is past due)
  • MoSCoW: Must Have — Input validation is a fundamental requirement per CONTRIBUTING.md (fail-fast argument validation). The plan correction workflow must validate decision IDs before attempting corrections.

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

Issue triaged by project owner: - **State**: Verified ✅ - **Priority**: Critical — `agents plan correct` does not validate that the target decision ID exists in the plan's decision tree. This means users can attempt to correct non-existent decisions, leading to undefined behavior. - **Milestone**: v3.2.0 (already assigned — milestone is past due) - **MoSCoW**: Must Have — Input validation is a fundamental requirement per CONTRIBUTING.md (fail-fast argument validation). The plan correction workflow must validate decision IDs before attempting corrections. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
freemo removed this from the v3.2.0 milestone 2026-04-06 20:50:56 +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.

Blocks
Reference
cleveragents/cleveragents-core#3271
No description provided.