Skip to content

fix: keep child cleanup failures from crashing the Gateway - #150427

Merged
steipete merged 3 commits into
mainfrom
upd/relay-host-discarded-rejection
Sep 17, 2026
Merged

steipete merged 3 commits into
mainfrom
upd/relay-host-discarded-rejection

Conversation

@steipete

@steipete steipete commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Related: #144911, #144941

What Problem This Solves

Fixes unhandled rejections from child cleanup and early supervised-process failures, and missing error stacks in Gateway stability bundles.

User Impact

Cleanup failures remain visible to their callers without escaping as process-level rejections. Stability bundles retain the error's redacted stack, bounded to 8,000 UTF-16 code units, so subsequent reports identify its origin.

The 2026.9.4 MCP crash path is already contained on main by #144941, which is unreleased and was not included in 2026.9.4. This PR closes the remaining unobserved-promise escape paths and makes dumps carry the producer's stack; it does not claim a new reproduction of that field crash on current main.

Why This Change Was Made

The relay host now retains authority-finalization outcomes and joins them into its published cleanup promise. Its shared identity-loss recorder also settles cleanup when error observers throw, including cancellation and lineage-notification failures. Tree signaling is owned through cleanup, and the supervisor records eager run outcomes before any caller requests them. These changes preserve observed root results, output drainage, repeated cancellation requests, and the existing cleanup deadline. Uncertain extinction remains a failure rather than being reported as successful cleanup.

Stack serialization reuses the existing redaction and shutdown-stack bound. Older bundles without a stack remain readable. No configuration, CLI options, dependencies, schema versions, or update-driver behavior change; the runtime fix takes effect when the Gateway starts on the candidate.

Integration with current main preserves #150392 control-EOF joining and deferred expiry, plus #150306 retained-handle retirement and forced-exit diagnostics. Rejected lineage and polling joins flow through the retained finalization outcome; unexpected finalization failures also release the relay IPC receipt hold. The 30-line service-child-cleanup.ts mechanism owns completion and finalization observation. Following #150564, spawnServiceChildRelay is its sole creation and publication site: it publishes the retained cleanup promise before broker transport readiness and returns the same object to the host. The host binds finalization to that object and remains the lifecycle owner within the 700-line cap. Cleanup regressions moved unchanged alongside the mechanism and still drive the public relay adapter.

Retained-handle escalation and forced-exit diagnostics remain with #150306's retirement mechanism. #149158 covers worker cleanup across crashes and shutdown; this PR preserves those authority decisions.

Thanks to @itanyplus, @waynegault, @chachi-max, and @kip-claw for the reports and field evidence.

Evidence

  • Against the original relay owner, four fault cases each emitted one unhandledRejection: close before/after root result, cancellation notification, and a rejected async group poll. They now return recorded cleanup failures. Tree-signaling and eager-supervisor result failures also failed before the repair and pass afterward.
  • The stack regressions failed before the repair on the missing field. They now cover redaction, readback, UTF-16-safe truncation, and bundles without stacks.
  • Final integration verification: 395 tests passed, 6 skipped across the original three shards, followed by 64 passing spawn-broker tests. The new boundary regression verifies cleanup publication before transport readiness and delayed observation of a rejected broker handoff without an unhandled rejection. The original-order Windows cancellation tests and the pending/out-of-order signaling cases preserve existing timing and settlement, including disposal after the root result.
  • Prior-revision macOS source probes used real MCP children and a listening Gateway before the spawn-broker integration. A 30-second initialize timeout kept HTTP health at 200 with zero unhandled rejections. Killing the fixture's own anchor during cleanup produced the exact missing-receipt error, recorded cleanup as uncertain, and also kept HTTP health at 200 with zero unhandled rejections. Both Gateways and their fixtures stopped cleanly. These are owner-boundary probes, not a Linux/systemd agent-turn reproduction.
  • pnpm check:changed: passed, including typechecks, lint, line caps, and all selected guards. Fresh Codex branch review (--mode branch --base origin/main --max-priority P1): scoped-clean at 2f5eaf7c1a371ed9a95500a423464ab29b3d8a3a. This review supersedes the earlier review after integration with the broker-owned cleanup creation site.
  • Production: +162/-104 LOC (net +58). Tests: +306/-7 LOC (net +299). Documentation: +1/-1 LOC. Production growth retains and joins previously unobserved operations without adding an alternate process owner or weakening extinction checks.

No lazy-loading or worker-entrypoint boundary changed; a build was not required for this revision.

