Skip to content

fix(gateway): stop treating restarts as plugin removal - #164975

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-plugin-cleanup-on-restart-20260919
Oct 4, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-plugin-cleanup-on-restart-20260919

Conversation

@steipete

@steipete steipete commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes slow, failed Gateway stops when normal shutdown retires loaded plugins as if they had been disabled. A production restart reported 38 identical plugin retirement timeouts after 5,000 ms, finished resource cleanup in 9,654 ms, and exited with status 1.

User Impact

Stopping or restarting preserves persistent plugin session state and invokes restart cleanup hooks. Settled plugin callback failures remain visible as named warnings without turning normal shutdown into a failed process exit. Required session-state cleanup failures remain fatal, and admitted write-capable work still settles before shared resources close.

Why This Change Was Made

Terminal registry clearing enabled persistent-state cleanup without a successor registry. That selected disable, causing every loaded plugin—including ones without cleanup callbacks—to enumerate every agent's session store. Each instance's five-second observer could expire while its single host-cleanup call ran; the cached timeout result then survived the actual cleanup join and became a fatal Gateway-close error.

Remove that state-deletion path from Gateway retirement, including sibling Gateway close. Explicit plugin disable/removal keeps its existing state cleanup. Preserve resource-specific warnings for completed callbacks while retaining fatal handling for session-store failures and rejected lifecycle prerequisites. No timeout increase, new configuration, migration, or plugin-specific workaround.

Production LOC: +5 net. The five added lines distinguish callback diagnostics from required state-write failures and apply the existing retirement owner’s preservation contract to sibling Gateway shutdown.

Evidence

  • Production before: forced retirement after 5000ms: 1 still-running call(s), 0 retained consumer(s) for 38 loaded plugins; shutdown failed in 9654ms; exit 1/FAILURE.
  • Isolated Ubuntu/Node 26 dist Gateway, identical 50,000-session fixture and 38 loaded plugins (ClickClack, Discord, Parallel, Team Reports, plus 34 inert fixtures): shutdown 10,546 → 169 ms; SIGTERM-to-exit 11,441 → 1,016 ms; forced retirements 20 → 0; exit 1 → 0. Plugin state was erased before and preserved after. No production restart performed. Both changed production files matched local Git object hashes.
  • Runtime builds: OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 pnpm build:docker passed before and after. Initial full-build attempt was invalidated by fixture packages being created during compilation; a redundant declaration build was stopped before selecting the supported runtime-only mode.
  • Blacksmith Testbox (openclaw-check), lease tbx_01m43m7pt02xa9g4pce3ajfrpj: both negative controls failed on original production code for the intended defects (74.94 s command, expected-failure driver exit 0). The first 175 focused and sibling tests passed, including bounded hanging-retirement observations, admitted-write joins, supervised exit 0 for callback errors, and fatal required-state errors.
  • CI exposed one missed successor-handoff contract: terminal cleanup must retain the existing successor-registry lookup to preserve scheduler jobs adopted while a command drains. Restoring that lookup passes the exact failing contract and the complete focused selection: 177 tests on fresh Testbox tbx_01m43qw8ays7fdqp54cg3c953k (rebased main removed two unrelated old cases). node scripts/check-changed.mjs --base HEAD --timed also passed every check; the focused-test-plus-gate command completed in 25m5.620s with exit 0. Its timing table records core types (43.02s), all core test types (1043.73s), lint (5.79s), export scan (69.34s), and all boundary guards as passing.
  • Injected native callback failure: synthetic socket cleanup failed was reported with its plugin/instance, shutdown completed in 161 ms with warnings, state survived, and the dist process exited 0.
  • Changed gate: the authorized Linux fallback caught a test-file growth ratchet; the new required-state case was moved to the existing focused plugin-cleanup table. node scripts/check-changed.mjs then passed on the Testbox lease (exit 0; focused-test-plus-gate command 23m54.865s): core types, all 27 test type graphs, formatting, lint, export/cycle scans, schema and boundary guards. Successful runs suppress the timing table without --timed.
  • Independent Codex review: final diff scoped-clean at P0–P2 after incorporating the test and dist proof.
  • Earlier CI exposed stale composer E2E assertions after fix(chat): model picker spins on every message #164963 changed the model-picker behavior. The identical assertion repair is now on main through perf(gateway): share update status preparation across reconnects #164984; rebase dropped the duplicate UI commit, so this PR has no UI changes. Its proof on Blacksmith Testbox tbx_01m43t27w720fpzjrthp2dbbrz: CI=1 OPENCLAW_UI_E2E_SKIP_REAL_GATEWAY=1 node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner --maxWorkers=1 ui/src/e2e/chat-composer-catalog.e2e.test.ts passed 12 tests in 43.89 s; node scripts/check-changed.mjs --base HEAD --timed passed, including UI types (44.58 s). Combined command: 5m1.985s, exit 0.
  • The next CI run exposed a missed sibling assertion in degraded model acquisition: settled callback faults still expected a rejected close and an unconsumed retirement queue. Successful close consumes that queue in the existing lifecycle owner. The corrected test checks successful close and the named shutdown warning, preserving acquisition cancellation, cleanup joins, resource release, and deadline assertions. Blacksmith Testbox tbx_01m43v4c3gxgr90r23j3kvn0k4: pnpm test src/gateway/server-close.model-acquisition.test.ts --maxWorkers=1 passed 6 cases in 21.91 s; node scripts/check-changed.mjs --base HEAD --timed -- src/gateway/server-close.model-acquisition.test.ts passed every selected gate, including Gateway test types (38.51 s) and export scans (64.47 s). Combined command 5m38.497s, exit 0. Fresh independent review was scoped-clean at P0–P2. All four Testbox leases are stopped; all three synthetic rig worktrees are removed.
  • Measured pnpm test <file> --maxWorkers=1 wall time: host-hook retirement 26.08 s (10 tests), Gateway plugin failures 16.09 s (5 tests), Gateway agent databases 35.07 s (5 tests), and model acquisition 21.91 s (6 tests). The database file uses its existing real Gateway/SQLite lifecycle fixtures to prove admitted writes settle before shared resources close; this change only adds the state-preservation assertion to that fixture. Across the corrected focused selections, 183 shutdown and sibling tests passed. Final CI run 37217348269 passed on head 1da3342e054e in 430 seconds (7m10s), including queue and orchestration time; every executed job passed. Hosted review reported no actionable findings. This head merged as 6636dd6709bd on 2026-10-04 at 16:44:02 UTC. Initial proof ran on base 2851e89750f5; corrected dist proof ran on 3cf1e6ffc01b plus the successor fix; the final acquisition proof used base b344da3b9855 plus the complete candidate overlay, verified by every changed file's Git hash. The clean rebase onto 5f497e71d52c preserves the exact production and acquisition-test hashes. CI validates final head 1da3342e054e. The first CI run also timed out hovering an unchanged widget in the mocked-Gateway UI sandbox test; that test passed on subsequent heads, without a claimed fix for the intermittent fixture failure.

