Skip to content

fix(gateway): reap adopted children during supervised shutdown - #178786

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-shutdown-session-effects-admissions-hang-20260919
Oct 20, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-shutdown-session-effects-admissions-hang-20260919

Conversation

@steipete

@steipete steipete commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes Linux Gateway shutdown failing with ERR_SPAWN_BROKER_UNAVAILABLE when an outer process supervisor retains an adopted zombie while the Gateway waits for that child's process group to disappear.

User Impact

Gateways running under nested process supervision can complete child cleanup and exit successfully. The mixed regression now covers twelve active runs and requires a clean exit within five seconds of managed SIGTERM.

The separately reported 84-second session-effects stall was not reproduced and is not claimed fixed. Pending-close diagnostics now identify remaining effect custody to make a recurrence attributable.

Why This Change Was Made

The Linux subreaper previously reaped adopted children only during final cleanup, after its application root exited. A synthetic Gateway reproduction proved a Git zombie belonged to the outer supervisor while the Gateway's spawn broker was waiting for its process group to disappear.

Observe SIGCHLD after admitting the root and reuse the existing native drain to reap adopted exits immediately. Tracked root statuses remain owned by Node, and final cleanup still requires authoritative extinction. The effect diagnostic projects existing owners into the existing bounded trace without changing their release barrier.

Production code grows by 33 lines for the missing active reaping and owner diagnostics. The existing native and mixed-workload fixtures cover both invariants; no new test file is added.

Evidence

On an isolated Linux sandbox with synthetic data, Node 26.8.2, baseline 8f0973e37405:

Functional shutdown proof Before With subreaper fix
Twelve active runs, managed SIGTERM Exit 1 after 7,774 / 7,893 ms Exit 0 after 789 ms
Session shutdown work 424 / 538 ms 471 ms
Git / Node child extinction Broker group cleanup timed out Passed

These are observed functional-test timings, not a performance benchmark. The workload includes held provider streams, nested delivery, subagents, a parent lifecycle wake, real exec/Git child work, and interrupted provisioning.

  • New native regression: red on the unchanged owner because the adopted child remained unreaped while the root was alive; green with the fix, preserving root exit code 37.
  • Expanded test/gateway-restart-abort-settlement.e2e.test.ts: passed, including the under-five-second and child-extinction assertions.
  • Existing process shutdown/recovery fixture passed on baseline and again with the fixed owner (62.01 s). Managed SIGTERM exited cleanly in 826 ms; raw SIGTERM took 20.81 s including its configured 20 s drain. Exactly-once history, five interrupted sessions, explicit Stop, reset authority, and another restart/SIGKILL during recovery all passed.
  • src/gateway/server-close.test.ts: all 63 tests passed. Its diagnostic regression was red before the trace change and green afterward, while retained writes continued blocking close.
  • Changed-file formatting/lint and diff checks passed. Independent Codex reviews of the complete production changes and final mixed regression found no actionable P0–P2 issues.

Coverage gaps: no code-mode-specific or cron-nested workload in this fixture; no production restart performed; the original 84-second retained-effect owner remains unidentified. The runtime proof used baseline plus the subreaper fix; the additional trace-only change has focused close-handler coverage.

@clawsweeper

clawsweeper Bot commented Oct 20, 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.

@steipete
steipete marked this pull request as ready for review October 20, 2026 21:18
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T21:33:07.772408Z a2318f9 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: XS labels Oct 20, 2026
Include remaining effect custody in the existing pending-close trace so shutdown stalls remain attributable after their sources settle. Preserve cancellation and retained-write settlement behavior.
Reap adopted exits on SIGCHLD without consuming the tracked root wait status. This breaks a nested-supervision shutdown cycle where the Gateway broker waits for a zombie process group and the outer subreaper waits for the Gateway to exit.
@steipete
steipete force-pushed the steipete/perf-micro-shutdown-session-effects-admissions-hang-20260919 branch from 799727c to a2318f9 Compare October 20, 2026 21:28
@steipete steipete changed the title fix(gateway): identify session effects blocking shutdown fix(gateway): reap adopted children during supervised shutdown Oct 20, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 20, 2026
@clawsweeper

clawsweeper Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Reap adopted Linux children while the supervised root remains alive and expose retained session effects in shutdown diagnostics.

Example: A supervised Gateway receives managed SIGTERM with twelve active runs and real Git child work.

  • Before: The supplied reproduction reports exit 1 with ERR_SPAWN_BROKER_UNAVAILABLE because an adopted zombie keeps its process group present.
  • After: The supplied fixed-owner run reports exit 0 with Git and Node children extinct.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch preserves ownership and settlement contracts; available behavioral evidence consists of reported fixture outcomes rather than inspectable runtime artifacts.
Proof confidence 🦐 gold shrimp (3/6) The review brief identifies this as maintainer-authored, outside the ordinary contributor proof gate; supplied evidence reports an isolated Linux Gateway workload and native regressions, while the trace-only change has focused close-handler coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A Linux Gateway under nested supervision can fail shutdown because its child cleanup waits on a zombie retained by the outer supervisor.
Reason: The maintainer-authored direction repairs a concrete shutdown failure with existing owners; the separate retained-effect incident is explicitly outside the claimed fix.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR addresses a current Linux supervision deadlock through the existing process owner, with no actionable introduced defect found.

