Skip to content

fix(cli): keep approvals JSON failures parseable - #124585

Merged
steipete merged 1 commit into
mainfrom
fix/autoqa-cli-machine-output-v3
Aug 16, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/autoqa-cli-machine-output-v3

Conversation

@steipete

@steipete steipete commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where operators scripting openclaw approvals ... --json would receive exit 1 with empty machine-readable stdout when pending, resolve, get, set, or allowlist operations failed. The same commands already returned JSON on success, so callers could not reliably parse the advertised output mode.

Why This Change Was Made

The approvals CLI now owns failure rendering at each command action boundary. Validation and mutation helpers throw to that boundary, which emits exactly one compact { "error": "..." } JSON value in JSON mode or the existing human-readable stderr message otherwise, then exits 1. Error text remains bounded and terminal-sanitized.

No flags, authentication behavior, Gateway methods, configuration, or protocol shapes change. This PR is AI-assisted and directly maintainer-reviewed.

Maintainer LOC decision: accept the net +3 production lines. The JSON-versus-human output branch is the required machine-output capability, and centralizing it at one owner boundary removes ten repeated failure-rendering lines; a net-neutral alternative would scatter that policy back across five command actions.

User Impact

Scripts can parse approvals command stdout as one JSON value on both success and failure. Human-mode failures remain on stderr with the same non-zero exit behavior.

Evidence

  • Before, the built CLI returned exit 1 with empty stdout for an approvals JSON-mode failure. After, Gateway, node, file-read, parse, validation, and mutation failures return exit 1 with one parseable {error} value on stdout; the human-mode control remains stderr-only.
  • node scripts/run-vitest.mjs src/cli/exec-approvals-cli.test.ts src/cli/exec-approvals-cli.pending-resolve.test.ts — focused owner-boundary tests passed on the reviewed candidate. No rerun was required after the mechanical rebase because all relevant blobs remained identical.
  • Source-blind built-CLI validation on the rebased head passed missing-file JSON and human controls, invalid stdin JSON, and a closed-port Gateway failure. Every JSON failure exited 1 with exactly one parseable {error} stdout value and no duplicated error across streams.
  • Full pnpm build, changed checks, lint, production/test types, import-cycle checks, built-dist controls, and git diff --check passed during direct review.
  • Exact-head CI run 31948737477 passed on 1599e73baeef5d6547d26f091c1c73e2c5d33c36, including openclaw/ci-gate, build artifacts, compact Node shards, lint, production/test types, dependencies, protocol, and boundary checks.
  • Autoreview on candidate 8ed5748a84867fbea4eff11f4335952ba95c5d25 completed clean with no accepted/actionable findings.
  • ClawSweeper reviewed the exact head with no actionable findings; its sole rank-up move was to wait for exact-head checks, now complete.
  • Rebased head 1599e73baeef5d6547d26f091c1c73e2c5d33c36 has byte-identical changed blobs to the reviewed candidate: production e3a481ba98779895e8804aa4d39d5b7b1d23af97, primary tests 96646a695a7237dbd02e836da3b03e81286ce6eb, pending/resolve tests 02086858b19fa1100718f96be5ba64fe6b255515.
  • Production LOC: +15/-12 (net +3), consolidating five command failure paths behind one bounded/redacted owner. Tests: +19/-3 (net +16).

@clawsweeper

clawsweeper Bot commented Aug 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: XS maintainer Maintainer-authored PR labels Aug 16, 2026
@steipete steipete self-assigned this Aug 16, 2026
@steipete
steipete marked this pull request as ready for review August 16, 2026 13:03
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Aug 16, 2026
@clawsweeper

clawsweeper Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 16, 2026, 9:15 AM ET / 13:15 UTC.

ClawSweeper review

What this changes

The PR makes approvals commands emit one compact JSON error object on stdout in --json mode while retaining human-readable stderr errors otherwise.

Regression provenance

Possible regression — probable (reviewed change; reproduction). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open for maintainer merge review. The patch is a coherent CLI-boundary repair with no source-level finding, but the maintainer label requires human handling and this sandbox could not recheck the supplied current-main revision live.

