Skip to content

fix(cli): return JSON for sessions list failures - #128316

Merged
steipete merged 1 commit into
mainfrom
autoqa30-sessions-list-json-latest
Aug 23, 2026
Merged

steipete merged 1 commit into
mainfrom
autoqa30-sessions-list-json-latest

Conversation

@steipete

@steipete steipete commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where openclaw sessions --json and sessions list --json returned exit code 1 with empty stdout for invalid --active or --limit values. Automation then encountered an unrelated JSON parse error instead of the actionable session-filter validation message.

Why This Change Was Made

The sessions-list command owner now throws canonical expected CLI errors instead of writing stderr and exiting directly. Both route-first bare sessions execution and Commander/list-alias execution therefore use the existing root renderer. Validation remains before session-store reads and preserves active-before-limit precedence.

Production delta: +5/-6, net -1 line. Tests: +105/-61, net +44 lines.

AI-assisted: yes. The route and owner boundaries, validation precedence, no-store-read invariant, human and machine output, and tests were reviewed and understood.

User Impact

Sessions-list JSON consumers now receive one canonical cli_error document for invalid active and limit filters. Human diagnostics, positive filters, --limit all, session selection, and successful list output remain unchanged.

Evidence

  • Pre-fix exact-main reproduction: active and limit failures exited 1 with empty stdout through fast-route and Commander execution.
  • Owner/route proof: 162 latest-head tests passed across sessions, route, registration, and failure-output surfaces.
  • Built-process proof: 25/25 sessions list and registration cases passed after an isolated full install and CLI build, covering bare/list alias forms, route-first, forced Commander, parent/leaf JSON placement, human mode, active-before-limit precedence, ANSI-free stdout, network prohibition, and dual-TTY finalization.
  • Complete changed-file gate passed on the implementation checkout, including formatting, typechecking, lint, and architecture guards.
  • Final-rebase owner sanity: 25/25 passed; the intervening main range did not touch any changed file.
  • Exact-head CI run 32656781248 on fb5d2db018101a2e3c1c474258c5f96482d856bc: green.
  • Fresh P1 autoreview: no accepted/actionable findings.
  • ClawSweeper: no findings; its live built command passed the canonical cli_error assertion. Its only rank-up was refreshed exact-head merge/check state, now satisfied. A duplicate unchanged-head review started afterward and does not block landing.
  • Trajectory-export request validation remains separately tracked as task feat: Add Google Antigravity Authentication Support #88.
  • git diff --check: passed.

@clawsweeper

clawsweeper Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: S maintainer Maintainer-authored PR labels Aug 23, 2026
@steipete
steipete marked this pull request as ready for review August 23, 2026 18:02
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 23, 2026
@clawsweeper

clawsweeper Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 23, 2026, 3:29 PM ET / 19:29 UTC.

ClawSweeper review

What this changes

The PR changes invalid sessions-list --active and --limit values to throw a standard CLI error so JSON callers receive a typed error document.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this maintainer PR open: its canonical error rendering is correct, but validation still occurs after explicit session-store resolution, so an invalid filter combined with a bad --store returns the store error instead of the requested filter error.

Priority: P2
Reviewed head: fb5d2db018101a2e3c1c474258c5f96482d856bc

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch has a sound error-rendering direction but retains a concrete P2 precedence defect in the stated validation contract.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer PR is exempt from the external-contributor proof gate; its body reports built-process evidence, but that evidence does not cover the unresolved explicit-store precedence case.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer PR is exempt from the external-contributor proof gate; its body reports built-process evidence, but that evidence does not cover the unresolved explicit-store precedence case.
Evidence reviewed 6 items Unresolved ordering defect: The PR head resolves session-store targets before parsing --active and --limit; an explicit store therefore reaches target validation first.
Explicit-store side effect: Explicit store validation calls fs.statSync and opens the SQLite target before returning a target-resolution error, establishing the precedence failure for a nonexistent store.
Root renderer is the right owner: The root entrypoint serializes thrown errors as the canonical JSON failure envelope, so throwing ExpectedCliError is the right mechanism once validation runs first.
Findings 1 actionable finding [P2] Validate filters before resolving an explicit store
Security None None.

Live Verification

