Skip to content

fix(cli): preserve automation error guidance in JSON mode - #142113

Merged
obviyus merged 4 commits into
openclaw:mainfrom
DasX:fix/cron-cli-expected-error-framing
Sep 8, 2026
Merged

obviyus merged 4 commits into
openclaw:mainfrom
DasX:fix/cron-cli-expected-error-framing

Conversation

@DasX

@DasX DasX commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Closes #142110

What Problem This Solves

Fixes an issue where automation commands in machine-output mode frame ordinary operator errors, such as a missing automation ID or invalid option value, as generic CLI failures with Doctor and debug hints.

Why This Change Was Made

Known automation input and domain failures now use the existing expected-error renderer. Their producers identify them explicitly, so unexpected runtime and programming failures keep their original diagnostics. The shared renderer, JSON envelope, exit status, Gateway requests, and human-mode output remain unchanged.

The contributor's first correction restored JSON cause gating. Further verification found that machine stderr still exposed nested causes and that internal runtime failures lost their debug stacks. Both are corrected: machine stdout and stderr use the canonical debug policy, while unexpected exceptions retain their original identity. Malformed cron-run wait durations also use the expected-input path; unrelated shared parsing and protocol-validation failures retain their existing policy.

User Impact

Missing automation IDs and invalid automation options produce direct guidance with exit1 and one canonical JSON document. Nested causes remain hidden in machine mode unless OPENCLAW_DEBUG is enabled. Human-mode diagnostics keep their existing full redacted message. Automation commands do not add --debug or --verbose options.

Evidence

  • Real source CLI and Gateway, with fresh isolated automation stores, reproduced generic command-failure stderr on pinned main 21ad735be2f4. The corrected integration prints only direct missing-ID guidance, preserving the same JSON and exit status.
  • The supported older-Gateway compatibility fixture proves wrapped causes remain hidden in both machine streams by default and appear with OPENCLAW_DEBUG=1.
  • Controlled missing-runtime-module cases preserve command/startup framing and debug stacks for genuine installation failures. Modules are restored after each control.
  • 599 focused tests passed: 521 cron-owner tests, 36 fast/renderer tests, and 42 CLI process tests. Three added regression checks failed on the original contributor implementation before correction.
  • Independent behavior validation executed 85 commands across the candidate, baseline, and two affected follow-up checks, including typed Gateway rejections, human/JSON output, parse and transport errors, debug policy, disabled automation creation and stored readback. All 66 JSON-producing results contained one document; every subprocess ended without a signal.
  • Formatting, lint, the normal pre-commit hook, and git diff --check passed. Fresh Autoreview found no actionable P0–P2 findings. After a required main merge, all six affected process cases passed with the upstream credential tests retained. Two duration regressions and 22 related run-command tests also passed. Fresh review of the final candidate found no actionable findings. Full CI and typechecking run on GitHub.
Missing automation in JSON mode Result
Before Generic CLI failure title, Reason, debug, Doctor and Help hints
After Automation not found: missing-job. Run openclaw cron list to see recent automation ids.

The old-Gateway control is a protocol fixture, not a historical Gateway binary. Source provenance and final physical cleanup are tracked separately from the independent behavioral observations. AI-assisted.

handleCronCliError now hands JSON-mode failures to the root renderer as
an ExpectedCliError with human and machine output, so stderr carries the
operator message instead of the "Could not start the CLI." title with
the Doctor and debug hints. Human-mode rendering, the JSON envelope, and
the exit code are unchanged.

Closes openclaw#142110
@clawsweeper

clawsweeper Bot commented Sep 8, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-08T10:27:05.755211Z dedc707 PR opened
🔒 Security Review ✅ Completed 2026-09-08T10:29:18.924789Z dedc707 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper

clawsweeper Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 8, 2026, 9:58 AM ET / 13:58 UTC.

ClawSweeper review

What this changes

The automation CLI identifies expected input and Gateway errors so JSON-mode failures show direct operator guidance while preserving debug-gated causes and unexpected-error diagnostics.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary: current main and v2026.9.2 retain the misleading error framing. The earlier cause-gating finding is resolved, GitHub reports the head mergeable, and no actionable correctness defect remains.