Priority: P2
Reviewed head: a2318f99f1aabee0d216048f161cf8430dec4c66

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied fixture result summaries are not accompanied by inspectable shipped-Gateway terminal output or logs.
Agent review details

How this fits together

The dedicated Linux supervisor owns adopted child waits beneath the Gateway; session lifecycle owners separately expose retained cleanup work to the Gateway shutdown trace.

flowchart TD
  A[Managed SIGTERM] --> B[Gateway shutdown]
  B --> C[Session cancellation and settlement]
  C --> D[Pending close diagnostics]
  B --> E[Dedicated Linux supervisor]
  F[Adopted child exit] --> E
  E --> G[Native wait inspection and reaping]
  G --> H[Verified descendant extinction]
Loading

Technical review

Best possible solution:

Use the existing dedicated Linux owner to reap adopted exits during root lifetime while preserving runtime-owned statuses and final extinction checks.

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

Current main lacks active adopted-child reaping, and the committed native scenario isolates the resulting live-root dependency cycle; the author reports baseline failure and fixed-owner success, which this read-only review did not rerun.

Is this the best way to solve the issue?

The patch fixes the lifecycle owner directly, preserves its kernel and runtime ownership contracts, and adds diagnostics through the existing bounded trace without introducing a competing cleanup path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 2f7572ad13d1.

Provenance checked

  • Dedicated Linux child ownership keeps the original intent (fix: prevent worker turns from stalling when group signals are denied #160465: Dedicated subreaping supplies positive-PID cleanup and authoritative extinction when process-group signaling is denied; subsequent native migration and Bun qualification preserve runtime-owned root statuses.)
  • Session settlement and pending-close diagnostics keeps the original intent (36e277d: The session controller captures exact effect owners and joins their release before shutdown; the existing close diagnostics distinguish retained work from source cancellation.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head diff; the fetched main retains the original production behavior in all three changed production modules. (src/process/supervisor/linux-child-subreaper.ts:54, a2318f99f1aa)
  • Root wait ownership preserved: The SIGCHLD callback calls drain without a signal; drain excludes tracked root statuses from native reaping and still requires ECHILD before declaring extinction. (src/process/supervisor/linux-child-subreaper.ts:102, a2318f99f1aa)
  • Determining native dependency contract: The changed owner imports and invokes proc-safe reaper APIs, making its contract applicable. The pinned v0.4.2 documentation requires coordinated exclusive ownership, non-consuming wait inspection, and exclusion of libuv-owned children; the patch preserves those requirements. (docs/reaper.md, 8a610a06e5ba)
  • Cleanup barrier preserved: The diagnostic projects captured effect owners while leaving interruption, release promises, and error aggregation intact; the close regression retains unfinished effect work after source settlement. (src/sessions/session-controller.lifecycle-work.ts:199, a2318f99f1aa)
  • Distinct native regression: The added real-process scenario verifies adoption, disappearance of the orphan while its root remains alive, and preservation of root exit code 37. (src/process/supervisor/service-child-subreaper.test-support.ts:123, a2318f99f1aa)
  • Supplied functional evidence: The complete PR body reports failing baseline and passing fixed-owner Gateway shutdown runs, native red/green coverage, and preserved shutdown/recovery behavior; it explicitly excludes the unreproduced 84-second effect stall. (a2318f99f1aa)

PR surface

Source +33, Tests +81, Docs +8. Total +122 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 35 2 +33
Tests 4 91 10 +81
Docs 1 8 0 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 134 12 +122

Review metrics

Metric Value Why it matters
Production versus test changes Production +35/-2; tests +91/-10 Growth reuses existing owners and fixtures to cover active-root reaping, authentic root results, retained-effect diagnostics, and the mixed shutdown workload.

Labels

Label changes:

  • add P2: The fix addresses failed shutdown under nested Linux supervision with a limited platform and topology scope.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: The fix addresses failed shutdown under nested Linux supervision with a limited platform and topology scope.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 20, 2026, 5:45 PM ET / 21:45 UTC.

@steipete
steipete merged commit 6055960 into main Oct 20, 2026
162 of 167 checks passed
@steipete
steipete deleted the steipete/perf-micro-shutdown-session-effects-admissions-hang-20260919 branch October 20, 2026 22:42
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 21, 2026
…law#178786)

* fix(gateway): identify session effects blocking shutdown

Include remaining effect custody in the existing pending-close trace so shutdown stalls remain attributable after their sources settle. Preserve cancellation and retained-write settlement behavior.

* fix(process): reap adopted children while supervised roots are active

Reap adopted exits on SIGCHLD without consuming the tracked root wait status. This breaks a nested-supervision shutdown cycle where the Gateway broker waits for a zombie process group and the outer subreaper waits for the Gateway to exit.

* test(gateway): cover twelve active runs during restart
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 gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S 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