Skip to content

fix(gateway): prevent shutdown stalls during plugin reloads - #157979

Merged
steipete merged 3 commits into
mainfrom
codex/gateway-metadata-close-20260925
Sep 25, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/gateway-metadata-close-20260925

Conversation

@steipete

@steipete steipete commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Related: #155982, #151608

What Problem This Solves

Fixes a metadata-retirement cycle that can stall Gateway shutdown when a plugin reload overlaps retained consumers.

User Impact

Shutdown can finish admitted reload work before releasing its retained consumers. Final close still joins actual cleanup and reports failures. No configuration changes or data migration are required.

Why This Change Was Made

The early shutdown admission fence was also switching publication waits into final retirement waits. Those consumers can be released later in shutdown, after the reloader has drained. Use the existing final-close promise to distinguish those phases while preserving the admission fence and final cleanup ownership. Keep deferred retirement outcomes until a caller joins the full result, so cleanup failures cannot disappear when a consumer finishes before final close.

Evidence

  • A real retained-cache consumer regression fails on the original owner and passes with the repair. It verifies that final close still waits for release and disposes the retained resource once.
  • All 85 metadata lifecycle, prepared-model generation/runtime, and setup-registry lifecycle tests passed, including consumers completing before or during final close, sibling and duplicate close behavior, and retirement-failure reporting.
  • Independent Codex review completed with no actionable findings through P2.
  • The metadata test file passed all 12 cases on one worker in 215 ms of test execution (42.87 s including compiler preparation and the maintained runner). Its completion-based waits still fail against both original defects.
  • All maintained changed-file checks passed for the production repair, including core and all 25 test type graphs, lint, dead-export, import-cycle, and database guards. The final test-only follow-up also passed its maintained checks.
  • Final-head CI passed on 1cd1496d10a544645ee95703f5f10091f796c3df. Production-parent CI also passed, including the uninstrumented original config file: 81/81 in 136.44 s through the maintained runner, with include-only completing in 1.75 s.
  • Historical config-patch hook-timeout attribution remains unproven. CI on the first PR head reproduced the include-only hook timeout, so the phase fix alone does not eliminate it. Current uninstrumented CI and two corrected-source Linux diagnostic runs passed the original 81 cases; the original baseline also passed in two diagnostic runs.

@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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S labels Sep 25, 2026
@steipete
steipete marked this pull request as ready for review September 25, 2026 06:37
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete steipete self-assigned this Sep 25, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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: needs changes before merge. Reviewed September 25, 2026, 3:10 AM ET / 07:10 UTC.

ClawSweeper review

What this changes

The branch lets plugin reload publication finish during Gateway shutdown while final close joins retained cleanup and reports failures, with regression tests and documentation.

Merge readiness

⛔ Needs changes before merge - 2 items remain

Current main still has the reload and shutdown wait cycle, so this focused repair remains useful. The new regression test needs deterministic waits before merge.

Priority: P2
Reviewed head: 4a653eefb9c66959b24ba42b4f5c6f085c37dfaa

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The lifecycle repair is focused and supported by owner-boundary regression coverage, with a small deterministic-test correction remaining.
Proof confidence 🌊 off-meta tidepool Not applicable: The changed production metadata owner is exercised by a fixture-driven retained-cache consumer through publication, release, final close, and once-only disposal; the claimed Testbox attempt stopped before tests ran. The trusted-author real-setup gate does not apply, and no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The changed production metadata owner is exercised by a fixture-driven retained-cache consumer through publication, release, final close, and once-only disposal; the claimed Testbox attempt stopped before tests ran. The trusted-author real-setup gate does not apply, and no stored-data contract changes.
Evidence reviewed 10 items Introduced lifecycle repair: The introduced patch chooses deferred consumer observation until final close and retains retirement outcomes for that join.
Current main remains affected: The fetched main source still switches retirement observation on the early closing phase, before the final close promise exists.
Production call order: Gateway shutdown closes metadata admission early; plugin reload later calls the metadata retirement wait, and final Gateway close joins cleanup.
Findings 1 actionable finding [P3] Replace polling with lifecycle completion signals
Security None None.

How this fits together

The Gateway publishes plugin metadata when plugins reload. Retired plugin resources may remain in use by existing consumers, so shutdown must drain reload work before joining their final cleanup.

flowchart LR
A[Plugin reload] --> B[Metadata publication]
B --> C[Retired plugin cache]
C --> D{Consumers retained?}
D -->|Yes| E[Deferred retirement]
D -->|No| F[Cleanup result]
E --> G[Final Gateway close]
H[Shutdown admission fence] --> G
G --> F
Loading

Before merge

  • Replace polling with lifecycle completion signals (P3) - The two new expect.poll waits use timer-based polling in a per-PR test, contrary to the repository's test guidance. Await the publication promise for the first condition and signal disposal or cache retirement explicitly for the second, then assert the resulting state.
  • Complete next step (P2) - Replace the introduced polling waits with deterministic lifecycle signals and add the measured single-worker test cost to the PR body.

Findings

  • [P3] Replace polling with lifecycle completion signals — src/plugins/plugin-metadata-lifecycle.test.ts:271-275
