UAT: agents session delete --format json/yaml/plain produces no structured output #6302

Open
opened 2026-04-09 20:08:06 +00:00 by HAL9000 · 0 comments
Owner

Summary

agents session delete produces no structured output for non-rich formats. When --format json, --format yaml, or --format plain is passed, the command falls through to an else branch that just calls console.print(...) (Rich console output), instead of emitting a machine-readable response. This means callers using --format json receive Rich-formatted text on stderr/stdout rather than a JSON object.

Spec Reference

docs/specification.md §agents session delete (around line 1936–1986) defines the JSON output:

{
  "command": "agents session delete 01HXM2A6K1P2E9Q9D4GQ7J4S7Z",
  "status": "ok",
  "exit_code": 0,
  "data": {
    "deletion_summary": {
      "session": "01HXM2A6K1P2E9Q9D4GQ7J4S7Z",
      "id": "01HXM2A6K1P2E9Q9D4GQ7J4S7Z",
      "messages_removed": 6,
      "storage_freed": "18 KB",
      "plans_orphaned": 0
    },
    "cleanup": {
      "backups": "none",
      "logs": "preserved",
      "context": "cleared",
      "checkpoints": "none"
    }
  },
  "timing": { "duration_ms": 62 },
  "messages": [{ "level": "ok", "text": "Session deleted" }]
}

Code Location

File: src/cleveragents/cli/commands/session.py
Lines 494–526 — the delete command's post-deletion output block:

if fmt == OutputFormat.RICH:
    # … renders Deletion Summary and Cleanup panels correctly …
    console.print("[green]✓ OK[/green] Session deleted")
else:
    # Non-rich formats: simple message  ← BUG IS HERE
    console.print(f"[green]✓ OK[/green] Session {session_id} deleted")

The else branch always calls console.print (Rich console) regardless of fmt. There is no call to format_output and no structured data dict is ever built for non-rich formats.

Steps to Reproduce

agents session create --format json   # create a session, note the ID
agents session delete <SESSION_ID> --yes --format json

Expected Result

A JSON object matching the spec envelope:

{
  "command": "agents session delete <SESSION_ID>",
  "status": "ok",
  "exit_code": 0,
  "data": {
    "deletion_summary": { ... },
    "cleanup": { ... }
  },
  "timing": { "duration_ms": ... },
  "messages": [{ "level": "ok", "text": "Session deleted" }]
}

Actual Result

Rich-markup text printed to stdout:

✓ OK Session <SESSION_ID> deleted

Additional Notes

  • The Rich path (lines 496–523) correctly builds and prints Deletion Summary and Cleanup panels. The fix must build the equivalent structured data dict and pass it to format_output in the else branch.
  • The fmt type annotation on delete uses OutputFormat enum (unlike other session commands which use plain str), so the comparison uses fmt == OutputFormat.RICH (line 496). The else branch must handle json, yaml, plain, table, etc.
  • messages_removed and storage_freed values are already available (message_count is captured at line 485); plans_orphaned and storage_freed are currently hardcoded as 0 / "0 KB freed" in the Rich path and will need the same treatment in the structured path.

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

## Summary `agents session delete` produces **no structured output** for non-rich formats. When `--format json`, `--format yaml`, or `--format plain` is passed, the command falls through to an `else` branch that just calls `console.print(...)` (Rich console output), instead of emitting a machine-readable response. This means callers using `--format json` receive Rich-formatted text on stderr/stdout rather than a JSON object. ## Spec Reference `docs/specification.md` §agents session delete (around line 1936–1986) defines the JSON output: ```json { "command": "agents session delete 01HXM2A6K1P2E9Q9D4GQ7J4S7Z", "status": "ok", "exit_code": 0, "data": { "deletion_summary": { "session": "01HXM2A6K1P2E9Q9D4GQ7J4S7Z", "id": "01HXM2A6K1P2E9Q9D4GQ7J4S7Z", "messages_removed": 6, "storage_freed": "18 KB", "plans_orphaned": 0 }, "cleanup": { "backups": "none", "logs": "preserved", "context": "cleared", "checkpoints": "none" } }, "timing": { "duration_ms": 62 }, "messages": [{ "level": "ok", "text": "Session deleted" }] } ``` ## Code Location **File**: `src/cleveragents/cli/commands/session.py` **Lines 494–526** — the `delete` command's post-deletion output block: ```python if fmt == OutputFormat.RICH: # … renders Deletion Summary and Cleanup panels correctly … console.print("[green]✓ OK[/green] Session deleted") else: # Non-rich formats: simple message ← BUG IS HERE console.print(f"[green]✓ OK[/green] Session {session_id} deleted") ``` The `else` branch always calls `console.print` (Rich console) regardless of `fmt`. There is **no call to `format_output`** and **no structured data dict** is ever built for non-rich formats. ## Steps to Reproduce ```bash agents session create --format json # create a session, note the ID agents session delete <SESSION_ID> --yes --format json ``` ## Expected Result A JSON object matching the spec envelope: ```json { "command": "agents session delete <SESSION_ID>", "status": "ok", "exit_code": 0, "data": { "deletion_summary": { ... }, "cleanup": { ... } }, "timing": { "duration_ms": ... }, "messages": [{ "level": "ok", "text": "Session deleted" }] } ``` ## Actual Result Rich-markup text printed to stdout: ``` ✓ OK Session <SESSION_ID> deleted ``` ## Additional Notes - The Rich path (lines 496–523) correctly builds and prints `Deletion Summary` and `Cleanup` panels. The fix must build the equivalent structured data dict and pass it to `format_output` in the `else` branch. - The `fmt` type annotation on `delete` uses `OutputFormat` enum (unlike other session commands which use plain `str`), so the comparison uses `fmt == OutputFormat.RICH` (line 496). The `else` branch must handle `json`, `yaml`, `plain`, `table`, etc. - `messages_removed` and `storage_freed` values are already available (`message_count` is captured at line 485); `plans_orphaned` and `storage_freed` are currently hardcoded as `0` / `"0 KB freed"` in the Rich path and will need the same treatment in the structured path. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: 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.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#6302
No description provided.