Priority: P2
Reviewed head: 550f8b4360cf11a65224cda820efa9dd9b926e89

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with relevant real CLI observations, meaningful regressions, and no remaining actionable finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied body reports real source CLI/Gateway runs through the changed automation error handler, showing direct missing-job guidance with unchanged JSON and exit status, plus debug and unexpected-runtime controls; the protocol fixture and unit tests are supplemental.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied body reports real source CLI/Gateway runs through the changed automation error handler, showing direct missing-job guidance with unchanged JSON and exit status, plus debug and unexpected-runtime controls; the protocol fixture and unit tests are supplemental.
Evidence reviewed 8 items Current main still needs the repair: The fetched main handler rethrows a plain Error for typed lookup misses in JSON mode, leaving the root renderer to add generic failure framing.
Latest release retains the same behavior: GitHub’s v2026.9.2 source contains the same plain-error machine-mode rethrow. The local release blob was unavailable; the read-only contents API supplied the source.
Expected failures and unexpected exceptions remain distinct: The reviewed handler preserves ExitError and existing expected errors, formats recognized cron/Gateway failures through formatCliOperatorError, and rethrows unexpected exceptions unchanged. Both machine-mode streams receive the same gated message.
Findings None None.
Security None None.

How this fits together

OpenClaw’s automation CLI validates command input and sends requests to the Gateway scheduler. Its error handler passes failures to the shared CLI renderer, which produces stderr guidance and machine-readable JSON.

flowchart TD
  A[Automation command input] --> B[Input validation]
  B --> C[Gateway request]
  B --> D[Automation error handler]
  C --> D
  D --> E{Expected operator error?}
  E -->|Yes| F[Direct guidance and JSON]
  E -->|No| G[Runtime failure diagnostics]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +100, Tests +264. Total +364 across 14 files.

View PR surface stats
Area Files Added Removed Net
Source 10 245 145 +100
Tests 4 290 26 +264
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 535 171 +364

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +100 lines; tests and test support net +264 lines Production growth supports explicit error classification and diagnostic preservation, with regression coverage for rendering and process behavior.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #142110
Summary: This PR is the open implementation candidate for the linked automation diagnostic defect; related renderer work does not supersede it.

Members:

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

Technical review

Best possible solution:

Keep automation error classification at its producers and use the existing shared renderer without changing output envelopes, exit codes, or unexpected-failure diagnostics.

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

Yes: a missing automation queried with cron show missing-job --json reaches the plain-error rethrow on current main. Source inspection and the supplied before/after CLI observations establish the path; this review did not execute it.

Is this the best way to solve the issue?

Yes: producer-owned classification reuses the established expected-error renderer and preserves genuine runtime diagnostics, avoiding a blanket conversion of all failures.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: Misleading automation diagnostics are a bounded usability defect; JSON output and exit status already remain usable.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied body reports real source CLI/Gateway runs through the changed automation error handler, showing direct missing-job guidance with unchanged JSON and exit status, plus debug and unexpected-runtime controls; the protocol fixture and unit tests are supplemental.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied body reports real source CLI/Gateway runs through the changed automation error handler, showing direct missing-job guidance with unchanged JSON and exit status, plus debug and unexpected-runtime controls; the protocol fixture and unit tests are supplemental.

Evidence

