UAT: session list empty-state JSON output uses total key instead of summary object — inconsistent with non-empty response #4640

Open
opened 2026-04-08 17:40:53 +00:00 by HAL9000 · 0 comments
Owner

Bug Report

Tested by: UAT tester worker uat-worker-cli-fmt-001
Feature area: CLI output formatting — session list empty state JSON structure
Severity: Medium — inconsistent data structure breaks JSON consumers


Summary

The agents session list --format json command produces different JSON data structures depending on whether sessions exist. When no sessions exist, it emits {"sessions": [], "total": 0}. When sessions exist, it emits {"sessions": [...], "summary": {"total": N, "most_recent": ..., "oldest": ..., "total_messages": ..., "storage": ...}}. The inconsistency breaks any JSON consumer that parses the output.


Expected Behavior

Both empty and non-empty cases should produce the same structure:

{
  "command": "agents session list",
  "status": "ok",
  "exit_code": 0,
  "data": {
    "sessions": [],
    "summary": {
      "total": 0,
      "most_recent": null,
      "oldest": null,
      "total_messages": 0,
      "storage": "0 KB"
    }
  },
  "timing": {"duration_ms": 5},
  "messages": [...]
}

Actual Behavior

Empty case:

{
  "command": "",
  "status": "ok",
  "exit_code": 0,
  "data": {"sessions": [], "total": 0},  // BUG: "total" key, no "summary" object
  ...
}

Non-empty case:

{
  "command": "",
  "status": "ok",
  "exit_code": 0,
  "data": {
    "sessions": [...],
    "summary": {"total": 2, "most_recent": "...", ...}  // "summary" object
  },
  ...
}

Code Location

src/cleveragents/cli/commands/session.py, list_sessions():

if not sessions:
    if fmt not in (OutputFormat.RICH.value, OutputFormat.COLOR.value):
        typer.echo(format_output({"sessions": [], "total": 0}, fmt))  # BUG: "total" not "summary"
        return

vs. the non-empty path:

data = _session_list_dict(sessions)  # Returns {"sessions": [...], "summary": {...}}
typer.echo(format_output(data, fmt))

Fix Suggestion

Replace the empty-state data structure to match the non-empty structure:

if not sessions:
    if fmt not in (OutputFormat.RICH.value, OutputFormat.COLOR.value):
        empty_data = {
            "sessions": [],
            "summary": {
                "total": 0,
                "most_recent": None,
                "oldest": None,
                "total_messages": 0,
                "storage": "0 KB",
            }
        }
        typer.echo(format_output(empty_data, fmt, command="agents session list"))
        return

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

## Bug Report **Tested by:** UAT tester worker `uat-worker-cli-fmt-001` **Feature area:** CLI output formatting — `session list` empty state JSON structure **Severity:** Medium — inconsistent data structure breaks JSON consumers --- ## Summary The `agents session list --format json` command produces different JSON data structures depending on whether sessions exist. When no sessions exist, it emits `{"sessions": [], "total": 0}`. When sessions exist, it emits `{"sessions": [...], "summary": {"total": N, "most_recent": ..., "oldest": ..., "total_messages": ..., "storage": ...}}`. The inconsistency breaks any JSON consumer that parses the output. --- ## Expected Behavior Both empty and non-empty cases should produce the same structure: ```json { "command": "agents session list", "status": "ok", "exit_code": 0, "data": { "sessions": [], "summary": { "total": 0, "most_recent": null, "oldest": null, "total_messages": 0, "storage": "0 KB" } }, "timing": {"duration_ms": 5}, "messages": [...] } ``` ## Actual Behavior **Empty case:** ```json { "command": "", "status": "ok", "exit_code": 0, "data": {"sessions": [], "total": 0}, // BUG: "total" key, no "summary" object ... } ``` **Non-empty case:** ```json { "command": "", "status": "ok", "exit_code": 0, "data": { "sessions": [...], "summary": {"total": 2, "most_recent": "...", ...} // "summary" object }, ... } ``` --- ## Code Location `src/cleveragents/cli/commands/session.py`, `list_sessions()`: ```python if not sessions: if fmt not in (OutputFormat.RICH.value, OutputFormat.COLOR.value): typer.echo(format_output({"sessions": [], "total": 0}, fmt)) # BUG: "total" not "summary" return ``` vs. the non-empty path: ```python data = _session_list_dict(sessions) # Returns {"sessions": [...], "summary": {...}} typer.echo(format_output(data, fmt)) ``` --- ## Fix Suggestion Replace the empty-state data structure to match the non-empty structure: ```python if not sessions: if fmt not in (OutputFormat.RICH.value, OutputFormat.COLOR.value): empty_data = { "sessions": [], "summary": { "total": 0, "most_recent": None, "oldest": None, "total_messages": 0, "storage": "0 KB", } } typer.echo(format_output(empty_data, fmt, command="agents session list")) return ``` --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: uat-tester
HAL9000 added this to the v3.5.0 milestone 2026-04-08 17:54:04 +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.

Dependencies

No dependencies set.

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