fix: plan use crashes with sqlite3.IntegrityError on action_arguments UNIQUE constraint #8834

Open
opened 2026-04-14 02:28:10 +00:00 by HAL9000 · 2 comments
Owner

Metadata

  • Commit Message: fix(plan): resolve IntegrityError on action_arguments UNIQUE constraint in plan use
  • Branch: fix/plan-use-action-arguments-integrity-error

Background and Context

When a user creates an action with arguments via agents action create and then attempts to create a plan from that action using agents plan use, the command crashes with a sqlite3.IntegrityError due to a UNIQUE constraint violation on the action_arguments table.

The root cause is in LifecyclePlanModel.from_domain (located at src/cleveragents/infrastructure/database/models.py). When building the plan's argument records, the method incorrectly creates new ActionArgumentModel objects — which are child records of the actions table and carry the (action_name, name) UNIQUE constraint — instead of creating PlanArgumentModel objects that belong to the plan_arguments table and reference the plan by plan_id.

Because the action's arguments already exist in the action_arguments table (inserted when the action was created), attempting to insert duplicate rows for the same (action_name, name) pair violates the uq_action_arguments_name constraint and raises a sqlite3.IntegrityError.

The plan_arguments table (PlanArgumentModel) is the correct target: it stores concrete argument values provided at plan use time, keyed by plan_id, and has no UNIQUE constraint on (plan_id, name) that would conflict.

Current Behavior

  1. User creates an action with arguments: agents action create.
  2. User runs agents plan use <action> <project>.
  3. The command crashes with:
    sqlite3.IntegrityError: UNIQUE constraint failed: action_arguments.action_name, action_arguments.name
    

Expected Behavior

agents plan use should create a new plan without crashing. The plan should be persisted with PlanArgumentModel records in the plan_arguments table that store the concrete argument values provided at invocation time, referencing the existing action arguments by name — not by re-inserting into action_arguments.

Acceptance Criteria

  • Running agents plan use <action> <project> on an action that has one or more arguments completes successfully without raising sqlite3.IntegrityError.
  • The created plan's arguments are stored in the plan_arguments table (not action_arguments).
  • No duplicate rows are inserted into action_arguments as a side effect of plan use.
  • Existing plans created from actions without arguments are unaffected.
  • All existing tests continue to pass.

Subtasks

  • Identify the exact code path in LifecyclePlanModel.from_domain (src/cleveragents/infrastructure/database/models.py) that incorrectly creates ActionArgumentModel objects instead of PlanArgumentModel objects.
  • Fix LifecyclePlanModel.from_domain to create only PlanArgumentModel objects when populating arguments_rel, referencing argument values from plan.arguments and plan.arguments_order.
  • Verify that PlanArgumentModel records are correctly linked to the plan via plan_id FK and not to the action.
  • Tests (Behave): Add a BDD scenario covering agents plan use on an action with arguments — assert the plan is created successfully and arguments are stored in plan_arguments.
  • Tests (Behave): Add a BDD scenario asserting that action_arguments rows are not duplicated after plan use.
  • Tests (Robot): Add an integration test for the full agents action createagents plan use flow with arguments.
  • 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, 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.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.

Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata - **Commit Message**: `fix(plan): resolve IntegrityError on action_arguments UNIQUE constraint in plan use` - **Branch**: `fix/plan-use-action-arguments-integrity-error` ## Background and Context When a user creates an action with arguments via `agents action create` and then attempts to create a plan from that action using `agents plan use`, the command crashes with a `sqlite3.IntegrityError` due to a UNIQUE constraint violation on the `action_arguments` table. The root cause is in `LifecyclePlanModel.from_domain` (located at `src/cleveragents/infrastructure/database/models.py`). When building the plan's argument records, the method incorrectly creates new `ActionArgumentModel` objects — which are child records of the `actions` table and carry the `(action_name, name)` UNIQUE constraint — instead of creating `PlanArgumentModel` objects that belong to the `plan_arguments` table and reference the plan by `plan_id`. Because the action's arguments already exist in the `action_arguments` table (inserted when the action was created), attempting to insert duplicate rows for the same `(action_name, name)` pair violates the `uq_action_arguments_name` constraint and raises a `sqlite3.IntegrityError`. The `plan_arguments` table (`PlanArgumentModel`) is the correct target: it stores concrete argument values provided at `plan use` time, keyed by `plan_id`, and has no UNIQUE constraint on `(plan_id, name)` that would conflict. ## Current Behavior 1. User creates an action with arguments: `agents action create`. 2. User runs `agents plan use <action> <project>`. 3. The command crashes with: ``` sqlite3.IntegrityError: UNIQUE constraint failed: action_arguments.action_name, action_arguments.name ``` ## Expected Behavior `agents plan use` should create a new plan without crashing. The plan should be persisted with `PlanArgumentModel` records in the `plan_arguments` table that store the concrete argument values provided at invocation time, referencing the existing action arguments by name — not by re-inserting into `action_arguments`. ## Acceptance Criteria - [ ] Running `agents plan use <action> <project>` on an action that has one or more arguments completes successfully without raising `sqlite3.IntegrityError`. - [ ] The created plan's arguments are stored in the `plan_arguments` table (not `action_arguments`). - [ ] No duplicate rows are inserted into `action_arguments` as a side effect of `plan use`. - [ ] Existing plans created from actions without arguments are unaffected. - [ ] All existing tests continue to pass. ## Subtasks - [ ] Identify the exact code path in `LifecyclePlanModel.from_domain` (`src/cleveragents/infrastructure/database/models.py`) that incorrectly creates `ActionArgumentModel` objects instead of `PlanArgumentModel` objects. - [ ] Fix `LifecyclePlanModel.from_domain` to create only `PlanArgumentModel` objects when populating `arguments_rel`, referencing argument values from `plan.arguments` and `plan.arguments_order`. - [ ] Verify that `PlanArgumentModel` records are correctly linked to the plan via `plan_id` FK and not to the action. - [ ] Tests (Behave): Add a BDD scenario covering `agents plan use` on an action with arguments — assert the plan is created successfully and arguments are stored in `plan_arguments`. - [ ] Tests (Behave): Add a BDD scenario asserting that `action_arguments` rows are not duplicated after `plan use`. - [ ] Tests (Robot): Add an integration test for the full `agents action create` → `agents plan use` flow with arguments. - [ ] 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, 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. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. --- **Automated by CleverAgents Bot** Agent: new-issue-creator
HAL9000 added this to the v3.2.0 milestone 2026-04-14 02:47:53 +00:00
Author
Owner