Join authority finalization and admitted tree signals into recorded cleanup
outcomes. Retain eager run failures until callers request the result, keep
cleanup deadlines armed through root settlement and disposal, and serialize
bounded redacted error stacks in stability bundles.

The 2026.9.4 MCP SDK close path is already contained by #144941 on main.
This change covers remaining owner failures established by fault injection.

Thanks to itanyplus and waynegault for the reports and field evidence.
Related: #144911, #144941.
Record observer failures at the identity-loss owner so cancellation and lineage rejection handlers cannot escape cleanup settlement. Cover cancellation and asynchronous group-poll faults while retaining known root results. Related: #144911.
@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M maintainer Maintainer-authored PR labels Sep 17, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 17, 2026
@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 17, 2026, 6:07 AM ET / 10:07 UTC (Revision 8).

ClawSweeper review

What this changes

The PR contains child-cleanup and early supervised-process rejections while preserving caller-visible failures, and adds bounded, redacted stacks to Gateway diagnostic bundles.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still contains the unobserved failure paths, and the earlier MCP fix does not supersede them. No blocking introduced correctness or security defect was found.

Priority: P2
Reviewed head: e7afd5f2abb9fe096e089d19b0a511246e0d522d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and no blocking defect found.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from the ordinary contributor-proof gate and does not materially expand authority. Reported real macOS Gateway probes cover timeout and missing-receipt containment on an earlier revision; they do not establish current broker-integration proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from the ordinary contributor-proof gate and does not materially expand authority. Reported real macOS Gateway probes cover timeout and missing-receipt containment on an earlier revision; they do not establish current broker-integration proof.
Evidence reviewed 9 items Current main still needs the repair: The relevant supervisor, relay, and diagnostic sources are unchanged between the pinned base and fetched main. Main still discards finishPosixAuthority's returned promise; the branch adds retained finalization observation.
Cleanup ownership and settlement: The shared cleanup object observes rejection immediately, joins finalization, and returns failure to callers. Its production creation site publishes that same promise before broker readiness; the relay retains receipt, lineage, output, retirement, and extinction decisions.
Tree signaling and early results: The child adapter joins admitted hard-kill signaling before successful cleanup and retains the existing cleanup deadline through result settlement and disposal. The supervisor observes eager run outcomes and rethrows failures only through the requested result.
Findings None None.
Security None None.

How this fits together

The process supervisor manages commands and MCP child processes for OpenClaw. It separates command results from cleanup confirmation, while Gateway stability bundles preserve diagnostic evidence when failures occur.

flowchart TD
  A[Commands and MCP children] --> B[Spawn transport]
  B --> C[Child lifecycle owner]
  C --> D[Command result and output]
  C --> E[Cleanup confirmation or failure]
  E --> F[Supervisor and Gateway callers]
  D --> F
  F --> G[Redacted diagnostic bundle]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +58, Tests +299, Docs 0. Total +357 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 6 162 104 +58
Tests 5 306 7 +299
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 469 112 +357

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +58 net lines; tests +299 net lines Production growth is justified by retaining previously unobserved operations, with regressions exercising public adapter and supervisor boundaries.

Technical review

Best possible solution:

Keep failure observation with the existing lifecycle owners while preserving command results, truthful cleanup outcomes, existing deadlines, and backward-readable diagnostics.

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

Yes, for the source-level defects: rejected finalization, tree-signaling, and eager-result promises have identifiable escape paths, exercised by focused fault-injection regressions. This review did not execute them or reproduce the original Linux/systemd field crash.

Is this the best way to solve the issue?

Yes. The patch observes failures at their existing owners, preserves cleanup uncertainty, and reuses diagnostic redaction without adding a competing lifecycle or configuration path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 847aef50adf6.

Labels

Label justifications:

  • P2: This is a bounded reliability repair for remaining source-proven failure paths; the older release's field crash is separately covered by merged MCP containment.
  • 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: The maintainer-authored PR is exempt from the ordinary contributor-proof gate and does not materially expand authority. Reported real macOS Gateway probes cover timeout and missing-receipt containment on an earlier revision; they do not establish current broker-integration proof.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • Vincent Koc: 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 (7 earlier review cycles)
  • reviewed 2026-09-17T01:01:42.830Z sha 9088566 :: blocked before merge. :: none
  • reviewed 2026-09-17T01:35:39.633Z sha 5fc2aae82fbf38923a43685da70f0307a59bbb6b :: needs maintainer review before merge. :: none
  • reviewed 2026-09-17T02:54:31.045Z sha b91d382 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-17T05:09:20.370Z sha b485396 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-17T06:02:41.821Z sha 362eb1f :: needs maintainer review before merge. :: none
  • reviewed 2026-09-17T07:38:57.056Z sha 2f5eaf7c1a371ed9a95500a423464ab29b3d8a3a :: needs maintainer review before merge. :: none
  • reviewed 2026-09-17T09:16:58.395Z sha 071ce2bfe1b7eed7cd0a2780586d67bd4ac3d5b1 :: needs maintainer review before merge. :: none

