Skip to content

fix: keep Gateway ready while plugins drain after updates - #206299

Merged
obviyus merged 1 commit into
mainfrom
fix/plugin-drain-leases
Nov 27, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/plugin-drain-leases

Conversation

@obviyus

@obviyus obviyus commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #205435, #195478

What Problem This Solves

A plugin reload after an update could make the whole Gateway fail /readyz for its 60-second drain, even though the previous plugin generation was still serving. A cancelled cron run could also abandon its selected plugin-generation lease before execution started, leaving future reloads waiting on work that had ended.

User Impact

Ordinary plugin reload drains no longer make the Gateway not-ready. Failed activation or recovery still fails readiness. Cancelling a prepared cron run releases its selected generation. No settings, stored formats, drain budgets, retries, or active-turn pinning rules change.

Why This Change Was Made

The readiness owner treated every reload status as a core outage. It now distinguishes an ordinary reload from failed or recovering activation.

Cron preparation acquired its selected execution lease before two awaits, but execution only registered disposal inside the later callback. The preparation owner now owns the lease across resource cleanup, session admission, and execution; the later duplicate ownership is removed. Its existing cleanup stack releases the session preparation hold, joins the session owner's settlement receipt, deletes the continuation after admission unwinds, then releases the lease. This preserves #180877 without a timer or retry.

This fixes a concrete leak on the cron preparation path used by the fleet run. The decision-only path reported in #205435 is not yet proven to have this cause, so that issue remains open. This does not solve #195478: active turns still retain their admitted plugins; only abandoned cron holds are removed.

Evidence

  • Base caf2a4d4f7dc: the new cron owner regression fails because one real retained plugin work reference remains after cancelled session admission; execution never starts (45 ms test time).
  • Readiness owner regression fails on the base with plugin-reload and passes on the candidate. Recovery/failed-health cases remain covered.
  • Real isolated source Gateway, with plugins.reload unresolved behind an admitted held request: base HTTP 200 → 503 → 200; candidate HTTP 200 → 200 → 200. Base run 23.11 s, candidate run 50.34 s. Both Gateways and state were cleaned.
  • Gateway consumer batch: 8 files / 179 tests passed, including real HTTP readiness during a held drain and after its forced drain failure.
  • Production delta measured with tokei: +8 code lines (971 → 979 across the three changed production modules).
  • Initial focused batch: 15 files / 271 tests passed in 376.50 s wall time. After the cleanup-order repair, the final three cron owner files passed 21/21 tests, including fix(cron): native completion waits on its own session cleanup #180877's external ordering assertion and the cancelled-continuation regression (12 ms; 45 ms on the failing base).
  • check:changed passed core production/test typechecks, formatting, and guards. Its dead-export scan reported three untouched exports (readUpdateDatabaseEngineConfig, DoctorContributionPending, formatUpdateSnapshotCapacity); no suppression or unrelated code repair is included.
  • Final scoped checks passed: formatting, oxlint (zero warnings/errors), core production types, and the services-cron test type graph. Final checks plus the three-file test run took 69.40 s; Vitest itself took 43.60 s.
  • Local ClawSweeper reviewed caf2a4d4f7dc → 25e3fdb6b90c at default service tier: complete, patch is correct, zero findings, security cleared. The offline review did not receive execution receipts; the observed runs are summarized above.

Readiness decision

Serving-health readiness is the requested contract for this repair: an ordinary reload does not report the whole serving Gateway as unavailable. New agent runs still wait on the existing replacement gate, visible in status. Recovery and failed activation remain unhealthy. This resolves the local review's advisory product-direction question without changing admission policy.

- Keep ordinary targeted reload drains out of core readiness; recovery failures remain unhealthy.
- Move the selected cron lease and existing cleanup stack to preparation, owning the lease before admission can fail.
- Release the preparation effect and join the existing session settlement receipt before continuation deletion, then release the generation.
- Cover cancelled continuations with real session custody and assert normal cleanup ordering outside warning handling.
- Keep drain budgets, stored formats, and active-turn generation pinning unchanged.
Related: #205435, #195478; preserves #180877.
@clawsweeper

