Repository navigation
fix(plugins): recover channels after replacement drain timeouts - #150953
Conversation
Retry admitted-work drain before restoring captured previous registrations. Settle failed reload pauses, preserve resource ownership, and expose replacement and activation failures through readiness.
|
🦞👀 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: blocked before merge. Reviewed September 17, 2026, 11:51 AM ET / 15:51 UTC (Revision 3). ClawSweeper reviewWhat this changesThe PR adds bounded plugin replacement recovery, releases channel pauses after failure, preserves restart budgets, and exposes recovery status through Gateway readiness. Merge readiness⛔ Blocked before merge - 2 items remain This remains a useful recovery fix that current main does not provide. No blocking code defect was found in the introduced changes; the repository-required update compatibility evidence remains outstanding. Priority: P1 Review scores
Verification
How this fits togetherThe Gateway replaces running plugins while coordinating admitted work, resource cleanup, and channel restarts. Its lifecycle owner publishes recovery status to readiness probes and controls when channel health monitoring can resume. flowchart TD
A[Plugin reload request] --> B[Pause and stop affected channels]
B --> C[Drain admitted work]
C --> D{Work settles safely?}
D -->|Yes| E[Restore captured plugin runtime]
E --> F[Restart eligible channels]
D -->|Deadline or cleanup failure| G[Release pauses and retain resource fences]
G --> H[Report actionable readiness failure]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +183, Tests +177, Docs +34. Total +394 across 22 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep recovery within the existing lifecycle owner, preserve unfinished-write ownership and manual stops, and establish update compatibility with existing operator state. Do we have a high-confidence way to reproduce the issue? Yes, from source: hold an admitted plugin write beyond both existing drain observations after its channels stop; current main can exit without releasing their reload pause. This review did not execute that scenario. Is this the best way to solve the issue? Yes. Retrying drain observation and restoring captured code through the existing lifecycle owner addresses the failure without abandoning writes or introducing competing recovery ownership. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 27bd778af0c4. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Keep failure diagnostics for retired plugins omitted by recovery. Exercise installed plugin retries against the reported deadline while preserving exclusive resources and sibling ownership.
|
Merged via squash.
|
…claw#150953) * fix(plugins): recover channels after replacement drain timeouts Retry admitted-work drain before restoring captured previous registrations. Settle failed reload pauses, preserve resource ownership, and expose replacement and activation failures through readiness. * fix(plugins): retain unresolved partial rollback failures Keep failure diagnostics for retired plugins omitted by recovery. Exercise installed plugin retries against the reported deadline while preserving exclusive resources and sibling ownership.
Related: #125596, #125990
What Problem This Solves
Fixes channels remaining permanently paused after plugin replacement stops their runtime and then times out waiting for admitted work.
On 2026-09-17, a production Gateway on build
9a4468148bclogged a Discord admitted-work cleanup timeout at 07:05:30Z andGateway generation 2: replacement not applied. Until its restart at 13:59Z, roughly seven hours later, readiness reported Discord and ClickClack failing. The health monitor retried every 30 seconds but receivedChannel plugins are reloading; retry the start after reload completes(42+ observed attempts). Plugin health/lifecycle calls rejected retired instances, andchat.metadata/session.discussion.inforeturnedUNAVAILABLEwith the failed replacement. No recovery completed automatically.User Impact
A failed replacement now retries the admitted-work drain for up to 60 seconds with bounded backoff, then restores captured previous code/configuration in fresh registrations and restarts channels. Manual stops remain respected. The monitor preserves its restart budget while a reload actually holds admission paused.
If admitted work outlives that window, or resource cleanup cannot safely succeed, replacement settles as failed, releases reload pauses, and reports
plugin-reloadwith affected plugin IDs and recovery instructions in detailed readiness. Callable channels can restart; unavailable plugins require a lateropenclaw plugins reload <id>after work settles, or a Gateway restart. Unrelated successful reloads and partial rollbacks preserve unresolved failure diagnostics for plugins they did not restore.Why This Change Was Made
The existing cleanup contract requires actual write settlement before another registration acquires the same resources. A timeout is not permission to abandon an admitted write. Recovery therefore retries only drain observation (one-, two-, then four-second backoff), never service stop or resource disposal. Channel pause state distinguishes active replacement from settled failure and retains safe account snapshots when old plugin callbacks are unavailable. The Gateway generation owner retains recovery status, consumed directly by readiness before its cache. Publication alone does not clear the failure: errors in later activation hooks or channel startup remain visible even though the new generation committed.
Strict service/channel stop failures and rejected-candidate cleanup failures retain their existing resource barriers; the new drain recovery loop does not retry those side effects. No configuration, schema, dependency, or reload-triggering policy changes.
Update behavior: the installed updater still runs first and the candidate's existing Gateway restart loads this recovery behavior. Existing operator config/state remains the input; no migration, new marker, or updater-side change is required. This does not repair an already wedged old process before restart. The published-driver × exact-candidate cell below verifies that configured channels survive the update. Installed-package regressions separately cover deliberate replacement drain failures.
Evidence
node scripts/check-changed.mjs: passed, including core/test typechecking, lint, line-cap and suppression ratchets, plugin boundaries, dead exports, docs consistency, database guards, and import cycles.git diff --check: passed. The first CI run exposed an installed-package test that still assumed two five-second drains; its fake clock now advances the reported recovery deadline, with unchanged real test timeouts and preserved resource/sibling assertions. Final correction checks also passed. Exact-head CI targets4969f33e0c844c14758dd3add84fee085ea2be88. Its first attempt passed the plugin-reload shard but hit a 60-second timeout in the unchanged Doctor refusal-receipts process test; that job passed on the prior head. One failed-job rerun was requested without changing code, timeouts, or assertions.Published updater and configured-channel survival
The required channel-survival assertions passed in Blacksmith Testbox run 35250228316, lease
tbx_01m2r52wd3r6wb43ka1pecb47d. A disposable real user-systemd service ran published[email protected]with the maintained external ClickClack HTTP/WebSocket fixture. Its normalopenclaw update --tag file:<candidate-tarball> --yes --jsonpath installed and restarted into the exact candidate.Source binding: approved head
4969f33e0c844c14758dd3add84fee085ea2be88, verified tree9bffbfed0c20117eaa95c51480105dd2e341272e, tarball SHA-25665804328a95266feef821955bb66ec257f8415d5caa23edd3d7bfc4e37dadb75. Testbox carrier7d3208bf975626cff382f748bc533899f3eb2a83has that same tree; the updater's running-build verification matched2026.9.4-7d3208bf9756-2026-09-17T17-07-32.332Z.status=ok; its run finishedsucceeded. Native verification recordedserviceRunning=true,versionMatch=true,channelsReady=true,readyz=true, andsettled=true, with the new service PID.clickclack/default. Before and after update it was enabled, configured, and running, withlastError=nulland no status issues. The fixture had one active WebSocket and its connection generation increased from 1 to 2, proving a new connection after replacement.ready=true,failing=[], and no suppressed orpluginReloadstate. Channel configuration output was unchanged, and the base unit and operator drop-in hashes matched across the update.gateway status --deepRPC assertion reportedDEVICE_IDENTITY_REQUIRED. The identical error occurred on the published baseline and candidate. Both actualgateway call channels.statuscalls succeeded, and the native updater independently verified the candidate's running build and readiness. The requested channel/update conditions are established by those retained artifacts; the unrelated deep-status failure is preserved. No assertion was removed, weakened, or rerun, and no transport/capacity retry was used.This is synthetic-channel update proof, not a production deployment or a replacement for the fault-injection lifecycle regressions above. The landing runner inspected the updater receipt, both channel/status/readiness snapshots, fixture connection evidence, source/package binding, and cleanup results.
Docs updated: plugin architecture/lifecycle, config hot reload, and Gateway health/readiness. Production Gateway changes and landing remain outside this PR preparation work.