What I checked:

  • Current main still needs the repair: The fetched main handler rethrows a plain Error for typed lookup misses in JSON mode, leaving the root renderer to add generic failure framing. (src/cli/cron-cli/shared.ts:231, a39239faf938)
  • Latest release retains the same behavior: GitHub’s v2026.9.2 source contains the same plain-error machine-mode rethrow. The local release blob was unavailable; the read-only contents API supplied the source. (src/cli/cron-cli/shared.ts, 3928bad9badf)
  • Expected failures and unexpected exceptions remain distinct: The reviewed handler preserves ExitError and existing expected errors, formats recognized cron/Gateway failures through formatCliOperatorError, and rethrows unexpected exceptions unchanged. Both machine-mode streams receive the same gated message. (src/cli/cron-cli/shared.ts:237, 550f8b4360cf)
  • Regression coverage preserves the prior correction: The error tests check hidden versus explicitly enabled causes in both streams and retained unexpected-error identity and stacks. Process cases exercise missing-job guidance in human/JSON modes and invalid wait durations before Gateway access. Tests were inspected, not executed during this read-only review. (src/cli/cron-cli/shared.errors.test.ts:79, 550f8b4360cf)
  • Reported real behavior matches the changed boundary: The supplied complete PR body reports source CLI/Gateway runs with isolated stores and gives before/after missing-job stderr: generic failure hints become direct lookup guidance, with unchanged JSON and exit status. It also reports debug controls, unexpected installation-failure controls, and post-integration validation. The older-Gateway case is explicitly a protocol fixture. Captured context sourceRevision: 56ea5efe0044603306e30b3584a09635eccbdda903e32d6bd3cbb357c089674c.
  • Existing renderer precedent and routing history: Merged fix(cli): report plugin policy refusals as expected conditions #125304 established ExpectedCliError for expected conditions. The commit API identifies steipete and shows the carrier rename. Local history also shows repeated related CLI/cron maintenance by Peter Steinberger; local line-blame inspection was limited by unavailable historical blobs. (src/cli/failure-output.ts:45, 8dfbaa6087aa)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-08T10:29:07.077Z sha dedc707 :: needs changes before merge. :: [P2] Preserve debug-gated causes in machine error messages
  • reviewed 2026-09-08T11:47:04.792Z sha 2961e7b :: needs maintainer review before merge. :: none
  • reviewed 2026-09-08T13:35:13.230Z sha aebd181 :: blocked before merge. :: none

The first revision handed the expanded formatErrorMessage result to the
root renderer as machineOutput, so a wrapped cron failure such as
readCronJobForEdit's "unknown automation id" leaked its "unknown method:
cron.get" cause into ordinary JSON. Machine output now goes through
formatCliOperatorError, which keeps the renderer's existing gate, so
causes stay behind --debug and OPENCLAW_DEBUG. The typed lookup-miss
message is unchanged, and human-facing output still carries the full
producer message as human mode does.

Co-Authored-By: Claude Opus 5 <[email protected]>
@DasX

DasX commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, the P2 finding is correct and is fixed in 2961e7b.

Reproduced it exactly as described: passing the expanded formatErrorMessage(err) result as machineOutput bypassed the renderer's cause gate. For readCronJobForEdit's wrapped lookup failure (cron edit <id> --exact --json against a Gateway without cron.get), the JSON message is unknown automation id: <id> on main, and the first revision turned it into unknown automation id: <id> | unknown method: cron.get with debug off. Machine output now goes through formatCliOperatorError, so ordinary JSON is byte-identical to main again and causes only appear for --debug or OPENCLAW_DEBUG=1. The typed lookup-miss path keeps its own message, which carries no cause.

Coverage for both directions, as requested: three new cases in src/cli/cron-cli/shared.test.ts pin the wrapped error terse without debug intent, full for --debug, and full for OPENCLAW_DEBUG=1. Stashing only the source hunk turns the terse case red (expected true to be false), so it is a real regression test rather than a restatement of current behavior.

One deliberate difference from the machine-output gate: human-facing stderr still carries the full producer message, because that is what human mode already prints today for the same failure. Making machine-mode stderr match human-mode stderr is the point of the PR.

Acceptance criteria, run locally: vitest run src/cli/cron-cli/shared.test.ts src/cli/failure-output.test.ts src/cli/cron-cli/register.cron-edit.test.ts 228 passed; vitest run src/cli/gateway-backed-exit.process.test.ts src/cli/cron-output.process.test.ts 37 passed, with five pre-existing cases in that process file unrunnable here for want of a non-loopback private IPv4 address (that guard is unchanged on main). Production and CLI test typechecks pass; oxfmt, oxlint, and git diff --check are clean. Instead of the full check:changed this sandbox could not finish, I ran the two shards that cover the touched files.

The red checks on the previous revision were not from the diff: every one failed in Setup Node environment because the @matrix-org/matrix-sdk-crypto-nodejs postinstall download answered HTTP 500, which also hit unrelated branches in the same window (example run). Details are under Evidence in the PR body.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 8, 2026
@obviyus obviyus self-assigned this Sep 8, 2026
Mark expected automation failures at their input and domain producers.
Keep both machine output streams behind the existing cause policy while
preserving original diagnostics for unexpected runtime failures.
@obviyus obviyus changed the title fix(cli): cron machine-mode failures were framed as CLI startup crashes fix(cli): preserve automation error guidance in JSON mode Sep 8, 2026
Translate duration validation failures at the automation input boundary
while preserving the original message and machine-output contract.

