Skip to content

fix(process): Gateway shutdown fails when broker groups retain zombies - #189415

Open
evaldass wants to merge 3 commits into
openclaw:mainfrom
evaldass:fix/spawn-broker-zombie-shutdown-20261031
Open

evaldass wants to merge 3 commits into
openclaw:mainfrom
evaldass:fix/spawn-broker-zombie-shutdown-20261031

Conversation

@evaldass

@evaldass evaldass commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Related: #170000

What Problem This Solves

Fixes joined Gateway shutdown failing when a spawn broker's private process group contains only dead processes awaiting reaping by another supervisor.

User Impact

Gateways launched under a child subreaper that does not reap adopted children can stop cleanly instead of reporting retained broker resources. Live descendants still receive TERM/KILL cleanup and must be joined. Timeouts, shutdown budgets, permissions, and non-Linux behavior do not change.

Why This Change Was Made

Node's process-group existence probe still succeeds for unreaped zombies. The host previously treated that as proof that broker work remained alive, waited through the TERM and confirmation windows, and reported Spawn broker group cleanup could not be confirmed.

After the existing group probe, Linux confirmation now uses the existing asynchronous process census, own-procfs guard and zombie/definite-death predicate to distinguish live members from zombies. This matches the broker-side drain policy without changing invocation or child custody. An empty or unavailable census does not prove death: while the kernel still reports that group, cleanup remains pending and preserves the existing TERM/KILL escalation and deadline error. Zombies pin the group identifier while they await their reaper; retiring their group observation does not authorize signaling a reused identifier.

A short-lived fork during a census remains an accepted edge of the existing census-based policy. This patch does not alter detached command-group cleanup or the global-singleton grace budget.

Refresh onto current main. Head 9ef4c65c411 merges main 6a6007663b3 into the previously published 49b93b101d0 (normal merge commit, no rebase). Since the old base, main rewrote terminateBrokerProcessGroup around asynchronous kernel and census probes and added a census fallback that applies only when the host denies the group probe (#197510, #198132). It did not fix this case: with a working probe, a zombie-only group still reads as alive. The one conflict was resolved by keeping main's structure and porting the check onto it as isBrokerProcessGroupExtinct. The synchronous process-exit force path and the SIGKILL escalation are main's, unchanged. Against main the diff is still three files (+165/−2); the two test files carry the same added tests as before. On a host that denies group signals and still has live members, each 50 ms confirmation tick now reads the census twice; that is accepted for this rare path rather than widening the shared probe API.

Evidence

  • Current-base regression, exact main 6a6007663b3: the real-process fixture from the new test launches a Node subreaper, a private group leader and a delayed-TERM child, with no mocked census or signals. With main's exact cleanup.ts it ends in Spawn broker group cleanup could not be confirmed after 7,031 ms. With this head it settles in 462 ms while the adopted child is an unreaped zombie, which is after the child's 300 ms exit delay and before the 5,000 ms TERM grace.
  • How that was run, and what is not yet proven: on the 9.9 GiB development host every check ran inside a cgroup capped at 3 GiB RAM. The repository test runner's compiled-worker build exceeds that cap, so cleanup.test.ts and the other real-broker spawn-broker test files did not run under Vitest on this head. The red/green above executed the test's own driver script, extracted byte-for-byte from cleanup.test.ts, directly under Node. Exact-head hosted CI must run the spawn-broker suite itself.
  • Mocked contract tests on head 9ef4c65c411: cleanup-group.test.ts passes 18 of 18 in 1 file. With the empty-census and unreadable-census guards removed from the fix, exactly the two "retains and escalates a kernel-visible broker group" cases fail, so those cases do protect TERM/KILL escalation.
  • Exact-head static checks: core production typecheck (tsgo:core), the src test typecheck (22 shards), core-scoped type-aware lint and format on the three changed files, and git diff --check pass. Ratchets against 6a60076 pass for max-lines, line-cap, assertion-safety, session-identity, timeout-race, mock-exports and test lines (net +132, within the 400-line allowance). The database-dialect ratchet exceeded the memory cap and the database-worker ratchet was not attempted; this change touches no database code, and hosted CI runs both. Frozen dependency installation passed without manifest or lockfile changes.
  • Earlier published head 49b93b101d0 (historical): 45 tests passed across 6 spawn-broker files with 1 Node-only case skipped, on base af300f44712. Those results are not claimed for the current head.
  • Earlier isolated-runtime red/green: with the same cleanup fix in an integration candidate, a real loopback Gateway launched under a synthetic non-reaping subreaper reproduced the failure before the fix: native-resource cleanup took about 7.2 seconds, exceeded the singleton grace, and ended in stop_close_failed. With the fix it logged clean shutdown in 445 ms and exited 0. Four normal-shell control runs were already clean. Temporary processes, zombies, state and ports were removed.

The original operator run's ancestor reaper state was not captured. The matching error and timings support this diagnosis, but the exact live ancestry and post-failure linger are not independently proven. No new call, model connection, production deployment, or live-service change was performed. The full build, the Vitest spawn-broker suite and the two database ratchets were not run on the current head; PR CI remains required. No canonical autoreview has run on this head.

Inspectable isolated-Gateway red/green proof

Baseline integration source: 3488f3f09731c1e1c0f83e9ce7ab7f080b0f70be. Fixed integration source: the same base with the cleanup.ts production change subsequently committed as 18e0aa7b5f051d7115ae09f76d67b88f4a15141b. This earlier runtime experiment predates both the previously published head 49b93b101d062edff8e1acb436140e80c1594433 (with its additional conservative empty/unavailable-census guards) and the current head 9ef4c65c41184f9991efc271ad6457eda5811209 (ported onto main's asynchronous cleanup); it is not relabeled as a runtime run on either head. No isolated-Gateway run exists for the current head.

Both runs launched the real source Gateway with isolated synthetic state, loopback listeners and a synthetic non-reaping child subreaper. No model, SIP or phone session was used. Here is selected original process-watch output for the baseline; numeric PIDs/PGIDs are consistently aliased. Columns within each entry are PID, PPID, process state and command. Z entries remain adopted by the synthetic supervisor while their broker groups await confirmation.

t=1 BROKER_A GATEWAY_A Ssl  MainThread;HELPER_A BROKER_A Sl   esbuild;NATIVE_BROKER_A GATEWAY_A Ssl  MainThread;HELPER_B NATIVE_BROKER_A Sl   esbuild;ZOMBIE_A SUPERVISOR_A Z    esbuild;ZOMBIE_B SUPERVISOR_A Z    esbuild;ZOMBIE_C SUPERVISOR_A Z    esbuild;
t=5 ZOMBIE_A SUPERVISOR_A Z    esbuild;ZOMBIE_B SUPERVISOR_A Z    esbuild;ZOMBIE_C SUPERVISOR_A Z    esbuild;
t=11 ZOMBIE_A SUPERVISOR_A Z    esbuild;ZOMBIE_B SUPERVISOR_A Z    esbuild;ZOMBIE_C SUPERVISOR_A Z    esbuild;
t=12 

The same run's recorded zombie census associates ZOMBIE_C with BROKER_A's PGID, and ZOMBIE_A/ZOMBIE_B with NATIVE_BROKER_A's PGID (all three commands were esbuild). This is a projection of recorded process identities, not an inferred relationship from the PPID column above.

Baseline Gateway log excerpt (timestamps/messages preserved; PGID aliased):

2026-10-31T12:37:50.590+00:00 [gateway] received SIGTERM; shutting down
2026-10-31T12:37:53.992+00:00 [shutdown] failed in 3315ms
2026-10-31T12:37:58.171+00:00 [gateway] shutdown step restart.close.global-singleton.openclaw.nativeWorkerLifetimes settled after 7183ms
2026-10-31T12:38:01.182+00:00 [gateway] shutdown step shutdown.spawn-broker settled after 7147ms
2026-10-31T12:38:01.184+00:00 [gateway] gateway-server-close: Plugin runtime still owns resources; inspect cleanup failures before retrying Gateway close. | global-singletons resources remain after grace; Spawn broker cleanup did not complete | Spawn broker group cleanup could not be confirmed for pgid=BROKER_A | ERR_SPAWN_BROKER_UNAVAILABLE | ERR_SPAWN_BROKER_UNAVAILABLE; resources remain

Fixed Gateway log excerpt:

2026-10-31T12:45:55.103+00:00 [gateway] received SIGTERM; shutting down
2026-10-31T12:45:55.631+00:00 [shutdown] completed cleanly in 445ms

Recorded launcher wait status for the fixed process:

{
  "status": 0,
  "elapsedS": 120.823
}

status: 0 is the recorded OS wait status; elapsedS is total launched-process lifetime including cold startup, not shutdown duration. The Gateway log reports its measured 445 ms shutdown. Temporary processes, zombies and listeners were checked absent afterward. The original operator run's supervisor ancestry was not captured; this proof establishes the controlled topology, not that unseen ancestry.

Refresh review

An independent parent review checked this exact committed range against main 6a6007663b3, the merge resolutions, preserved upstream owners and terminal verification logs. The carrier feature and dependency patch was independently compared with the previous published range and remains unchanged. For the shutdown repair, the parent also reran the real-process fixture on 9ef4c65 under a task-owned memory cgroup: it settled in 460 ms while the adopted child was a zombie, with all four fixture checks passing. This is a focused refresh review, not a canonical autoreview, not full original-feature re-review, and not a current installed Gateway or conversation proof. The disclosed missing Vitest / resource-limited checks still require exact-head hosted CI.

evaldass and others added 2 commits October 31, 2026 13:03
Gateway stop failed with "Spawn broker group cleanup could not be confirmed"
whenever a broker's private process group retained only dead members that an
ancestor child subreaper adopted but never reaped. kill(-pgid, 0) still
succeeds for zombies, so the host waited out the full TERM grace plus its
2 s confirmation window, then reported a cleanup failure. The native-resource
broker hit the same 7 s wait inside nativeWorkerLifetimes, overran the 3 s
global-singletons grace, and turned the stop into retained resources that
keep the process alive until the hard-exit watchdog.

Host-side group confirmation now counts only live members, matching the
broker's own drainCurrentBrokerProcessGroup. Live members are still signaled,
escalated and joined. Zombies pin the PGID until reaped, so no reuse can
follow retirement.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clawsweeper

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

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment 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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 31, 2026
@clawsweeper

clawsweeper Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR lets broker cleanup finish when Linux process-group members are confirmed dead but remain unreaped.

Example: A Linux Gateway receives SIGTERM under a supervisor retaining adopted esbuild zombies.

  • Before: Shutdown reports that spawn-broker group cleanup could not be confirmed.
  • After: Shutdown completes cleanly and the Gateway exits with status 0.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair with inspectable Gateway proof, useful boundary regressions and successful current-head CI.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): Inspectable logs exercise real source-Gateway SIGTERM shutdown under a synthetic non-reaping supervisor, showing baseline zombie-group failure and repaired clean exit 0; the earlier integration run is clearly distinguished from current-head regression coverage of the additional conservative census guards.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Gateway shutdown fails despite broker work being dead when an ancestor supervisor retains adopted zombies.
Reason: Successful shutdown should join live work without depending on another supervisor to reap dead processes.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current Linux shutdown failure and remains useful; no actionable defects were found, and the reviewed head’s CI gate passes.

Priority: P2
Reviewed head: 49b93b101d062edff8e1acb436140e80c1594433

Before merge

None.

Findings

None.

Agent review details

How this fits together

After a broker exits, its host joins private process-group cleanup; kernel group probes and process observations determine whether cleanup must continue.

flowchart TD
  A[Gateway shutdown] --> B[Spawn broker host]
  B --> C[Broker exit join]
  C --> D[Private group cleanup]
  D --> E[Linux process census]
  E --> F[Live members retain TERM and KILL cleanup]
  E --> G[Confirmed dead members settle cleanup]
Loading

Technical review

Best possible solution:

Keep the existing cleanup owner and use its conservative Linux census to distinguish live work from unreaped dead members.

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

Current-main source explains the failure, and contributor-supplied Gateway logs demonstrate it under controlled non-reaping supervision; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch is a focused repair using existing census and death-detection owners, while preserving live-member escalation and conservative handling of unavailable observations.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Host-side broker process-group cleanup keeps the original intent (67cedc3: Retain and terminate non-detached broker children even before their individual PIDs are published.)
  • Joined native shutdown and broker-side draining keeps the original intent (98813c2: Finish owned native work before natural exit and drain abandoned live process-group members.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +31, Tests +136. Total +167 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 33 2 +31
Tests 2 137 1 +136
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 170 3 +167

Review metrics

Metric Value Why it matters
Production versus test changes Production +33/-2; tests +137/-1 Growth is justified by one real-process zombie regression and distinct empty/unavailable-census escalation controls, without new production state or public APIs.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The failure affects Linux shutdown under a specific non-reaping supervisor topology, with no demonstrated broader outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-31T13:40:37.303Z sha 49b93b1 :: needs real behavior proof before merge. :: none

Reviewed October 31, 2026, 11:19 AM ET / 15:19 UTC (Revision 2).

@evaldass

Copy link
Copy Markdown
Contributor Author

Added inspectable, redacted output to the PR body from the reported real isolated Gateway under a non-reaping supervisor: original process topology, baseline failure, repaired clean shutdown and recorded exit status. The earlier integration candidate is identified separately from this publication head and its extra guards. No new live call was made.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 31, 2026
Merge main 6a60076 into the published head 49b93b1.

One conflict, in src/process/spawn-broker/cleanup.ts: main rewrote
terminateBrokerProcessGroup around asynchronous kernel and census probes
(openclaw#197510, openclaw#198132). The resolution keeps main's structure and ports the
zombie-only extinction check onto it as isBrokerProcessGroupExtinct, which
reuses main's asynchronous census, own-procfs guard and zombie predicate.
An empty or unreadable census still keeps a kernel-visible group pending,
so TERM/KILL escalation and the deadline error are retained.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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