@steipete
steipete marked this pull request as ready for review September 17, 2026 01:26
@steipete
steipete force-pushed the upd/relay-host-discarded-rejection branch 2 times, most recently from b91d382 to b485396 Compare September 17, 2026 05:02
@steipete
steipete force-pushed the upd/relay-host-discarded-rejection branch 2 times, most recently from 362eb1f to 2f5eaf7 Compare September 17, 2026 07:29
steipete added a commit that referenced this pull request Sep 17, 2026
…0642)

Keep metadata-close Gateway listeners reserved from allocation through startup, preventing intermittent GatewayLockError/EADDRINUSE when another process claims a probed port. The shared fixture transfers the actual HTTP listener to the existing transport and shutdown owners, migrates all three callers, and closes reservations on failed startup or cleanup.

Ordinary Gateway startup retains the existing bind/retry path. There are no user-visible or update behavior changes, new options, schema changes, dependency changes, or timeout increases.

Related: #150427, whose CI exposed the fixture race but did not cause it.

Validation: deterministic collision, real health response, and shutdown port-release regression; focused Linux/macOS fixture proof; HTTP/transport sibling coverage; exact-head CI run 35193350398 green with zero pending checks. Historical unrelated failures remain documented in the PR and were not rerun. Recorded Codex autoreview and exact-head ClawSweeper review found no actionable defects.
@steipete
steipete force-pushed the upd/relay-host-discarded-rejection branch from 2f5eaf7 to 071ce2b Compare September 17, 2026 09:08
Merge current main while retaining #150392 control-EOF joining and deferred expiry. Route extinction wait failures through the retained finalization outcome, and revalidate authority after both observational joins before probing the process group. The PR adds no dependency or protocol changes.
@steipete
steipete force-pushed the upd/relay-host-discarded-rejection branch from 071ce2b to e7afd5f Compare September 17, 2026 10:00
@steipete
steipete merged commit 3477c48 into main Sep 17, 2026
208 checks passed
@steipete
steipete deleted the upd/relay-host-discarded-rejection branch September 17, 2026 10:41
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 17, 2026
Full catalog refreshes could expose provider results before native discovery and its paired auth facts settled, temporarily dropping native model choices. Keep the previous complete catalog, runtime models, and inventory published until the new generation is complete, and restore the previous publication on acquisition failure.

Preserve the five-second foreground bound, scoped provider refreshes, and recorded discovery failures. The worker-boundary regression holds native acquisition to exercise concurrent readers and verifies the final merged catalog.

Related: #150427

Validation: forced-ordering regressions reproduced the defect on macOS and Linux, then passed 20/20 serial runs per platform with the fix. Catalog/model-selection suites passed 641 tests across 41 files; build and changed checks passed. Exact-head CI: https://github.com/openclaw/openclaw/actions/runs/35209693054.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 18, 2026
…nclaw#150642)

Keep metadata-close Gateway listeners reserved from allocation through startup, preventing intermittent GatewayLockError/EADDRINUSE when another process claims a probed port. The shared fixture transfers the actual HTTP listener to the existing transport and shutdown owners, migrates all three callers, and closes reservations on failed startup or cleanup.

Ordinary Gateway startup retains the existing bind/retry path. There are no user-visible or update behavior changes, new options, schema changes, dependency changes, or timeout increases.

Related: openclaw#150427, whose CI exposed the fixture race but did not cause it.

Validation: deterministic collision, real health response, and shutdown port-release regression; focused Linux/macOS fixture proof; HTTP/transport sibling coverage; exact-head CI run 35193350398 green with zero pending checks. Historical unrelated failures remain documented in the PR and were not rerun. Recorded Codex autoreview and exact-head ClawSweeper review found no actionable defects.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 18, 2026
…150427)