Agent review details

Security

None.

PR surface

Source +5, Tests +66, Docs +2. Total +73 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 13 8 +5
Tests 1 67 1 +66
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 82 9 +73

Review metrics

Metric Value Why it matters
Production versus test growth production +5 net; tests +66 net Production growth is limited to the lifecycle repair; most added code guards retained-consumer ordering and failure reporting.

Technical review

Best possible solution:

Keep the metadata lifecycle as the single owner of deferred retirement, with final close joining its result and deterministic tests guarding both consumer release orders.

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

Yes. Current-main source shows shutdown fencing metadata admission before reload drains, while the reload's retirement wait can join consumers released later in shutdown; this read-only review did not execute that path.

Is this the best way to solve the issue?

Yes. The branch changes the existing metadata lifecycle owner's phase decision and preserves the final cleanup join; its regression test needs completion signals in place of polling.

Full review comments:

  • [P3] Replace polling with lifecycle completion signals — src/plugins/plugin-metadata-lifecycle.test.ts:271-275
    The two new expect.poll waits use timer-based polling in a per-PR test, contrary to the repository's test guidance. Await the publication promise for the first condition and signal disposal or cache retirement explicitly for the second, then assert the resulting state.
    Confidence: 0.97

Overall correctness: patch is correct
Overall confidence: 0.86

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 04fb3c8e35b3.

Labels

Label changes:

  • add P2: The patch addresses a bounded Gateway shutdown stall when plugin reload overlaps retained consumers.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The changed production metadata owner is exercised by a fixture-driven retained-cache consumer through publication, release, final close, and once-only disposal; the claimed Testbox attempt stopped before tests ran. The trusted-author real-setup gate does not apply, and no stored-data contract changes.

Label justifications:

  • P2: The patch addresses a bounded Gateway shutdown stall when plugin reload overlaps retained consumers.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool 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 changed production metadata owner is exercised by a fixture-driven retained-cache consumer through publication, release, final close, and once-only disposal; the claimed Testbox attempt stopped before tests ran. The trusted-author real-setup gate does not apply, and no stored-data contract changes.

Evidence

Acceptance criteria:

  • [P1] pnpm test src/plugins/plugin-metadata-lifecycle.test.ts --maxWorkers=1.
  • [P1] pnpm check:changed.

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vyctorbrzezowski: 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.

  • Use completion signals instead of the two new polling waits and record the changed test file's one-worker runtime.

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.

@steipete

Copy link
Copy Markdown
Contributor Author

Addressed the lifecycle-wait finding in 1cd1496. The test now awaits publication and the cache's owned retirement promise directly. The existing timeout helper is only a bounded failure deadline, so the original deadlock can fail while finally still releases its consumer; it does not poll state.

The revised test still fails on both original defects: two publication-deadline failures against the original owner, and one missing cleanup-failure assertion against the intermediate implementation. With the repaired owner restored, all 12 cases pass on one worker in 215 ms of test execution (42.87 s including compiler preparation and the maintained runner). Fresh independent P2 review is clean.

Production is unchanged from the fully green 4a653eef CI run, which also passed the uninstrumented original config file, 81/81. The historical intermittent hook timeout remains unlocalized and is not claimed fixed by this PR.

@steipete
steipete enabled auto-merge (squash) September 25, 2026 07:40
@steipete
steipete merged commit 3932ca0 into main Sep 25, 2026
208 of 209 checks passed
@steipete
steipete deleted the codex/gateway-metadata-close-20260925 branch September 25, 2026 07:50
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

steipete added a commit that referenced this pull request Sep 25, 2026
Compose the reviewed metadata retirement, shared model acquisition shutdown,
and catalog provenance repairs with the repair-turn worker candidate.
Preserve first-discovery starter models and explicit no-discovery outcomes.

Sources: #157979, #158047, #158113, and 36def8b.
The historical include-only CI hook timeout remains unattributed.

Co-authored-by: Dallin Romney <[email protected]>
steipete added a commit that referenced this pull request Sep 25, 2026
* feat(update): accept owner-bound repair turns

* fix(update): harden delegated repair authority

* fix(update): keep repair worker schema private

* test(update): retain released worker protocol coverage

* fix(update): terminate failed repair result delivery

* fix(update): exit idle repair worker on disconnect

* test(update): retain repair worker timeout diagnostics

* test(update): surface diagnostics in silent E2E runs

* test(update): capture repair worker startup logs

* fix(update): share fresh authority snapshots per repair check

Keep requester policy and update-run checks on one fresh synchronous snapshot of the original installation. Do not inherit discovery snapshots or reuse authority across callbacks. Preserve every executor, requester, IPC and run-phase check and keep source SQLite artifacts untouched.

The real Windows repair turn previously exhausted its budget while repeatedly spawning snapshot readers. Real-WAL regressions cover fresh commits, inherited-scope restoration and closed-scope refusal; preserve the existing worker deadlines and behavior.

* chore(update): trace repair authority timing

Measure cumulative executor, requester-policy, update-row and total assertion elapsed time under the existing trace log level. Record synchronous snapshot subprocess elapsed time to distinguish guard work from launch and copy costs. Preserve checks, error propagation and deadlines.