Command: OPENCLAW_CONFIG_PATH=/tmp/openclaw-missing-config.json OPENCLAW_STATE_DIR=/tmp/openclaw-empty-state pnpm openclaw sessions --json --active 0 --store /tmp/openclaw-missing-store.sqlite

Result: PASS (completed)

OPENCLAW_CONFIG_PATH=/tmp/openclaw-missing-config.json OPENCLAW_STATE_DIR=/tmp/openclaw-empty-state pnpm openclaw sessions --json --active 0 --store /tmp/opencl
aw-missing-store.sqlite
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128316-xOO3FN/target$ OPENCLAW_CONFIG_PATH=/tmp/openclaw-missing-config.json OPENCLAW_STATE_DIR=/tmp/openclaw-e
mpty-state pnpm openclaw sessions --json --active 0 --store /tmp/openclaw-missing-store.sqlite
$ node scripts/run-node.mjs sessions --json --active 0 --store /tmp/openclaw-missing-store.sqlite
OPENCLAW_CONFIG_PATH=/tmp/openclaw-missing-config.json OPENCLAW_STATE_DIR=/tmp/openclaw-empty-state pnpm openclaw sessions --json --active 0 --store /tmp/opencl
aw-missing-store.sqlite
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 100.73 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.7s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

[tsdown-build] invocation 2/2 finished in 13.9s
[plugin-control-plane-loads] verified 35 built modules with native require and checked doctor closures
runtime-postbuild: 11 phases comp
… output truncated …

Assertions:

  • PASS expect_output: Session store target does not exist

How this fits together

The sessions CLI validates list filters, selects a session database, then emits session rows or an error. The root CLI renderer converts thrown expected errors into human diagnostics or a JSON cli_error response.

flowchart LR
  A[CLI arguments] --> B[Sessions list command]
  B --> C[Session store selection]
  C --> D[Filter validation]
  D --> E[Session listing]
  D --> F[Root failure renderer]
  F --> G[Human or JSON error output]
Loading

Before merge

  • Validate filters before resolving an explicit store (P2) - The new ExpectedCliError throws occur after resolveSessionStoreTargetsOrExit has already processed --store. That resolver stats and opens the target, so sessions --json --active 0 --store <missing> still returns the store-target error rather than the filter cli_error promised by this PR. Move both filter parses ahead of target resolution and cover this combination; this is the prior P2 finding still present on the unchanged head.
  • Complete next step (P2) - The unchanged P2 blocker has a narrow repair, but this protected maintainer PR should return to its author or a maintainer for the ordering amendment.

Findings

  • [P2] Validate filters before resolving an explicit store — src/commands/sessions.ts:345-354
Agent review details

Security

None.

PR surface

Source -1, Tests +44. Total +43 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 5 6 -1
Tests 2 105 61 +44
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 110 67 +43

Review metrics

Metric Value Why it matters
Production vs test LOC production +5/-6 (net -1); tests +105/-61 (net +44) The implementation stays net-negative, while the added test surface still misses the explicit-store precedence path.

Stored data model

Persistent data-model change detected: serialized state: src/commands/sessions.test.ts, serialized state: src/commands/sessions.ts, unknown-data-model-change: src/commands/sessions.test.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Parse both list filters before resolving any session-store target, preserve active-before-limit precedence, and add an explicit-invalid-store regression case for routed and Commander JSON execution.

Do we have a high-confidence way to reproduce the issue?

Yes—source reproducibly shows resolveSessionStoreTargetsOrExit running before filter parsing, and explicit --store handling performs a stat/open before the new expected error can be thrown.

Is this the best way to solve the issue?

No—the shared error type is the right output path, but it must be reached before session-store selection for the stated validation-before-store invariant to hold.

Full review comments:

  • [P2] Validate filters before resolving an explicit store — src/commands/sessions.ts:345-354
    The new ExpectedCliError throws occur after resolveSessionStoreTargetsOrExit has already processed --store. That resolver stats and opens the target, so sessions --json --active 0 --store <missing> still returns the store-target error rather than the filter cli_error promised by this PR. Move both filter parses ahead of target resolution and cover this combination; this is the prior P2 finding still present on the unchanged head.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against b3b33d24195d.

Labels

