Skip to content

fix(cli): accept daemon --json before subcommands - #126447

Merged
steipete merged 3 commits into
mainfrom
codex/autoqa-152-daemon-json
Aug 19, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/autoqa-152-daemon-json

Conversation

@steipete

@steipete steipete commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #126444

AI-assisted: Codex

What Problem This Solves

Fixes an issue where operators using the legacy openclaw daemon lifecycle CLI could not place the universal --json flag before a subcommand. All six forms such as openclaw daemon --json status failed during parsing with commander.unknownOption, even though the corresponding after-subcommand forms worked.

Why This Change Was Made

The daemon parent now declares --json, while every existing lifecycle leaf keeps its own declaration. The shared registration owner resolves JSON mode source-aware: an explicit leaf CLI value wins; otherwise the leaf inherits only a CLI-sourced parent value through inheritOptionFromParent. This preserves both placements without argv scanning, duplicate renderers, fallback paths, or service-runtime changes. The Gateway parent remains unchanged because JSON is not universal across its subcommands.

The daemon CLI reference now documents both JSON placements and includes the already-registered stop --force option. A one-line process-test fixture correction updates the Memory Core Doctor public artifact from api.js to doctor-health-api.js, matching the split introduced by f8ba65636c23 and allowing the requested CLI JSON process sibling to exercise its intended contract.

User Impact

Scripts and operators can use --json before or after any legacy daemon lifecycle subcommand. Existing human output, JSON envelopes, and after-subcommand behavior are unchanged.

Release-note context: legacy daemon lifecycle automation now accepts --json in either nested CLI position.

Evidence

Before the fix, a real positional-parser table failed all six before-leaf cases with commander.unknownOption; all six after-leaf cases passed.

After the fix:

  • node scripts/run-vitest.mjs src/cli/daemon-cli/register-service-commands.test.ts --reporter=verbose — 19/19 passed, covering all six leaves and both placements with mocked runner assertions for json: true.
  • Focused daemon parser/coverage/lifecycle run — 68/68 passed.
  • OPENCLAW_E2E_SKIP_BUILD=1 node scripts/run-vitest.mjs src/cli/command-options.test.ts test/cli-json-stdout.e2e.test.ts --reporter=verbose — 48/48 passed.
  • Built-CLI source-blind proof in isolated state: both daemon --json status --no-probe and daemon status --json --no-probe exited 0 with parseable JSON. Mutating lifecycle leaves remained mocked to avoid touching a live service.
  • pnpm check:docs — passed formatting, lint, MDX, glossary, 6,524 internal links, and config-example validation.
  • node scripts/check-changed.mjs -- <five changed paths> — passed the selected core, core-test, root-test, docs, and tooling gates.
  • First exact-head CI run 32304925895 found one attributable stale inventory entry: daemon remained in JSON_NOT_APPLICABLE after gaining parent JSON support. Removing that obsolete exception made root-command-descriptions.test.ts and the parser suite pass 23/23 without weakening the guard.
  • git diff --check — clean.
  • Production LOC: +14/-5 (net +9); tests/test support: +23/-2; docs: +3/-1.
  • Fresh P1 autoreview: clean, no accepted/actionable findings.
  • Separate read-only Codex review of final diff SHA-256 505f2f00873a4adfe86101e54cd5ca85c7411b88f36bcb59fa2258eeefa569bb: no P1 findings; start/end guards matched.

@clawsweeper

clawsweeper Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 19, 2026 21:38
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes size: XS maintainer Maintainer-authored PR labels Aug 19, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for head 3ec7107964ee068ef84b748a265e6ed7ed9205fa:

  • Issue [Bug]: daemon rejects --json before lifecycle subcommands #126444 is valid: on the original baseline, all six daemon --json <leaf> forms failed with commander.unknownOption, while every after-leaf form parsed.
  • Root cause: positional Commander parsing stopped at the daemon parent, which did not declare the only flag shared by all six lifecycle leaves. The fix declares parent --json and resolves each leaf source-aware through inheritOptionFromParent; Gateway registration and service runtimes are unchanged.
  • Regression proof: real parser table covers all six leaves in both placements and asserts each mocked runner receives json: true (19/19 passed). Focused daemon parser/coverage/lifecycle proof passed 68/68.
  • Process proof: built CLI in isolated state returned parseable JSON for both daemon --json status --no-probe and daemon status --json --no-probe. Mutating leaves remained mocked to avoid touching a live service.
  • Sibling proof: shared option-source plus CLI JSON process suites passed 48/48. Docs checks passed formatting, lint, MDX, glossary, 6,524 internal links, and config examples. The changed gate passed its core, core-test, root-test, docs, and tooling lanes.
  • Attributable CI repair: initial run 32304925895 exposed the stale daemon JSON-N/A inventory entry. Removing only that obsolete exception made the exact failed guard plus parser suite pass 23/23 without weakening the inventory assertion.
  • Exact-head CI: run 32305708187 is green with no pending checks.
  • Reviews: fresh P1 autoreview and a separate read-only Codex review found no P1 issues on final diff SHA-256 505f2f00873a4adfe86101e54cd5ca85c7411b88f36bcb59fa2258eeefa569bb.
  • LOC: production +14/-5 (net +9), tests/test support +23/-2, docs +3/-1. The production growth is the parent declaration and canonical propagation required to preserve both placements.

Known proof gap: only the read-only status --no-probe path was exercised as a real process; install/uninstall/start/stop/restart were intentionally kept behind mocked runners to avoid live service mutation.

@clawsweeper

clawsweeper Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 19, 2026, 5:56 PM ET / 21:56 UTC.

ClawSweeper review

What this changes

The PR makes legacy daemon lifecycle commands accept the existing JSON-output flag before or after every lifecycle subcommand, with matching documentation and regression coverage.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this maintainer-labeled PR open: it is the focused owner-boundary repair for the linked daemon parsing bug, with no blocking patch finding. Exact-head CI is still running, and this read-only checkout could not independently load current main because its promisor remote and GitHub DNS were unavailable.

Priority: P2
Reviewed head: 3ec7107964ee068ef84b748a265e6ed7ed9205fa

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is focused and well-covered; the described terminal proof is useful but was not independently viewable in this read-only environment.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless describes after-fix built-CLI JSON parsing checks.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless describes after-fix built-CLI JSON parsing checks.
Evidence reviewed 9 items Canonical option resolution: The shared service-command owner uses the existing source-aware parent inheritance helper, so a leaf value remains authoritative and a CLI-supplied daemon value is inherited only when the leaf is defaulted.
All lifecycle handlers receive JSON mode: Status, install, uninstall, start, stop, and restart route their JSON option through the same resolver rather than creating per-command parsing paths.
Parser-boundary regression coverage: The table drives both before-leaf and after-leaf JSON placement across all six lifecycle leaves and asserts that each real action registration receives JSON mode.
Findings None None.
Security None None.

Live Verification

Command: OPENCLAW_STATE_DIR="$(mktemp -d)" pnpm openclaw daemon --json status --no-probe | node -e 'let s="";process.stdin.on("data",d=›s+=d).on("end",()=›{JSON.parse(s);console.log("JSON_OK")})'

Result: PASS (completed)

runner@runnervmzvulz:/tmp/clawsweeper-live-proof-126447-wbdX0s/target$ OPENCLAW_STATE_DIR="$(mktemp -d)" pnpm openclaw daemon --json status --no-probe | node -e
 'let s="";process.stdin.on("data",d=›s+=d).on("end",()=›{JSON.parse(s);console.log("JSON_OK")})'
$ node scripts/run-node.mjs daemon --json status --no-probe
OPENCLAW_STATE_DIR="$(mktemp -d)" pnpm openclaw daemon --json status --no-probe | node -e 'let s="";process.stdin.on("data",d=›s+=d).on("end",()=›{JSON.parse(s)
;console.log("JSON_OK")})'
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 98.37 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.7s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

[tsdown-build] invocation 2/2 finished in 12.8s
[plugin-control-plane-loads] verified 36 built modules with native require and checked doctor closures
runtime-postbuild: 10 phases completed in 4165ms (slowest: built plugin control-plane loads 3419ms)
JSON_OK
runner@runnervmzvulz:/tmp/clawsweeper-live-proof-126447-wbdX0s/target$ OPENCLAW_STATE_DIR="$(mktemp -d)" pnpm openclaw daemon --json status --n
… output truncated …

Assertions:

  • PASS expect_output: JSON_OK

How this fits together

The daemon CLI is the legacy service-management interface for the Gateway. Commander parses the nested command, then lifecycle handlers receive normalized options and emit either human-readable or JSON output.

flowchart LR
  A[Operator lifecycle command] --> B[Daemon command parser]
  B --> C[Parent or leaf JSON flag]
  C --> D[Source-aware option resolution]
  D --> E[Service lifecycle handler]
  E --> F[JSON or human output]
Loading

Before merge

  • Resolve merge risk (P1) - Production code grows by net nine lines for this bug fix; the shared resolver is justified because Commander defaults require source-aware inheritance across six handlers, but exact-head CI should finish before merge.
  • Resolve merge risk (P1) - The read-only environment could not independently compare the PR against current main because the partial clone required an unreachable promisor remote.
  • Complete next step (P2) - This maintainer-labeled PR already owns the bounded repair; await exact-head CI rather than creating a competing repair lane.
Agent review details

Security

None.

PR surface

Source +9, Tests +21, Docs +2. Total +32 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 2 14 5 +9
Tests 3 23 2 +21
Docs 1 3 1 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 40 8 +32

Review metrics

Metric Value Why it matters
Production versus test LOC production +14/-5 (net +9); tests +23/-2; docs +3/-1 The production increase is concentrated in one shared JSON resolver and six handler integrations; tests cover both flag placements for every affected leaf.

Stored data model

Persistent data-model change detected: migration/backfill/repair: test/cli-json-stdout.e2e.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #126444
Summary: This PR is the linked candidate repair for the canonical daemon JSON-placement bug.

Members:

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

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the parent-and-leaf declaration pattern with one shared source-aware resolver, then merge after exact-head CI confirms the documented CLI contract.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the parent-and-leaf declaration pattern with one shared source-aware resolver, then merge after exact-head CI confirms the documented CLI contract.

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

Yes—source and the PR’s parser matrix establish a deterministic reproduction: before this change the parent lacked the flag while every leaf declared it. This read-only review did not execute the command because the package-manager cache could not be created on the read-only host.

Is this the best way to solve the issue?

Yes—the parent declaration plus source-aware inheritance is the narrowest maintainable fix; argv scanning or changing the broader Gateway parent would duplicate policy or affect unrelated commands.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This repairs deterministic JSON-mode parsing for daemon lifecycle scripts without evidence of an availability, security, or data-loss incident.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.

Label justifications:

  • P2: This repairs deterministic JSON-mode parsing for daemon lifecycle scripts without evidence of an availability, security, or data-loss incident.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.

Evidence

What I checked:

Likely related people:

  • steipete: Peter Steinberger authored the current daemon JSON changes and the earlier CLI reliability work that introduced the related option-resolution surface. (role: recent CLI JSON-output and daemon-area contributor; confidence: high; commits: 3ec7107964ee, 433bb3f954ed, f8ba65636c23; files: src/cli/daemon-cli/register-service-commands.ts, src/cli/command-options.ts, extensions/memory-core/doctor-health-api.ts)

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.

@steipete

Copy link
Copy Markdown
Contributor Author

ClawSweeper rank-up moves resolved for reviewed head 3ec7107964ee068ef84b748a265e6ed7ed9205fa:

  • The net +9 production LOC is the parent declaration plus one shared source-aware resolver propagated to all six existing handlers. Keeping the six leaf declarations is required to preserve after-leaf syntax, so a net-neutral deletion would regress the shipped placement contract.
  • Refreshed current origin/main to e00f86019827d2a8b41a4e137ceb1faab94d3563 after the review. No commit since the branch base touched any of the six changed files or the daemon CLI owner subtree; the PR remains mergeable.
  • Exact-head CI completed green in run 32305708187 with zero pending checks.

The review’s stored-data-model heuristic is not applicable: test/cli-json-stdout.e2e.test.ts only renames a temporary public-artifact fixture from api.js to the canonical doctor-health-api.js; there is no runtime state, schema, migration, or compatibility change.

@steipete
steipete merged commit 7769cb6 into main Aug 19, 2026
164 checks passed
@steipete
steipete deleted the codex/autoqa-152-daemon-json branch August 19, 2026 22:17
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 20, 2026
* fix(cli): accept daemon json before subcommands

* test(cli): update doctor public-surface fixture

* test(cli): classify daemon parent JSON output
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 maintainer Maintainer-authored PR size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: daemon rejects --json before lifecycle subcommands

1 participant