Keep child cleanup and eager supervised-process failures visible to callers without letting unobserved rejections crash the Gateway. Publish the retained cleanup promise at the sole spawnServiceChildRelay creation site, join authority finalization and admitted tree signaling, and preserve retained-handle escalation, forced-exit diagnostics, output drainage, and cleanup deadlines. Uncertain extinction remains a failure.

Include redacted error stacks in Gateway stability bundles, bounded to 8,000 UTF-16 code units; older bundles without stacks remain readable. No configuration, CLI option, dependency, schema version, or installed update-driver behavior changes. The runtime repair takes effect when the candidate Gateway starts.

Related: openclaw#144911, openclaw#144941. Preserve integration with openclaw#150306, openclaw#150392, and openclaw#150564. The earlier MCP field-crash path is separately contained by openclaw#144941; this change closes remaining unobserved-promise paths.

Thanks to @itanyplus, @waynegault, @chachi-max, and @kip-claw for the reports and field evidence.

Validation: exact-head CI run 35208176360 is green. Recorded focused proof: 395 tests passed and 6 skipped, followed by 64 passing spawn-broker tests; check:changed passed. Codex review is scoped-clean through P1 on a patch-identical revision, and ClawSweeper reports no findings on the landed head. Prior macOS Gateway probes predate final broker integration and do not claim a Linux/systemd field-crash reproduction.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 18, 2026
…w#150806)

Full catalog refreshes could expose provider results before native discovery and its paired auth facts settled, temporarily dropping native model choices. Keep the previous complete catalog, runtime models, and inventory published until the new generation is complete, and restore the previous publication on acquisition failure.

Preserve the five-second foreground bound, scoped provider refreshes, and recorded discovery failures. The worker-boundary regression holds native acquisition to exercise concurrent readers and verifies the final merged catalog.

Related: openclaw#150427

Validation: forced-ordering regressions reproduced the defect on macOS and Linux, then passed 20/20 serial runs per platform with the fix. Catalog/model-selection suites passed 641 tests across 41 files; build and changed checks passed. Exact-head CI: https://github.com/openclaw/openclaw/actions/runs/35209693054.
steipete added a commit that referenced this pull request Sep 18, 2026
…Jobs

Follow up on #151325 by sharing the stdio-preserving Job launcher between runtime children and tooling. Admit target code only after Job assignment, retain certification after root exit, and preserve worker IPC. Existing non-fatal MCP/LSP cleanup containment from #150427 is unchanged; this extends the ownership work in #150244.
steipete added a commit that referenced this pull request Sep 18, 2026
…Jobs

Follow up on #151325 by sharing the stdio-preserving Job launcher between runtime children and tooling. Admit target code only after Job assignment, retain certification after root exit, and preserve worker IPC. Existing non-fatal MCP/LSP cleanup containment from #150427 is unchanged; this extends the ownership work in #150244.
steipete added a commit that referenced this pull request Sep 18, 2026
Windows owned stdio children now use the existing retained Job owner to confirm descendant cleanup after the parent exits, preserving interactive input and worker IPC.

Keep native support optional: unavailable or failed Job setup falls back to ordinary command startup and reports typed uncertainty. Tree-required cleanup retains state locks and temporary artifacts until extinction is certified; transport-only cleanup remains independent. Claude prompt and skill artifacts are retained with a warning when cleanup is uncertain.

Related: #151325, #150427, #150244.

Validation: exact-head CI run 35354835669 is green, including both Windows node-test jobs; 243 focused tests passed locally on macOS with six native Windows skips. The P1 review is scoped-clean, and all 13 reviewed commits are preserved by a semantic-equivalent rebase. Hosted Windows proof and the capability matrix satisfy the maintainer's compatibility-proof ruling.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 19, 2026
…aw#151443)

Windows owned stdio children now use the existing retained Job owner to confirm descendant cleanup after the parent exits, preserving interactive input and worker IPC.

Keep native support optional: unavailable or failed Job setup falls back to ordinary command startup and reports typed uncertainty. Tree-required cleanup retains state locks and temporary artifacts until extinction is certified; transport-only cleanup remains independent. Claude prompt and skill artifacts are retained with a warning when cleanup is uncertain.

Related: openclaw#151325, openclaw#150427, openclaw#150244.

Validation: exact-head CI run 35354835669 is green, including both Windows node-test jobs; 243 focused tests passed locally on macOS with six native Windows skips. The P1 review is scoped-clean, and all 13 reviewed commits are preserved by a semantic-equivalent rebase. Hosted Windows proof and the capability matrix satisfy the maintainer's compatibility-proof ruling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation maintainer Maintainer-authored PR 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.

1 participant