Skip to content

fix(cron): preserve complete JSON when run output is piped - #133661

Merged
steipete merged 3 commits into
mainfrom
codex/qa-20260830-cron-output-drain-implementation
Aug 31, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/qa-20260830-cron-output-drain-implementation

Conversation

@steipete

@steipete steipete commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Related: #133259

What Problem This Solves

Operators piping openclaw cron run <id> --wait to another process could receive truncated, invalid JSON despite the correct success or failure exit code. A valid 128 KiB run summary reproduced a 65,536-byte cutoff for successful and failed waited runs.

Why This Change Was Made

Cron now uses the existing one-shot output finalizer before terminating, including non-waited outcomes and human-error exits. Its error handler preserves ExitError so cleanup and stdout/stderr draining finish without replacing the outcome's diagnostic or exit code. This follows the same output-drain ownership used by Doctor in #133259.

The canonical run-log type replaces a redundant partial type. Scheduling, Gateway responses, summary generation, stores, configuration and shared finalizer deadlines remain unchanged. Production is +12/−12 (net zero); tests/support are +283/−148 (net +135) and docs +1/−1.

User Impact

Scripts receive complete waited-run JSON with the original exit status: success remains 0, failure remains 1. Queued/not-due outcomes, run history and missing-job diagnostics retain their behavior.

Evidence

  • Maintained OS-pipe regression: original production fails two waited JSON cases while four controls pass; the repair passes all six. Only Gateway RPC results are synthetic; Commander, runtime, finalizer and OS pipes are real.
  • Actual source-entry after proof: all six cases pass. Waited outputs contain 133,845/133,885 bytes, the exact 131,072-byte summary and final sentinel, valid JSON, correct 0/1 exits and empty stderr. Proof used Node 26.8.1 source entry, not a packaged binary or live Gateway/job/provider.
  • 517 maintained Cron/owner/sibling tests pass: six process cases, 378 across seven owner/sibling files, and 133 across four corrected validation files. Initial hosted CI exposed 68 obsolete exit-mock expectations; the corrected assertions retain diagnostic and Gateway/no-write checks.
  • A later hosted run exposed two tooling-test failures. The heap fixture now retains a named allocation through sampler stop and asserts its positive sampled size; the missing-allocation counterfactual fails, and the full 32-case profiler file passes. The benchmark uses the existing canonical zombie-aware PID helper; its 16 cases and 10 focused PID/wait controls pass. No sampling interval, production cleanup or test deadline was changed.
  • One unchanged benchmark diagnostic on Linux Node 24.19.0 passed and observed the child already absent. It did not reproduce the historical CI failure, whose PID state/cause remains unknown. The cleanup oracle is corrected against the existing process-liveness contract, not claimed as proof of that historical cause.
  • Original 30-check gate and prior 20-check correction gate passed. The final two-test gate is covered by its retained successful prefix and a corrected format/typecheck/lint remainder. An installed Node typing mismatch in redundant heap sample-array assertions was corrected while retaining the named allocation oracle. No full test replay was needed.
  • Both the complete final 14-file managed P0–P2 review and the separate review of exact commit 78851fe3 found no actionable findings. Fresh hosted CI for that commit remains pending.

Named follow-up: the benchmark's final cleanup wait result is ignored. The diagnostic did not exercise a live group remaining after that wait, and this PR does not change that production owner.

An earlier coordinator Git metadata scan required a 20-to-60-second allowance after Trace2 showed filesystem traversal latency. Product/check deadlines stayed unchanged. A prior gate's separate temporary-cache cleanup was reconciled without repeating the successful checks. Those original failure receipts remain preserved.

@clawsweeper

clawsweeper Bot commented Aug 31, 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 docs Improvements or additions to documentation cli CLI command changes size: M maintainer Maintainer-authored PR labels Aug 31, 2026
@steipete
steipete marked this pull request as ready for review August 31, 2026 00:31
@clawsweeper

clawsweeper Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 31, 2026, 1:46 AM ET / 05:46 UTC.

ClawSweeper review

What this changes

The branch defers cron CLI termination to the shared output finalizer so complete JSON reaches piped consumers, and adds process-level regression coverage plus related test updates.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking correctness findings. This PR remains necessary because fetched current main still exits immediately after cron JSON output; the protected maintainer label and incomplete exact-head CI keep it open for normal maintainer handling.

