Skip to content

fix(cli): surface the blank --agent remedy in sessions compact --json failures - #199386

Merged
obviyus merged 2 commits into
openclaw:mainfrom
shuisadev:fix/sessions-compact-agent-blank-remedy-433
Nov 15, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
shuisadev:fix/sessions-compact-agent-blank-remedy-433

Conversation

@shuisadev

@shuisadev shuisadev commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

sessions compact <key> --agent " " --json emits the generic failure and Doctor hint on stderr instead of the existing --agent must not be blank remedy. The JSON envelope already contains the remedy; text mode already prints it.

Fix

Raise the blank-agent guard through the existing throwExpectedCliError owner, as the neighboring argument guards do. No message text, exit code, JSON envelope, accepted input, or Gateway RPC behavior changes. Validation still happens before any Gateway call.

Reuse the existing compact failure-contract row for the regression (net zero test lines). The max-lines registration regression remains, with source CLI controls on both arms. Production +2/-1; tests +2/-2; no allocation file or helper.

Evidence

  • Real isolated source CLI, base 78d3696 versus candidate: only blank-agent JSON stderr changes. Text mode, max-lines JSON/text, valid-agent connection failures, exit codes, and JSON bytes match. No Gateway was started.
  • E2E regression through ocx test: candidate 9 passed; base 1 failed / 8 passed, specifically the missing stderr remedy. This E2E suite automatically prepares compiled subprocess artifacts. Candidate runner wall 450 s (test phase 136.51 s), base 144.72 s; hosted CI time will be recorded by its run.
  • Formatting and focused Oxlint passed. The broader lint wrapper timed out waiting for checkout artifact ownership.
  • Full host-ocx build with declarations and packed tarball integrity/launcher smoke passed before push at 2137efd.
  • Before/after receipts and execution limits.

Original contributor commit retained. PR author: @shuisadev. Commit author: SunnyShu [email protected] (@SunnyShu0925), a different human.

Risk

Two-way door: a revert fully undoes the change. No stored state, migration, configuration, or published API changes. Blast radius is stderr rendering for this one invalid sessions compact --agent input in JSON mode.

@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: XS labels Nov 15, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 15, 2026
@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR makes blank --agent failures print their existing remedy on stderr when sessions compact runs with --json.

Example: Run openclaw sessions compact agent:main:test --agent " " --json.

  • Before: Stderr prints a generic command failure and Doctor hint.
  • After: Stderr prints --agent must not be blank; JSON stdout and exit status 1 remain unchanged.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused repair with real CLI before/after proof, a meaningful consolidated regression, and no correctness findings; the failed PR-context check remains separate from code readiness.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The exact-head receipt exercises the real isolated CLI with a whitespace agent, demonstrates the repaired stderr message and unchanged JSON/exit status, and supplies text-mode and transport controls plus base-red/head-green regression results.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An operator passing a blank agent in JSON mode sees a generic failure instead of the argument error already available to the CLI.
Reason: The existing error classification restores a useful diagnostic without changing accepted inputs, routing, or machine-readable output.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR provides a focused, proven fix for a diagnostic still hidden on current main, with no actionable code findings.

Priority: P3
Reviewed head: 2137efdadde243bf4f95a3bfc16969066233d098

Before merge

None.

Findings

None.

Agent review details

How this fits together

The sessions compact CLI validates arguments before dispatching a Gateway RPC; the shared CLI failure renderer turns rejected arguments into human diagnostics and a JSON error envelope.

flowchart LR
  A[CLI arguments] --> B[Compact registration]
  B --> C[Blank agent validation]
  C --> D[Expected CLI error]
  D --> E[Shared failure renderer]
  E --> F[Stderr remedy and JSON stdout]
  C --> G[Gateway RPC for valid input]
Loading

Technical review

Best possible solution:

Use the existing expected-error helper at the blank-agent guard and retain the consolidated CLI regression.

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

Current-main source explains the hidden stderr remedy, and the supplied isolated CLI comparison demonstrates the exact before/after behavior; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch is the smallest complete repair: classify the known argument error at its producer and let the established renderer handle both output channels.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 669576890a1f.

