Repository navigation
fix(cli): keep Doctor JSON reports complete when piped - #133259
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 6:44 AM ET / 10:44 UTC. ClawSweeper reviewWhat this changesRoutes Doctor’s machine-readable report modes through the shared one-shot exit finalizer so piped JSON finishes writing before the CLI exits. Merge readinessNo 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 Priority: P1 Review scores
Verification
How this fits togetherDoctor 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]
Decision needed
Why: The patch is technically clean, but the protected maintainer label requires normal human handling rather than automated closure or repair routing. Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +3, Tests +127. Total +130 across 17 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
* fix(cli): keep Doctor reports complete when piped * test(cli): preserve completion exports in runtime mocks * fix(cli): preserve lazy runtime loading for help
Closes #133258
What Problem This Solves
Fixes an issue where users piping
openclaw doctor --jsonreceive truncated, invalid JSON when a report exceeds the pipe buffer, even though Doctor exits successfully. Explicitdoctor --lint --jsonhas 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.
doctor --jsondoctor --lint --jsonThe final normal sourcePerformance build stamps commit
4a6bc5e2a9b068292ed64fe83401c57f3a600d2a. All four after controls (file and pipe for both modes) have empty stderr and identical output SHA256335dbc95a0214cdc382256f275b1209374e464eabfe600fa03e5a0e82f403be0, 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
ExitErrorexport 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 requiredopenclaw/ci-gatepassed 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.