clawsweeper Bot commented Nov 27, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S labels Nov 27, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. impact:crash-loop Crash, hang, restart loop, or process-level availability failure. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 27, 2026
@clawsweeper

clawsweeper Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

This PR keeps ordinary plugin drains out of Gateway readiness failures and gives cron preparation ownership of its selected runtime lease before execution admission.

Example: A plugin reload waits behind an admitted request within its 60-second drain budget.

  • Before: The serving Gateway returns HTTP 503 from /readyz.
  • After: The Gateway returns HTTP 200 while recovery and failed activation still fail readiness.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation has no identified correctness defect and preserves existing stored formats, but required real-flow proof is incomplete for cron cancellation.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A serving Gateway becomes unready during routine plugin drains, and abandoned cron preparation can leave plugin reloads waiting on retained work.
Reason: The scoped repair has clear operational value, and the collaborator-authored PR explicitly accepts serving-health readiness while retaining current admission policy.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses two source-confirmed lifecycle failures that remain on current main; no introduced correctness defect was found.

Reviewed head: 25e3fdb6b90c37e8e33c8179e63d4903f96ac7bc

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Show cancelled cron preparation after runtime selection through an isolated Gateway with a real agent/model setup, followed by plugins.inspect and reload confirming lease release and settled cleanup; redact credentials, IPs, phone numbers, and non-public endpoints.
Agent review details

How this fits together

The Gateway readiness owner turns runtime health into HTTP readiness responses, while cron preparation selects a plugin generation and carries its lease through session admission, execution, and cleanup.

flowchart TD
  A[Plugin reload] --> B[Generation drain]
  B --> C[Readiness owner]
  C --> D[HTTP readiness response]
  E[Cron preparation] --> F[Session admission and execution]
  F --> G[Continuation cleanup]
  G --> H[Runtime lease release]
Loading

Technical review

Best possible solution:

Keep the existing readiness and cron preparation owners, with one runtime disposal path that runs after session settlement and continuation cleanup.

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

Current-main source establishes unconditional reload readiness failure and an unowned selected lease when admission fails before execution; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch repairs lease ownership before the failing awaits and preserves the earlier cleanup-order invariant without adding retries, budgets, configuration, or a parallel lifecycle owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +8, Tests +106, Docs +1. Total +115 across 9 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 3 27 19 +8
Tests 5 117 11 +106
Docs 1 6 5 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 150 35 +115

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.

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Provide the isolated Gateway cancellation and subsequent plugin-reload evidence described in the proof gap.

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 26, 2026, 9:37 PM ET / November 27, 2026, 02:37 UTC.

@obviyus
obviyus merged commit 2f246fd into main Nov 27, 2026
154 checks passed
@obviyus
obviyus deleted the fix/plugin-drain-leases branch November 27, 2026 02:39
@obviyus

obviyus commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 2f246fd. Two fixes for the fleet fingerprint git-release:plugins:drain-not-settled-60s (Peanutto update run 94864d80, where readyz returned 503 for 59.7 s during the post-update plugin reload). (1) A targeted plugin reload no longer takes Gateway readiness down while the previous plugin generation keeps serving. A recovering or failed plugin still fails health. (2) A cron run now owns its prepared plugin-generation lease from right after preparation, so a cancellation or rejection before the run starts releases it. Before, the lease stayed referenced and blocked the drain. Cleanup still runs after session admission unwinds, so the #180877 ordering is kept. Proof: a real Gateway's readyz stayed 200→200→200 during a reload that could not drain (it was 200→503→200 on base). The cancellation test failed on main with retainedWorkCount 1 and passes here. CI is green on the exact head, and the review is clean.

vincentkoc added a commit that referenced this pull request Nov 27, 2026
* commit '7df6cb759f9e604921536a700e2f527c5516e7de': (185 commits)
  docs: clarify what telemetry OpenClaw sends and how to opt out
  refactor(ui): remove retired stream-follow test seams (#206316)
  fix: distinguish missing command results from unknown outcomes (#206313)
  fix(build): reuse stamps after identical pnpm installs (#206282)
  chore(ci): inventory Gateway model catalog worker lifecycles (#206251)
  fix: keep failed image inspections inside chat activity (#206283)
  fix: clarify sent-message labels and chat activity icons (#206048)
  fix(cron): use the service's free memory for extra automation runs (#206322)
  test(android): reuse the shared TLS fixture (#206280)
  fix(ui): restore New Session recovery during startup (#206319)
  test(macos): align new Gateway URL expectations (#206281)
  feat: let doctor --fix tell when its startup repairs have nothing to do (#206246)
  fix(android): pause idle gateway discovery without blocking consumers (#196209)
  fix(ci): prepare the Android SDK for scheduled CodeQL scans (#203843)
  fix(memory): read delegated cgroup pressure from the mapped leaf (#206308)
  improve(config): reuse plugin metadata during auto-enable (#206289)
  improve: copy only the selected model for agent completions (#206287)
  fix(pr): refresh tooling before preparing reviewed incoming PRs (#206236)
  fix: keep Gateway ready while plugins drain after updates (#206299)
  fix(crabbox): keep unused prepared mirrors reusable (#206267)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 27, 2026
…06299)

Related: openclaw#205435, openclaw#195478

## What Problem This Solves

A plugin reload after an update could make the whole Gateway fail `/readyz` for its 60-second drain, even though the previous plugin generation was still serving. A cancelled cron run could also abandon its selected plugin-generation lease before execution started, leaving future reloads waiting on work that had ended.

## User Impact

Ordinary plugin reload drains no longer make the Gateway not-ready. Failed activation or recovery still fails readiness. Cancelling a prepared cron run releases its selected generation. No settings, stored formats, drain budgets, retries, or active-turn pinning rules change.

## Why This Change Was Made

The readiness owner treated every reload status as a core outage. It now distinguishes an ordinary reload from failed or recovering activation.

Cron preparation acquired its selected execution lease before two awaits, but execution only registered disposal inside the later callback. The preparation owner now owns the lease across resource cleanup, session admission, and execution; the later duplicate ownership is removed. Its existing cleanup stack releases the session preparation hold, joins the session owner's settlement receipt, deletes the continuation after admission unwinds, then releases the lease. This preserves openclaw#180877 without a timer or retry.

This fixes a concrete leak on the cron preparation path used by the fleet run. The decision-only path reported in openclaw#205435 is **not yet proven** to have this cause, so that issue remains open. This does not solve openclaw#195478: active turns still retain their admitted plugins; only abandoned cron holds are removed.

## Evidence

- Base `a92d5919a899`: the new cron owner regression fails because one real retained plugin work reference remains after cancelled session admission; execution never starts (45 ms test time).
- Readiness owner regression fails on the base with `plugin-reload` and passes on the candidate. Recovery/failed-health cases remain covered.
- Real isolated source Gateway, with `plugins.reload` unresolved behind an admitted held request: base HTTP **200 → 503 → 200**; candidate HTTP **200 → 200 → 200**. Base run 23.11 s, candidate run 50.34 s. Both Gateways and state were cleaned.
- Gateway consumer batch: 8 files / 179 tests passed, including real HTTP readiness during a held drain and after its forced drain failure.
- Production delta measured with `tokei`: **+8 code lines** (971 → 979 across the three changed production modules).
- Initial focused batch: **15 files / 271 tests passed** in 376.50 s wall time. After the cleanup-order repair, the final three cron owner files passed **21/21 tests**, including openclaw#180877's external ordering assertion and the cancelled-continuation regression (12 ms; 45 ms on the failing base).
- `check:changed` passed core production/test typechecks, formatting, and guards. Its dead-export scan reported three untouched exports (`readUpdateDatabaseEngineConfig`, `DoctorContributionPending`, `formatUpdateSnapshotCapacity`); no suppression or unrelated code repair is included.
- Final scoped checks passed: formatting, oxlint (zero warnings/errors), core production types, and the services-cron test type graph. Final checks plus the three-file test run took 69.40 s; Vitest itself took 43.60 s.
- Local ClawSweeper reviewed `a92d5919a899` → `25e3fdb6b90c` at default service tier: complete, **patch is correct**, zero findings, security cleared. The offline review did not receive execution receipts; the observed runs are summarized above.

### Readiness decision

Serving-health readiness is the requested contract for this repair: an ordinary reload does not report the whole serving Gateway as unavailable. New agent runs still wait on the existing replacement gate, visible in status. Recovery and failed activation remain unhealthy. This resolves the local review's advisory product-direction question without changing admission policy.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 28, 2026
Related: #205435, #195478

## What Problem This Solves

A plugin reload after an update could make the whole Gateway fail `/readyz` for its 60-second drain, even though the previous plugin generation was still serving. A cancelled cron run could also abandon its selected plugin-generation lease before execution started, leaving future reloads waiting on work that had ended.

## User Impact

Ordinary plugin reload drains no longer make the Gateway not-ready. Failed activation or recovery still fails readiness. Cancelling a prepared cron run releases its selected generation. No settings, stored formats, drain budgets, retries, or active-turn pinning rules change.

## Why This Change Was Made

The readiness owner treated every reload status as a core outage. It now distinguishes an ordinary reload from failed or recovering activation.

Cron preparation acquired its selected execution lease before two awaits, but execution only registered disposal inside the later callback. The preparation owner now owns the lease across resource cleanup, session admission, and execution; the later duplicate ownership is removed. Its existing cleanup stack releases the session preparation hold, joins the session owner's settlement receipt, deletes the continuation after admission unwinds, then releases the lease. This preserves #180877 without a timer or retry.

This fixes a concrete leak on the cron preparation path used by the fleet run. The decision-only path reported in #205435 is **not yet proven** to have this cause, so that issue remains open. This does not solve #195478: active turns still retain their admitted plugins; only abandoned cron holds are removed.

## Evidence

- Base `caf2a4d4f7dc`: the new cron owner regression fails because one real retained plugin work reference remains after cancelled session admission; execution never starts (45 ms test time).
- Readiness owner regression fails on the base with `plugin-reload` and passes on the candidate. Recovery/failed-health cases remain covered.
- Real isolated source Gateway, with `plugins.reload` unresolved behind an admitted held request: base HTTP **200 → 503 → 200**; candidate HTTP **200 → 200 → 200**. Base run 23.11 s, candidate run 50.34 s. Both Gateways and state were cleaned.
- Gateway consumer batch: 8 files / 179 tests passed, including real HTTP readiness during a held drain and after its forced drain failure.
- Production delta measured with `tokei`: **+8 code lines** (971 → 979 across the three changed production modules).
- Initial focused batch: **15 files / 271 tests passed** in 376.50 s wall time. After the cleanup-order repair, the final three cron owner files passed **21/21 tests**, including #180877's external ordering assertion and the cancelled-continuation regression (12 ms; 45 ms on the failing base).
- `check:changed` passed core production/test typechecks, formatting, and guards. Its dead-export scan reported three untouched exports (`readUpdateDatabaseEngineConfig`, `DoctorContributionPending`, `formatUpdateSnapshotCapacity`); no suppression or unrelated code repair is included.
- Final scoped checks passed: formatting, oxlint (zero warnings/errors), core production types, and the services-cron test type graph. Final checks plus the three-file test run took 69.40 s; Vitest itself took 43.60 s.
- Local ClawSweeper reviewed `caf2a4d4f7dc` → `25e3fdb6b90c` at default service tier: complete, **patch is correct**, zero findings, security cleared. The offline review did not receive execution receipts; the observed runs are summarized above.

### Readiness decision

Serving-health readiness is the requested contract for this repair: an ordinary reload does not report the whole serving Gateway as unavailable. New agent runs still wait on the existing replacement gate, visible in status. Recovery and failed activation remain unhealthy. This resolves the local review's advisory product-direction question without changing admission policy.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 2f246fd)
tideclaw-bot pushed a commit that referenced this pull request Nov 28, 2026
Related: #205435, #195478

A plugin reload after an update could make the whole Gateway fail `/readyz` for its 60-second drain, even though the previous plugin generation was still serving. A cancelled cron run could also abandon its selected plugin-generation lease before execution started, leaving future reloads waiting on work that had ended.

Ordinary plugin reload drains no longer make the Gateway not-ready. Failed activation or recovery still fails readiness. Cancelling a prepared cron run releases its selected generation. No settings, stored formats, drain budgets, retries, or active-turn pinning rules change.

The readiness owner treated every reload status as a core outage. It now distinguishes an ordinary reload from failed or recovering activation.

Cron preparation acquired its selected execution lease before two awaits, but execution only registered disposal inside the later callback. The preparation owner now owns the lease across resource cleanup, session admission, and execution; the later duplicate ownership is removed. Its existing cleanup stack releases the session preparation hold, joins the session owner's settlement receipt, deletes the continuation after admission unwinds, then releases the lease. This preserves #180877 without a timer or retry.

This fixes a concrete leak on the cron preparation path used by the fleet run. The decision-only path reported in #205435 is **not yet proven** to have this cause, so that issue remains open. This does not solve #195478: active turns still retain their admitted plugins; only abandoned cron holds are removed.

- Base `caf2a4d4f7dc`: the new cron owner regression fails because one real retained plugin work reference remains after cancelled session admission; execution never starts (45 ms test time).
- Readiness owner regression fails on the base with `plugin-reload` and passes on the candidate. Recovery/failed-health cases remain covered.
- Real isolated source Gateway, with `plugins.reload` unresolved behind an admitted held request: base HTTP **200 → 503 → 200**; candidate HTTP **200 → 200 → 200**. Base run 23.11 s, candidate run 50.34 s. Both Gateways and state were cleaned.
- Gateway consumer batch: 8 files / 179 tests passed, including real HTTP readiness during a held drain and after its forced drain failure.
- Production delta measured with `tokei`: **+8 code lines** (971 → 979 across the three changed production modules).
- Initial focused batch: **15 files / 271 tests passed** in 376.50 s wall time. After the cleanup-order repair, the final three cron owner files passed **21/21 tests**, including #180877's external ordering assertion and the cancelled-continuation regression (12 ms; 45 ms on the failing base).
- `check:changed` passed core production/test typechecks, formatting, and guards. Its dead-export scan reported three untouched exports (`readUpdateDatabaseEngineConfig`, `DoctorContributionPending`, `formatUpdateSnapshotCapacity`); no suppression or unrelated code repair is included.
- Final scoped checks passed: formatting, oxlint (zero warnings/errors), core production types, and the services-cron test type graph. Final checks plus the three-file test run took 69.40 s; Vitest itself took 43.60 s.
- Local ClawSweeper reviewed `caf2a4d4f7dc` → `25e3fdb6b90c` at default service tier: complete, **patch is correct**, zero findings, security cleared. The offline review did not receive execution receipts; the observed runs are summarized above.

Serving-health readiness is the requested contract for this repair: an ordinary reload does not report the whole serving Gateway as unavailable. New agent runs still wait on the existing replacement gate, visible in status. Recovery and failed activation remain unhealthy. This resolves the local review's advisory product-direction question without changing admission policy.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 2f246fd)

Release adaptation: Merge runtime lease ownership and settlement-ordered continuation cleanup into the existing prepareCronRunContext in run-prepare.ts, without the later owner split (3ad2cce). The regression drives the stable preparation path with its existing harness, aborts at continuation initialization, and observes real lease holds and admission unwind. Stable readiness stays in its existing owner. The later same-file 6d86389 only relocates the readiness type; 1ed6fd2 (#207091) adds provider rate-limit reset handling. Neither is needed.

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

docs Improvements or additions to documentation gateway Gateway runtime impact:crash-loop Crash, hang, restart loop, or process-level availability failure. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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