Repository navigation
fix: prevent Gateway shutdown failures after in-place updates - #160674
Merged
Merged
Conversation
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review blockedAutomated review did not run, so no review verdict was produced. Reason: The input-safety check rejected material in this revision. No detected value, path, or scanner output is reproduced here. Automatic review is on hold, including after source changes. Request a fresh re-review after resolving the failure; maintainers can also release the hold through an intentional scanner-policy update. Next step: If this is a genuine credential, remove and rotate it. If it is an intentional test fixture, a maintainer must review and qualify it. |
steipete
force-pushed
the
codex/shutdown-eager-imports
branch
from
September 28, 2026 19:45
10d9623 to
cdc0337
Compare
steipete
enabled auto-merge (squash)
September 28, 2026 19:47
steipete
disabled auto-merge
September 28, 2026 19:58
steipete
enabled auto-merge (squash)
September 28, 2026 20:24
steipete
force-pushed
the
codex/shutdown-eager-imports
branch
2 times, most recently
from
September 30, 2026 01:14
42c52c5 to
fae5784
Compare
Retain cleanup owners before in-place updates replace loaded runtime chunks. Move transcript capture ownership and disable drainage into the lightweight startup owner, and retain provider lifecycle stop callbacks. Preload worker-pool artifact cleanup before resource creation in the detached pool context. Reuse browser lazy accessors during teardown, and keep the provider lifecycle tsdown bridge entry and Knip entry for published update compatibility.
steipete
force-pushed
the
codex/shutdown-eager-imports
branch
from
September 30, 2026 23:56
f228f3f to
c91c656
Compare
Wait for actual suspended startup admission before closing, preserving the drain assertion and retained-import contract. Move those cases into a sibling fixture to respect the test file growth ratchet. Bundle the worker cleanup owner used by the native SDK admission fixture while retaining deferred-import and child-exit assertions.
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Oct 1, 2026
…aw#160674) An in-place update replaces the package's hashed chunks while the old Gateway is still running. Shutdown then lazily imported cleanup modules that no longer existed: 2026.9.6 exited with ERR_MODULE_NOT_FOUND for the transcript capture-operations chunk, and other teardown paths (MCP runtime retirement, provider local services, browser relay and Chrome MCP, worker temp-artifact cleanup) had the same hazard. Cleanup owners are now retained when their resources are created, so teardown never first-imports code. Transcript capture ownership moves into the eagerly loaded capture-startup module, and shutdown persists heuristic notes without starting optional model inference. Provider local services register their stop callback when they start. MCP cleanup has a lightweight owner module. Browser teardown peeks the lazy accessors that production ingress loads. The worker pool preloads artifact cleanup in its async preparation step before creating resources, which keeps chalk/tslog out of the native hook relay's static graph. The provider-runtime-lifecycle stable tsdown entry stays, because published-update compatibility bridges map older hashed chunks onto it, and Knip treats it as an entry. Protection applies to updates from a release containing this change; older running Gateways keep the limitation, as docs/install/updating.md describes. Proof: a built-runtime smoke removed 7,011 hashed chunks after startup and still shut down cleanly (exit 0, 6.3 s). Focused shutdown, transcript, worker-pool, browser and MCP suites pass, along with core types, import-cycle checks, Knip and the CLI bootstrap guard. Codex autoreview is scoped-clean. The final CI failures were main-side inventory breaks (wrapper components, suppression count), fixed on main by afe70b5 and 55ca32f.
steipete
added a commit
that referenced
this pull request
Nov 21, 2026
…age is replaced in place (#203185) A Gateway whose package is replaced in place (for example `openclaw update --no-restart` with a running Gateway, or a manual npm install over it) lost its restart markers at the next shutdown: since #185730 (first shipped 2026.11.5) shutdown imported session-restart-resume and subagent-registry only at close, and on a release-to-release swap those chunks are gone (ERR_MODULE_NOT_FOUND). Interrupted sessions then were not resumed. The existing shutdown owner, prepareGatewayShutdownRuntime, now retains both module namespaces at startup and close calls through them, restoring the #160674 contract that shutdown never first-imports code. Docs note that running 2026.11.5/2026.11.6 Gateways keep the limitation for their next in-place replacement. Proof: kernel regression test red on base / green; Crabbox live rotate lanes (all hashed chunks removed, SIGTERM) show session-restart-resume import failures 11.6=3, base=5, fix=0. Other late loads in the same class (state worker restart-lifecycle, memory-core runtime-provider, temp-artifact-cleanup, supervisor) remain and are tracked separately. Refs #202700 Co-authored-by: Peter Steinberger <[email protected]>
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Nov 22, 2026
…age is replaced in place (openclaw#203185) A Gateway whose package is replaced in place (for example `openclaw update --no-restart` with a running Gateway, or a manual npm install over it) lost its restart markers at the next shutdown: since openclaw#185730 (first shipped 2026.11.5) shutdown imported session-restart-resume and subagent-registry only at close, and on a release-to-release swap those chunks are gone (ERR_MODULE_NOT_FOUND). Interrupted sessions then were not resumed. The existing shutdown owner, prepareGatewayShutdownRuntime, now retains both module namespaces at startup and close calls through them, restoring the openclaw#160674 contract that shutdown never first-imports code. Docs note that running 2026.11.5/2026.11.6 Gateways keep the limitation for their next in-place replacement. Proof: kernel regression test red on base / green; Crabbox live rotate lanes (all hashed chunks removed, SIGTERM) show session-restart-resume import failures 11.6=3, base=5, fix=0. Other late loads in the same class (state worker restart-lifecycle, memory-core runtime-provider, temp-artifact-cleanup, supervisor) remain and are tracked separately. Refs openclaw#202700 Co-authored-by: Peter Steinberger <[email protected]>
tideclaw-bot
pushed a commit
that referenced
this pull request
Nov 24, 2026
…age is replaced in place (#203185) A Gateway whose package is replaced in place (for example `openclaw update --no-restart` with a running Gateway, or a manual npm install over it) lost its restart markers at the next shutdown: since #185730 (first shipped 2026.11.5) shutdown imported session-restart-resume and subagent-registry only at close, and on a release-to-release swap those chunks are gone (ERR_MODULE_NOT_FOUND). Interrupted sessions then were not resumed. The existing shutdown owner, prepareGatewayShutdownRuntime, now retains both module namespaces at startup and close calls through them, restoring the #160674 contract that shutdown never first-imports code. Docs note that running 2026.11.5/2026.11.6 Gateways keep the limitation for their next in-place replacement. Proof: kernel regression test red on base / green; Crabbox live rotate lanes (all hashed chunks removed, SIGTERM) show session-restart-resume import failures 11.6=3, base=5, fix=0. Other late loads in the same class (state worker restart-lifecycle, memory-core runtime-provider, temp-artifact-cleanup, supervisor) remain and are tracked separately. Refs #202700 Co-authored-by: Peter Steinberger <[email protected]> (cherry picked from commit 061fd34) Companions: #203241 is selected next in this lane for other late shutdown imports. #203170 guards database migration admission, not marker persistence. Later docs-only overlaps describe independent update UI, recovery, activation, package, advisory, service, or platform contracts; none supplies a dependency of the retained shutdown namespaces. Co-authored-by: RomneyDa <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
Fixes Gateway shutdown failing with
ERR_MODULE_NOT_FOUNDafter an in-place update replaces the running installation's hashed bundles.Related: #159699, whose published 2026.9.6 update proof exposed this failure.
User Impact
Gateways containing this fix can finish cleanup after their package is replaced. This is fixed forward for updates from a release containing the fix: installing the candidate cannot repair code already running in an older Gateway, including 2026.9.6. Final transcript speech and deterministic notes are saved during shutdown; model notes can be regenerated afterward.
Why This Change Was Made
Cleanup consumes state, callbacks, and module promises retained by the subsystem that created the resources. Transcript admission stays in its lightweight owner; Browser relay and Chrome MCP teardown use existing lazy module references; provider, MCP view, discarded-plugin-startup, and worker-artifact cleanup avoid first-loading implementations during retirement. Optional transcript inference is fenced during shutdown.
Worker preparation resolves one cached cleanup module in the pool's detached context before creating resources. Cancellation joins preparation and preserves caller-owned input settlement. Loading during worker preparation preserves the native hook relay's import budget. No Gateway-wide preload, startup budget increase, or timeout relaxation is added.
The audit covered session-end drain, plugin/channel close, sidecars, memory/database cleanup, and restart handoff. Loading a module elsewhere in the process is insufficient: Node can still resolve a new importer's first import against replaced files. Ordinary startup work and already-admitted turn execution remain separate from this cleanup contract.
Evidence
W9: tooling CI attribution and local stop report
The six requested job logs ran merge
2382ffd4742e63765e38b04ac3d2866a6c30b109(PR headf2e9db60beab8eb280ec4d911d8a320840514665into main3e05f6b380cd2d6f68b6205109aacdb5a201d836). Both root causes came from that newer main, not this PR:110167927941,110167927923,110167927868,110167927827, and110167927826contain respectively 16, 5, 2, 8, and 1 unique failing cases. Main commit588b5d7d50b7added theopenclaw-state-maintenance-context.tsimport atsrc/state/openclaw-state-db-async-lifecycle.ts:18without its wrapper inventory entry. Extraction failed before provisioner startup, cascading into private-store injection and main-refresh assertions. Main owner fixb3b34beebe08adds the missing inventory entry. A local extracted-source probe reproduced the exact missing-module error using the CI main lifecycle module; adding only the omitted module let the same provisioner reach normal argument validation.110167927924contains one unique failure: 17 expected-error annotations versus 16 registered entries. Main commit45a3d1723847added the intentional missing-session-key fixture atsrc/auto-reply/reply/get-reply-run-admission.session-file.test.ts:169; it is absent from this PR head. A local scanner probe reproduced that exact additional file/excerpt. Main owner fixbd1138797711now registers it. The moved MCP singleton assertion is unrelated; no inventory allowance was broadened here.No W9 source/test/tooling changes: net 0 LOC. The wrapper inventory already includes the PR's shared lazy-runtime dependency. No duplicate main fixes, commit, force-push, rebase, workflow rerun, or auto-merge re-arm was performed. The PR remains open and mergeable at the original head with its existing squash auto-merge request armed.
Validation on unchanged
f2e9db60: the full six-file selection finished 344 passed, 1 failed, 1 skipped across 5 passing files and 1 failing file in 3156.76 s. All runnable originally reported failing cases passed. The unsupported-filesystem case is skipped on macOS. The additional local failure is the macOS-onlymaterializes full cold/warm PR siblings, then preserves native sparse transitionscase attest/scripts/pr-worktree-provision.test.ts:386: it exceeded its unchanged 120-second limit at 143.497 s. One isolated diagnostic replay failed at 134.309 s (1 failed, 16 filtered/skipped, 141.75 s Vitest duration). Its test and provisioning owner are unchanged by this PR, but the timeout's causal attribution remains unresolved; host load is context, not proof of cause. No timeout, assertion, or test was weakened. This is the W9 stop-report blocker.Commands:
node scripts/run-vitest.mjs test/scripts/pr-wrapper-source-closure.test.ts test/scripts/eager-import-closure.test.ts test/scripts/pr-wrappers.test.ts test/scripts/type-suppression-inventory.test.ts test/scripts/pr-worktree-provision.test.ts test/scripts/pr-main-refresh.test.ts --maxWorkers=1 node scripts/run-vitest.mjs test/scripts/pr-worktree-provision.test.ts --maxWorkers=1 -t 'materializes full cold/warm PR siblings, then preserves native sparse transitions' node scripts/check-changed.mjs --timed -- test/scripts/pr-wrapper-source-closure.test.ts test/scripts/eager-import-closure.test.ts test/scripts/pr-wrappers.test.ts test/scripts/type-suppression-inventory.test.ts test/scripts/pr-worktree-provision.test.ts test/scripts/pr-main-refresh.test.tsThe scoped changed gate passed 17/17 checks, including root tooling/scripts/E2E/other type graphs, scoped lint/format, and three Knip scans with zero entries. Separate type-aware oxlint passed for all 86 changed TypeScript files using their core, extension, root-test, and script configs. Installed oxfmt passed for 88 matched changed files;
git diff --checkpassed. Full-candidate local Codex autoreview against merge base503de53d455c6101e5194a7c960c2c110f434addis P2 scoped-clean. No Gateway was started or stopped.W8: remaining CI failures
Fixed the two fixture failures reported by jobs 110152285448 and 110152281569. Startup shutdown now waits until the real stage-specific admission owner has parked behind suspension before closing; the assertion that drain finishes without reopening suspension is unchanged. The cases remain in their original suite position and share the same fixtures, but live in
server-startup-admission.test-support.tsto satisfy the oversized-file growth ratchet. The SDK fixture now bundles the worker cleanup dependency used during preparation, while retaining its unexpected-import guard, child exit-status assertion, and awaited database cleanup. The clean-close receipt was merely part of the diagnostic message: the actual child failure was the rejectedtemp-artifact-cleanup.tsimport. W8 changes no production code or public contracts; net +39 test/support LOC.Attribution: both exact CI assertions reproduced locally on c91c656. A throwaway comparison using the relevant owner/test files from main 7e7c8d4 reproduced the startup failure unchanged (84 passed, 1 failed). That test supplies no
loadStartupPlugins, so the PR's disposer capture is not executed. Its event-loop assumption predates this PR. The SDK failure is a PR-caused fixture mismatch with cleanup preloading; its main-file comparison instead reached the existing 5-secondnative-same-store parenttimeout on the loaded host, so that comparison is not claimed as passing evidence.Validation: 167 tests passed across nine files, covering both failing files, Gateway startup/connection/admission siblings, transcript sidecar cleanup, and worker cleanup/retirement. After the fixture extraction, the full startup file passed again (85/85, 48.93 s wrapper wall, 45.51 s Vitest duration). The SDK file passed 1/1, covering all three scenarios (12.849 s test execution; 204.94 s wrapper wall including 111.255 s worker-artifact preparation). Original failing CI case costs were 0.058 s and 1.978 s respectively; new-head CI timing is pending. No new test cases, process boots, sleeps, polling, or timeout relaxations were introduced.
node scripts/check-changed.mjs --timed -- <three changed test/support paths>passed all 21 checks in 705.22 s, includinggateway-serverandmessagingtsgo graphs, scoped oxlint/oxfmt, line/assertion ratchets, and all three Knip scans (zero entries). Diff checks pass. Full-candidate local autoreview against merge base 503de53 is P2 scoped-clean. A summary-inference concern was reassessed with the actual tool dispatch and documented global-disable contract; no production change was warranted. No workflow was dispatched or rerun, and no Gateway was started or stopped.Built runtime smoke: started an isolated Gateway, waited for post-ready initialization and a successful
cron.statusread, renamed 7,011 hashed JS/MJS chunks, then sent SIGTERM. It reported clean shutdown and exited 0 in 6,273 ms, with no missing-module errors. Total smoke wall time: 106.77 s. The fixture used private configuration/state, a free loopback port, and disabled plugins/channel/cron timers.Loader guards fail on the corresponding unpatched main code for transcript sidecar stop, Browser relay/Chrome MCP teardown, MCP view disposal, and worker-artifact retirement. Candidate cases pass. The request-context guard also failed before detached worker preparation and passes afterward.
Focused consumers: 937 tests passed across Gateway, transcripts, CLI, agents, plugins, and Browser. Final worker lifecycle siblings: 79 passed. Startup import-boundary tests: 11 passed.
Builds:
pnpm build:ci-artifactspassed in 437.53 s, including 95 bundled plugins, published-updater compatibility bridges, SDK exports, and startup import guards. The final runtime refresh using the canonicalqaRuntimeprofile passed in 109.96 s.Types:
pnpm tsgo:core, eight relevant core test graphs, root E2E/other graphs, and extension production/test graphs passed. Affected worker and CLI/MCP graphs were rechecked after follow-ups.Runtime value cycles and Madge: zero. Scoped type-aware lint, formatting, runtime-sidecar loader guards, line-count/assertion-safety ratchets, and diff checks passed. Resolve-undo is empty. Final full-candidate P2 review is clean. After resolving the documentation-only rebase conflict, core types, focused shutdown regressions, the runtime build, and the chunk-removal smoke passed again on the rebased head.
Maintainer review follow-up (
refactor: drop lazy and aliased shutdown cleanup imports, net −6 LOC):closeCliResourcesreads dispatcher-pool facts from its existing staticprovider-runtime-lifecycleimport, so no teardown path in this build lazily imports that module. The stabletsdownentry stays:scripts/lib/update-compat-chunks.mtsbridges published builds' hashedprovider-runtime-lifecycle-*.jschunks to a current chunk that still exports those facts. Removing it broke every CI shard withCannot bridge ... no equivalent current export; restoring it lets theprevious release update compat chunkspostbuild phase pass locally. The canonicalstopActiveManagedProviderLocalServicesname replaces a naming-only alias. MCP cleanup callers importreleaseSessionMcpRuntimeandcompleteDeferredSessionMcpRuntimeRetirementfrom their owner module instead of a forwarding re-export. Chrome MCP teardown'speek()is exact: every session-creating route call runs afterensureTabAvailable, which loads the adapter throughgetChromeMcpModule(). Re-run: 29 targeted consumer files (bundle-mcp, mcp-app, run-loop, runtime-cleanup, run-main.exit, MCP runtime/manager) gave 847 passed and 1 failed. That failure wassettles private MCP acquisition cancellation at ready(agent-bundle-mcp-runtime.test.ts:2298, cleanup-failure check atagent-bundle-mcp-runtime.ts:1110) during a 506 s loaded run. The full file replayed in its original order passed 114/114, which is recorded here as unexplained; it is not treated as fixed.agent-command-local.test.tscould not run locally because the Gateway-artifact preparation fence refused runtime preparation, so CI covers it. Import cycles are 0, lint and format are clean, core, extension and root production/test type graphs pass (test-root-otherwas interrupted at the 15-minute budget), and local-candidate Codex autoreview P2 is scoped-clean.Rebased onto
maine92ab30 (toolchain moved to TypeScript 7.1-dev, Vitest 5):mainsplit worker construction intosrc/infra/worker-task-pool-worker.ts, so temp-artifact cleanup is now imported statically there, and this PR's superseded asynchronous preparation path and its two interleaving tests were removed (−104 LOC against the earlier PR revision). CI follow-ups: the launchd fixture uses the canonicalstopActiveManagedProviderLocalServices; the browser relay integration fixtures (gateway-relay-ingress,gateway-relay-route,bootstrap.chromium) load the handler throughgetGatewayExtensionRelayModule()like production does; Knip treatsprovider-runtime-lifecycleas an entry because published-update bridges consumehasManagedProviderLocalServices; the admission-identity fixture awaits its async database-close owners. Locally: launchd 4/4, browser relay and shutdown suites 24/24, all Knipdeadcodescans 0 entries, oxfmt/oxlint clean, and Codex autoreview P2 is scoped-clean on the full rebased candidate. The runtime inventory and npm package-planning failures in the previous CI run were already fixed onmain(5b76930, 172043b).reply-turn-admission.module-identitycould not be judged locally: it hit its 5 s probe bound at 8.2 s with the host at load average 65–80, so this CI run is its proof. Package planning could not run locally because the Gateway-artifact fence detected running operator services.Worker cleanup preload follow-up (
f228f3f926b0): replaces the rebase's static import with one cached dynamic loader awaited by task preparation in the detached pool context, beforeprepareWorkercreates resources. Worker construction stays synchronous. The interim preload reproduced 4 failed / 3 passed cleanup cases; the repair passes 124/124 worker-pool tests across 12 files in 151.78 s, including all four guards. Core production types and all 27 selected test graphs (including infra) passed. Scoped oxlint, oxfmt, diff checks, and full-candidate local Codex autoreview P2 are clean. The native relay CLI source closure has 149 modules, zero forbidden imports, and zero unresolved edges. The existing-dist CLI bootstrap guard passes; fresh emitted-bundle proof remains for CI because no full build was run. The changed-lanes run stopped at the 15-minute host budget during the broader deprecated-API audit, after typechecks passed; scoped lint then passed separately. Net +20 production LOC; no tests added or changed.Squashed to one commit and rebased onto
main503de53 (the PR had gonedirty), resolving seven conflicts ontomain's newer shapes: the shared MCP acquisition helper, transcript fixtures, shared run-loop mocks and the workerPostedTasktype. Worker artifact cleanup is now preloaded in detached task preparation instead of statically imported, which keepschalk/tslogout of the native hook relay's static graph (the CI build guard failure on fae5784). Local results on the rebased candidate: 221 focused tests passed; core production types and six core-test graphs pass; Knip deadcode, the CLI bootstrap guard and a relay source traversal (0 forbidden imports) pass; oxfmt is clean; Codex autoreview P2 is scoped-clean. One local failure is recorded here rather than hidden:transcripts-tool.account-ownership.test.ts› "applies provider access to historical rows after the agent boundary" hit its 120 s timeout at 134 s with host load 104–140, then passed in an original-order standalone replay at 104 s. The replay does not prove a fix; this CI run is the judge. The remaining type graphs and oxlint were cut short by the local time budget and run in CI.Measured test cost and fixture corrections
One-worker runs used
pnpm test <selected files> --maxWorkers=1. The eight-file regression run took 213.99 s wall. The final five-file worker selection took 59.11 s, including shared compiler preparation. Measured file execution times:The summary tests exercise real SQLite-backed accepted-speech persistence and finalization, which a loader-only mock cannot prove. The import guard traverses real source graphs; batching and caching import facts reduced its kernel case from a 120 s timeout to 21.3 s without changing assertions or budgets. Existing CLI consumer files took 75.837 s and 5.779 s; their changes only adapt mocks.
The retirement fixture now waits for fake-worker task admission. A diagnostic also demonstrated that concurrent first imports could resolve one mocked and one real cleanup export; retaining one loader promise gives all workers the same owner-held export. The transcript sidecar fixture registers its mocks before importing the now-lightweight owner. Smoke setup follows the current published launcher inventory and readiness parser, and waits for post-ready initialization before removing files.
No new process boots, sleeps, polling, or worker pins were introduced into CI tests. CI timing is pending; no workflow was dispatched or rerun for proof.