Repository navigation
fix(process): preserve output and cleanup after command exit - #140927
Conversation
Keep successful owned descendant output under the existing command deadline. Clean up failed command trees without replacing their exit result with a later timeout, and retain the selected group target throughout signaling. Remove the group-to-positive-PID fallback and duplicate child-exited state. Preserve force-and-observe cleanup, explicit deadlines, and Windows ownership. Process lifetime replacement for #132180; the other slices remain separate.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 7, 2026, 2:37 AM ET / 06:37 UTC. ClawSweeper reviewWhat this changesThe PR preserves descendant output until the command deadline, cleans up failed command trees without replacing their exit result, and keeps termination signals targeted to the selected process group. Merge readiness✅ Ready for maintainer review This remains a useful, focused repair absent from fetched main. No actionable introduced defect was found; the broader related PR retains separate work, and the maintainer-authored PR is protected from cleanup closure. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s command runner launches subprocesses and returns their output, exit status, and cleanup outcome to callers. Its process-lifetime helpers coordinate inherited output pipes, deadlines, and descendant termination. flowchart TD
A[Command and execution options] --> B[Spawn subprocess]
B --> C[Collect output and root exit]
C --> D{Root outcome}
D -->|Successful owned tree| E[Wait within command deadline]
D -->|Failed or terminated| F[Bound diagnostic drain and clean tree]
E --> G[Return output and execution outcome]
F --> G
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource 0, Tests +234. Total +234 across 11 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep output lifetime and descendant cleanup under the existing command owner, preserving original failure results and exact process-group targeting. Do we have a high-confidence way to reproduce the issue? Yes, from source: a successful root can exit while a quiet descendant holds its pipes beyond the diagnostic cutoff, and a failed root can retain descendants until a later deadline. The supplied regression cases exercise these paths; this review did not execute them. Is this the best way to solve the issue? Yes. The patch repairs the existing lifetime owners, reuses bounded drainage and cleanup observation, and avoids adding competing configuration or execution paths. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a2770e4592fe. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Land-ready for exact head This repairs the process owner rather than adding command retries or larger timeouts: successful owned output retains its deadline, failed roots start cleanup without losing their original exit result, and selected-group signaling cannot retarget the old positive PID. Production is net zero; regression tests are net +234. The updated PR body contains the exact local commands: the tests-only reproduction produced nine intended failures, the repaired owner/sibling suite passed 161 tests, and the packaged build plus all changed checks passed on the unchanged candidate tree. Independent isolated Codex review is scoped-clean at P0. ClawSweeper's current review has no findings or before-merge requirements. Exact-head CI 34091063703 and the required gate are green. Native Windows proof explicitly passed the default/tree root-exit cases and the nested Node timeout case in 60.502 seconds. An additional 37 tests passed on GitHub merge tree This completes proof for the process slice only. The remaining native/session work stays with the split series, and the original #132180 remains open. |
|
Merged via squash.
|
…w#140927) Keep successful owned descendant output under the existing command deadline. Clean up failed command trees without replacing their exit result with a later timeout, and retain the selected group target throughout signaling. Remove the group-to-positive-PID fallback and duplicate child-exited state. Preserve force-and-observe cleanup, explicit deadlines, and Windows ownership. Process lifetime replacement for openclaw#132180; the other slices remain separate.
Restore the successful owned-tree output contract from #140927: retain descendant output until the command deadline and preserve timeout classification for held pipes. Remove early output release and group termination after a successful root exit. At the deadline, give an already-successful root one fixed 100ms EOF grace using the existing stdio grace constant. Both streams reaching EOF preserve the exit result; a held stream enters the existing timeout and cleanup path. Keep runExec and non-tree post-exit handling, the broker execution-only backstop, and broker timeout propagation. Validation: 314 process tests passed with one platform skip, including all requested process ownership suites. The 12-case deadline regression file passed in 5.72s wall; wrapper inventory and both provisioning cases passed. Core and services test tsgo, changed-file lint/format, and full-branch P2 autoreview with the macOS private temporary directory passed.
Restore the successful owned-tree output contract from #140927: retain descendant output until the command deadline and preserve timeout classification for held pipes. Remove early output release and group termination after a successful root exit. At the deadline, give an already-successful root one fixed 100ms EOF grace using the existing stdio grace constant. Both streams reaching EOF preserve the exit result; a held stream enters the existing timeout and cleanup path. Keep runExec and non-tree post-exit handling, the broker execution-only backstop, and broker timeout propagation. Validation: 314 process tests passed with one platform skip, including all requested process ownership suites. The 12-case deadline regression file passed in 5.72s wall; wrapper inventory and both provisioning cases passed. Core and services test tsgo, changed-file lint/format, and full-branch P2 autoreview with the macOS private temporary directory passed.
…ent loop lags (#159578) * fix(process): preserve exits across delayed deadlines Let pending child notifications run before accepting process deadlines, and preserve exited commands whose drained output precedes broker result delivery. Keep inherited-pipe deadlines and existing cancellation, output limits, and process-tree cleanup. Use one watchdog for native and brokered runExec calls. Remove supervisor timeout inference based on delayed result observation. This prevents successful Gateway subprocesses from becoming spurious timeout failures during event-loop stalls. Validation: deterministic regressions fail before their fixes; 126 focused tests pass with one platform skip; related supervisor and idle-timeout tests pass. Core and all 25 selected test typecheck graphs, changed-file lint, and independent review pass. The full changed-check command was stopped under the host time limit during import-cycle scanning after its preceding gates passed. * build(pr): add the shared process deadline to the PR wrapper inventory * test(process): isolate deadline regression spawn fixtures Mock the spawn boundary for deterministic deadline tests so their fake children do not load the unrelated spawn and worker runtime closure. Keep all nine behavior assertions; standalone wall time falls from 30.84 seconds to 3.15 seconds. Validation: 208 process tests passed with one platform skip; PR wrapper inventory and both requested provisioning cases passed. Scoped services tsgo, changed-file lint, formatting, and independent review passed. This commit does not change runtime timeout behavior; the independent backstop finding remains unresolved. * fix(process): separate broker execution deadlines from output drain Give brokered command wrappers an execution-only deadline with one second of scheduling grace. The broker checks the native root state, retains configured kill escalation, clears the backstop on exit or earlier host cancellation, and reports accepted timeouts even after a cooperative zero exit. Native commands retain their local primary watchdog. Preserve observed root exits while EOF or broker results are pending. Apply the existing 100ms idle and 1000ms hard output drain bounds to successful tree roots, and join owned descendants without rewriting the root exit status. Raw Execa timeout contracts remain unchanged. Validation: 250 process tests passed with one platform skip, including live broker execution with frozen Gateway timers; wrapper inventory and both provisioning cases passed. Core and services test tsgo, changed-file lint and format, and independent review passed. Deterministic deadline regressions take 3.77s standalone. The live broker proof takes 40.06s wall with 2.47s test execution; its real process and IPC are required to prove an independently running deadline, while shared worker artifact setup accounts for most of the overhead. * fix(process): preserve descendant deadlines with bounded EOF grace Restore the successful owned-tree output contract from #140927: retain descendant output until the command deadline and preserve timeout classification for held pipes. Remove early output release and group termination after a successful root exit. At the deadline, give an already-successful root one fixed 100ms EOF grace using the existing stdio grace constant. Both streams reaching EOF preserve the exit result; a held stream enters the existing timeout and cleanup path. Keep runExec and non-tree post-exit handling, the broker execution-only backstop, and broker timeout propagation. Validation: 314 process tests passed with one platform skip, including all requested process ownership suites. The 12-case deadline regression file passed in 5.72s wall; wrapper inventory and both provisioning cases passed. Core and services test tsgo, changed-file lint/format, and full-branch P2 autoreview with the macOS private temporary directory passed. * test(daemon): let systemd deadline decisions settle after expiry Command deadlines now take their timeout decision one timer turn after the deadline fires. The systemd availability test advanced fake time by exactly the deadline, leaving that decision pending until the real child exited and CI's 10 s test timeout expired. Advance to the next timer after the deadline. Failed 5/5 before, passes 5/5 after; process deadline suites pass (76). * test(process): settle deferred deadlines in consumer tests Advance fake clocks through the queued deadline decision before asserting cancellation or awaiting construction and process settlement. Preserve MCP authority, exec liveness, and native process-group cleanup assertions. Keep the production timer: setImmediate preserves native exit handling but still requires another fake-clock tick. No new real waits or child processes are introduced.
…ent loop lags (openclaw#159578) * fix(process): preserve exits across delayed deadlines Let pending child notifications run before accepting process deadlines, and preserve exited commands whose drained output precedes broker result delivery. Keep inherited-pipe deadlines and existing cancellation, output limits, and process-tree cleanup. Use one watchdog for native and brokered runExec calls. Remove supervisor timeout inference based on delayed result observation. This prevents successful Gateway subprocesses from becoming spurious timeout failures during event-loop stalls. Validation: deterministic regressions fail before their fixes; 126 focused tests pass with one platform skip; related supervisor and idle-timeout tests pass. Core and all 25 selected test typecheck graphs, changed-file lint, and independent review pass. The full changed-check command was stopped under the host time limit during import-cycle scanning after its preceding gates passed. * build(pr): add the shared process deadline to the PR wrapper inventory * test(process): isolate deadline regression spawn fixtures Mock the spawn boundary for deterministic deadline tests so their fake children do not load the unrelated spawn and worker runtime closure. Keep all nine behavior assertions; standalone wall time falls from 30.84 seconds to 3.15 seconds. Validation: 208 process tests passed with one platform skip; PR wrapper inventory and both requested provisioning cases passed. Scoped services tsgo, changed-file lint, formatting, and independent review passed. This commit does not change runtime timeout behavior; the independent backstop finding remains unresolved. * fix(process): separate broker execution deadlines from output drain Give brokered command wrappers an execution-only deadline with one second of scheduling grace. The broker checks the native root state, retains configured kill escalation, clears the backstop on exit or earlier host cancellation, and reports accepted timeouts even after a cooperative zero exit. Native commands retain their local primary watchdog. Preserve observed root exits while EOF or broker results are pending. Apply the existing 100ms idle and 1000ms hard output drain bounds to successful tree roots, and join owned descendants without rewriting the root exit status. Raw Execa timeout contracts remain unchanged. Validation: 250 process tests passed with one platform skip, including live broker execution with frozen Gateway timers; wrapper inventory and both provisioning cases passed. Core and services test tsgo, changed-file lint and format, and independent review passed. Deterministic deadline regressions take 3.77s standalone. The live broker proof takes 40.06s wall with 2.47s test execution; its real process and IPC are required to prove an independently running deadline, while shared worker artifact setup accounts for most of the overhead. * fix(process): preserve descendant deadlines with bounded EOF grace Restore the successful owned-tree output contract from openclaw#140927: retain descendant output until the command deadline and preserve timeout classification for held pipes. Remove early output release and group termination after a successful root exit. At the deadline, give an already-successful root one fixed 100ms EOF grace using the existing stdio grace constant. Both streams reaching EOF preserve the exit result; a held stream enters the existing timeout and cleanup path. Keep runExec and non-tree post-exit handling, the broker execution-only backstop, and broker timeout propagation. Validation: 314 process tests passed with one platform skip, including all requested process ownership suites. The 12-case deadline regression file passed in 5.72s wall; wrapper inventory and both provisioning cases passed. Core and services test tsgo, changed-file lint/format, and full-branch P2 autoreview with the macOS private temporary directory passed. * test(daemon): let systemd deadline decisions settle after expiry Command deadlines now take their timeout decision one timer turn after the deadline fires. The systemd availability test advanced fake time by exactly the deadline, leaving that decision pending until the real child exited and CI's 10 s test timeout expired. Advance to the next timer after the deadline. Failed 5/5 before, passes 5/5 after; process deadline suites pass (76). * test(process): settle deferred deadlines in consumer tests Advance fake clocks through the queued deadline decision before asserting cancellation or awaiting construction and process settlement. Preserve MCP authority, exec liveness, and native process-group cleanup assertions. Keep the production timer: setImmediate preserves native exit handling but still requires another fake-clock tick. No new real waits or child processes are introduced.
Related: #132180 (node-session completion delays and execution outcomes). This replaces only its process-output lifetime slice; the original remains open while the other slices are handled.
What Problem This Solves
Fixes an issue where command users could lose quiet descendant output before the configured command deadline, or keep waiting on descendants after the command had already failed. A later deadline could also replace the command's original failure with a timeout result.
Why This Change Was Made
Make the command owner retain successful, tree-owned POSIX output until its existing deadline, while failed or terminated commands enter bounded diagnostic drainage and owned descendant cleanup immediately. Keep a selected process group as the signal target throughout cleanup rather than falling back to its reusable positive PID, preserving current main's force-and-observe and PID-incarnation checks.
User Impact
Commands retain expected output and report their original failure while cleaning up owned descendants. Existing deadlines, output limits, explicit restrictions, and Windows retired-root behavior remain unchanged. Cleanup still reports uncertainty when termination cannot be proved; this does not promise containment of escaped descendants.
No configuration, schema, dependency, or public API change. Production is +69/-69 (net zero); tests are +341/-107 (net +234). The obsolete group-to-PID fallback and duplicate child-exited flag are removed.
Evidence
Tests-only reproduction on unchanged production at
3de516d21fc4bb05e4c9166c3be9a985b53f5a92: 9 intended failures, 6 passes, 90 unselected. The failing cases cover late drain attachment, failed-root cleanup, quiet inherited pipes, and selected-group targeting.Post-fix proof: 161 tests passed, four platform skips, including real POSIX child/descendant/escaped-pipe cases, no-output deadlines, and local-provider lifecycle coverage. Readiness handshakes precede policy-clock advancement; no timeout or grace budget was increased.
The packaged build passed in 257.647 seconds; all changed checks passed in 517.334 seconds. Both receipts bind the same unchanged candidate tree,
4e92d18397babbae8ca1e483e6e60275a11f186c. Two earlier build attempts were stopped by CPU admission before executing, not build failures.Independent isolated Codex review returned scoped-clean at P0, with no accepted/actionable findings. Exact-head CI 34091063703 and the required gate passed. The native Windows job passed both default and explicit tree modes for success/failure, plus the real nested Node timeout integration case in 60.502 seconds. ClawSweeper's review reports no findings or before-merge requirements.
Current main added a separate command-cleanup scope after this branch's base. An additional 37 tests passed on GitHub's merge tree
cab1a08cca3ab402d3ddc852be6e9614fdadaa67(main parentd8af304112659dda862df8bde111cae2ba1b1dc6plus exact PR head2aa7aa7f0922c263919a5ec1cdb5d1e8592ede7b). The inspected new scope and caller match maince174871076b4a5db8524ef8eb8ea17a3abe97fabyte-for-byte; all eleven PR files match the reviewed candidate. This proof used its own checkout and dependencies, without rebasing or modifying the PR.Dependency inspection covered Execa's separate exit/stream settlement and Codex's exact-group signaling contract. The Windows fixture's Node/libuv job behavior does not establish general descendant containment or Bun equivalence.