Skip to content

fix(cli): show why a command failed when the config cannot be read - #196816

Merged
obviyus merged 3 commits into
openclaw:mainfrom
masatohoshino:fix/cli-config-read-failure-reason
Nov 10, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
masatohoshino:fix/cli-config-read-failure-reason

Conversation

@masatohoshino

Copy link
Copy Markdown
Contributor

Closes #196815

What Problem This Solves

Fixes: when the config file cannot be read, commands such as openclaw status say only "The CLI command failed." and send the user to openclaw doctor, which fails the same way, instead of naming the file that could not be read.

User Impact

User impact: a user with an unreadable config now sees why the command failed:

[openclaw] The CLI command failed.
[openclaw] Reason: Config could not be read at /home/user/.openclaw/openclaw.json:
- <root>: Failed to read include file: missing.json (resolved: /home/user/.openclaw/missing.json)

The circular "run openclaw doctor" line is no longer printed for this failure, since Doctor cannot read the file either.

Why This Change Was Made

Before a command runs, the CLI reads the config to choose the storage engine. When that read fails, the error is thrown without being printed, and the root failure output only showed a reason for invalid configs and a few named commands, so the read error was dropped. The root failure output now treats a config read failure the way it already treats state-database refusals: it prints the title and the redacted reason, without the Doctor line. #158671 separated read failures from invalid configs and removed Doctor advice for them on the paths it touched; this is the root path it did not reach.

Behavior to know:

  • Only errors with code CONFIG_READ_FAILED change. Invalid configs, state-database refusals and every other failure keep their current output.
  • The reason goes through the same redaction as other reasons; nested causes and stacks stay behind OPENCLAW_DEBUG=1.
  • --json failure output is unchanged.
  • openclaw config validate, setup and bare openclaw are not changed here; fix(cli): diagnose unreadable configuration in validation and setup #166573 (open) owns their read-failure wording, and this change does not touch its files.

Docs: docs/cli/index.md gains one line under failure output.

Evidence

Tested at c8eae97 (baseline 080ed32).

Before/After at the CLI boundary: a before/after harness built both sides from source and ran the same steps in fresh isolated homes. Each side wrote a config whose only content is {"$include":"missing.json"} and then ran openclaw status, openclaw agents list and openclaw doctor --non-interactive. All three exit 1 on both sides; stdout is identical. Stderr, with the per-side home path normalized:

 [openclaw] The CLI command failed.
-[openclaw] For help, run `openclaw doctor`.
+[openclaw] Reason: Config could not be read at <openclaw-home>/.openclaw/openclaw.json:
+- <root>: Failed to read include file: missing.json (resolved: <openclaw-home>/.openclaw/missing.json)

The same difference appears for all three commands. The expectation "stderr names the read error" is not met before and is met after for each of them.

Regression test: a createConfigReadError row in the existing "keeps actionable refusal details without leaking diagnostics" table of src/cli/failure-output.test.ts. It expects the read error as the reason, no Doctor line, and no leaked token, nested cause or stack. It fails on the baseline (the reason line is missing) and passes at the head; the other 20 tests in the file pass on both.

Checks at the head:

  • pnpm test src/cli/failure-output.test.ts --maxWorkers=1: 21 passed.
  • Typecheck of test/tsconfig/tsconfig.core.test.config-cli.json: clean.
  • oxfmt: clean. scripts/check-test-lines-ratchet.mts: Test lines OK.
  • oxlint did not run locally (the local install lacked a lint plugin dependency); CI runs it.

Local review: autoreview (Codex gpt-6.1-sol, medium), base 080ed32 to head c8eae97, priority P0–P1: scoped-clean, no remaining findings.

Simplification pass: the smallest complete fix is one branch at the existing root failure printer, which already decides which reasons are shown. Fixing it at the throw site would print the error twice. Against the merge base, production code is +5/−1 (a four-line branch and the import), test code +6/−1 (one table row and the import), and docs +1. Nothing was removed because no duplicate path exists.

Test file Added cost
src/cli/failure-output.test.ts one row in an existing it.each table; pnpm test src/cli/failure-output.test.ts --maxWorkers=1: 57.5 s wall locally, almost all of it worker startup; the new row adds no measurable CI seconds

Not covered:

  • Unreadable files for other reasons (permissions, a failed SQLite snapshot read) go through the same CONFIG_READ_FAILED error, but only the missing include was run end to end.
  • openclaw models list and other commands that select the storage engine take the same path but were not run end to end.
  • Commands that read the config themselves after engine selection (config validate, setup, bare openclaw) keep their own output; see fix(cli): diagnose unreadable configuration in validation and setup #166573.

@clawsweeper

clawsweeper Bot commented Nov 10, 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 docs Improvements or additions to documentation cli CLI command changes size: XS labels Nov 10, 2026
@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 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The CLI displays configuration read failures without sending users back to Doctor.

