Repository navigation
fix(process): retain cleanup ownership through canceled startup - #138093
Conversation
Keep timeout and cancellation results responsive while scope and shutdown joins retain the adapter construction and cleanup outcome. Register cleanup before fallible startup work, preserve service identity-loss uncertainty, and distinguish observed child/PTY closure from result fallbacks. Use the canonical tree-first path for direct-child startup failures and retire signaling after observed closure. Preserve private-input revocation, first terminal reasons, output fencing, and independent anchor cleanup. Regression and live TUI proof cover the owner boundary without changing configuration, schemas, protocols, dependencies, or timeout durations. Fixes #138078. Related: #127514 (older direct-child secret-FD cleanup issue; not closed).
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: blocked before merge. Reviewed September 4, 2026, 6:12 AM ET / 10:12 UTC. ClawSweeper reviewWhat this changesThis PR keeps canceled or timed-out process startup cleanup owned by the supervisor so scope retirement and Gateway shutdown wait for confirmed cleanup or report uncertainty. Regression provenancePossible regression — probable (reviewed change; known regression link). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 1 item remains Keep open: current main still returns a canceled-startup result before the late adapter cleanup is joinable, while this PR moves that ownership into the process supervisor and covers the child, PTY, and service-relay paths. No concrete introduced correctness defect was found. Priority: P2 Review scores
Verification
How this fits togetherThe process supervisor starts child and PTY commands for CLI, TUI, and Gateway callers. It separates a prompt terminal result from the later physical cleanup that scope retirement and shutdown must own. flowchart LR
A[CLI, TUI, or Gateway request] --> B[Process supervisor]
B --> C[Child, PTY, or relay startup]
C --> D[Prompt terminal result]
C --> E[Cleanup owner]
E --> F[Scope retirement]
E --> G[Gateway shutdown]
E --> H[Confirmed closure or uncertainty]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +42, Tests +193, Docs +6. Total +241 across 16 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep cleanup ownership in the supervisor from before adapter construction through adapter-specific closure; a caller-side guard or net-neutral deletion cannot retain late cleanup without again conflating timeout results with process extinction. Do we have a high-confidence way to reproduce the issue? Yes — source-reproducible: current main’s construction race returns before a retained cleanup join exists, and the PR’s focused tests exercise late adapter completion through both scope and shutdown. The read-only review did not execute the test suite. Is this the best way to solve the issue? Yes — reserving the cleanup join at the supervisor before fallible adapter construction is the owning-layer repair; caller-side waiting cannot recover ownership once startup returns. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 671b9ca211f7. LabelsLabel 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)
|
Keep the real command, supervisor, and process adapters in the construction fixture, but give its deliberately failed cleanup owner a test-local lifetime. Assert cleanup independently of the timeout result and physical child death, preserving Windows direct-child closure semantics. The unchanged fixture reproduced the CI singleton-drain failure locally. The repair passed all 41 command/channel files in their original CI order (742 tests passed, two platform skips), including the five files that the failed teardown previously prevented from running. Refs #138093 and #138078.
|
Pre-merge verification for 382df20b058: exact-head CI 33861250034 is green, with zero pending checks in the final repository watcher observation. Addressed the ClawSweeper CI/rank-up follow-up. The compact-small-4 failure was the existing CLI construction fixture intentionally leaving cleanup identity loss in the global supervisor. The unchanged test reproduced the same singleton-drain error locally. It now owns a real test-local supervisor and explicitly checks cleanup separately from the timeout result and physical child death; no adapter mock, suppressed teardown, isolation override, or longer timeout was introduced. All 41 command/channel files passed in the recorded original CI order: 742 passed, two platform skips, including the five files the failed teardown had previously prevented from running. The initial Windows failure was earlier in Checkout: three 90-second fetch attempts, exit 124, before any tests. The new head's CI re-exercised that lane successfully. The follow-up is test-only; production remains +240/-198, net +42, for the missing cleanup lifetime and observed-close boundary. Tests are +294/-101, including consolidation/movement; docs are +6. Production proof remains applicable because the follow-up did not change production files: node scripts/run-vitest.mjs src/process/supervisor src/tui/tui-local-shell.test.ts223 tests passed, with additional focused direct-child and supervisor reruns. The final production build passed: pnpm build qaRuntimeThe original 15-file changed gate and the added fixture's complete gate both passed: node scripts/check-changed.mjs -- src/commands/agent-exec.construction.test.tsThe exact original-order replay command and temporary-sequencer scope are recorded in the PR Evidence section. Fresh full-candidate isolated Codex autoreview after the fixture repair is clean at P0. Native review artifacts are bound to the current head. The real isolated TUI proof remains attached: the synthetic descendant outlived its root, then |
|
Merged via squash.
|
…claw#138093) * fix(process): retain cleanup ownership through canceled startup Keep timeout and cancellation results responsive while scope and shutdown joins retain the adapter construction and cleanup outcome. Register cleanup before fallible startup work, preserve service identity-loss uncertainty, and distinguish observed child/PTY closure from result fallbacks. Use the canonical tree-first path for direct-child startup failures and retire signaling after observed closure. Preserve private-input revocation, first terminal reasons, output fencing, and independent anchor cleanup. Regression and live TUI proof cover the owner boundary without changing configuration, schemas, protocols, dependencies, or timeout durations. Fixes openclaw#138078. Related: openclaw#127514 (older direct-child secret-FD cleanup issue; not closed). * test(process): own CLI construction cleanup uncertainty Keep the real command, supervisor, and process adapters in the construction fixture, but give its deliberately failed cleanup owner a test-local lifetime. Assert cleanup independently of the timeout result and physical child death, preserving Windows direct-child closure semantics. The unchanged fixture reproduced the CI singleton-drain failure locally. The repair passed all 41 command/channel files in their original CI order (742 tests passed, two platform skips), including the five files that the failed teardown previously prevented from running. Refs openclaw#138093 and openclaw#138078.
Closes #138078 — process cleanup joins can report success after canceled startup.
Related: #127514 — the older direct-child secret-FD rejection/root-only cleanup problem; this PR does not automatically close that issue.
What Problem This Solves
Fixes an issue where operators stopping a command scope or shutting down OpenClaw could receive a successful cleanup result after command startup timed out or was canceled, even though process cleanup was still outstanding or could not be confirmed.
Timeout results themselves must stay responsive. The problem was treating that terminal result—or a constructor rejection after spawn—as if it also completed cleanup.
Why This Change Was Made
Each admission now retains a separate cleanup join across adapter construction. Child, PTY, and service-relay owners publish their cleanup outcome before fallible private-input or readiness work. Late successful constructors are killed and joined before disposal; failed constructors retain the cleanup owner's result, including uncertainty. Failed admissions remain observable to later scope/shutdown joins without looping over already-rejected joins or signaling retired owners.
Direct-child construction failures reuse the existing tree-first cleanup path, with observed closure retiring further signals. Child/PTY result fallbacks remain bounded terminal results, not manufactured exit confirmation. The existing service construction-abort identity-loss policy and independent anchor cleanup are preserved; no stronger POSIX extinction receipt is invented.
Raw-parent comparison locates the early-return regression in #136507 (
693c16dbccce1144badd66d9afd7929b456506f7, parent3d6c4d959e48a7e56bf5ff5339ccd80c7e9f1a8f). The repair does not change configuration, storage schemas, protocols, dependencies, or timeouts.User Impact
A command can still report its timeout promptly. Scope retirement and shutdown now wait for their cleanup owner or report that cleanup is uncertain, rather than proceeding on false success. Private input remains withheld after admission is revoked, late output remains fenced, and ordinary successful commands retain their existing behavior.
This is not a claim of a default automatic-triage failure. The automatic-triage worktree and its source/proof were not used or modified.
Evidence
Candidate head:
382df20b0586550827b15feec567d23af704db40. The follow-up changes only a test fixture; production build/live proof fromdbae8fb9092dfa5aeae8d041c5374aa45dc34a7cstill matches the unchanged production files.19f22ef90731529624c159871ee89cb685d79c1d. They cover late adapter success, post-spawn rejection, immediate/later scope and shutdown joins, real unread-secret service construction, tree-first direct-child cleanup, PTY fallback uncertainty, and real inherited-pipe forced settlement. The exact candidate production patch was restored and byte-compared after the test process exited.pnpm build qaRuntimepassed for the final production source. Existing third-partyevalwarnings were not suppressed.check-changedrun passed (exit 0): formatting, core/test typechecks, changed-file lint, dead-export scans, import cycles, and all selected repository guards. The added CLI fixture separately passed its full changed-scope gate. Earlier test-only lint failures were fixed by consolidating construction tests into their existing suite and asserting the required cleanup contract; no file-size suppression or weakened check was added.agent-exec.construction.test.tsdeliberately leaving a rejected cleanup owner in the global supervisor. The unchanged test reproduced the same singleton-drain failure locally. It now uses a real test-owned supervisor through the existing accessor and explicitly asserts cleanup separately from terminal timeout and physical child death. The final candidate passed all 41 command/channel files in their original CI order: 742 tests passed, two platform skips, including the five files previously blocked by teardown. Production code was not changed for this follow-up.Scoped test command:
Changed-scope check command:
CLI fixture check:
The original-order replay used the stock commands config with a temporary Vitest sequencer that only pins the 41 file paths captured before editing. It kept serial files, non-isolated workers, and the normal cleanup hooks; the observed order was compared against the captured list afterward.
Real live TUI proof
Ran the built
openclaw.mjs tui --localentrypoint with a fresh home/state/config created by the repository's isolated test-state helper. No operator Gateway or saved operator configuration was used, and no model inference was exercised.Through the actual TUI, approved one local
!command that spawned a synthetic descendant retaining the lineage descriptor and then let the root command exit. The TUI displayed[local] exit 0; a native process check independently confirmed the descendant was still alive. Submitted/exit, observed TUI exit code0, and independently confirmed that the same descendant PID no longer existed.The attached command-complete and exited screenshots were inspected and contain only the synthetic test session. The screen recorder produced black frames and was not used as evidence.
Scope and remaining proof limits