Private external plugins unavailable in this checkout are covered by the shared lifecycle contract, not direct plugin-loading proof. Authenticated channel traffic is outside this synthetic shutdown proof. Arbitrary native cleanup that never settles and can still write retains the existing resource-safety barrier; this change does not abandon accepted writes.

@clawsweeper

clawsweeper Bot commented Oct 4, 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 4, 2026 15:10
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime plugin: file-transfer size: S labels Oct 4, 2026
@steipete
steipete enabled auto-merge (squash) October 4, 2026 15:12
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 12:41 PM ET / 16:41 UTC (Revision 4).

ClawSweeper review

What this changes

The PR preserves plugin session state during Gateway shutdown, reports settled cleanup callback failures as warnings, and updates lifecycle documentation and regression coverage.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still deletes plugin session state during terminal retirement and treats settled callback faults as fatal. The pinned patch addresses both behaviors without an actionable correctness finding, and the supplied shutdown proof covers the changed production path.

Priority: P1
Reviewed head: 1da3342e054ec9c2e1fa9c9fca1d7cff6aa7175c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused lifecycle repair with strong production-path observations and meaningful regression coverage; no blocking defect was found.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied isolated dist Gateway SIGTERM runs exercise registry retirement and Gateway close with existing plugin session state, showing preserved state, zero forced retirements, and exit zero; injected native callback failure shows the changed warning outcome. Supplemental regressions cover required-state failure and cleanup joins. No stored format, schema, or migration changes are introduced.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The supplied isolated dist Gateway SIGTERM runs exercise registry retirement and Gateway close with existing plugin session state, showing preserved state, zero forced retirements, and exit zero; injected native callback failure shows the changed warning outcome. Supplemental regressions cover required-state failure and cleanup joins. No stored format, schema, or migration changes are introduced.
Evidence reviewed 8 items Pinned introduced change: Reviewed the merge-base-to-head delta. Production changes are limited to Gateway failure classification and registry retirement; the original head's raw parent agrees with the host record.
Still necessary on current main: Fetched main still passes cleanupPersistentState: true during terminal registry clearing and makes every reported plugin cleanup failure fatal. Neither related merged UI/update-status PR implements this shutdown repair.
Failure classification preserves required cleanup: Gateway close retains cleanup joins before database retirement, emits named callback warnings, and continues to reject session-store failures and rejected lifecycle prerequisites.
Findings None None.
Security None None.

How this fits together

The Gateway coordinates plugin retirement when OpenClaw stops or restarts. Its lifecycle owners drain admitted work, release plugin resources, and then close shared databases.

flowchart TD
  A[Stop or restart] --> B[Gateway shutdown]
  B --> C[Drain admitted work]
  C --> D[Retire plugin resources]
  D --> E[Preserve session state]
  D --> F[Classify cleanup failures]
  F --> G[Warnings or failed shutdown]
  E --> H[Close shared databases]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +5, Tests -4, Docs +7. Total +8 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 2 12 7 +5
Tests 4 50 54 -4
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 69 61 +8

Review metrics

Metric Value Why it matters
Production versus test growth production +5 net; tests -4 net The small production increase is justified by failure classification and sibling retirement using the existing preservation contract.

Technical review

Best possible solution:

Keep restart cleanup in the existing retirement owner, preserve stored plugin state, and retain visible warnings plus fatal handling for required cleanup failures.

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

Yes: current-main terminal retirement selects persistent-state deletion, and the supplied dist Gateway comparison exercises that shutdown path with existing sessions. This read-only review did not execute it.

Is this the best way to solve the issue?

Yes: the patch reuses the existing retirement preservation contract, keeps disable/removal cleanup, and distinguishes callback diagnostics from required state failures.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The supplied production failure shows normal Gateway restart deleting plugin state and exiting unsuccessfully.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The supplied isolated dist Gateway SIGTERM runs exercise registry retirement and Gateway close with existing plugin session state, showing preserved state, zero forced retirements, and exit zero; injected native callback failure shows the changed warning outcome. Supplemental regressions cover required-state failure and cleanup joins. No stored format, schema, or migration changes are introduced.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied isolated dist Gateway SIGTERM runs exercise registry retirement and Gateway close with existing plugin session state, showing preserved state, zero forced retirements, and exit zero; injected native callback failure shows the changed warning outcome. Supplemental regressions cover required-state failure and cleanup joins. No stored format, schema, or migration changes are introduced.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head delta. Production changes are limited to Gateway failure classification and registry retirement; the original head's raw parent agrees with the host record. (src/plugins/runtime.ts:516, 1da3342e054e)
  • Still necessary on current main: Fetched main still passes cleanupPersistentState: true during terminal registry clearing and makes every reported plugin cleanup failure fatal. Neither related merged UI/update-status PR implements this shutdown repair. (src/plugins/runtime.ts:668, aad828fe5bb8)
  • Failure classification preserves required cleanup: Gateway close retains cleanup joins before database retirement, emits named callback warnings, and continues to reject session-store failures and rejected lifecycle prerequisites. (src/gateway/server-close.ts:641, 1da3342e054e)
  • Existing retirement owner and disable contract: The existing retirement implementation maps skipped persistent cleanup to restart hooks. Explicit replacement/removal retains persistent cleanup, and the retirement table verifies old-store preservation only for terminal clearing while retaining deletion assertions for the other modes. (src/plugins/host-hook-cleanup.retirement.test.ts:84, 1da3342e054e)
  • Production shutdown proof: The captured body reports an isolated Ubuntu/Node 26 dist Gateway with 38 plugins and 50,000 existing sessions: shutdown improved from 10,546 to 169 ms, forced retirements from 20 to zero, exit status from one to zero, and plugin state survived. An injected native callback fault produced its named warning, preserved state, and exited zero. The body records production-file identity across the final rebase and 183 corrected shutdown/sibling tests. Captured source identity: 0266d4e8f886eb0e2246c5be468160e6018f1c7fd52f47cd29a27b0d85eed356. These runs were supplied evidence, not executed by this review.
  • Re-review continuity: The previous completed review retained no findings or published rank-up moves. The current acquisition test now awaits successful close and checks the named warning while preserving cancellation, cleanup settlement, worker release, and deadline assertions. The earlier reviewed object was unavailable locally, so a direct historical comparison could not be completed. (src/gateway/server-close.model-acquisition.test.ts:387, 1da3342e054e)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • JC: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-04T15:15:47.762Z sha 3cf1e6ffc01b619d5600bd904b3afe1f7ae3dcc4 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-04T15:54:32.117Z sha a383de3 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-04T16:12:54.069Z sha e818e0638793c2a14c77a847f216eb3417fec89b :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the steipete/perf-micro-plugin-cleanup-on-restart-20260919 branch 2 times, most recently from a383de3 to e818e06 Compare October 4, 2026 16:06
@openclaw-barnacle openclaw-barnacle Bot added the app: web-ui App: web-ui label Oct 4, 2026
Treat normal Gateway retirement as restart cleanup, leaving persistent plugin
session state to the explicit disable/removal owner. Report settled plugin
callback failures as named warnings while preserving fatal state-write errors
and admitted-work settlement.

The Linux dist shutdown rig with 38 plugins and 50,000 synthetic sessions
improves cleanup from 10,546 ms to 159 ms, removes 20 forced retirements,
preserves plugin state, and changes exit status from 1 to 0.
Resolve the current successor registry after admitted command work settles,
so retiring cleanup preserves scheduler jobs adopted by that successor.

The existing held-command cleanup contract reproduces the missed handoff.
All 177 focused tests and the changed-file gate pass on Blacksmith Testbox.
Assert successful close and a named warning after a settled callback fault.
Successful close consumes the retirement queue, so verify the operator
diagnostic instead of expecting an already-consumed failure afterward.

Preserve acquisition cancellation, cleanup joins, resource release, and the
shutdown deadline. All six acquisition cases pass on Blacksmith Testbox.
@steipete
steipete force-pushed the steipete/perf-micro-plugin-cleanup-on-restart-20260919 branch from e818e06 to 1da3342 Compare October 4, 2026 16:35
@openclaw-barnacle openclaw-barnacle Bot removed the app: web-ui App: web-ui label Oct 4, 2026
@steipete
steipete merged commit 6636dd6 into main Oct 4, 2026
153 of 154 checks passed
@steipete
steipete deleted the steipete/perf-micro-plugin-cleanup-on-restart-20260919 branch October 4, 2026 16:44
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
* fix(gateway): preserve plugin state during shutdown

Treat normal Gateway retirement as restart cleanup, leaving persistent plugin
session state to the explicit disable/removal owner. Report settled plugin
callback failures as named warnings while preserving fatal state-write errors
and admitted-work settlement.

The Linux dist shutdown rig with 38 plugins and 50,000 synthetic sessions
improves cleanup from 10,546 ms to 159 ms, removes 20 forced retirements,
preserves plugin state, and changes exit status from 1 to 0.

* fix(plugins): preserve successor jobs during shutdown

Resolve the current successor registry after admitted command work settles,
so retiring cleanup preserves scheduler jobs adopted by that successor.

The existing held-command cleanup contract reproduces the missed handoff.
All 177 focused tests and the changed-file gate pass on Blacksmith Testbox.

* test(gateway): verify cleanup warnings after degraded acquisition

Assert successful close and a named warning after a settled callback fault.
Successful close consumes the retirement queue, so verify the operator
diagnostic instead of expecting an already-consumed failure afterward.

Preserve acquisition cancellation, cleanup joins, resource release, and the
shutdown deadline. All six acquisition cases pass on Blacksmith Testbox.
RomneyDa pushed a commit that referenced this pull request Oct 6, 2026
* fix(gateway): preserve plugin state during shutdown

Treat normal Gateway retirement as restart cleanup, leaving persistent plugin
session state to the explicit disable/removal owner. Report settled plugin
callback failures as named warnings while preserving fatal state-write errors
and admitted-work settlement.

The Linux dist shutdown rig with 38 plugins and 50,000 synthetic sessions
improves cleanup from 10,546 ms to 159 ms, removes 20 forced retirements,
preserves plugin state, and changes exit status from 1 to 0.

* fix(plugins): preserve successor jobs during shutdown

Resolve the current successor registry after admitted command work settles,
so retiring cleanup preserves scheduler jobs adopted by that successor.

The existing held-command cleanup contract reproduces the missed handoff.
All 177 focused tests and the changed-file gate pass on Blacksmith Testbox.

* test(gateway): verify cleanup warnings after degraded acquisition

Assert successful close and a named warning after a settled callback fault.
Successful close consumes the retirement queue, so verify the operator
diagnostic instead of expecting an already-consumed failure afterward.

Preserve acquisition cancellation, cleanup joins, resource release, and the
shutdown deadline. All six acquisition cases pass on Blacksmith Testbox.

(cherry picked from commit 6636dd6)
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 P1 High-priority user-facing bug, regression, or broken workflow. plugin: file-transfer 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