Merge main and retain upstream explicit-URL credential tests alongside
automation lookup and invalid-duration process coverage.
@obviyus
obviyus merged commit 1b011fe into openclaw:main Sep 8, 2026
107 checks passed
@obviyus

obviyus commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Thanks @DasX!

Proof: Real CLI/Gateway before-and-after runs preserve JSON and exit status while removing generic crash guidance for expected automation errors. Focused tests passed, independent validation exercised 85 commands across baseline and candidate revisions, and final-head CI is green.

  • Bug: Missing automation IDs and invalid inputs received misleading crash/Doctor hints in machine mode.
  • Fix: The input and error owners classify expected failures explicitly. Both machine streams keep the existing debug gate, while unexpected runtime failures keep their diagnostics.
Before After
Generic CLI failure framing for a missing automation Direct missing-ID and list guidance

Additional candidate corrections retain nested-cause gating on machine stderr and preserve debug stacks for unexpected runtime errors.

Legacy compatibility was checked with a protocol fixture. Controlled missing-module tests cover installation failures. Contributor credit and both upstream credential and automation regression tests were retained. Final CI.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 9, 2026
…42113)

Closes openclaw#142110

## What Problem This Solves

Fixes an issue where automation commands in machine-output mode frame ordinary operator errors, such as a missing automation ID or invalid option value, as generic CLI failures with Doctor and debug hints.

## Why This Change Was Made

Known automation input and domain failures now use the existing expected-error renderer. Their producers identify them explicitly, so unexpected runtime and programming failures keep their original diagnostics. The shared renderer, JSON envelope, exit status, Gateway requests, and human-mode output remain unchanged.

The contributor's first correction restored JSON cause gating. Further verification found that machine stderr still exposed nested causes and that internal runtime failures lost their debug stacks. Both are corrected: machine stdout and stderr use the canonical debug policy, while unexpected exceptions retain their original identity. Malformed cron-run wait durations also use the expected-input path; unrelated shared parsing and protocol-validation failures retain their existing policy.

## User Impact

Missing automation IDs and invalid automation options produce direct guidance with exit1 and one canonical JSON document. Nested causes remain hidden in machine mode unless `OPENCLAW_DEBUG` is enabled. Human-mode diagnostics keep their existing full redacted message. Automation commands do not add `--debug` or `--verbose` options.

## Evidence

- Real source CLI and Gateway, with fresh isolated automation stores, reproduced generic command-failure stderr on pinned main `c128afa34681`. The corrected integration prints only direct missing-ID guidance, preserving the same JSON and exit status.
- The supported older-Gateway compatibility fixture proves wrapped causes remain hidden in both machine streams by default and appear with `OPENCLAW_DEBUG=1`.
- Controlled missing-runtime-module cases preserve command/startup framing and debug stacks for genuine installation failures. Modules are restored after each control.
- 599 focused tests passed: 521 cron-owner tests, 36 fast/renderer tests, and 42 CLI process tests. Three added regression checks failed on the original contributor implementation before correction.
- Independent behavior validation executed 85 commands across the candidate, baseline, and two affected follow-up checks, including typed Gateway rejections, human/JSON output, parse and transport errors, debug policy, disabled automation creation and stored readback. All 66 JSON-producing results contained one document; every subprocess ended without a signal.
- Formatting, lint, the normal pre-commit hook, and `git diff --check` passed. Fresh Autoreview found no actionable P0–P2 findings. After a required main merge, all six affected process cases passed with the upstream credential tests retained. Two duration regressions and 22 related run-command tests also passed. Fresh review of the final candidate found no actionable findings. Full CI and typechecking run on GitHub.

| Missing automation in JSON mode | Result |
| --- | --- |
| Before | Generic CLI failure title, Reason, debug, Doctor and Help hints |
| After | `Automation not found: missing-job. Run openclaw cron list to see recent automation ids.` |

The old-Gateway control is a protocol fixture, not a historical Gateway binary. Source provenance and final physical cleanup are tracked separately from the independent behavioral observations. AI-assisted.

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 P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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.

[Bug]: cron machine-mode failures are framed as "Could not start the CLI" with Doctor and debug hints

2 participants