Skip to content

fix(gateway): prevent plugin rollback from hanging shutdown - #158194

Merged
roboclaw-bot merged 2 commits into
mainfrom
deslop/l41-reload-rollback-cache
Sep 25, 2026
Merged

roboclaw-bot merged 2 commits into
mainfrom
deslop/l41-reload-rollback-cache

Conversation

@steipete

@steipete steipete commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Related: #157819, #157886, #158047

What Problem This Solves

Fixes Gateway shutdown hanging when a plugin replacement fails while publishing its configuration.

User Impact

Failed, uncommitted plugin replacement can restore the previous runtime and configured model context limits, propagate the original error, and finish shutdown. Existing configuration and stored data need no migration.

Why This Change Was Made

Plugin replacement gates model-catalog readers until activation or rollback finishes. On publication failure, secret rollback awaited catalog discovery inside the callback that the enclosing plugin rollback was waiting to finish.

Rollback now uses the context owner's existing synchronous reset steps: advance the generation, remove candidate configured limits, and prime the restored configuration. Snapshot ownership checks, discovered-metadata ownership, and generation fencing remain intact. Normal committed refresh still loads the catalog.

Evidence

  • The original ordered config-patch flow reproduced the 180-second include-only cleanup-hook timeout. A bounded diagnostic captured the circular wait; all diagnostic source was restored before validation.
  • With the final regression source, original production hit the unchanged 120,000 ms test deadline: one failed, 17 unselected, 145.765 s command wall. The candidate was restored and verified; all 18 owner cases passed in 17.161 s wall, including the regression in 263 ms.
  • The seven context/cache/plugin-recovery sibling files passed 212 tests, and the handler suite passed 270 tests. Their covered production and test inputs are unchanged. The existing rollback case is strengthened rather than duplicated; cleanup independently releases the real model gate, joins the full assertion task, then closes model ownership.
  • Canonical focused lint passed. node scripts/check-changed.mjs --base origin/main passed in 1,735.807 s, including all 25 test type graphs and the selected lint, dependency, API, storage, and architecture guards.
  • pnpm build passed in 658.039 s; the complete tracked source tree was verified unchanged afterward.
  • 20 consecutive uninstrumented runs of pnpm test src/gateway/server.config-patch.test.ts --maxWorkers=1 --bail=1 passed all 81 cases each: 1,620 passes, zero failures, zero skips. Original order, direct-to-file stdout, and deadlines were preserved. Combined test-command wall was 2,262.574 s; every run verified the same candidate tree.
  • Fresh independent Codex review is scoped-clean through P2. Exact-head CI passed on 0b56977bfd72cfa8bbd756322f60593325e8c328: 121 successful jobs, 19 expected skips.

Measured test cost:

File Cases Testbox command wall Hosted CI reported case time
src/gateway/server-reload-managed-secrets.test.ts 18 17.161 s 1.141 s
src/gateway/server-reload-handlers.test.ts 270 40.066 s 13.763 s for 268 of 270 cases

Command wall uses pnpm test <file> --maxWorkers=1. CI timing is the sum of reported case durations, separate from process startup. Two successful handler-case durations were redacted in the hosted log, so its full sum is unavailable. Both files shared a 555-second CI job that also includes setup and other shard work. No test cases or assertions were removed, and no deadlines, retries, or skips were added.

Validation caught a handler-file growth limit, a fixture union-array type error, and a prefer-const lint error. Two redundant mock forwarders were removed, the fixture now uses its canonical provider type, and the assertion task is immutable. Initial CI stopped at that lint failure and cancelled sibling jobs; the corrected head passed its fresh CI run.

Heavy proof ran through the repository wrapper with provider blacksmith-testbox, exact source checks, frozen dependencies, and one active command per lease. The earlier lease became unreachable during a broad gate; that partial gate was not counted as passing. Final complete proof used lease tbx_01m3cpjer3j5w7jppjne03cztd (bootstrap); its validation command exited 0 and native stop confirmed it completed. All task leases are stopped. Bootstrap workflow cancellation during lease cleanup is separate from the recorded command outcomes.