Priority: P2
Reviewed head: 1599e73baeef5d6547d26f091c1c73e2c5d33c36
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, coherent repair with behavioral regression coverage and reported built-CLI proof; current-main refresh could not be independently checked in this sandbox.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: The PR is maintainer-authored; its body additionally reports after-fix built-CLI terminal validation, so the external-contributor proof gate does not apply.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The PR is maintainer-authored; its body additionally reports after-fix built-CLI terminal validation, so the external-contributor proof gate does not apply.
Evidence reviewed 6 items Shared failure owner: The PR adds one bounded, sanitized failure renderer that writes { error } in JSON mode and preserves stderr output otherwise.
All affected action boundaries use it: Pending, resolve, get, set, and allowlist mutation catch paths delegate to the same renderer, so the JSON/human choice is not duplicated per command.
Pre-fix behavior: The base revision rendered caught failures directly through the human error runtime and exited, including the pending and set action boundaries, without a JSON-mode branch.
Findings None None.
Security None None.

How this fits together

The approvals CLI sends operator requests to local state, a Gateway, or a node and renders their results for scripts or terminals. Its action boundary must preserve a machine-readable JSON contract without changing approval transport or policy behavior.

flowchart LR
  A[Operator approvals command] --> B[CLI action]
  B --> C[Local state or Gateway]
  C --> D[Success or failure]
  D --> E[Shared output decision]
  E --> F[JSON stdout]
  E --> G[Human stderr]
Loading

Decision needed

Question Recommendation
Should this maintainer-owned CLI contract change be merged after the normal current-base and exact-head checks are confirmed? Merge the unified JSON error contract: Accept the intentional JSON-mode error object once normal merge-time current-base and exact-head checks confirm the reviewed behavior.

Why: The patch is protected by the maintainer label, and the review sandbox could not independently refresh current-main state.

Before merge

  • Resolve merge risk (P1) - This intentionally changes JSON-mode failure stdout from empty output to {error}; scripts that treated empty stdout as a contract will observe the new advertised machine-output behavior.
  • Resolve merge risk (P1) - Production code is net +3 lines for the shared output-mode branch; it is justified by removing five repeated render paths, but no net-neutral shape avoids reintroducing that duplication.
  • Resolve merge risk (P1) - The reviewer could not inspect the supplied current-main SHA or live GitHub state because the partial-clone promisor fetch and GitHub API access failed.
Agent review details

Security

None.

PR surface

Source +3, Tests +16. Total +19 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 15 12 +3
Tests 2 19 3 +16
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 34 15 +19

Review metrics

Metric Value Why it matters
Production versus test LOC production +15/-12 (net +3); tests +19/-3 (net +16) The small production increase centralizes five error paths; the added tests cover pending and file-read JSON failure behavior.

Merge-risk options

Maintainer options:

  1. Accept the repaired JSON contract (recommended)
    Merge with the intentional change that --json failures emit one parseable error object rather than empty stdout.
  2. Pause for script-compatibility confirmation
    Hold the PR if maintainers need to preserve empty failure stdout for an identified existing automation contract.

Technical review

Best possible solution:

Keep one bounded output-boundary renderer; no net-neutral alternative preserves all five command actions without restoring duplicated JSON-versus-human failure branches.

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

Yes, from source: the base catch paths write only human errors, while the PR-head parser-level test demonstrates the same rejected Gateway call now produces one JSON error and exit 1. The sandbox did not run the test because this review is read-only.

Is this the best way to solve the issue?

Yes. Centralizing the output-mode decision at the shared action failure boundary is preferable to adding per-command JSON branches or changing Gateway behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 8638d50ce663.

Labels

Label changes:

  • add merge-risk: 🚨 compatibility: JSON-mode failures gain stdout content where existing callers previously received no machine-readable value.

