feat(config): add openclaw config validate and improve startup error messages#31220
Conversation
Greptile SummaryThis PR adds a Key Changes:
Minor Suggestion:
Confidence Score: 4/5
Last reviewed commit: 88c8737 |
src/cli/config-cli.ts
Outdated
| const configPath = CONFIG_PATH ?? "openclaw.json"; | ||
| const shortPath = shortenHomePath(configPath); |
There was a problem hiding this comment.
Consider using snapshot.path instead of CONFIG_PATH for display accuracy. CONFIG_PATH is resolved at module load time, while readConfigFileSnapshot() resolves the path at runtime. If config candidates change or env vars are modified between module load and runtime, the displayed path might not match the actual file being validated. Replace configPath with snapshot.path in outputs (lines 338, 353, 369) and use shortenHomePath(snapshot.path) for lines 340, 355, 371.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/config-cli.ts
Line: 330-331
Comment:
Consider using `snapshot.path` instead of `CONFIG_PATH` for display accuracy. `CONFIG_PATH` is resolved at module load time, while `readConfigFileSnapshot()` resolves the path at runtime. If config candidates change or env vars are modified between module load and runtime, the displayed path might not match the actual file being validated. Replace `configPath` with `snapshot.path` in outputs (lines 338, 353, 369) and use `shortenHomePath(snapshot.path)` for lines 340, 355, 371.
How can I resolve this? If you propose a fix, please make it concise.88c8737 to
dafee15
Compare
dafee15 to
4dc4103
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4dc41036a0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
src/cli/config-cli.ts
Outdated
| const configPath = CONFIG_PATH ?? "openclaw.json"; | ||
| const shortPath = shortenHomePath(configPath); |
There was a problem hiding this comment.
Use snapshot path for validate output
runConfigValidate reports path and human-readable location from the module-level CONFIG_PATH, but the file actually validated comes from readConfigFileSnapshot() and can differ from that constant (for example when candidate resolution selects another existing config path). In those cases config validate will claim it validated one file while reading another, which can mislead operators and break automation that relies on the emitted path; use snapshot.path for all output/error path fields instead.
Useful? React with 👍 / 👎.
…r messages Add a `config validate` CLI subcommand that checks the current config against the Zod schema without starting the gateway. Supports `--json` for machine-readable output so agents and scripts can validate after external file edits. Also improve the error thrown by `loadConfig` to include the specific offending key paths in the Error message itself, not just as a side property — making crash logs immediately actionable. Closes openclaw#31148 Made-with: Cursor
9eb472d to
4598f2a
Compare
…r messages (openclaw#31220) Merged via squash. Prepared head SHA: 4598f2a Co-authored-by: Sid-Qin <201593046+Sid-Qin@users.noreply.github.com> Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com> Reviewed-by: @gumadeiras
…r messages (openclaw#31220) Merged via squash. Prepared head SHA: 4598f2a Co-authored-by: Sid-Qin <201593046+Sid-Qin@users.noreply.github.com> Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com> Reviewed-by: @gumadeiras
…r messages (openclaw#31220) Merged via squash. Prepared head SHA: 4598f2a Co-authored-by: Sid-Qin <201593046+Sid-Qin@users.noreply.github.com> Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com> Reviewed-by: @gumadeiras
…r messages (openclaw#31220) Merged via squash. Prepared head SHA: 4598f2a Co-authored-by: Sid-Qin <201593046+Sid-Qin@users.noreply.github.com> Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com> Reviewed-by: @gumadeiras
…r messages (openclaw#31220) Merged via squash. Prepared head SHA: 4598f2a Co-authored-by: Sid-Qin <201593046+Sid-Qin@users.noreply.github.com> Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com> Reviewed-by: @gumadeiras
…r messages (openclaw#31220) Merged via squash. Prepared head SHA: 4598f2a Co-authored-by: Sid-Qin <201593046+Sid-Qin@users.noreply.github.com> Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com> Reviewed-by: @gumadeiras
…r messages (openclaw#31220) Merged via squash. Prepared head SHA: 4598f2a Co-authored-by: Sid-Qin <201593046+Sid-Qin@users.noreply.github.com> Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com> Reviewed-by: @gumadeiras
…r messages (openclaw#31220) Merged via squash. Prepared head SHA: 4598f2a Co-authored-by: Sid-Qin <201593046+Sid-Qin@users.noreply.github.com> Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com> Reviewed-by: @gumadeiras (cherry picked from commit 3002f13)
Summary
openclaw.json(by agents,jq, text editors) sit undetected until the next gateway restart, causing crash loops. The startup error says "Invalid config" without identifying which key is invalid.openclaw config validateCLI command for pre-flight config validation without starting the gateway. Supports--jsonfor machine-readable output. (2) Improved theloadConfigerror to include specific key paths in the Error message itself.writeConfigFilevalidation (which already works forconfig set/config patchpaths) is untouched. No changes to Zod schema strictness —.strict()was already applied to all objects.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
openclaw config validate— validates the current config against the active Zod schema, reports all offending key paths, and exits with code 0 (valid) or 1 (invalid).--jsonflag:openclaw config validate --jsonoutputs{ "valid": true/false, "path": "...", "issues": [...] }for machine consumption. Agents can call this after writing config to detect errors before restart.loadConfig()now throws with the full validation details in the Error message (e.g."Invalid config at ~/.openclaw/openclaw.json:\n- agents.defaults.suppressToolErrorWarnings: Unrecognized key(s)"), making crash logs immediately actionable without searching separate log lines.Security Impact (required)
NoNoNoNo— read-only validation, no config modificationNoRepro + Verification
Environment
openclaw.jsonSteps
openclaw.json:{ "agents": { "defaults": { "suppressToolErrorWarnings": true } } }openclaw config validateExpected
openclaw config validateexits with code 1 and prints:× agents.defaults.suppressToolErrorWarnings: Unrecognized key(s) in objectActual
validatesubcommand exists. Startup error says "Invalid config" without the key path.config validatecatches the issue immediately. Startup error includes the key path.Evidence
Verified
runConfigValidatewith valid config (exit 0, "Config valid") and with invalid keys (exit 1, per-key error output). Verified--jsonmode produces parseable JSON.Human Verification (required)
--jsonflag produces correct JSON structure.<root>path fallback for top-level errors.Compatibility / Migration
Yes— additive CLI subcommand, no existing behavior changed.NoNoFailure Recovery (if this breaks)
validatesubcommand is entirely additive. Removing it has no effect on gateway startup or config handling.src/cli/config-cli.ts— removerunConfigValidateand thevalidatesubcommand registration.Risks and Mitigations
CONFIG_PATHcould resolve toundefinedif called before config initialization."openclaw.json"literal. ThereadConfigFileSnapshot()call itself handles path resolution independently.