Priority: P1
Reviewed head: 78851fe3c7b39904b85f5c699bee5aea29fd5a0e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused, net-neutral owner-boundary repair with meaningful process coverage; exact-head CI completion remains the outstanding merge gate.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its added process test nevertheless exercises the changed CLI/finalizer path through an OS pipe with synthetic Gateway responses.
Patch quality 🐚 platinum hermit (4/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 added process test nevertheless exercises the changed CLI/finalizer path through an OS pipe with synthetic Gateway responses.
Evidence reviewed 6 items Introduced owner-boundary repair: The PR replaces the two immediate cron run exits with the existing deferred finalizer; its error boundary rethrows the typed completion signal instead of rendering it as a new error.
Shared finalizer contract: The top-level entry wraps CLI execution in the shared finalizer, which converts the typed exit into a requested exit and drains both standard streams before process termination.
Current main still has the defect: Fetched main retains synchronous runtime exits after both waited and non-waited cron JSON output, so the central repair is not already implemented.
Findings None None.
Security None None.

How this fits together

The cron CLI calls the Gateway, optionally polls the durable run record, and writes machine-readable results. The top-level CLI finalizer then drains stdout and stderr before terminating the process.

flowchart LR
  Script[Operator script] --> Cron[Cron CLI]
  Cron --> Gateway[Gateway request]
  Gateway --> RunLog[Durable run record]
  RunLog --> Result[Completed run result]
  Result --> Json[JSON output]
  Json --> Finalizer[Shared output finalizer]
  Finalizer --> Reader[Piped JSON reader]
Loading

Before merge

  • Resolve merge risk (P1) - Exact-head required checks were still in progress in the captured PR state; merge readiness should be reconfirmed after they complete.
  • Complete next step (P2) - No repair lane is needed: the PR already contains the focused implementation, and the remaining work is ordinary maintainer validation of exact-head checks.
Agent review details

Security

None.

PR surface

Source 0, Tests +135, Docs 0. Total +135 across 14 files.

View PR surface stats
Area Files Added Removed Net
Source 2 12 12 0
Tests 11 283 148 +135
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 296 161 +135

Review metrics

Metric Value Why it matters
Production versus test delta production +12/-12 (net 0); tests/test support +283/-148 (net +135); docs +1/-1 Production replaces direct exits with the existing finalizer without growth; the added test surface covers the OS-pipe regression and updated typed-exit expectations.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Merge this net-neutral cron owner-boundary repair once the exact PR head has completed its required checks.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Merge this net-neutral cron owner-boundary repair once the exact PR head has completed its required checks.

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

Yes, source-reproducible: current main calls synchronous process exit immediately after cron JSON output, and the added process test constructs the reported large OS-pipe case. This review did not execute the test because the checkout is read-only.

Is this the best way to solve the issue?

Yes. Reusing the established top-level finalizer keeps stream draining and exit ownership in one canonical place; local cron-specific draining would duplicate that lifecycle responsibility.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: Truncated waited-run JSON breaks an active automation-facing cron CLI workflow even when its exit code is correct.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its added process test nevertheless exercises the changed CLI/finalizer path through an OS pipe with synthetic Gateway responses.

Evidence

What I checked:

  • Introduced owner-boundary repair: The PR replaces the two immediate cron run exits with the existing deferred finalizer; its error boundary rethrows the typed completion signal instead of rendering it as a new error. (src/cli/cron-cli/register.cron-simple.ts:281, a278231bf35b)
  • Shared finalizer contract: The top-level entry wraps CLI execution in the shared finalizer, which converts the typed exit into a requested exit and drains both standard streams before process termination. (src/cli/one-shot-exit.ts:98, 78851fe3c7b3)
  • Current main still has the defect: Fetched main retains synchronous runtime exits after both waited and non-waited cron JSON output, so the central repair is not already implemented. (src/cli/cron-cli/register.cron-simple.ts:285, ffa83609c8cd)
  • Process-boundary regression coverage: The new test writes a sentinel-bearing 128 KiB summary through real Commander, runtime, finalizer, and an OS child-process pipe; it verifies JSON parsing, status, stderr, and controls while substituting only Gateway RPC responses. (src/cli/cron-output.process.test.ts:53, 78851fe3c7b3)
  • History and release status: The functional change was introduced by the first PR commit; no release tag contains the unmerged PR head. (src/cli/cron-cli/register.cron-simple.ts:281, a278231bf35b)
  • Prior review continuity: The latest ClawSweeper review had no findings and identified only incomplete exact-head checks; this head adds the tooling-test correction described in the PR body. (78851fe3c7b3)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Confirm the required checks complete successfully on commit 78851fe.

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 (3 earlier review cycles)
  • reviewed 2026-08-31T00:31:11.468Z sha a278231 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-31T00:37:52.746Z sha a278231 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-31T01:40:14.451Z sha dcc7faa :: needs maintainer review before merge. :: none

@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 31, 2026
@steipete
steipete merged commit e888f38 into main Aug 31, 2026
169 checks passed
@steipete
steipete deleted the codex/qa-20260830-cron-output-drain-implementation branch August 31, 2026 06:44
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 1, 2026
…133661)

* fix(cron): drain one-shot output before exiting

* test(cron): assert deferred validation exit signals

* test(tooling): retain heap workloads and reuse PID checks
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 P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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.

1 participant