Label justifications:

  • P2: This repairs a bounded CLI scripting contract without evidence of broader runtime impact.
  • merge-risk: 🚨 compatibility: JSON-mode failures gain stdout content where existing callers previously received no machine-readable value.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR is maintainer-authored; its body additionally reports after-fix built-CLI terminal validation, so the external-contributor proof gate does not apply.

Evidence

What I checked:

  • Shared failure owner: The PR adds one bounded, sanitized failure renderer that writes { error } in JSON mode and preserves stderr output otherwise. (src/cli/exec-approvals-cli.ts:383, 1599e73baeef)
  • All affected action boundaries use it: Pending, resolve, get, set, and allowlist mutation catch paths delegate to the same renderer, so the JSON/human choice is not duplicated per command. (src/cli/exec-approvals-cli.ts:1093, 1599e73baeef)
  • Pre-fix behavior: The base revision rendered caught failures directly through the human error runtime and exited, including the pending and set action boundaries, without a JSON-mode branch. (src/cli/exec-approvals-cli.ts:1135, 0d9a424d81e2)
  • Regression coverage: The new parser-level pending test asserts one JSON error, no human error, and exit 1; existing file-read failure cases now assert JSON error output in the node-set JSON path. (src/cli/exec-approvals-cli.pending-resolve.test.ts:276, 1599e73baeef)
  • Feature provenance: Blame ties the shared approvals CLI baseline to fa57fe5, while the new renderer and all changed catches date to this PR commit by the same area contributor. (src/cli/exec-approvals-cli.ts:383, 1599e73baeef)
  • Current-main inspection limitation: The supplied current-main object was absent from the partial clone and its promisor fetch failed because GitHub DNS/network access was unavailable; live PR state and current-main equivalence could not be independently refreshed.

Likely related people:

  • steipete: Current blame attributes the surrounding approvals CLI and this PR’s shared renderer to the same contributor. (role: feature owner and recent area contributor; confidence: high; commits: fa57fe5ae5c9, 1599e73baeef; files: src/cli/exec-approvals-cli.ts, src/cli/exec-approvals-cli.test.ts, src/cli/exec-approvals-cli.pending-resolve.test.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Confirm normal current-base and exact-head checks at merge time.

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 (1 earlier review cycle)
  • reviewed 2026-08-16T13:09:25.373Z sha 1599e73 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Aug 16, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready evidence for 1599e73baeef5d6547d26f091c1c73e2c5d33c36:

  • Before: a built approvals command failing in --json mode exited 1 with empty machine stdout. After: failure exits 1 with exactly one compact, parseable {error} value on stdout; human mode keeps its stderr error path.
  • Focused owner proof: node scripts/run-vitest.mjs src/cli/exec-approvals-cli.test.ts src/cli/exec-approvals-cli.pending-resolve.test.ts passed on candidate 8ed5748a84867fbea4eff11f4335952ba95c5d25; all three changed blobs are byte-identical on the rebased head.
  • Source-blind built-CLI proof passed missing-file JSON/human controls, invalid stdin JSON, and closed-port Gateway failure. Every JSON probe emitted exactly one parseable error object with no duplicate error across streams.
  • Direct review passed full build, changed checks, lint, production/test types, import-cycle checks, dist controls, git diff --check, and clean autoreview.
  • Exact-head CI: https://github.com/openclaw/openclaw/actions/runs/31948737477 — openclaw/ci-gate, build artifacts, compact Node shards, lint, types, dependencies, protocol, and boundary checks all passed.
  • ClawSweeper found no actionable defect; its sole rank-up move (wait for exact-head checks) is complete.
  • Production LOC: +15/-12 (net +3), accepted as the single JSON-versus-human output owner replacing five repeated error paths. Tests: +19/-3 (net +16).
  • No flags, auth, Gateway method, config, protocol, release, or deployment changes. No known proof gap remains.

@steipete
steipete merged commit b5491a0 into main Aug 16, 2026
265 of 266 checks passed
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete
steipete deleted the fix/autoqa-cli-machine-output-v3 branch August 16, 2026 13:35
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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.

1 participant