Skip to content

fix(cli): keep secrets JSON failures machine-readable - #136142

Merged
obviyus merged 2 commits into
openclaw:mainfrom
qingminglong:codex/fix-secrets-json-failures-20260902
Sep 2, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
qingminglong:codex/fix-secrets-json-failures-20260902

Conversation

@qingminglong

@qingminglong qingminglong commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw secrets ... --json wrote plain-text terminal errors for command failures. Scripts received no JSON document on stdout.

The same defect also affected secrets store list/get --json. Valid secrets audit --check --json reports could be caught as operational failures in non-exiting runtimes.

Root Cause

Each secrets command owned success and failure output separately. The store commands had another failure owner. Audit performed its nonzero result exit inside the operational catch.

Fix

  • Route secrets JSON success and failure through one result owner.
  • Reuse the canonical sanitized CLI failure envelope.
  • Exit only after the selected result is written and stdout can drain.
  • Preserve human output and documented exit codes, including audit exits 1 and 2 and store-get exit 3.
  • Cover reload, audit, configure, apply, and store list/get.

No secret values are added to failures. No configuration, persistence schema, or security policy changes.

Evidence

  • Current main 0f553a2d60752dbc739812e4dcad92f3cf5281de: missing-plan apply exited 1, wrote empty stdout, and wrote plain text to stderr.
  • Anti-cheat: changing the missing plan path changed the plain-text terminal failure.
  • Exact head 980a5f9be0c40943bf52f38942fcdcc6ffbecc5a: missing-plan apply exits 1 with one parsed JSON failure and empty stderr.
  • Exact head: missing store get exits 3 with one parsed JSON failure and empty stderr.
  • Exact head: empty store list exits 0 with one parsed JSON array and empty stderr.
  • Human apply and store failures keep their prior text and exit codes.
  • Regression tests fail eight cases on the recorded baseline and pass 43/43 on the repaired source.
  • Focused formatting, lint, assertion-safety, dead-export, import-cycle, coercion, deprecated-API, and diff checks pass.

Review Note

The ClawSweeper rank-up move is applied: the repeated mode guards were replaced with one result owner. Production growth creates that owner and covers the previously omitted store commands and audit outcome sequencing.

@clawsweeper

clawsweeper Bot commented Sep 2, 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: S labels Sep 2, 2026
@qingminglong
qingminglong marked this pull request as ready for review September 2, 2026 08:06
@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 2, 2026
@clawsweeper

clawsweeper Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 2, 2026, 6:29 AM ET / 10:29 UTC.

ClawSweeper review

What this changes

The PR makes secrets CLI failures emit the canonical JSON error envelope on stdout when --json is requested, including store list/get and audit exit handling.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open. The PR repairs a current scripting defect with one shared output owner; no introduced correctness or security defect was found.

Priority: P2
Reviewed head: 980a5f9be0c40943bf52f38942fcdcc6ffbecc5a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with direct CLI behavior evidence and targeted regression coverage.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The changed production owner is the secrets CLI result path; the PR supplies exact-head built-CLI evidence for apply and store-get failures with parsed JSON output, while focused tests cover the remaining command-specific exit paths.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed production owner is the secrets CLI result path; the PR supplies exact-head built-CLI evidence for apply and store-get failures with parsed JSON output, while focused tests cover the remaining command-specific exit paths.
Evidence reviewed 6 items Shared output owner: The new helper writes either the command result or the canonical sanitized failure envelope before unwinding through the existing one-shot exit path.
Caller coverage: Reload, audit, apply, and store list/get route their JSON results through the helper while retaining their distinct human-output paths and documented exit codes.
Documented contract: The docs advertise JSON modes for store list, reload, audit, configure, and apply, and define store-get exit codes 2 and 3.
Findings None None.
Security None None.

How this fits together

The secrets CLI invokes local store operations or Gateway-backed secret operations, then emits human text or script-consumable JSON. Its output path determines what automation receives before the process exits.

flowchart LR
  A[Operator or script] --> B[Secrets CLI command]
  B --> C[Local store or Gateway operation]
  C --> D[Success or failure result]
  D --> E[Human text or JSON output]
  E --> F[Drained output and exit status]
Loading

Before merge

  • Resolve merge risk (P1) - Production code is net +47 lines in a bug fix; the shared owner is justified by removing split result/error handling across the affected commands, but it should remain the single canonical path rather than grow parallel output helpers.
Agent review details

Security

None.

PR surface

Source +47, Tests +178. Total +225 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 289 242 +47
Tests 3 198 20 +178
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 487 262 +225

Review metrics

Metric Value Why it matters
Production versus test delta production +47; tests +178 The production increase creates one shared output owner and the test growth covers the prior JSON-failure gap across command families.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain one secrets-result owner for all JSON-capable commands, preserving command-specific human diagnostics and their existing exit semantics.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain one secrets-result owner for all JSON-capable commands, preserving command-specific human diagnostics and their existing exit semantics.

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

Yes—high-confidence source reproduction is available with secrets apply --from <missing-path> --json; current main retains the pre-fix CLI blobs and the PR records the before/after terminal behavior.

Is this the best way to solve the issue?

Yes. A shared result owner fixes the split success/failure handling at the output boundary while preserving each command’s existing human rendering and exit code.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This fixes machine-readable output for a bounded CLI workflow without evidence of broader runtime or security impact.
  • 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 (terminal): The changed production owner is the secrets CLI result path; the PR supplies exact-head built-CLI evidence for apply and store-get failures with parsed JSON output, while focused tests cover the remaining command-specific exit paths.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is the secrets CLI result path; the PR supplies exact-head built-CLI evidence for apply and store-get failures with parsed JSON output, while focused tests cover the remaining command-specific exit paths.

Evidence

What I checked:

  • Shared output owner: The new helper writes either the command result or the canonical sanitized failure envelope before unwinding through the existing one-shot exit path. (src/cli/secrets-cli-output.ts:13, 980a5f9be0c4)
  • Caller coverage: Reload, audit, apply, and store list/get route their JSON results through the helper while retaining their distinct human-output paths and documented exit codes. (src/cli/secrets-cli.ts:132, 980a5f9be0c4)
  • Documented contract: The docs advertise JSON modes for store list, reload, audit, configure, and apply, and define store-get exit codes 2 and 3. Public docs: docs/cli/secrets.md. (docs/cli/secrets.md:102, 980a5f9be0c4)
  • Regression coverage: Focused tests cover JSON failure envelopes across reload, audit, configure, and apply; built-CLI tests exercise missing-plan apply and missing store get. (test/cli-json-stdout.e2e.test.ts:253, 980a5f9be0c4)
  • Current-main necessity: Current main retains the same pre-PR blobs for both secrets CLI owners, while the PR head contains the new helper and changed owners; the central fix is not already on main. (src/cli/secrets-cli.ts:132, a244b3a2c246)
  • Real behavior evidence: The PR body records exact-head built-CLI runs showing one parsed JSON failure for missing-plan apply and missing store get, plus a successful empty store list with no stderr. (980a5f9be0c4)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; 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 (1 earlier review cycle)
  • reviewed 2026-09-02T08:14:31.957Z sha 34a38ec :: needs maintainer review before merge. :: none

@obviyus obviyus self-assigned this Sep 2, 2026
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 2, 2026
@obviyus

obviyus commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@obviyus
obviyus merged commit aa88b1d into openclaw:main Sep 2, 2026
385 of 391 checks passed
@obviyus

obviyus commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Thanks @qingminglong!

Proof: openclaw secrets apply --from <missing> --json and openclaw secrets store get MISSING_VALUE --json now each return one parseable failure document with their documented exit code. Human output is unchanged.

  • Bug: Secrets JSON commands could emit only plain terminal errors, and audit exits could be caught as a second failure.
  • Fix: One secrets result owner now writes success or failure once, preserves exit codes, and drains stdout before exit.
Before After
Empty JSON stdout plus a plain terminal error One canonical JSON document on stdout

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 3, 2026
## What Problem This Solves

`openclaw secrets ... --json` wrote plain-text terminal errors for command failures. Scripts received no JSON document on stdout.

The same defect also affected `secrets store list/get --json`. Valid `secrets audit --check --json` reports could be caught as operational failures in non-exiting runtimes.

## Root Cause

Each secrets command owned success and failure output separately. The store commands had another failure owner. Audit performed its nonzero result exit inside the operational catch.

## Fix

- Route secrets JSON success and failure through one result owner.
- Reuse the canonical sanitized CLI failure envelope.
- Exit only after the selected result is written and stdout can drain.
- Preserve human output and documented exit codes, including audit exits `1` and `2` and store-get exit `3`.
- Cover `reload`, `audit`, `configure`, `apply`, and store `list/get`.

No secret values are added to failures. No configuration, persistence schema, or security policy changes.

## Evidence

- Current main `ab2638c77e2754fa17df299b0730b99944bd0be2`: missing-plan apply exited `1`, wrote empty stdout, and wrote plain text to stderr.
- Anti-cheat: changing the missing plan path changed the plain-text terminal failure.
- Exact head `980a5f9be0c40943bf52f38942fcdcc6ffbecc5a`: missing-plan apply exits `1` with one parsed JSON failure and empty stderr.
- Exact head: missing store get exits `3` with one parsed JSON failure and empty stderr.
- Exact head: empty store list exits `0` with one parsed JSON array and empty stderr.
- Human apply and store failures keep their prior text and exit codes.
- Regression tests fail eight cases on the recorded baseline and pass 43/43 on the repaired source.
- Focused formatting, lint, assertion-safety, dead-export, import-cycle, coercion, deprecated-API, and diff checks pass.

## Review Note

The ClawSweeper rank-up move is applied: the repeated mode guards were replaced with one result owner. Production growth creates that owner and covers the previously omitted store commands and audit outcome sequencing.

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: S 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.

2 participants