Skip to content

fix(cli): retain command diagnostics in JSON failures - #199970

Merged
obviyus merged 1 commit into
mainfrom
fix/cli-json-root-errors
Nov 16, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/cli-json-root-errors

Conversation

@obviyus

@obviyus obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes actionable command errors disappearing from stderr when commands using the shared runtime run with --json.

User Impact

JSON-mode failures show the diagnostic already shown in text mode, including command-specific prefixes. Existing message wording, redaction, JSON stdout and exit codes are preserved. Startup failures outside the command wrapper are unchanged.

Why This Change Was Made

runCommandWithRuntime now uses its existing text diagnostic path in both modes. A reported-error marker prevents the root renderer from printing a second diagnostic, while JSON formatting unwraps the original error to preserve its envelope and structured recovery/run fields. Existing completed exits and expected errors still pass through unchanged.

The unreachable JSON-only triage callback is removed: calling it after this repair would write a second envelope. Existing per-command expected-error classifications remain because changing their direct consumers, prefixes or debug behavior would not be an equivalent cleanup.

The shared regression replaces the redundant docs-search JSON-envelope e2e case; docs-specific failure wrapping remains covered in docs-cli.test.ts. Nodes and skills subprocess assertions now require the concrete diagnostic, and the maintenance consumer still checks structured recovery fields and redaction.

Supersedes the wrapper-covered closed PRs: #199448 (migrate plan/apply), #199891 (local backup verification), #199900 (remote backup guards), and #199910 (skills list/check/info).

Not covered: #198333 and #198345 fail outside runCommandWithRuntime. They remain closed; this change deliberately does not expose arbitrary root/startup errors.

Evidence

  • Host isolation check: no dependency manifests, lockfiles, lifecycle scripts, hooks or scripts changed; all execution uses ocx, isolated CLI HOME/state, and no live Gateway.
  • vitest-source: 156 tests passed across the shared owner and six consumer suites (564.03 s including cold transforms); all 124 consumer tests also passed on base (289.93 s). The shared regression failed on base as expected (the pre-consolidation variant: 2 failed, 31 passed). Redaction, completed exits and structured recovery fields remain covered.
  • Formatting and targeted lint: all eight changed files pass.
  • full: ocx build --dts passed on 45094a2819a7 (713 s wall).
  • Packed smoke: the canonical self-contained tarball passed integrity checks, then an isolated installation passed all six canonical CLI smoke commands plus the remote-backup JSON failure. The installed failure has the original cli_error envelope, concrete stderr and exit 1.
  • Built CLI consumer e2e: 87 passed; five pre-existing Gateway filesystem postconditions failed identically on built base ef8d709a05a3. All changed nodes/skills checks and all preceding output assertions pass. The five failures are invalid call params (human), contradictory usage options (human), and health config failure (JSON/human/TTY), all at unchanged expectMissing/fs.access in cli-json-stdout.gateway.e2e.test.ts:124. No filesystem expectation was weakened.
  • source: frozen base ef8d709a05a3 and candidate each ran twice: 76 isolated CLI invocations, 150 comparison assertions passed. All failure text-mode streams, JSON stdout bytes and exit codes were unchanged; JSON stderr now equals the text diagnostic exactly. Expected-error output is unchanged, and successful help differs only in the verified source build stamp (unknown in the no-git base copy).
Command/input Base JSON stderr Candidate JSON stderr
backup verify <missing-archive> --json Generic failure + Doctor hint Existing archive verification remedy
backup verify bogus-key --from archive --json Generic failure + Doctor hint Existing backup-key remedy
skills list --agent " " --json Generic failure + Doctor hint --agent must not be blank
skills check --agent " " --json Generic failure + Doctor hint --agent must not be blank
skills info fixture --agent " " --json Generic failure + Doctor hint --agent must not be blank
migrate plan hermes --agent " " --json Generic failure + Doctor hint --agent must not be blank
migrate apply hermes --yes --agent " " --json Generic failure + Doctor hint --agent must not be blank
nodes status --last-connected not-a-duration --json Generic failure + Doctor hint Existing nodes status failed: diagnostic

Redacted source receipts (each command exits 1, before and after):

$ backup verify <isolated-home>/missing.tar.gz --json
base stderr: [openclaw] The CLI command failed.
candidate stderr: Backup archive verification failed: <isolated-home>/missing.tar.gz. Archive does not exist. Check the path and run `openclaw backup verify <archive>` again.

$ backup verify bogus-key --from archive --json
base stderr: [openclaw] The CLI command failed.
candidate stderr: Expected a backup key from `openclaw backup list --from <location>` or latest.

Production delta: +51/-26 lines. Test delta: +29/-45 lines (net -16); no test allocations or dependency changes.

An additional candidate backup snapshot lease integration hit its child-process deadlock guard; its standalone baseline case passed. This unresolved integration result is not counted in the passing suites. No snapshot/lease implementation changed.

Two-way door: reverting restores the prior JSON stderr behavior. The blast radius is failures from commands using the shared runtime; no configuration or stored-data changes.

@clawsweeper

clawsweeper Bot commented Nov 16, 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 cli CLI command changes size: S labels Nov 16, 2026
@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 16, 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. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The shared command wrapper preserves existing stderr diagnostics in JSON mode while retaining the original JSON failure envelope.

Example: Run openclaw backup verify bogus-key --from archive --json.

  • Before: Stderr shows a generic failure and Doctor hint.
  • After: Stderr says to choose a backup key from openclaw backup list --from &lt;location> or use latest; JSON stdout and exit 1 remain unchanged.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused shared-owner repair with relevant CLI proof, preserved machine metadata, and no actionable findings; hosted checks are still running.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Supplied isolated CLI before-and-after output exercises the changed wrapper through backup failures, with concrete stderr remedies and preserved JSON and exit status; installed-package smoke and additional skills, migration, and nodes comparisons support the same boundary.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Operators reading stderr from JSON-mode commands receive generic failure guidance instead of the command's existing actionable diagnostic.
Reason: The maintainer-authored direction consolidates demonstrated failures at their shared boundary while retaining startup policy, validation, and machine output.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR fixes a current shared CLI diagnostic defect, and no actionable correctness or security finding was identified.

Priority: P2
Reviewed head: 45094a2819a7a7490e3b2c389ed6e68d9cf3061b

Before merge

None.

Findings

None.

Agent review details

How this fits together

CLI commands pass failures through the shared runtime wrapper; command diagnostics go to stderr, while the executable boundary formats JSON stdout and sets the failure exit status.

flowchart TD
  A[CLI command] --> B[Shared runtime wrapper]
  B --> C[Existing stderr diagnostic]
  B --> D[Reported error carrying original cause]
  D --> E[Root failure renderer]
  E --> F[Original JSON envelope]
  E --> G[Failure exit status]
Loading

Technical review

Best possible solution:

Keep command diagnostics in the shared wrapper and preserve JSON formatting at the executable boundary, as this PR does.

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

Current-main source shows that JSON failures bypass the existing diagnostic path, and supplied before-and-after CLI captures demonstrate the result; this read-only review executed no target code.

Is this the best way to solve the issue?

The required invariant is one command diagnostic on stderr with the original machine envelope intact; the existing wrapper and renderer satisfy it without per-command conversions or another output owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 79f3c17faaf8.

Provenance checked

  • JSON-mode command-wrapper rethrow changes intended behavior with a stated reason (6c66f48: Centralize JSON failure envelopes at the executable boundary instead of rendering them independently in commands.)
  • Concise root failure presentation changes intended behavior with a stated reason (d0b48d6: Lead with short explanations and recovery guidance while keeping diagnostics available on demand; this PR explicitly distinguishes command diagnostics from startup failures.)
  • Operator-safe cause formatting keeps the original intent (9cbf998: Keep nested causes behind debug intent in the shared operator formatter.)
  • Completed-command exit propagation keeps the original intent (c95e348: Preserve completed reports and typed exit outcomes through the cleanup and output-drain owner.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 6c66f48 adds src/cli/failure-output.ts:24 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 6c66f48a7c11; files: src/cli/failure-output.ts)
  • Vincent Koc: Raw commit ebd59f1 adds src/cli/failure-output.ts:37 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ebd59f1e01da; files: src/cli/failure-output.ts)

PR surface

Source +25, Tests -16. Total +9 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 51 26 +25
Tests 5 29 45 -16
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 80 71 +9

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.

Root-cause cluster

Relationship: canonical
Canonical: #199970
Summary: This PR owns the shared-wrapper repair that replaces four closed per-command diagnostic fixes.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add P2: A bounded CLI diagnostic defect obscures existing remedies on stderr while JSON stdout and failure status remain usable.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: A bounded CLI diagnostic defect obscures existing remedies on stderr while JSON stdout and failure status remain usable.
  • 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.

Reviewed November 15, 2026, 11:57 PM ET / November 16, 2026, 04:57 UTC.

@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: both validation failures on 45094a2819a7a7490e3b2c389ed6e68d9cf3061b reproduce on the CI merge's exact main parent.

The tested merge is 404be958c557afeeee5a3b0d234cd35926665bb2, whose first parent is main 79f3c17faaf8343ee28bf0d9d71b27fc227486cb. I obtained that exact parent with ocx base 79f3c17faaf8343ee28bf0d9d71b27fc227486cb --no-fetch and left its source and tests unmodified.

Node shard

PR failure: checks-node-changed-2.

On the parent, I replayed scripts/ci-run-node-test-shard.mts through ocx run --heavy, with the same bun-all runtime policy, prebuilt dist, and the exact ordered target list:

["test/cli-json-stdout.skills.e2e.test.ts","test/cli-json-stdout.gateway.e2e.test.ts"]

Host replay used the pinned OpenClaw Bun fork, one admitted plan and two maximum workers. Both planned invocations completed. Skills: 21 passed. Gateway: 24 passed, the identical 5 failed:

  • invalid call params, human mode;
  • contradictory usage options, human mode;
  • health config failure, JSON mode, human mode and dual TTYs.

All five fail at the final unchanged filesystem postcondition, not an old message assertion. Parent and PR have the same case names and stack:

AssertionError: promise resolved "undefined" instead of rejecting
expectMissing test/cli-json-stdout-contract.test-support.ts:37:35
test/cli-json-stdout.gateway.e2e.test.ts:124:11

All preceding output assertions pass. No filesystem expectation was weakened.

Lint stripe

PR failure: check-lint-core-2.

On that same parent, the focused replay used in the earlier maintainer receipts also exits 1:

ocx run --heavy -- node scripts/run-oxlint.mjs --openclaw-focused-config src/agents/tool-search-prepared-catalog.ts
src/agents/tool-search-prepared-catalog.ts:118:48: error: Use `structuredClone(…)` to create a deep clone. (unicorn(prefer-structured-clone))

This PR does not change the failing agent source or lint rules. All other selected PR checks passed; 0 jobs were cancelled. The aggregate CI gate and gate status are red because of these inherited failures. No GitHub jobs were rerun and no unrelated code was changed.

Exact-head hosted review is ready, 5/6, with no findings or before-merge items. The full declarations build, installed-tarball smoke and before/after CLI proof remain unchanged.

@obviyus
obviyus merged commit 25c9790 into main Nov 16, 2026
138 of 142 checks passed
@obviyus
obviyus deleted the fix/cli-json-root-errors branch November 16, 2026 05:26
@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 25c9790.

fuller-stack-dev added a commit that referenced this pull request Nov 16, 2026
…00199)

#199970 made commands that run through the shared wrapper report their
diagnostic in --json mode as they do in text mode. The in-process nodes push
case still asserted that JSON mode writes nothing to stderr and never exits,
so it has failed on main since 25c9790 and fails the changed-files check
of any PR whose lanes select it.

The JSON case now requires the diagnostic exactly once, the exit, an empty
stdout and no Gateway call, and that the error reaching the JSON failure
owner still carries the original message. The runtime mock throws the same
ExitError the real runtime throws, because that is the exit the wrapper
converts for JSON output.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
fix(cli): show the existing failure message for plain errors in --json mode

`runCommandWithRuntime` rethrew every plain error in JSON mode, so the root renderer printed only the generic "The CLI command failed." plus the Doctor hint on stderr, while text mode printed the error's own (redacted) message. Contributors had been patching this one command at a time by converting individual throws to expected errors. JSON mode now shows the same redacted message text mode already shows, once in the shared wrapper; the JSON stdout envelope, exit codes and text-mode output are unchanged. Commands that fail outside the wrapper (for example `models auth login` conflicts and `attach` target resolution) are not covered. No new text.

Evidence: host, isolated state. 76 CLI runs across eight command flows (including `backup verify`, `backup remote`, `skills list/check/info` and `migrate plan/apply`), twice per side: base prints the generic failure in --json mode, this change prints the existing message; text failure output, JSON stdout and exit codes are identical across 150 comparisons. 156 unit and 124 consumer tests pass; full build and installed packed smoke pass. CI reds are inherited from main (receipt: openclaw#199970 (comment)).

Supersedes the closed per-command PRs openclaw#199891, openclaw#199900, openclaw#199910 and openclaw#199448.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…enclaw#200199)

openclaw#199970 made commands that run through the shared wrapper report their
diagnostic in --json mode as they do in text mode. The in-process nodes push
case still asserted that JSON mode writes nothing to stderr and never exits,
so it has failed on main since 3411f31 and fails the changed-files check
of any PR whose lanes select it.

The JSON case now requires the diagnostic exactly once, the exit, an empty
stdout and no Gateway call, and that the error reaching the JSON failure
owner still carries the original message. The runtime mock throws the same
ExitError the real runtime throws, because that is the exit the wrapper
converts for JSON output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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.

1 participant