UAT: agents plan execute uses wrong JSON output format — _execute_output_dict is defined but never called #3792

Open
opened 2026-04-06 06:22:31 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: fix/plan-execute-json-output-format
  • Commit Message: fix(cli): use _execute_output_dict for agents plan execute non-rich output formats
  • Milestone: Backlog (see note below)
  • Parent Epic: #397

Backlog note: This issue was discovered during autonomous operation
on milestone v3.3.0. It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.

Note on parent epic: The caller suggested #362 ("Epic: Security & Safety Hardening") as the parent, but that epic covers security audit findings and is unrelated to CLI output rendering. This issue has been linked to #397 ("Epic: Server & Autonomy Infrastructure"), which explicitly covers output rendering and CLI polish for the plan lifecycle commands.

Bug Description

The agents plan execute command uses _plan_spec_dict(plan) for non-rich output formats (JSON, YAML, plain, table), but the specification (§agents plan execute) requires a completely different output structure.

Expected Behavior (from spec §agents plan execute)

The JSON output must follow this structure:

{
  "command": "plan execute",
  "status": "ok",
  "exit_code": 0,
  "data": {
    "plan_id": "...",
    "phase": "execute",
    "sandbox": {
      "strategy": "git_worktree",
      "path": "...",
      "branch": "cleveragents/plan-...",
      "status": "active"
    },
    "worker": "local/executor",
    "started": "HH:MM:SS",
    "attempt": 1,
    "strategy_summary": {
      "decisions": 8,
      "invariants": 2,
      "planned_child_plans": "2+",
      "estimated_files": 12,
      "risk": "low"
    },
    "progress": [
      {"label": "Collect context", "status": "running"},
      {"label": "Run tools", "status": "pending"},
      {"label": "Build changeset", "status": "pending"},
      {"label": "Validate", "status": "pending"}
    ]
  },
  "timing": {"started": "...", "duration_ms": 150},
  "messages": ["Execution started"]
}

Actual Behavior

The command uses _plan_spec_dict(plan) which returns a flat plan model dict with fields like plan_id, namespaced_name, phase, processing_state, state, project_links, arguments, automation_profile, action_name, etc. This does not match the spec-required structure.

Code Location

  • src/cleveragents/cli/commands/plan.py line ~2033-2035:

    if fmt != OutputFormat.RICH.value:
        data = _plan_spec_dict(plan)  # BUG: should use _execute_output_dict
        console.print(format_output(data, fmt))
    
  • The correct function _execute_output_dict(plan, started_at, duration_ms) is defined in the same file (lines ~270-400) but is never called anywhere in the codebase.

Impact

  • Any tooling, scripts, or integrations that parse agents plan execute --format json output will receive incorrect data
  • The spec-required sandbox, worker, started, attempt, strategy_summary, and progress fields are absent from the output
  • The _execute_output_dict function is dead code

Steps to Reproduce

  1. Create an action and plan
  2. Run agents plan execute <PLAN_ID> --format json
  3. Observe output uses plan model fields instead of spec-required execute envelope

Subtasks

  • Replace _plan_spec_dict(plan) with _execute_output_dict(plan, started_at, duration_ms) in the execute_plan CLI command
  • Track started_at and duration_ms in the execute command
  • Add BDD test (Behave) verifying the JSON output structure matches the spec §agents plan execute
  • Verify YAML and plain formats also match spec

Definition of Done

  • agents plan execute --format json output matches spec §agents plan execute JSON example exactly
  • agents plan execute --format yaml and --format plain also match spec
  • BDD scenario added covering the JSON output structure
  • _execute_output_dict is no longer dead code
  • All nox stages pass
  • Coverage >= 97%

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

## Metadata - **Branch**: `fix/plan-execute-json-output-format` - **Commit Message**: `fix(cli): use _execute_output_dict for agents plan execute non-rich output formats` - **Milestone**: Backlog (see note below) - **Parent Epic**: #397 > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.3.0. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. > **Note on parent epic:** The caller suggested #362 ("Epic: Security & Safety Hardening") as the parent, but that epic covers security audit findings and is unrelated to CLI output rendering. This issue has been linked to #397 ("Epic: Server & Autonomy Infrastructure"), which explicitly covers output rendering and CLI polish for the plan lifecycle commands. ## Bug Description The `agents plan execute` command uses `_plan_spec_dict(plan)` for non-rich output formats (JSON, YAML, plain, table), but the specification (§agents plan execute) requires a completely different output structure. ### Expected Behavior (from spec §agents plan execute) The JSON output must follow this structure: ```json { "command": "plan execute", "status": "ok", "exit_code": 0, "data": { "plan_id": "...", "phase": "execute", "sandbox": { "strategy": "git_worktree", "path": "...", "branch": "cleveragents/plan-...", "status": "active" }, "worker": "local/executor", "started": "HH:MM:SS", "attempt": 1, "strategy_summary": { "decisions": 8, "invariants": 2, "planned_child_plans": "2+", "estimated_files": 12, "risk": "low" }, "progress": [ {"label": "Collect context", "status": "running"}, {"label": "Run tools", "status": "pending"}, {"label": "Build changeset", "status": "pending"}, {"label": "Validate", "status": "pending"} ] }, "timing": {"started": "...", "duration_ms": 150}, "messages": ["Execution started"] } ``` ### Actual Behavior The command uses `_plan_spec_dict(plan)` which returns a flat plan model dict with fields like `plan_id`, `namespaced_name`, `phase`, `processing_state`, `state`, `project_links`, `arguments`, `automation_profile`, `action_name`, etc. This does **not** match the spec-required structure. ### Code Location - `src/cleveragents/cli/commands/plan.py` line ~2033-2035: ```python if fmt != OutputFormat.RICH.value: data = _plan_spec_dict(plan) # BUG: should use _execute_output_dict console.print(format_output(data, fmt)) ``` - The correct function `_execute_output_dict(plan, started_at, duration_ms)` is defined in the same file (lines ~270-400) but is **never called anywhere** in the codebase. ### Impact - Any tooling, scripts, or integrations that parse `agents plan execute --format json` output will receive incorrect data - The spec-required `sandbox`, `worker`, `started`, `attempt`, `strategy_summary`, and `progress` fields are absent from the output - The `_execute_output_dict` function is dead code ### Steps to Reproduce 1. Create an action and plan 2. Run `agents plan execute <PLAN_ID> --format json` 3. Observe output uses plan model fields instead of spec-required execute envelope ## Subtasks - [ ] Replace `_plan_spec_dict(plan)` with `_execute_output_dict(plan, started_at, duration_ms)` in the `execute_plan` CLI command - [ ] Track `started_at` and `duration_ms` in the execute command - [ ] Add BDD test (Behave) verifying the JSON output structure matches the spec §agents plan execute - [ ] Verify YAML and plain formats also match spec ## Definition of Done - [ ] `agents plan execute --format json` output matches spec §agents plan execute JSON example exactly - [ ] `agents plan execute --format yaml` and `--format plain` also match spec - [ ] BDD scenario added covering the JSON output structure - [ ] `_execute_output_dict` is no longer dead code - [ ] All nox stages pass - [ ] Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
Author
Owner

UAT Follow-up Analysis:

After deeper code review, the bug is slightly different from the initial report. The _execute_output_dict function IS called at line 2112 of plan.py, but the result is then passed to format_output(envelope, fmt) which double-wraps the output.

_execute_output_dict returns a complete envelope:

{
  "command": "plan execute",
  "status": "ok",
  "exit_code": 0,
  "data": {...},
  "timing": {...},
  "messages": [...]
}

But format_output(envelope, fmt) wraps this AGAIN in another envelope (with command="" since no command parameter is passed), producing:

{
  "command": "",
  "status": "ok",
  "exit_code": 0,
  "data": {
    "command": "plan execute",
    "status": "ok",
    "exit_code": 0,
    "data": {...},
    ...
  },
  "timing": {...},
  "messages": [...]
}

The fix should either:

  1. Pass only the data portion of _execute_output_dict to format_output with command="plan execute", or
  2. Serialize the _execute_output_dict result directly without going through format_output

The _execute_output_dict function is NOT dead code — it IS called. But the double-wrapping produces incorrect output.


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

**UAT Follow-up Analysis:** After deeper code review, the bug is slightly different from the initial report. The `_execute_output_dict` function IS called at line 2112 of `plan.py`, but the result is then passed to `format_output(envelope, fmt)` which **double-wraps** the output. `_execute_output_dict` returns a complete envelope: ```json { "command": "plan execute", "status": "ok", "exit_code": 0, "data": {...}, "timing": {...}, "messages": [...] } ``` But `format_output(envelope, fmt)` wraps this AGAIN in another envelope (with `command=""` since no `command` parameter is passed), producing: ```json { "command": "", "status": "ok", "exit_code": 0, "data": { "command": "plan execute", "status": "ok", "exit_code": 0, "data": {...}, ... }, "timing": {...}, "messages": [...] } ``` The fix should either: 1. Pass only the `data` portion of `_execute_output_dict` to `format_output` with `command="plan execute"`, or 2. Serialize the `_execute_output_dict` result directly without going through `format_output` The `_execute_output_dict` function is NOT dead code — it IS called. But the double-wrapping produces incorrect output. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-uat-tester
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
#397 Epic: Server & Autonomy Infrastructure
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#3792
No description provided.