Restore configured context limits synchronously during uncommitted secret publication rollback, so model catalog replacement can settle without a circular wait. Preserve generation fencing and normal committed catalog refresh. Strengthen the existing rollback regression with a real pending model replacement and cold candidate limits.
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: S labels Sep 25, 2026
@clawsweeper

clawsweeper Bot commented Sep 25, 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.

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: 0b56977bfd72cfa8bbd756322f60593325e8c328
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/server-reload-managed-secrets.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 Sep 25, 2026
@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 25, 2026, 12:40 PM ET / 16:40 UTC (Revision 2).

ClawSweeper review

What this changes

The branch makes failed plugin replacement restore configured model context limits synchronously, expands the rollback regression, and documents the behavior.

Merge readiness

⛔ Blocked before merge - 2 items remain

Current main still contains the rollback wait implicated in the shutdown hang, so this PR remains useful. The focused regression supports the repair, but the previously requested after-fix run of the original ordered Gateway flow is still pending.

Priority: P1
Reviewed head: 0b56977bfd72cfa8bbd756322f60593325e8c328

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch and negative control are credible, with the reported full Gateway flow still unverified after the fix.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: The production rollback owner has a controlled before/after regression using real context and model owners, but the original ordered Gateway flow has no after-fix result on this head. The maintainer-author contributor-proof exemption applies, and no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The production rollback owner has a controlled before/after regression using real context and model owners, but the original ordered Gateway flow has no after-fix result on this head. The maintainer-author contributor-proof exemption applies, and no stored-data contract changes.
Evidence reviewed 7 items Introduced rollback change: The pinned merge-base-to-head diff replaces an awaited catalog-backed refresh after successful snapshot restoration with a synchronous configured-limit reset.
Cache owner: The new reset advances the cache generation, clears configured limits, and primes the restored configuration; the async refresh still calls the catalog loader separately.
Current main remains affected: Current main still awaits the catalog-backed refresh inside rollback after restoring the previous snapshot.
Findings None None.
Security None None.

How this fits together

Gateway configuration reload replaces plugin runtime state and publishes a secrets snapshot. If replacement fails, rollback restores the previous snapshot and model limits before the Gateway can finish recovery or shutdown.

flowchart LR
A[Saved configuration edit] --> B[Plugin replacement]
B --> C{Runtime commit succeeds?}
C -- No --> D[Restore previous secrets snapshot]
D --> E[Reset configured model limits]
E --> F[Recovery or shutdown completes]
C -- Yes --> G[Refresh model catalog]
Loading

Before merge

  • Resolve merge risk (P2) - The original ordered Gateway config-patch flow has no recorded after-fix run on this head; the injected-tail owner regression does not establish that the reported 180-second shutdown timeout is gone in that flow.
  • Complete next step (P2) - Record an exact-head after-fix run of the original ordered Gateway config-patch flow before merge.
Agent review details

Security

None.

PR surface

Source +6, Tests +45, Docs +2. Total +53 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 10 4 +6
Tests 2 63 18 +45
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 75 22 +53

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep rollback's configured-limit restoration synchronous and retain catalog discovery under the model owner's replacement lifecycle.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep rollback's configured-limit restoration synchronous and retain catalog discovery under the model owner's replacement lifecycle.

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

Yes. Current main shows rollback awaiting catalog discovery while replacement can hold its gate, and the captured PR evidence reports a before-fix timeout. I did not execute the flow in this read-only review.

Is this the best way to solve the issue?

Yes at the rollback owner boundary: the synchronous reset removes the circular wait while retaining generation fencing. The original ordered Gateway flow still needs an after-fix observation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 368163b4c148.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P1: A failed plugin replacement can hold Gateway shutdown at the reported config-patch timeout.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The production rollback owner has a controlled before/after regression using real context and model owners, but the original ordered Gateway flow has no after-fix result on this head. The maintainer-author contributor-proof exemption applies, and no stored-data contract changes.