Label justifications:

  • P2: A bounded sessions CLI automation path still returns the wrong validation error for an invalid filter paired with an invalid explicit store.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer PR is exempt from the external-contributor proof gate; its body reports built-process evidence, but that evidence does not cover the unresolved explicit-store precedence case.

Evidence

What I checked:

  • Unresolved ordering defect: The PR head resolves session-store targets before parsing --active and --limit; an explicit store therefore reaches target validation first. (src/commands/sessions.ts:327, fb5d2db01810)
  • Explicit-store side effect: Explicit store validation calls fs.statSync and opens the SQLite target before returning a target-resolution error, establishing the precedence failure for a nonexistent store. (src/commands/session-store-targets.ts:53, fb5d2db01810)
  • Root renderer is the right owner: The root entrypoint serializes thrown errors as the canonical JSON failure envelope, so throwing ExpectedCliError is the right mechanism once validation runs first. (src/index.ts:148, fb5d2db01810)
  • Regression coverage gap: The new owner test only asserts that session rows are not listed; it does not cover the earlier target-resolution path, and the end-to-end matrix has no invalid-filter plus explicit-bad-store case. (src/commands/sessions.test.ts:750, fb5d2db01810)
  • Current-main comparison: Current main retains the same target-before-filter ordering and direct runtime exits, so the PR is still needed and is not superseded. (src/commands/sessions.ts:326, b3b33d24195d)
  • Area provenance: History shows Peter Steinberger as the recent dominant contributor to this sessions command; blame ties the reviewed head lines to the current PR commit. (src/commands/sessions.ts:345, fb5d2db01810)

Likely related people:

  • steipete: Authored the PR and the recent session-command history, including explicit-store validation work. (role: recent area contributor; confidence: high; commits: fb5d2db01810, 15a01bcc5e48; files: src/commands/sessions.ts, src/commands/session-store-targets.ts)
  • Josh Lehman: History credits this contributor with the session-read command seam that the command continues to use. (role: adjacent owner; confidence: medium; commits: e1744184b8c0; files: src/commands/sessions.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Move --active and --limit parsing before session-store resolution while retaining active-before-limit order.
  • Add a routed and forced-Commander JSON case with an invalid filter and nonexistent explicit --store, asserting the canonical filter error.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-23T18:09:35.122Z sha fb5d2db :: needs maintainer review before merge. :: none
  • reviewed 2026-08-23T19:08:33.288Z sha fb5d2db :: found issues before merge. :: [P2] Validate filters before resolving an explicit store

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 23, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready review complete.

The sessions-list owner now throws canonical expected CLI errors for invalid --active and --limit values instead of writing stderr and exiting directly. Both route-first bare sessions and Commander/list-alias paths reach the root renderer; active-before-limit precedence and validation-before-store-read remain intact. Production delta is +5/-6 (net -1); tests are +105/-61 (net +44).

Proof:

  • Pre-fix reproduction: active and limit JSON failures exited 1 with empty stdout in both routing modes.
  • Latest-head owner/route proof: 162 tests passed.
  • Built-process proof: 25/25 sessions list and registration cases passed after a full isolated install and CLI build, covering bare/list alias forms, route-first, forced Commander, parent/leaf JSON, human mode, precedence, ANSI-free stdout, prohibited network access, and dual-TTY finalization.
  • Complete changed-file gates passed.
  • Final-rebase owner sanity: 25/25 passed; intervening main changes did not touch the changed files.
  • Exact-head CI run 32656781248 on fb5d2db018101a2e3c1c474258c5f96482d856bc: green.
  • Fresh P1 autoreview: no accepted/actionable findings.
  • ClawSweeper: no findings; its live built command passed the canonical JSON assertion. Its only rank-up was refreshed exact-head merge/check state, now satisfied. A duplicate unchanged-head review started afterward and does not block landing.
  • Trajectory-export request validation remains independently tracked as task feat: Add Google Antigravity Authentication Support #88.
  • Native review artifacts and hosted preparation remain to run before merge.

@steipete
steipete merged commit a3e69b2 into main Aug 23, 2026
253 checks passed
@steipete
steipete deleted the autoqa30-sessions-list-json-latest branch August 23, 2026 21:11
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant