Repository navigation
fix(cli): retain command diagnostics in JSON failures - #199970
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesThe shared command wrapper preserves existing stderr diagnostics in JSON mode while retaining the original JSON failure envelope. Example: Run
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherCLI 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]
Technical reviewBest 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
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +25, Tests -16. Total +9 across 8 files. Added test files: 0. View PR surface stats
Preflight sourceSource 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 clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 15, 2026, 11:57 PM ET / November 16, 2026, 04:57 UTC. |
|
Maintainer override: both validation failures on The tested merge is Node shardPR failure: checks-node-changed-2. On the parent, I replayed ["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:
All five fail at the final unchanged filesystem postcondition, not an old message assertion. Parent and PR have the same case names and stack: All preceding output assertions pass. No filesystem expectation was weakened. Lint stripePR failure: check-lint-core-2. On that same parent, the focused replay used in the earlier maintainer receipts also exits 1: 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 |
|
Landed in 25c9790. |
…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.
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]>
…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.
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
runCommandWithRuntimenow 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
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.full:ocx build --dtspassed on45094a2819a7(713 s wall).cli_errorenvelope, concrete stderr and exit 1.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 unchangedexpectMissing/fs.accessincli-json-stdout.gateway.e2e.test.ts:124. No filesystem expectation was weakened.source: frozen baseef8d709a05a3and 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 (unknownin the no-git base copy).backup verify <missing-archive> --jsonbackup verify bogus-key --from archive --jsonskills list --agent " " --json--agent must not be blankskills check --agent " " --json--agent must not be blankskills info fixture --agent " " --json--agent must not be blankmigrate plan hermes --agent " " --json--agent must not be blankmigrate apply hermes --yes --agent " " --json--agent must not be blanknodes status --last-connected not-a-duration --jsonnodes status failed:diagnosticRedacted source receipts (each command exits 1, before and after):
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.