* test(gateway): complete lifecycle logger fixture

* fix(skills): filter selection before probing binaries

* fix(update): bind delegated repair to its recorded requester

Compare the IPC requester with the original update row before preparing
inference and at every fresh authority assertion. Reuse the existing managed
requester resolver and profile continuation owner so internal/operator update
routes keep their admitted authority while chat identity cannot be omitted or
substituted.

Cover the worker boundary with inert inference and real isolated ledger/config
state, including post-await origin/policy changes. Record the admitted requester
in the existing positive delegated E2E fixture.

* fix(update): integrate catalog and Gateway lifecycle repairs

Compose the reviewed metadata retirement, shared model acquisition shutdown,
and catalog provenance repairs with the repair-turn worker candidate.
Preserve first-discovery starter models and explicit no-discovery outcomes.

Sources: #157979, #158047, #158113, and 36def8b.
The historical include-only CI hook timeout remains unattributed.

Co-authored-by: Dallin Romney <[email protected]>

* fix(update): retain only required canonical integrations

Remove the imported catalog inference and marker adaptations so omitted
outcomes retain their existing contract. Keep the worker and reviewed Gateway
shutdown changes, captured provider-alias normalization, first-discovery
starter handling, and explicit HTTP-success lifecycle fixtures.

Preserve the native augmentation assertions and existing deadlines. The new
legacy-retention work in #158113 is independent of this repair-turn worker.

Co-authored-by: Dallin Romney <[email protected]>

* test(update): initialize survivor registry fixture baseline

Reuse canonical 4fa09e9 so the extracted registry-order orchestration
receives the baseline version that the real runner has already resolved.
Keep production code, ordering assertions, and timeouts unchanged.

The ten-case file, root-test types, lint, and fresh P2 review pass.

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Dallin Romney <[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
…#157979)

* fix(gateway): prevent metadata retirement stalls during reload shutdown

* fix(plugins): retain deferred cleanup outcomes until joined

* test(plugins): await metadata retirement completion directly
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 26, 2026
* feat(update): accept owner-bound repair turns

* fix(update): harden delegated repair authority

* fix(update): keep repair worker schema private

* test(update): retain released worker protocol coverage

* fix(update): terminate failed repair result delivery

* fix(update): exit idle repair worker on disconnect

* test(update): retain repair worker timeout diagnostics

* test(update): surface diagnostics in silent E2E runs

* test(update): capture repair worker startup logs

* fix(update): share fresh authority snapshots per repair check

Keep requester policy and update-run checks on one fresh synchronous snapshot of the original installation. Do not inherit discovery snapshots or reuse authority across callbacks. Preserve every executor, requester, IPC and run-phase check and keep source SQLite artifacts untouched.

The real Windows repair turn previously exhausted its budget while repeatedly spawning snapshot readers. Real-WAL regressions cover fresh commits, inherited-scope restoration and closed-scope refusal; preserve the existing worker deadlines and behavior.

* chore(update): trace repair authority timing

Measure cumulative executor, requester-policy, update-row and total assertion elapsed time under the existing trace log level. Record synchronous snapshot subprocess elapsed time to distinguish guard work from launch and copy costs. Preserve checks, error propagation and deadlines.

* test(gateway): complete lifecycle logger fixture

* fix(skills): filter selection before probing binaries

* fix(update): bind delegated repair to its recorded requester

Compare the IPC requester with the original update row before preparing
inference and at every fresh authority assertion. Reuse the existing managed
requester resolver and profile continuation owner so internal/operator update
routes keep their admitted authority while chat identity cannot be omitted or
substituted.

Cover the worker boundary with inert inference and real isolated ledger/config
state, including post-await origin/policy changes. Record the admitted requester
in the existing positive delegated E2E fixture.

* fix(update): integrate catalog and Gateway lifecycle repairs

Compose the reviewed metadata retirement, shared model acquisition shutdown,
and catalog provenance repairs with the repair-turn worker candidate.
Preserve first-discovery starter models and explicit no-discovery outcomes.

Sources: openclaw#157979, openclaw#158047, openclaw#158113, and 3cb4c86.
The historical include-only CI hook timeout remains unattributed.

Co-authored-by: Dallin Romney <[email protected]>

* fix(update): retain only required canonical integrations

Remove the imported catalog inference and marker adaptations so omitted
outcomes retain their existing contract. Keep the worker and reviewed Gateway
shutdown changes, captured provider-alias normalization, first-discovery
starter handling, and explicit HTTP-success lifecycle fixtures.

Preserve the native augmentation assertions and existing deadlines. The new
legacy-retention work in openclaw#158113 is independent of this repair-turn worker.

Co-authored-by: Dallin Romney <[email protected]>

* test(update): initialize survivor registry fixture baseline

Reuse canonical d2295c6 so the extracted registry-order orchestration
receives the baseline version that the real runner has already resolved.
Keep production code, ordering assertions, and timeouts unchanged.

The ten-case file, root-test types, lint, and fresh P2 review pass.

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Dallin Romney <[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 P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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