Skip to content

fix(cli): keep Doctor JSON reports complete when piped - #133259

Merged
steipete merged 3 commits into
mainfrom
codex/qa-20260830-doctor-json-output
Aug 30, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/qa-20260830-doctor-json-output

Conversation

@steipete

@steipete steipete commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #133258

What Problem This Solves

Fixes an issue where users piping openclaw doctor --json receive truncated, invalid JSON when a report exceeds the pipe buffer, even though Doctor exits successfully. Explicit doctor --lint --json has the same truncation with its normal threshold exit code.

Why This Change Was Made

Completed Doctor reports called the synchronous runtime exit before queued stdout finished. Route the maintenance registrar and Doctor report modes through the existing one-shot output finalizer, and let the shared command wrapper propagate its typed completion outcome without rendering another error. The wrapper loads the completion class only on its error path, preserving lazy help registration. The finalizer keeps ownership of cleanup, stream draining, and process exit.

Repeated runtime selection and unreachable returns/throws are removed. Production LOC: +21/-21, net 0; test changes are separate. No new helper, configuration, schema, dependency, or repair policy is introduced. Returning status codes through the Doctor API would duplicate the established lifecycle contract; adding report-specific drain logic would create another output owner.

Provenance: original introduction unknown. The advisory JSON exit change in 6e5bf3e carried forward the immediate-exit pattern, verified against its raw parent. The existing finalizer from #131656 already provides the required drain behavior.

User Impact

Piped Doctor reports complete before exit. Bare JSON remains advisory (exit 0); explicit lint retains its configured threshold result; usage failures remain exit 2. Report modes retain their existing status decisions, and injected runtimes keep their exit callback behavior.

Ordinary internal Doctor callers remain unchanged. Named follow-up: the ordinary health flow's config-write refusal and post-install advisory exits also need lifecycle work, but converting them requires checking nested updater catches and advisory exit 86. This PR does not claim every Doctor exit is repaired. The runtime-exception ownership reported in #127502 is separate and unchanged.

Evidence

Before, on unchanged current source 039187a, the supported compiled CLI was run with an isolated synthetic HOME/state/config containing 1,500 invalid numeric provider base URLs. Config validation emits these findings before provider execution; no credentials, network calls, live service, or destructive maintenance operation was used.

Actual CLI flow Before pipe After pipe Exit, unchanged
doctor --json 65,536 bytes; invalid JSON 268,948 bytes; valid JSON, 1,500 findings 0
doctor --lint --json 65,536 bytes; invalid JSON 268,948 bytes; valid JSON, 1,500 findings 1

The final normal sourcePerformance build stamps commit 4a6bc5e2a9b068292ed64fe83401c57f3a600d2a. All four after controls (file and pipe for both modes) have empty stderr and identical output SHA256 335dbc95a0214cdc382256f275b1209374e464eabfe600fa03e5a0e82f403be0, matching the full before-file report. The compiled registrar/runtime/finalizer binding was inspected, including the lazy completion-class import. The final 41.1-second build and all four output controls include that correction; all 17 committed files match the reviewed content hashes.

Production LOC: +21/-21; tests/test support: +144/-14. The canonical changed-file gate passed. Its initial run caught three consistent-return lint findings; explicit returns corrected them, and 94 focused maintenance/process tests plus targeted lint passed before the complete gate rerun.

Focused coverage: 204 tests across the Doctor registrar, report commands, one-shot finalizer, invalid-config recovery and shared wrapper; 496 tests across ten direct caller/process suites. Initial subprocess and typed-exit regressions failed before the repair. Existing runtime mocks that omitted the real ExitError export now retain module exports with all assertions unchanged. A grouped run masked incomplete factories, so the remaining 12 relevant suites were checked in separate processes: 14 failures demonstrated four additional incomplete factories. Eight affected suites then passed 201 tests individually; four unaffected suites passed 61 tests unchanged. No test assertions or test-isolation policy were weakened. The subprocess tests use synthetic 1 MiB report producers with the real parser/runtime/finalizer; actual compiled CLI proof separately checks the production report writer.

Selected configure-help failed on the eager import and passes after correction, alongside all 60 shared-wrapper tests and three process regressions. Selected setup/onboard/agents help checks still load runtime through separate unchanged imports; all three failures reproduce with the original baseline wrapper. Their lazy-help and mock-cache isolation cleanup is a named follow-up, not part of this output repair.

Final source/peer review and separate exact-commit CLI review are clean at 4a6bc5e2a9b068292ed64fe83401c57f3a600d2a; structured autoreview is scoped-clean at P0. The final 17-file changed gate and compiled proof passed. Exact-head CI run 33306283992 and the required openclaw/ci-gate passed on this commit.

The latest ClawSweeper review has no actionable findings; its sole rank-up move, waiting for exact-head CI, is complete. The data-model marker is a file-based false positive: this change only selects the existing output runtime and completion owner in Doctor report branches; no schema, storage operation, or persistence semantics change. The protected maintainer label requires normal maintainer handling, which this PR is following.