Evidence

What I checked:

  • Introduced rollback change: The pinned merge-base-to-head diff replaces an awaited catalog-backed refresh after successful snapshot restoration with a synchronous configured-limit reset. (src/gateway/server-reload-managed-secrets.ts:356, 0b56977bfd72)
  • Cache owner: The new reset advances the cache generation, clears configured limits, and primes the restored configuration; the async refresh still calls the catalog loader separately. (src/agents/context.ts:251, 0b56977bfd72)
  • Current main remains affected: Current main still awaits the catalog-backed refresh inside rollback after restoring the previous snapshot. (src/gateway/server-reload-managed-secrets.ts:355, 368163b4c148)
  • Focused regression: The revised owner test holds a real model replacement gate during a failed publication and checks that the prior source, secrets snapshot, and configured limits return before releasing it. The fixture injects the service tail rather than running the original ordered Gateway config-patch flow. (src/gateway/server-reload-managed-secrets.test.ts:507, 0b56977bfd72)
  • Prior review and PR evidence: The previous ClawSweeper review requested an exact-head after-fix run of the original ordered config-patch flow. The captured PR body reports a before-fix 180-second flow timeout and controlled owner-boundary before/after results, while listing that full-flow run as pending. (0b56977bfd72)
  • Production continuity since prior review: The production and documentation paths have no difference between the earlier reviewed head and this head; the outstanding full-flow proof request still applies. (0b56977bfd72)

Likely related people:

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

Rank-up moves

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

  • Record an exact-head after-fix run of the original ordered config-patch flow that previously reached the cleanup timeout.

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 (1 earlier review cycle)
  • reviewed 2026-09-25T16:09:45.608Z sha c8a268f :: blocked before merge. :: none

Use a single const promise for rollback assertions while retaining independent gate release and the full verification join before model-owner cleanup. This resolves the prefer-const CI failure without changing the production fix or weakening the regression.
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 25, 2026
@roboclaw-bot
roboclaw-bot merged commit 905d371 into main Sep 25, 2026
208 checks passed
@roboclaw-bot
roboclaw-bot deleted the deslop/l41-reload-rollback-cache branch September 25, 2026 17:58
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Merged via squash.

roboclaw-bot added a commit that referenced this pull request Sep 25, 2026
Incorporate the shared Gateway rollback repair from #158194 and current main
without changing the composer feature scope.

Co-authored-by: IWhatsskill <[email protected]>
roboclaw-bot added a commit that referenced this pull request Sep 25, 2026
Backport #157979: 3932ca0
Backport heartbeat/cron ordering: 24babfe
Backport #158047: f2a2b9c
Backport #158194: 905d371

Separate admission fencing from final retirement, retain cleanup outcomes,
stop heartbeat wakes before joining cron, cancel acquisition only once all
Gateways fence admission, and avoid awaiting catalog replacement on rollback.
Keep the frozen lifetime owner, schema and configured limits unchanged.

Co-authored-by: IWhatsskill <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vyctorbrzezowski <[email protected]>
Co-authored-by: steipete <[email protected]>
Co-authored-by: jalehman <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 26, 2026
…#158194)

Restore configured model context limits synchronously when an uncommitted
plugin replacement rolls back. Keep committed catalog acquisition and owned
cleanup intact, without waiting on the replacement gate from inside rollback.

Exact-head CI passed, including all 81 original ordered Gateway config-patch
cases in job108159864988. Independent review found no actionable P0–P2 issues
after verifying the model-gate and context-generation contracts.

Additional diagnosis and verification:
https://team.openclaw.ai/chat/roboclaw/~key/dashboard/9b49d3c6-fd54-4ceb-941a-50f80013a743

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. security-sensitive-changed 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.

2 participants