Skip to content

fix: prevent queued replies from wedging plugin reloads - #193501

Merged
steipete merged 1 commit into
mainfrom
fix/drain-hotloop
Nov 5, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/drain-hotloop

Conversation

@steipete

@steipete steipete commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Related: #193313. Preserves the exact-claim settlement fence from #193423.

What Problem This Solves

Fixes a Gateway hang when an ordinary queued follow-up starts preparing while its channel plugin is being replaced.

User Impact

Health and status requests keep responding during reload. Queued inputs survive successful replacement and rollback without duplicate model runs. Disabling a channel preserves unexecuted durable input as pending for re-enablement, with its existing abandonment record.

Why This Change Was Made

A pre-execution plugin refusal retained the same queue head and immediately retried it. At zero debounce, the promise chain starved I/O, replacement progress, timers, and signal handling. This reproduces on current main without the queue-cap PR.

The drain now waits on the existing plugin owner's replacement settlement while keeping its exact FIFO claim. Source, claim, or mailbox cancellation releases that wait through existing custody handling. The successor channel reclaims the durable input with fresh callbacks; early rollback can resume the original instance. An unavailable instance without a pending replacement records abandonment instead of spinning. Existing live-authority checks and settlement fences remain intact. No schema, dependency, configuration, or public API change.

Evidence

Current-main control: Node 26.12.1 and pinned Bun, real isolated Gateway, shared Ollama qwen2.5:7b, ordinary follow-up queue, one survivor, no cap drops. The running request received its model response; the survivor stayed claimed at attempts=0. Health/status timed out and SIGTERM needed an exact-PID SIGKILL fallback. The clean Bun capture recorded 4,694 repeated refusals and more than five seconds without the main-thread timer running.

All six candidate cases pass. Measurements run after the running request is held and the follow-up is queued, through reload and source settlement. Requests and replies are RUNNER/B/C/D exactly once for success and recovery. Disablement cancels the running turn and leaves B pending with attempts=1 and last_error=turn-abandoned, without a B model request.

Runtime Outcome Max health Max status Unavailable errors SIGTERM exit
Node 26.12.1 Success 222 ms 427 ms 1 257 ms
Node 26.12.1 Registration failure/recovery 232 ms 357 ms 1 153 ms
Node 26.12.1 Disabled 142 ms 158 ms 0 254 ms
Pinned Bun Success 9 ms 100 ms 1 155 ms
Pinned Bun Registration failure/recovery 95 ms 102 ms 1 259 ms
Pinned Bun Disabled 67 ms 128 ms 0 254 ms

Every reload-window health/status probe succeeded. The 200 ms main-thread timer's maximum observed interval was 375 ms across the candidate reloads, compared with over five seconds of starvation on main. Reload operations settled in 1.1–3.1 seconds. CPU was sampled separately: median samples were 130.2% in the main reproduction and 30.9% in the candidate Bun success window. Registration and disablement still produce brief CPU bursts; these observations are not a peak-CPU ceiling.

  • Eight deterministic replacement/rollback/unavailability/cancellation regressions fail on the original premature retry and pass with the fix.
  • 415 focused tests across 18 files pass, covering queue/drain, source custody, ingress claim ownership, plugin retention and Gateway reload/recovery. Final changed-test run: 15 tests, 66.49 seconds wall time; test bodies remain small. The broader 394-test run took 169.55 seconds.
  • Full build, core and affected test types, scoped lint/format, all nine baseline ratchets, and the separate line-cap ratchet pass. No ceiling raised.
  • Independent Codex autoreview: clean through P2.

Production +40/-15 (net +25); tests +152/-154 (net -2); docs +2/-0. The added production code waits and cancels through existing owners; no new retry framework or state owner. A nearby delivery-preparation retry already yields through a timer and remains outside this execution-drain fix.

The transport fixture uses the real Discord plugin, ingress ledger, Gateway and model with synthetic local Discord HTTP/Gateway contracts. Proof is on macOS arm64; real Discord service behavior and Linux/Windows are not covered. Raw startup samples are retained separately from the reload window; one cold-start health timeout was observed before a mutation. No state schema or update migration changed.

Wait on the plugin owner's replacement settlement for refused pre-execution
work while retaining the exact FIFO claim. Let cancellation hand durable input
back before channel teardown, and record abandonment for unavailable owners
without a replacement instead of immediately retrying them.

Preserve the existing claim settlement and live-authority checks. Cover reload,
rollback, unavailable owners, and cancellation with a regression that fails on
main. Real isolated Node and Bun Gateways with Ollama also pass reload success,
registration failure, and disablement without losing the queued source.
@clawsweeper