@clawsweeper

clawsweeper Bot commented Aug 30, 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 commands Command implementations size: M maintainer Maintainer-authored PR labels Aug 30, 2026
@steipete
steipete marked this pull request as ready for review August 30, 2026 10:21
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 6:44 AM ET / 10:44 UTC.

ClawSweeper review

What this changes

Routes Doctor’s machine-readable report modes through the shared one-shot exit finalizer so piped JSON finishes writing before the CLI exits.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

No blocking defects found: the PR moves completed Doctor report exits to the existing output-drain owner while preserving documented exit codes. It should remain open for normal maintainer review because it carries the protected maintainer label.

Priority: P1
Reviewed head: 4a6bc5e2a9b068292ed64fe83401c57f3a600d2a
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Strong compiled-CLI evidence, focused boundary coverage, and a net-neutral owner-boundary repair support an above-average review result.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: The repository state identifies this as a MEMBER-authored PR, so the external-contributor proof gate does not apply; independently, its body records compiled CLI before/after pipe results for the changed Doctor modes, while the checked-in process test covers the registrar-to-finalizer boundary.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository state identifies this as a MEMBER-authored PR, so the external-contributor proof gate does not apply; independently, its body records compiled CLI before/after pipe results for the changed Doctor modes, while the checked-in process test covers the registrar-to-finalizer boundary.
Evidence reviewed 7 items Documented report contract: Doctor documentation defines bare doctor --json as advisory after producing a report and explicit doctor --lint --json as retaining threshold-based exit codes.
Current-main failure owner: Current main still calls the synchronous runtime exit immediately after lint and report output, so it does not yet contain this PR’s drain handoff.
Canonical lifecycle routing: The introduced report branches call exitCliAfterOutput; the finalizer catches its typed outcome, drains both streams, then exits with the retained status.
Findings None None.
Security None None.

How this fits together

Doctor produces local health and upgrade reports for operators and scripts. Its command registrar selects a report mode, writes stdout, then hands termination to the CLI lifecycle owner that drains output streams before process exit.

flowchart LR
  A[Doctor command options] --> B[Report mode selection]
  B --> C[Write JSON report]
  C --> D[Shared CLI exit lifecycle]
  D --> E[Drain stdout and stderr]
  E --> F[Complete piped JSON and exit code]
Loading

Decision needed

Question Recommendation
Should a CLI owner approve this focused lifecycle repair for merge on its exact reviewed head? Approve normal merge review: Accept the shared-finalizer repair after the CLI owner confirms the exact-head evidence and required checks remain green.

Why: The patch is technically clean, but the protected maintainer label requires normal human handling rather than automated closure or repair routing.

Before merge

None.

Agent review details

Security

None.

PR surface

Source +3, Tests +127. Total +130 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 4 25 22 +3
Tests 13 140 13 +127
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 17 165 35 +130

Review metrics

Metric Value Why it matters
Production versus test delta production +21/-21 (net 0); tests/test support +144/-14 The fix absorbs the lifecycle change without production growth while adding process-boundary regression coverage.

Stored data model

Persistent data-model change detected: unknown-data-model-change: src/commands/doctor.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #133258
Summary: This PR is the direct candidate fix for the reported Doctor JSON pipe truncation; the other related items share lifecycle context but not the same remaining behavior.

Members:

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

Technical review

Best possible solution:

Keep one canonical completion path: Doctor report modes should continue to request the shared finalizer, with the documented advisory, lint, and post-upgrade status semantics preserved.

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

Yes. The PR supplies a compiled-CLI pipe reproduction with large reports, and current main retains the immediate-exit paths that cause the truncation.

Is this the best way to solve the issue?

Yes. Reusing the existing one-shot finalizer keeps stream draining and process termination under one lifecycle owner instead of adding report-specific pipe logic.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P1: Invalid piped Doctor JSON breaks scripts and CI consumers on an existing documented CLI workflow.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository state identifies this as a MEMBER-authored PR, so the external-contributor proof gate does not apply; independently, its body records compiled CLI before/after pipe results for the changed Doctor modes, while the checked-in process test covers the registrar-to-finalizer boundary.

Evidence

What I checked:

Likely related people:

  • steipete: 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-08-30T10:28:30.493Z sha 4a6bc5e :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 30, 2026
@steipete
steipete merged commit c95e348 into main Aug 30, 2026
320 checks passed
@steipete
steipete deleted the codex/qa-20260830-doctor-json-output branch August 30, 2026 10:46
@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 31, 2026
* fix(cli): keep Doctor reports complete when piped

* test(cli): preserve completion exports in runtime mocks

* fix(cli): preserve lazy runtime loading for help
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M 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]: Doctor JSON reports are truncated when piped

1 participant