Repository navigation
fix(process): a finished command is reported as timed out when the event loop lags - #159578
Conversation
|
🦞👀 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: blocked before merge. Reviewed September 28, 2026, 1:43 AM ET / 05:43 UTC (Revision 9). ClawSweeper reviewWhat this changesAdjusts Gateway command runners, the spawn broker, and the process supervisor so delayed exit notifications do not turn completed commands into timeouts, with regression tests and a wrapper inventory update. Merge readiness⛔ Blocked before merge - 3 items remain Keep open: current main still has the reported timeout race, and the branch has credible direct-path proof. The previously identified descendant-cleanup defect remains a merge blocker. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw runs agent and Gateway helper commands through its process runner. Local or brokered child processes produce exit and output events that the runner turns into command results and cleanup. flowchart LR
A[Agent or Gateway command] --> B[Process runner]
B --> C[Local child or spawn broker]
C --> D[Exit and output events]
E[Configured timeout] --> F[Deadline decision]
D --> F
F --> G[Command result and cleanup]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +82, Tests +500, Other +1. Total +583 across 28 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Route broker-accepted execution timeouts through the existing process-tree termination owner before settlement, preserve the selected group identity, and prove descendant extinction through the real broker. Do we have a high-confidence way to reproduce the issue? Yes. The PR gives a concrete production-helper run with a short git command and a blocked event loop, and current main retains the responsible timeout path; this read-only review did not execute it. Is this the best way to solve the issue? No, not yet. Deferring the deadline decision addresses the reported exit-ordering race, but the independent broker deadline must preserve the existing owned-tree cleanup contract. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 45b00bdd13c1. LabelsLabel changes: No label changes. Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (8 earlier review cycles)
|
fc2e8be to
254de9c
Compare
254de9c to
ae114fe
Compare
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.
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.
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.
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.
ae114fe to
1f46232
Compare
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).
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.
What Problem This Solves
Fixes: on a busy Gateway, a subprocess that already exited successfully can be reported as timed out (exit 124) because the overdue deadline timer runs before Node delivers the queued exit notification.
User Impact
User impact: short commands the Gateway runs (git, Crabbox, helper scripts) no longer fail as "timed out" just because the event loop was briefly busy when they finished; their real exit status and output are used. Commands that genuinely hang still time out, have their process tree killed, and report a timeout with the existing grace and settlement behavior.
Behavior note: a command that finishes and is fully drained before the deadline decision runs is reported with its real result even if the exit landed slightly after the nominal deadline during event-loop lag; the supervisor no longer infers a timeout from elapsed time alone. Deadline, kill, and grace ownership are otherwise unchanged.
Why This Change Was Made
Found during cloud-session stress testing: a managed
git initreturned 124 although it succeeded instantly when run directly. Reproduced with the production helper —runCommandWithTimeout(["git","--version"], { timeoutMs: 20 })plus a 250 ms event-loop block returned 124 after ~291 ms with Git's successful stdout. The deadline timer ran before the queued childexitcallback populated the exit state, and the accepted timeout then normalized native success to 124. Checkingchild.exitCodeinside the timer is not enough on current Node (v26 assigns it inside the exit callback just before emitting). All three owners had the same ordering bug:exec-runner.ts: deadline and no-output timers now decide through a shared deadline helper that defers the decision one I/O turn and preserves an exited, fully drained child;exec.tsrunExec: native and spawn-broker transports use the same corrected deadline (execa's owntimeoutis no longer used, so both transports share one owner);supervisor.ts: timeout classification uses completed process state; the elapsed-time inference (resolveElapsedTimeoutReason, which classified any exit observed after the deadline as a timeout) is removed.Production +17 lines.
Evidence
runExec.pnpm test src/process/exec-runner.timeout.test.ts --maxWorkers=1: main3 failed | 2 passed; here 9 passed, 30.8 s wall. Supervisor regression ("preserves a queued successful exit") fails on main.pnpm test src/process/exec-runner.timeout.test.ts src/process/exec.test.ts src/process/exec.windows.test.ts src/process/child-process.test.ts src/process/spawn-broker/command-startup.test.ts --maxWorkers=1: 126 passed, 1 skipped (71.7 s). Supervisor suites (timeout-overflow, output-fence, readiness, output-activity): 20 passed.Follow-up (ClawSweeper: independent broker deadline; test cost)
timeoutalso removed the spawn broker's independent deadline. Putting it back as a padded Execa timeout reintroduced the original bug: in the broker, Execa's timeout covers the whole subprocess promise, including output drain that waits on the stalled Gateway. With a 200 ms deadline plus 100 ms margin, a child that exited at 101 ms was still reportedtimedOutafter a 453 ms parent stall. The broker now enforces an execution-only deadline instead (timeout + 1 s; the margin only absorbs broker scheduling lag). It kills the root only while the root is still running, using the configured kill semantics, and marks the resulttimedOut. Root exit clears it, and so does an earlier host cancellation. Because the check looks only at the root, it can never relabel an exited child. The Gateway's deferred decision stays primary. Native (non-broker) commands keep the Gateway-side watchdog only, since a second timer in the same process adds no independence.runExecand non-tree runs, which already had a bounded post-exit drain. Successful owned trees keep the fix(process): preserve output and cleanup after command exit #140927 contract (descendant output stays under the command deadline; held pipes still time out). At the deadline they get one fixed 100 ms EOF grace (EXIT_STDIO_GRACE_MS) before the existing timeout path.pnpm test <file> --maxWorkers=1):exec-runner.timeout.test.ts12 tests / 5.7 s (was 30.8 s before moving its mock boundary toexec-spawn). The live-broker file (execution-deadline.test.ts, real broker process with frozen Gateway timers) takes 40 s wall but only 2.5 s of test execution: shared worker-artifact setup dominates, and only real IPC can prove the deadline runs independently of Gateway callbacks. The expanded process run passes 314 tests (1 platform skip), including every fix(process): preserve output and cleanup after command exit #140927 ownership suite with its original expectations. Core and services tsgo, lint, format, and full-branch P2 review are clean.