clawsweeper Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review November 5, 2026 13:32
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Nov 5, 2026
@steipete

steipete commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 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-11-05T13:35:05.217079Z a8cba8d Draft marked ready
ℹ️ 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.

@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 Nov 5, 2026
@clawsweeper

clawsweeper Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Queued replies wait for plugin replacement settlement instead of immediately retrying an unavailable plugin.

Example: Discord input B is queued with zero debounce while its plugin reloads.

  • Before: Repeated preparation refusals can starve health requests, reload progress, and shutdown.
  • After: B waits cancellably for replacement or rollback, then retries through current admission; disablement leaves durable input recoverable.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused owner-level repair with meaningful regressions and detailed production-run results; raw runtime captures are not attached, and broad CI is still running.
Proof confidence 🐚 platinum hermit (4/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its body reports real isolated Gateway/model runs on Node and pinned Bun for successful reload, rollback/recovery, and disablement, using synthetic Discord transport contracts.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A queued reply overlapping plugin reload can make the Gateway stop answering requests and delay shutdown.
Reason: The maintainer-authored direction repairs a demonstrated availability failure while preserving existing admission, custody, and persistence contracts.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current-main Gateway starvation path using existing lifecycle owners; no definite introduced defect was found, and exact-head CI remains pending.

Priority: P1
Reviewed head: a8cba8d79d9f2fd7797ec57e765c4c652fe40bac

Before merge

None.

Findings

None.

Agent review details

How this fits together

The session mailbox passes claimed queued inputs to the follow-up runner; plugin preparation refusals return to the drain, which coordinates retry or abandonment with source custody.

flowchart TD
  A[Durable channel ingress] --> B[Session mailbox claim]
  B --> C[Follow-up preparation]
  C --> D[Plugin replacement settlement]
  D --> E[Authority and cancellation checks]
  E --> C
  C --> F[Model execution and reply]
  E --> A
Loading

Technical review

Best possible solution:

Use the existing replacement settlement and source-custody owners to suspend refused preparation without replaying executed work.

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

Current-main source returns a refused pre-execution input directly to dispatch at zero debounce, matching the reported isolated-Gateway starvation; this read-only review ran no target code.

Is this the best way to solve the issue?

The repair addresses the retry owner directly, retains FIFO custody, and reuses established cancellation and authority checks without adding a competing lifecycle.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit d38a8d3 adds src/auto-reply/reply/queue/drain.ts:322 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d38a8d317126; files: src/auto-reply/reply/queue/drain.ts)
  • Josh Lehman: Raw commit 4bbb815 adds src/plugins/plugin-replacement-retry.test.ts:16 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4bbb8154288d; files: src/plugins/plugin-replacement-retry.test.ts)
  • Mariano: Raw commit fe1b4f5 adds src/auto-reply/reply/queue.drain-generation.test.ts:13 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: fe1b4f51a346; files: src/auto-reply/reply/queue.drain-generation.test.ts)

PR surface

Source +25, Tests -2, Docs +2. Total +25 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 40 15 +25
Tests 2 152 154 -2
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 194 169 +25

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test delta Production +40/-15; tests +152/-154 Production growth implements cancellable settlement through existing owners; consolidated tests cover replacement, rollback, unavailable owners, and cancellation without net test growth.

Labels

Label changes:

  • add P1: A queued preparation refusal during plugin reload can starve Gateway requests and signal handling, disrupting active channel workflows.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: A queued preparation refusal during plugin reload can starve Gateway requests and signal handling, disrupting active channel workflows.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • 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.

Reviewed November 5, 2026, 8:38 AM ET / 13:38 UTC.

@steipete
steipete merged commit 668744f into main Nov 5, 2026
199 of 201 checks passed
@steipete
steipete deleted the fix/drain-hotloop branch November 5, 2026 14:21
@steipete

steipete commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 6, 2026
)

Wait on the plugin owner's replacement settlement for refused pre-execution
work while retaining the exact FIFO claim. Let cancellation hand durable input
back before channel teardown, and record abandonment for unavailable owners
without a replacement instead of immediately retrying them.

Preserve the existing claim settlement and live-authority checks. Cover reload,
rollback, unavailable owners, and cancellation with a regression that fails on
main. Real isolated Node and Bun Gateways with Ollama also pass reload success,
registration failure, and disablement without losing the queued source.
RomneyDa added a commit that referenced this pull request Nov 17, 2026
Backport 668744f (#193501),
a required dependency of approved #193564. Preserve FIFO claim and live
source checks while replacement settles; abandon unavailable owners.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. docs Improvements or additions to documentation size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant