Skip to content

fix(process): retain cleanup ownership through canceled startup - #138093

Merged
steipete merged 2 commits into
mainfrom
steipete/supervisor-construction-cleanup
Sep 4, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/supervisor-construction-cleanup

Conversation

@steipete

@steipete steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

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, parent 3d6c4d959e48a7e56bf5ff5339ccd80c7e9f1a8f). 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 from dbae8fb9092dfa5aeae8d041c5374aa45dc34a7c still matches the unchanged production files.

  • Pre-fix regression proof: eight focused cases failed against unchanged production at 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.
  • Owner/caller tests: 223 tests passed across the supervisor and TUI local-shell caller suites. A further direct-child regression caught a secret-write error arriving after child closure; the closed-child guard was red/green, and all 44 direct-child tests passed. The final cleanup-contract assertion was then rerun with all 27 supervisor tests passing.
  • Build: pnpm build qaRuntime passed for the final production source. Existing third-party eval warnings were not suppressed.
  • Changed-scope validation: the complete original 15-file check-changed run 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.
  • CI fixture repair: the initial compact-small-4 run exposed agent-exec.construction.test.ts deliberately 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.
  • Independent review: fresh full-candidate Codex autoreview after the CI fixture repair passed at its P0 threshold with no accepted/actionable findings.
  • CI: initial run 33856119607 also had a Windows checkout-only failure after three 90-second fetch attempts; no tests ran in that job. Fresh exact-head run 33861250034 passed, with zero pending checks in the final watcher observation. No timeout or CI gate was weakened.

Scoped test command:

node scripts/run-vitest.mjs src/process/supervisor src/tui/tui-local-shell.test.ts

Changed-scope check command:

node scripts/check-changed.mjs -- \
  docs/gateway/background-process.md \
  src/process/supervisor/adapters/child.secret-abort.test.ts \
  src/process/supervisor/adapters/child.service-lifecycle.test.ts \
  src/process/supervisor/adapters/child.test.ts \
  src/process/supervisor/adapters/child.ts \
  src/process/supervisor/adapters/pty.test.ts \
  src/process/supervisor/adapters/pty.ts \
  src/process/supervisor/service-child-relay-host.test.ts \
  src/process/supervisor/service-child-relay-host.ts \
  src/process/supervisor/supervisor.cancellation-reason.test.ts \
  src/process/supervisor/supervisor.forced-settlement.real.test.ts \
  src/process/supervisor/supervisor.scope-extinction.test.ts \
  src/process/supervisor/supervisor.test.ts \
  src/process/supervisor/supervisor.ts \
  src/process/supervisor/types.ts

CLI fixture check:

node scripts/check-changed.mjs -- src/commands/agent-exec.construction.test.ts

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.

CI=true OPENCLAW_VITEST_MAX_WORKERS=2 OPENCLAW_VITEST_INCLUDE_FILE=.artifacts/supervisor-construction-cleanup/ci-original-order-1FZG0I/order.json OPENCLAW_VITEST_SHARD_NAME=agentic-commands-agent-channel node scripts/run-vitest.mjs run --config .artifacts/supervisor-construction-cleanup/ci-original-order-1FZG0I/vitest.commands.original-order.config.ts --no-cache

Real live TUI proof

Ran the built openclaw.mjs tui --local entrypoint 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 code 0, 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

  • Native Windows execution was not run; Windows relay-host closure/uncertainty and tree-before-root ordering are covered by the owner tests.
  • A POSIX anchor's closing receipt and self-exit can precede a killed group member's physical termination. This repair therefore preserves construction cleanup uncertainty instead of upgrading that receipt to unconditional success. Follow-up: review strict whole-group extinction for the broader already-ready path as a separate owner-mechanism decision.
  • Production LOC: +240/-198, net +42. The additional state is the previously missing construction/cleanup ownership and observed-close distinction. The patch removes detached late cleanup and shares terminal construction-result settlement; it adds no second supervisor, compatibility stack, configuration switch, or timeout extension. Tests: +294/-101, net +193, including movement into the existing construction suite and the CLI fixture ownership repair. Docs: +6/-0.

Live TUI after the synthetic root command exits

Live TUI exits successfully after joining owned cleanup

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).
@clawsweeper

clawsweeper Bot commented Sep 4, 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 gateway Gateway runtime size: L maintainer Maintainer-authored PR labels Sep 4, 2026
@steipete
steipete marked this pull request as ready for review September 4, 2026 08:59
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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 Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 6:12 AM ET / 10:12 UTC.

ClawSweeper review

What this changes

This 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 provenance

Possible 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
Reviewed head: 382df20b0586550827b15feec567d23af704db40

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A solid owner-boundary repair with targeted cross-adapter coverage and no actionable source finding.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository State identifies a MEMBER author, so the external-contributor proof gate does not apply; the PR body additionally documents an isolated built-TUI after-fix run for the process-lifecycle surface.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository State identifies a MEMBER author, so the external-contributor proof gate does not apply; the PR body additionally documents an isolated built-TUI after-fix run for the process-lifecycle surface.
Evidence reviewed 6 items Current-main behavior: Current main races construction against cancellation and returns a terminal result while scheduling late adapter cleanup without a retained construction cleanup join; the PR remains necessary.
Supervisor owner-boundary repair: The PR reserves a supervisor cleanup promise before adapter construction, receives the adapter cleanup promise, and resolves or rejects the retained join only after that lifecycle settles.
Adapter cleanup publication: The child adapter publishes cleanup before authority checks and private-input delivery, then resolves it only on observed closure; this prevents constructor failure from being treated as no process ownership.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

  • Resolve merge risk (P1) - This bug fix adds 42 net production lines to availability-critical lifecycle code; the added state represents the pre-readiness cleanup handoff, but mistakes here can cause shutdown to wait indefinitely or report cleanup uncertainty.
Agent review details

Security

None.

PR surface

Source +42, Tests +193, Docs +6. Total +241 across 16 files.

View PR surface stats
Area Files Added Removed Net
Source 5 240 198 +42
Tests 10 294 101 +193
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 540 299 +241

Review metrics

Metric Value Why it matters
Production versus test LOC production +240/-198 (net +42); tests +294/-101 (net +193); docs +6/-0 The production growth is concentrated in the cleanup-ownership handoff across supervisor and adapters, with focused lifecycle regressions carrying most added coverage.

Merge-risk options

Maintainer options:

  1. Retain explicit cleanup uncertainty (recommended)
    Merge with the documented contract that an unconfirmed cleanup rejects scope or shutdown joining instead of manufacturing a successful cleanup result.

Technical review

Best 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.

Labels

Label justifications:

  • P2: This fixes a bounded but real process-cleanup correctness regression without evidence of a broad current outage.
  • merge-risk: 🚨 availability: The change alters cancellation, cleanup joining, and shutdown settlement, where a regression can leave processes running or make shutdown fail.
  • 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: Repository State identifies a MEMBER author, so the external-contributor proof gate does not apply; the PR body additionally documents an isolated built-TUI after-fix run for the process-lifecycle surface.

Evidence

What I checked:

Likely related people:

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

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 (1 earlier review cycle)
  • reviewed 2026-09-04T09:30:57.496Z sha dbae8fb :: blocked before merge. :: none

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.
@openclaw-barnacle openclaw-barnacle Bot added the commands Command implementations label Sep 4, 2026
@steipete

steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor Author

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.ts

223 tests passed, with additional focused direct-child and supervisor reruns. The final production build passed:

pnpm build qaRuntime

The 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.ts

The 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 /exit returned zero and that descendant was absent. The lead inspected both screenshots; ClawSweeper's inability to retrieve them was a DNS limitation in its review environment. Native Windows local live execution and strict whole-group extinction for the broader already-ready POSIX path remain the explicitly documented proof limits/follow-up. The automatic 10:12 UTC review now covers this exact head with high confidence and no code findings. Its remaining +42-line availability tradeoff is accepted with the reviewer-recommended contract: retain explicit cleanup uncertainty rather than manufacture success. Those lines express the missing construction/cleanup lifetime and observed-close distinction; caller-side waiting or deletion cannot recover ownership after startup returns. Exact-head CI and the owner/caller proofs above validate that boundary.

@steipete
steipete merged commit 99cbe32 into main Sep 4, 2026
185 checks passed
@steipete
steipete deleted the steipete/supervisor-construction-cleanup branch September 4, 2026 10:31
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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.

Process cleanup joins can report success after canceled startup

1 participant