Example: Run openclaw status with {"$include":"missing.json"} and no missing.json file.

  • Before: The command prints a generic failure and suggests Doctor, which fails the same way.
  • After: The command names the unreadable configuration and missing include, without the Doctor hint.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, useful repair with shipped-CLI evidence, a meaningful regression row, and no open findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The body records built-CLI before/after output for status, agents list, and non-interactive Doctor with a missing include; obviyus additionally verifies the exact reviewed head in secretless Docker on Node 24.22.1, including unchanged JSON and unrelated-failure controls. Expired media from the earlier related PR returned HTTP 403 and is not needed for this proof.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Commands hide the configuration read error and suggest Doctor, which encounters the same failure.
Reason: The change restores actionable diagnostics through the existing owner while preserving unrelated output and recovery contracts.

Merge readiness

✅ Ready for maintainer review

This PR fixes a distinct current-main diagnostic gap with a focused change; no actionable defects were found.

Priority: P2
Reviewed head: 455f04165f13ce50be6d4360df1487bb65a1d7ad

Before merge

None.

Findings

None.

Agent review details

How this fits together

CLI startup reads configuration before selecting storage; tagged read errors reach the shared root failure renderer, which produces redacted stderr diagnostics.

flowchart LR
  A[CLI command] --> B[Configuration snapshot]
  B --> C[Engine selection]
  C --> D[Tagged read error]
  D --> E[Root failure renderer]
  E --> F[Redacted stderr]
Loading

Technical review

Best possible solution:

Merge the focused shared-renderer repair once the existing required checks pass.

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

The source traces a missing include through CONFIG_READ_FAILED into the generic main-branch renderer, and supplied built-CLI before/after output confirms the failure; no target code was executed during this review.

Is this the best way to solve the issue?

The existing root renderer owns diagnostic visibility, so recognizing the established error code there is the smallest complete fix and avoids duplicate printing at throw sites.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Concise root CLI failure output keeps the original intent (d0b48d6: Keep ordinary failures concise while preserving actionable recovery guidance and debug-only diagnostic detail.)
  • Visible actionable refusal reasons keeps the original intent (656c851: Show state-access refusal reasons without loading heavy runtime owners or exposing nested diagnostics.)
  • Consolidated renderer regression tests keeps the original intent (eaf1aba: Remove duplicate proof layers while retaining owning-boundary assertions; this PR extends an existing table without adding scaffolding.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 688f68e adds src/cli/failure-output.ts:247 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 688f68e7779c; files: src/cli/failure-output.ts)
  • Eric Cai: Raw commit 656c851 adds src/cli/failure-output.ts:287 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 656c851b2463; files: src/cli/failure-output.ts)
  • Masato Hoshino: Raw commit e20d4f7 adds src/cli/failure-output.ts:298 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: e20d4f7562e7; files: src/cli/failure-output.ts)

PR surface

Source +4, Tests -1, Docs +1. Total +4 across 3 files. Added test files: 0.

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

Preflight source

Source stale. 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:

No label changes.

Label justifications:

  • P2: A configuration read failure hides the actionable cause across CLI commands; the repair has limited scope and preserves command outcomes.
  • 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-10T19:24:25.739Z sha c8eae97 :: needs maintainer review before merge. :: none

Reviewed November 10, 2026, 2:58 PM ET / 19:58 UTC (Revision 2).

@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Proof at 455f041 (merged current main), built CLI on node:24.22.1 in a secretless Docker container, config { "$include": "./missing.json" }:

  • main 0c5c475: openclaw status and openclaw doctor both print only "The CLI command failed." plus "For help, run openclaw doctor.", exit 1.
  • this PR: both print "Reason: Config could not be read at .../openclaw.json: - : Failed to read include file: ./missing.json (resolved: ...)" with no doctor hint, exit 1. The reason text is the existing createConfigReadError message.
  • status --json: same JSON envelope on both; exit 1.
  • Control, unrelated failure (agent sqlite filled with random bytes, openclaw sessions): generic line and doctor hint on both, exit 1.
  • Control, valid config: status and status --json identical on both, exit 0.

Also folded the new test case into one row so test lines are net -1.

@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 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. 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 10, 2026
@obviyus
obviyus merged commit 9d5de42 into openclaw:main Nov 10, 2026
120 checks passed
@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Landed in 9d5de42. Thanks @masatohoshino. Unreadable configs now show the real reason.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 11, 2026
…penclaw#196816)

fix(cli): show why a command failed when the config cannot be read

When the config file could not be read, for example because an included file is missing, commands such as openclaw status printed only "The CLI command failed." and pointed to openclaw doctor, which failed the same way. For this case the CLI now prints the existing config-read reason from createConfigReadError and drops the Doctor hint. Other unexpected errors keep the generic line and the hint, and no wording is new.

Evidence: the built CLI on node:24.22.1 in Docker with a config containing an include of a missing file. On main, status and doctor --non-interactive printed only the generic failure line and the Doctor hint, exit 1. With this change both print "Reason: Config could not be read at .../openclaw.json: - <root>: Failed to read include file: ./missing.json (resolved: ...)" with no Doctor hint, exit 1. status --json gives the same JSON on both, an unrelated failure still prints the generic line and the hint on both, and a valid config behaves the same on both. Details: openclaw#196816 (comment).

Closes openclaw#196815. Thanks @masatohoshino.

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

cli CLI command changes docs Improvements or additions to documentation 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: 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.

CLI commands print only "The CLI command failed." when the config file cannot be read

2 participants