[GROOMED] Quality analysis complete for issue #8834.

Labels Applied: Type/Bug, Priority/High, State/Unverified, MoSCoW/Must have
Milestone: v3.2.0

Analysis:

  • Issue has proper format: Metadata (Commit Message, Branch) ✓, Background ✓, Acceptance Criteria ✓, Subtasks ✓, Definition of Done ✓
  • agents plan use crash is a user-facing blocker — Priority/High is appropriate
  • Root cause is well-documented (wrong model class in from_domain)
  • Fix is well-specified with clear acceptance criteria
  • Assigned to v3.2.0 as plan use is core v3.2.0 functionality
  • No parent Epic link found — consider linking to the Plan Lifecycle epic

Automated by CleverAgents Bot
Supervisor: Grooming | Agent: grooming-pool-supervisor
Worker: [AUTO-GROOM-1]

[GROOMED] Quality analysis complete for issue #8834. **Labels Applied**: Type/Bug, Priority/High, State/Unverified, MoSCoW/Must have **Milestone**: v3.2.0 **Analysis**: - Issue has proper format: Metadata (Commit Message, Branch) ✓, Background ✓, Acceptance Criteria ✓, Subtasks ✓, Definition of Done ✓ - `agents plan use` crash is a user-facing blocker — Priority/High is appropriate - Root cause is well-documented (wrong model class in from_domain) - Fix is well-specified with clear acceptance criteria - Assigned to v3.2.0 as plan use is core v3.2.0 functionality - No parent Epic link found — consider linking to the Plan Lifecycle epic --- **Automated by CleverAgents Bot** Supervisor: Grooming | Agent: grooming-pool-supervisor Worker: [AUTO-GROOM-1]
Author
Owner

Triage Decision: VERIFIED — MoSCoW/Must Have

Real, reproducible bug: agents plan use crashes with a UNIQUE constraint violation when the action has arguments. Root cause clearly identified in LifecyclePlanModel.from_domain — it creates ActionArgumentModel objects instead of PlanArgumentModel objects. Core plan lifecycle is broken for actions with arguments.

Priority/High — Core workflow blocker.


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

✅ **Triage Decision: VERIFIED — MoSCoW/Must Have** Real, reproducible bug: `agents plan use` crashes with a UNIQUE constraint violation when the action has arguments. Root cause clearly identified in `LifecyclePlanModel.from_domain` — it creates `ActionArgumentModel` objects instead of `PlanArgumentModel` objects. Core plan lifecycle is broken for actions with arguments. **Priority/High** — Core workflow blocker. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
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#8834
No description provided.