Provenance checked

  • Blank-agent rejection keeps the original intent (46dcc57: Reject blank selectors caused by empty shell variables before dispatch; verified in merged fix(cli): reject an unconfigured --agent across every operator selector #126983 and its patch.)
  • CLI failure-contract test table keeps the original intent (e3a2d48: Consolidate repeated fixture and assertion plumbing while retaining distinct observable contracts; this change reuses that table and preserves max-lines coverage in registration tests.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 46dcc57 adds src/commands/sessions-compact.ts:77 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 46dcc57c5498; files: src/commands/sessions-compact.ts)

PR surface

Source +1, Tests 0. Total +1 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 2 1 +1
Tests 1 2 2 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 4 3 +1

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P3: This improves diagnostics for an invalid advanced CLI invocation; rejection, JSON output, and exit status already work.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-15T02:40:21.487Z sha 26ad221 :: needs maintainer review before merge. :: none

Reviewed November 14, 2026, 10:23 PM ET / November 15, 2026, 03:23 UTC (Revision 2).

@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Before/after proof for 2137efd against merge base 78d3696. Current main 99157f8 still has the same plain-Error guard.

Host-ocx safety check: the entire PR touches only src/commands/sessions-compact.ts and test/cli-json-stdout.sessions.e2e.test.ts; no package, lockfile, workspace, lifecycle, scripts, patches, or hooks changed. All local execution used ocx on the host in the task worktree or ocx base scratch. No Git hook ran.

The real registration at register.status-health-sessions.ts:501-502 calls sessionsCompactCommand; its blank-agent guard at lines 72-74 runs before the Gateway call at line 94. The error text is unchanged byte for byte.

Source tier: ocx src -- --profile p199386 sessions compact agent:main:test --agent " " --json, once on each arm, using Node + tsx. HOME, OpenClaw home/state/config and profile were isolated under a disposable task directory. No Gateway was started. For the valid-agent controls only, the command explicitly targeted the unused ws://127.0.0.1:29986 endpoint with a synthetic fixture token and a 1000 ms timeout.

                            base stderr                      candidate stderr
blank agent, JSON           [openclaw] The CLI command failed. --agent must not be blank
                            [openclaw] For help, run
                            `openclaw --profile p199386 doctor`.
blank agent, text           --agent must not be blank         identical
--max-lines 0, JSON/text    --max-lines must be a positive     identical
                            integer.
valid --agent main          connection failure                identical

Every invocation exited 1. The blank-agent JSON stdout was byte-identical on both arms:

{"ok":false,"error":{"type":"cli_error","message":"--agent must not be blank"}}

Both valid-agent JSON controls reached the Gateway transport naturally and returned Gateway not reachable at ws://127.0.0.1:29986 (ECONNREFUSED). All control stdout/stderr matched byte for byte after removing ocx's own tier/install diagnostics. The text-mode connection diagnostic was also identical. No faults were injected into these source runs.

Vitest-source command: ocx test test/cli-json-stdout.sessions.e2e.test.ts --maxWorkers=1. Candidate: 9 passed; base with the same regression row: 1 failed / 8 passed. The only failure is the missing blank-agent remedy on stderr at expectFailure(...):56. This E2E file prepares compiled runtime/subprocess artifacts automatically; it is not a purely source-only test despite the ocx tier label. Candidate runner wall time 450 s (test phase 136.51 s); base 144.72 s. The real source CLI proof above is independent of that test fixture.

Simplification: the existing compact canonical-failure row now exercises the blank-agent guard instead of adding a second row. --max-lines 0 remains covered by the registration suite and the before/after source controls. Production +2/-1; tests +2/-2 (net zero); no allocation file or new helper. Formatting and focused Oxlint passed. The broader lint wrapper timed out waiting for dist-artifact checkout ownership; no wrapper-lint success is claimed.

Credit: PR author @shuisadev; original commit author/committer SunnyShu [email protected] (@SunnyShu0925), a different human. The original commit is retained. The test consolidation commit is authored/committed by Ayaan Zaidi [email protected]. Agent: OpenAI coding worker SessionsCompactBlankC; no agent-attribution trailers.

Full tier before push: ocx build --dts completed on the host through ocx at this exact head (283 s, declarations included). Packed tarball inventory, bundled dependencies, and dist import graph checks passed. The extracted package launcher returned OpenClaw 2026.11.3 (2137efd) with exit 0. The smoke uses the package's bundled workspace dependencies and links the already-installed external dependencies; it is not a fresh dependency-install proof.

ocx: build 95a1fc11a76db619 published: 41 output paths, 283s wall
ocx: proof tier: full (dist with declarations)
OpenClaw package tarball integrity passed.
OpenClaw 2026.11.3 (2137efd)

@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 15, 2026
@obviyus
obviyus merged commit d6a7f29 into openclaw:main Nov 15, 2026
134 of 136 checks passed
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Landed in d6a7f29. Thanks @shuisadev.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 15, 2026
… failures (openclaw#199386)

fix(cli): show the blank --agent error for sessions compact --json

`openclaw sessions compact <key> --agent " " --json` threw its blank-agent check as a plain error, so the JSON failure printed only "The CLI command failed." and the doctor hint instead of the existing "--agent must not be blank". It now throws the same message through the existing expected-CLI-error path, as the command's --max-lines and --timeout checks already do. Text mode, exit codes and valid-agent behavior are unchanged. No new text.

Evidence: source tier with isolated state and no Gateway. With --json, base's stderr had only the generic failure and the doctor hint; this change prints the existing message, with JSON bytes and exit code unchanged. Text mode, the --max-lines 0 message and a valid --agent (connection error with no Gateway) are the same on both. The e2e test fails on base (1 failed, 8 passed) and passes here (9 passed); full build and packed launcher pass. Net 0 test lines. Receipts: openclaw#199386 (comment).

Thanks @shuisadev and @SunnyShu0925.

Co-authored-by: SunnyShu <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants