Skip to content

fix: Gateway shutdown hangs during recovered worker provisioning - #176777

Merged
steipete merged 9 commits into
mainfrom
steipete/team-shutdownhang
Oct 19, 2026
Merged

steipete merged 9 commits into
mainfrom
steipete/team-shutdownhang

Conversation

@steipete

@steipete steipete commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes Gateway shutdown exceeding its deadline while worker provisioning or allocation recovery is in progress. Team's 2026-10-18 21:45 restart was SIGKILLed by systemd at its 90-second stop limit.

User Impact

Stop and restart cancel provisioning through the service owner's signal and wait for the actual producer to settle before closing state. Durable operation IDs, recorded leases and factual cleanup receipts remain available for recovery; shutdown does not request machine destruction. Providers that ignore cancellation remain owned and awaited.

Why This Change Was Made

Recovered provisioning runs without a caller signal. Allocation and node installation previously forwarded only that optional caller signal, so shutdown could wait for the normal 300-second provider timeout while joining reconciliation. provider-lifecycle.ts:439 now composes caller cancellation with the owner's shutdown signal and carries it through allocation, preparation and node installation (provider-node-provisioning.ts:334). Only caller cancellation records destruction intent. No timeout increase, abandoned writer, schema/config change or parallel lifecycle owner is introduced.

Both missing-signal paths predate the session-controller cutover. This is separate from #172971, which was already present in the affected build 2aca4a06b2c8. The journal is consistent with this defect but does not name the exact blocked provider call or prove this was the incident's only contributor.

Evidence

Sanitized journal lines from the full shutdown window (UTC):

67  21:45:36.125 shutdown budget at shutdown: drain=74410ms shutdown=84410ms
146 21:45:37.267 aborted 12 active run(s) during restart shutdown
279 21:47:00.536 shutdown deadline reached ... pending close steps:
    restart.close.session-admissions=83243ms
    shutdown.connection-dependent-sidecars=83039ms
    shutdown.worker-placement.environments=83036ms
    shutdown.worker-environments.reconcile-guard=83036ms
282–286 systemd: Killing process (node-MainThread) and four (git) children with SIGKILL
287 systemd: Failed with result 'signal'.

All twelve aborted lane tasks released their active slots by 21:45:38.004; the deadline activity counts were explicitly a last-observed snapshot. Four later agent-database clean-close receipts were written. The journal does not establish which call owned the Git children.

  • The recovered-allocation and node-installation owner discriminators are RED on base / GREEN with the fix. The committed service-lifetime cases verify cancellation, retained producer ownership until actual settlement, preserved recovery facts and no machine destruction.
  • Seven focused provisioning/service files have passing evidence for 98 distinct tests. The two signal-option expectations were corrected and their file rerun (19/19). The production rebuild passed, including 97 plugins and 54 built-module load checks.
  • Both requested restart suites passed on Blacksmith Testbox: process shutdown/recovery 1/1 (59.99s), subagent restart 5/5 (130.12s). No live Gateway was touched.
  • The new real-process regression exercises recovered provisioning, six ordinary/nested/subagent turns and a yielded Git/Node child. It passed under Bun on the refreshed head in CI job 117864265098, retaining exit-zero, no-deadline and child-extinction assertions (11.719s test time; 16.44s shard wrapper). A process-level base/fix comparison was not completed; the red/green discriminator is at the lifecycle owner.

Scheduler-first node cancellation repair

The ClawSweeper P1 was valid: scheduler shutdown aborts the work before service teardown sets stopping. The node handler previously consulted that later flag and could treat the abort as bootstrap failure, record destruction intent and tear down the recoverable machine. The handler now takes the authoritative owner signal and checks its cancellation independently of isStopping, matching the existing SSH bootstrap path. The shared catch covers node installation and prepared-workspace registration. Explicit request cancellation keeps its existing destruction semantics.

Extended the existing scheduler-first lifetime regression to node installation. RED on 10f3396ae362: the node case called provider.destroy once after scheduler cancellation, while SSH passed. GREEN with the repair: both transports preserve state, operation identity, lease facts, destroy intent and last error before service teardown. All 55 tests in the four focused lifetime/node-owner/cancellation/shutdown-replay files passed. Test run: 391.07s; wrapper including worker-build verification: 457.56s on the local host. The new node case took 1.138s and reuses the existing real service/store fixture.

Targeted tsrs production and gateway test typechecks, lint/format and git diff --check pass. Pre-commit and full committed-branch Codex reviews are scoped-clean, with no actionable P0–P2 findings. The allocation-preservation repair is commit bcc6f784f32cb42d1d8506873e5b1b063506d003. The stopped native landing worktree has not been touched. No timeout, schema, configuration or cleanup-ownership change is included.

CI refresh and independent fixture repair

CI on bcc6f784f32c passed every job except check-test-types-core-2 and its aggregate gate. Its merge result included main's #177038, which supplied the retired load dependency in a subscription test. The exact diagnostic was control-ui.test.ts(485,7): TS2353: 'load' does not exist in type 'SubscriptionDeps'. The latest completed scheduled main run's same job passed on 4278e94e48b2; that revision predates #177038, so it does not establish that the new fixture is valid.

The failing graph was reproduced on current main 99f5d0f8e4e0 (RED, 5.2s), then passed after removing only the unused test argument (GREEN, 4.2s). That independent one-line repair is tracked in #177111, whose exact-head CI passed; its type graph has direct local RED/GREEN proof (CI path routing skipped type jobs). This branch incorporates that main revision and repair to make its CI result meaningful. After integration, all 35 service-lifetime tests passed, including the scheduler-first SSH/node cases and main's idle-reconciliation cancellation test. The production typecheck, both affected Gateway test type graphs, lint and format also passed. The refresh head was 29a5592a95418a173cd6b217211bb5a6a1a6d2ab. Its exact-head CI has a restart-process test failure under investigation: Gateway exit was zero and shutdown completed in 564ms, but the subsequent raw PID-existence assertion found a reported child PID. The log does not identify whether it was live, terminal/unreaped, or reused. No assertion or timeout has been weakened. Follow-up commit 25bdbff142c1fa437adee4e350cfc0eb88f44b0a records the failed PID and Linux process status/stat only after the original assertion fails, preserving its timing and behavior. A Testbox diagnostic lease queued and was stopped before any payload ran (cancelled run); PR CI supplies the supported diagnostic fallback. Local root-test typechecking (10.2s), targeted lint/format, precommit and committed-branch Codex review passed. The diagnostic change does not claim to fix or classify the earlier survivor. Diagnostic head: 25bdbff142c1fa437adee4e350cfc0eb88f44b0a; exact-head CI and the aggregate gate are green. The restart shard passed its unchanged strict assertions (11.17s test time, 16.20s wrapper). No failure diagnostic was emitted: the prior intermittent PID-existence failure remains unexplained and is not claimed fixed. All type/UI gates on that diagnostic head passed. The PR remains READY and unmerged.

SDK cancellation contract correction

The ClawSweeper P2 identified stale provider guidance that treated every aborted provisioning signal as explicit cancellation and destruction intent. The SDK capability guide and both provisioning/runtime-enrollment signal JSDoc comments now distinguish stopping an attempt from requesting machine destruction. Gateway shutdown can abort the existing signal; providers stop and settle owned work while preserving allocations for replay. Core records destruction intent for a cancelled attempt only after an explicit cancellation or destroy request. No executable code, type signature, signal API, or runtime behavior changes in this follow-up.

Commit 8f38c4e7ef4ec2a5d76de5b84bdb673dc0adf0d7: full pnpm check:docs passed, including docs lint, formatting, MDX, glossary, 15,712 link checks, config examples and changelog checks. Targeted source lint/format and git diff --check passed. Local and committed-branch Codex reviews are scoped-clean. Current head: 8f38c4e7ef4ec2a5d76de5b84bdb673dc0adf0d7; exact-head CI is green (67 successful jobs, no failed jobs). The PR remains READY and unmerged.

Accepted scope limitation: Node spawn-broker cleanup

The P1 review was raised by the automated Codex GitHub review of 7c6e17222a58, based on the earlier Node 24.19.0/Linux Testbox run of this new regression. That run reached real restart and settled all six lanes, then failed the strict clean-exit assertion:

01:38:44.941 aborted 6 active run(s) during restart shutdown
01:38:45.048 last nested/subagent lane error after abort
01:38:45.139 completed in 239ms with warnings: restart-reply-drain
01:38:52.199 shutdown step failed (gateway server close):
Spawn broker cleanup did not complete | Spawn broker shutdown failed |
ERR_SPAWN_BROKER_UNAVAILABLE | exited with code=1 signal=none
stderr: Spawn broker cleanup failed: AggregateError: Spawn broker native cleanup failed

This is an accepted scope limitation, not a resolved broker defect or proven baseline failure. The captured aggregate omits nested causes and child/process-group state; it does not establish whether a live child, terminal process group or another native resource blocked cleanup. The separate provisioning cancellation defect has owner-level red/green proof, and the Node failure occurred after its reconciliation and lane settlement completed. Changing native process cleanup without that missing evidence would risk weakening ownership guarantees. No broker change, relaxed assertion, longer deadline or writer abandonment is included. The Bun pass does not prove Node cleanup. A follow-up needs nested cleanup causes and a PID/group census, then a process-level base/fix comparison.

Two local restart runs hit the existing 300-second no-output watchdog before Gateway startup. A second Testbox attempt never reached its payload during source preparation. These are tooling results, not product verdicts. Both task-owned leases were stopped. No fresh Node base/fix comparison is claimed after the main merge.

Delta against merged main: production source including JSDoc +30/-14 (net +16), tests +560/-44 (net +516), docs +5/-1 (net +4). The documentation follow-up adds only comments (+5/-2) and prose (+3/-1); the executable production diff remains +25/-12. The production increase carries the existing owner's cancellation across both provisioning transports and recognizes it before service teardown begins. The larger test addition is the requested real-process boundary proof; no test-only production seam was added.

Focused proof commands
node scripts/run-vitest.mjs \
  src/gateway/worker-environments/service-lifetime.test.ts \
  src/gateway/worker-environments/provider-provisioning.test.ts \
  src/gateway/worker-environments/provider-provisioning.replay.test.ts \
  src/gateway/worker-environments/provider-provisioning.cancellation.test.ts \
  src/gateway/worker-environments/provider-provisioning.shutdown-replay.test.ts \
  src/gateway/worker-environments/provider-provisioning-node.test.ts \
  src/gateway/worker-environments/provider-provisioning-node.owner.test.ts --maxWorkers=1
node scripts/prepare-vitest-runtime.mjs
OPENCLAW_TYPECHECKER=tsrs pnpm tsgo:core
OPENCLAW_TYPECHECKER=tsrs pnpm tsgo:ui
OPENCLAW_TYPECHECKER=tsrs node scripts/run-tsgo-core-test-shards.mjs \
  --ci-graphs-json '["core-test-gateway-other","core-test-gateway-methods","test-root-other"]'
node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json \
  src/gateway/worker-environments/provider-lifecycle.ts \
  src/gateway/worker-environments/provider-node-provisioning.ts \
  src/gateway/worker-environments/provider-provisioning.test.ts \
  src/gateway/worker-environments/service-lifetime.test.ts \
  test/gateway-restart-abort-settlement.e2e.test.ts
node scripts/run-format.mts --check docs/gateway/cloud-workers/session-lifecycle.md \
  src/gateway/worker-environments/provider-lifecycle.ts \
  src/gateway/worker-environments/provider-node-provisioning.ts \
  src/gateway/worker-environments/provider-provisioning.test.ts \
  src/gateway/worker-environments/service-lifetime.test.ts \
  test/gateway-restart-abort-settlement.e2e.test.ts
git diff --check
# Remote payload through the repository Testbox wrapper; one worker:
CI=1 NODE_OPTIONS=--max-old-space-size=4096 OPENCLAW_VITEST_MAX_WORKERS=1 \
OPENCLAW_TESTBOX=1 OPENCLAW_TESTBOX_REMOTE_RUN=1 \
node scripts/run-vitest.mjs run --config test/vitest/vitest.e2e.config.ts \
  test/gateway-restart-abort-settlement.e2e.test.ts \
  test/gateway-process-shutdown-recovery.e2e.test.ts \
  test/gateway-subagent-restart.e2e.test.ts --maxWorkers=1

@clawsweeper

clawsweeper Bot commented Oct 19, 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 gateway Gateway runtime size: L labels Oct 19, 2026
@steipete
steipete marked this pull request as ready for review October 19, 2026 01:47
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 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-19T08:50:18.086641Z 8f38c4e 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7c6e17222a

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}),
).toBe(true);
expect(child.kill("SIGTERM")).toBe(true);
expect(await gate(closed), instance.logs()).toEqual([0, null]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Fix the known-red restart regression before enabling it

When this E2E reaches restart with the spawn broker enabled, the Gateway exits with code 1 because native broker cleanup fails, so this strict [0, null] assertion fails; the commit's own corrected Testbox run records exactly that outcome. Committing the test unskipped therefore leaves the restart E2E suite red in that supported environment rather than providing a green post-fix regression, so fix the cleanup failure or defer enabling this test.

AGENTS.md reference: AGENTS.md:L80-L80

Useful? React with 👍 / 👎.

@steipete steipete Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lead has accepted this as a scope limitation for the provisioning fix. This remains an unresolved Node process-cleanup failure, not a proven baseline defect. Its source is this review (original commit 7c6e172) and the Node 24.19.0/Linux Testbox run: all six lanes and reconciliation settled in 239 ms with clean-close receipts, then the broker reported native cleanup failure about seven seconds later.

The captured aggregate omitted nested causes and PID/process-group state. Changing cleanup semantics without those facts would risk weakening ownership. The provisioning-owner discriminator is independently RED on base / GREEN with the patch. The successful Bun process test does not prove Node cleanup. We retain the strict exit-zero, no-deadline and child-extinction assertions; nothing is skipped or weakened.

Main has now been merged for fresh typechecks and CI. No fresh Node process-level base/fix comparison is claimed. The PR body records this limitation and the next evidence needed: nested cleanup errors plus PID/group state, followed by a base/fix comparison.

@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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 19, 2026
@clawsweeper

clawsweeper Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Propagates Gateway shutdown cancellation through recovered worker provisioning and node installation while preserving allocations for recovery.

Example: Restart the Gateway while recovering a provisioning operation with a 300-second provider timeout.

  • Before: The provider receives no shutdown signal, so reconciliation can outlast the supervisor’s 90-second stop limit.
  • After: The provider receives owner cancellation, shutdown awaits actual settlement, and the durable operation remains recoverable without destruction intent.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused repair is coherent and both prior findings are fixed; proof is predominantly automated boundary coverage, with accepted process-cleanup limitations and current-head CI still running.
Proof confidence 🦐 gold shrimp (3/6) Maintainer-authored PR outside the ordinary contributor proof gate: supplied evidence exercises the compiled Gateway with a synthetic provider and real HTTP cancellation, supported by lifecycle-owner red/green tests; process-level base/fix and Node cleanup conclusions remain limited as documented.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Stopping or restarting a Gateway during recovered cloud-worker provisioning can hang until the supervisor kills it.
Reason: The source establishes a concrete cancellation omission, and the maintainer-authored repair preserves recovery ownership with a small production change.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it fixes a current provisioning cancellation gap, and both prior actionable findings are resolved without introducing another lifecycle owner.

Priority: P1
Reviewed head: 8f38c4e7ef4ec2a5d76de5b84bdb673dc0adf0d7

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The process-level base/fix comparison remains unavailable; the supplied discriminator is lifecycle-owner red/green, with Node cleanup limitations explicitly recorded.
Agent review details

How this fits together

The worker-environment service owns provisioning, reconciliation, and shutdown; it passes cancellation to provider and node operations and records their outcomes in the existing environment store.

flowchart TD
  A[Gateway shutdown] --> B[Service owner signal]
  B --> C[Provider lifecycle]
  C --> D[Allocation and preparation]
  C --> E[Node installation]
  D --> F[Producer settlement]
  E --> F
  F --> G[Retained recovery state]
Loading

Technical review

Best possible solution:

Carry the existing owner signal through provisioning and installation, retain actual producer settlement, and keep destruction intent exclusive to explicit cancellation or teardown.

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

Current main visibly omits owner cancellation on recovered provisioning and node installation, and the contributor records discriminating lifecycle-owner red/green results; this read-only review executed no target code.

Is this the best way to solve the issue?

The patch repairs cancellation at the existing lifecycle owner, preserves explicit Stop semantics and factual cleanup receipts, and adds no parallel state or teardown mechanism.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Explicit provisioning cancellation and node installation changes intended behavior with a stated reason (5c388e5: Carry explicit cancellation through provider work and enrollment while retaining real producer settlement and independent teardown authority.)
  • Shutdown allocation preservation keeps the original intent (5e616e1: Cancel shutdown-owned work before joining reconciliation while retaining durable allocations for restart adoption.)
  • Shared worker-bundle preparation keeps the original intent (ae5a4b4: Overlap bundle preparation with startup while keeping the service responsible for the actual producer.)
  • Subscription preparation-failure fixture keeps the original intent (de2700c: Exercise reporting of subscription preparation failures without rejecting the acknowledged request; removing the retired fixture argument preserves that regression.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 5c388e5 adds src/gateway/worker-environments/provider-lifecycle.ts:398 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5c388e5e16c1; files: src/gateway/worker-environments/provider-lifecycle.ts)

PR surface

Source +16, Tests +516, Docs +4. Total +536 across 9 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 3 30 14 +16
Tests 4 560 44 +516
Docs 2 5 1 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 595 59 +536

Review metrics

Metric Value Why it matters
Production versus test growth Production +30/-14; tests +560/-44 Production growth propagates cancellation through existing owners; most test growth exercises the separate process-shutdown boundary without a production test seam.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Recovered cloud-worker provisioning can hold Gateway shutdown beyond the supervisor deadline and force process termination.
  • merge-risk: 🚨 compatibility: Provider options.signal now also aborts on Gateway shutdown; the maintainer-authored direction accepts this behavior, updates the public contract, and preserves bundled Crabbox allocation semantics.
  • 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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-19T02:04:16.073Z sha 7c6e172 :: needs changes before merge. :: [P1] Recognize owner cancellation before the service stopping flag
  • reviewed 2026-10-19T07:37:19.051Z sha bcc6f78 :: needs changes before merge. :: [P2] Align the SDK contract with shutdown cancellation
  • reviewed 2026-10-19T08:06:03.544Z sha 29a5592 :: needs changes before merge. :: [P2] Align the SDK contract with shutdown cancellation

Reviewed October 19, 2026, 4:46 AM ET / 08:46 UTC (Revision 4).

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 89f387d699

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
: {}),
...(cancellation ? { signal: cancellation.signal } : {}),
signal: workSignal,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep shutdown out of the explicit-cancel signal

When beginClose() aborts ownerSignal, this now aborts options.signal for every provider even when no request cancellation occurred. The published provider contract still states that an aborted provisioning signal means explicit cancellation (docs/plugins/sdk-overview/capabilities.md:108), so a provider following that contract may cancel or release its in-flight allocation while core deliberately leaves destroyRequestedAtMs null for restart recovery, potentially losing the retained worker during a routine restart. Introduce a distinguishable shutdown cancellation contract and migrate providers/docs together, or preserve the existing explicit-cancel semantics of this signal.

AGENTS.md reference: AGENTS.md:L55-L55

Useful? React with 👍 / 👎.

@steipete

steipete commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixed the scheduler-first owner-cancellation P1 in bcc6f78.

The node failure handler now receives the authoritative owner signal and checks ownerSignal.aborted independently of isStopping, matching the SSH bootstrap path. It rethrows owner cancellation before failBootstrap; the shared handler covers node installation and prepared-workspace registration. Explicit request cancellation retains its existing destruction semantics.

Extended the existing scheduler-first lifetime regression to node installation. On 10f3396, the new case failed because provider.destroy was called once after scheduler cancellation; SSH passed. With the fix, all 55 tests in the four focused lifetime/node-owner/cancellation/shutdown-replay files passed. The regression also verifies preserved state, provision-operation identity, lease facts, destruction intent and last error before service teardown. Production/gateway test typechecks using tsrs, targeted lint/format, and pre-commit plus committed-branch Codex autoreview pass. No timeout or assertion was weakened.

The separate, previously accepted Node spawn-broker cleanup limitation is unchanged. This repair addresses allocation destruction during owner cancellation. The stopped native landing worktree was not touched, and the PR remains unmerged.

The P1 fix was verified on refreshed head 29a5592a95418a173cd6b217211bb5a6a1a6d2ab. All 35 service-lifetime tests pass after integrating current main, including the SSH/node ordering cases. Production and both affected Gateway test type graphs, lint, format and the refreshed committed-branch Codex review are clean. The independent main fixture type error is fixed separately in #177111 and incorporated here. That CI run passed all type/UI gates but failed the process regression: Gateway exit was zero after a 564ms shutdown; a raw PID-existence assertion still succeeded. Current head 25bdbff142c1fa437adee4e350cfc0eb88f44b0a adds failure-only PID/stat/status diagnostics without changing that assertion. A Testbox lease queued and was stopped before its payload; current exact-head CI and its aggregate gate are now green. The strict restart test passed in 11.17s (16.20s wrapper), so no failure diagnostic was emitted. The prior intermittent PID failure remains unexplained, not attributed to infrastructure or claimed fixed. All type/UI checks passed. The owner-cancellation P1 is fixed with RED/GREEN proof; the PR is READY and remains unmerged.

@clawsweeper

clawsweeper Bot commented Oct 19, 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-repro Preliminary submission classification; full source review pending. labels Oct 19, 2026
@clawsweeper

clawsweeper Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 19, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Coordination from #176770 at 67eb9917c2c4f426842b949b6c0d9a2e13b08bdd: its local Node process restart e2e failed at shutdown-managed:wait-process-close (expected exit 0, observed SIGKILL). Raw restart recovery, Stop/reset, and the first accepted effect had completed; the final second-restart phase was not reached.

Sanitized failure diagnostics:

[gateway] restart drain budget … exhausted; queueSize=1 embeddedRuns=1 agentRuns=1
[gateway] shutdown deadline reached; pending close steps: restart.close.session-admissions=9932ms, shutdown.received-connection-work=9921ms
[agent/embedded] agent cleanup timed out: runId=managed step=openclaw-trajectory-flush timeoutMs=10000 details=pendingRows=1 queuedBytes=827 activeOperation=sqlite-append

The fixture is test/gateway-process-shutdown-recovery.e2e.test.ts:451, reached from line 689. Test execution failed after 174.21 s under the unchanged 180-second timeout. The trajectory/drain files and fixture are unchanged by #176770. A prior-head warm diagnostic run passed, so this is unresolved evidence, not a proven inherited failure or a claimed repair. No drain fix is being duplicated in the delivery PR; sharing this with the existing shutdown owner for classification.

@steipete

steipete commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixed the SDK cancellation-contract P2 in 8f38c4e7ef4ec2a5d76de5b84bdb673dc0adf0d7.

The worker-provider guide now states that an aborted options.signal stops the current attempt and can mean Gateway shutdown. Providers must settle owned work and preserve allocations on a plain abort. For a cancelled attempt, core records destruction intent only for an explicit cancellation or destroy request. The runtime/enrollment and provisioning signal JSDoc use the same distinction. This changes prose/comments only: no executable code, type signature, or new signal API.

Full pnpm check:docs passed, including docs lint, formatting, MDX, glossary, links (15,712 checked; zero broken), config examples, and changelog validation. Targeted source lint/format and git diff --check passed. Local and committed-branch Codex reviews are scoped-clean. Exact-head CI is now green: 67 successful jobs, no failed jobs. The PR body is current.

The prior process-cleanup limitations remain documented. No merge performed; the stopped landing worktree was not touched.

@clawsweeper

clawsweeper Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 19, 2026
@steipete
steipete merged commit d01eb83 into main Oct 19, 2026
163 of 164 checks passed
@steipete
steipete deleted the steipete/team-shutdownhang branch October 19, 2026 09:04
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 20, 2026
…nclaw#176777)

* fix: cancel recovered worker provisioning during gateway shutdown

* test: use advertised dispatch surface in restart regression

* test: expect reply-drain warning during forced restart

* fix: preserve node allocations during scheduler shutdown

* test: diagnose child state after gateway shutdown

* docs: distinguish worker attempt aborts from destruction
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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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