Repository navigation
fix(gateway): stop treating restarts as plugin removal - #164975
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 12:41 PM ET / 16:41 UTC (Revision 4). ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherThe 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +5, Tests -4, Docs +7. Total +8 across 7 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
a383de3 to
e818e06
Compare
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.
e818e06 to
1da3342
Compare
* 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.
* 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)
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
forced retirement after 5000ms: 1 still-running call(s), 0 retained consumer(s)for 38 loaded plugins;shutdown failed in 9654ms; exit1/FAILURE.OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 pnpm build:dockerpassed 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.openclaw-check), leasetbx_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.tbx_01m43qw8ays7fdqp54cg3c953k(rebased main removed two unrelated old cases).node scripts/check-changed.mjs --base HEAD --timedalso 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.synthetic socket cleanup failedwas reported with its plugin/instance, shutdown completed in 161 ms with warnings, state survived, and the dist process exited 0.node scripts/check-changed.mjsthen 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.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.tspassed 12 tests in 43.89 s;node scripts/check-changed.mjs --base HEAD --timedpassed, including UI types (44.58 s). Combined command: 5m1.985s, exit 0.tbx_01m43v4c3gxgr90r23j3kvn0k4:pnpm test src/gateway/server-close.model-acquisition.test.ts --maxWorkers=1passed 6 cases in 21.91 s;node scripts/check-changed.mjs --base HEAD --timed -- src/gateway/server-close.model-acquisition.test.tspassed 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.pnpm test <file> --maxWorkers=1wall 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 head1da3342e054ein 430 seconds (7m10s), including queue and orchestration time; every executed job passed. Hosted review reported no actionable findings. This head merged as6636dd6709bdon 2026-10-04 at 16:44:02 UTC. Initial proof ran on base2851e89750f5; corrected dist proof ran on3cf1e6ffc01bplus the successor fix; the final acquisition proof used baseb344da3b9855plus the complete candidate overlay, verified by every changed file's Git hash. The clean rebase onto5f497e71d52cpreserves the exact production and acquisition-test hashes. CI validates final head1da3342e054e. 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.