Skip to content

fix(gateway): Gateway stalls after startup recapturing plugins for model catalog updates - #167544

Merged
obviyus merged 2 commits into
mainfrom
fix-catalog-refresh-recapture
Oct 9, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix-catalog-refresh-recapture

Conversation

@obviyus

@obviyus obviyus commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #160959

What Problem This Solves

Fixes: shortly after every Gateway start, the scheduled remote model catalog refresh copies every external plugin a second time and loads it cold. With a large plugin, this blocks the Gateway for as long as the startup capture did.

User Impact

User impact: when the hosted model catalog is newer than the installed build (the normal case for released versions), adopting it no longer re-copies or re-evaluates external plugins. The Gateway stays responsive after startup. Prepared turns keep using the Gateway's unchanged plugin instances, as they already do after config hot reloads.

Why This Change Was Made

#161267 made prepared model runtimes borrow unchanged plugin instances from the admitting Gateway. The lender is resolved from the Gateway registry scope of the work that triggers the rebuild. Hot reloads already run their prepared-runtime refresh inside that scope (server-reload-hot.ts).

The post-ready update.remote-model-catalog scheduler job calls applyRemoteModelCatalogUpdate with no registry scope. The prepared rebuild therefore finds no lender, and its inbound registry cold-loads every plugin. This change runs scheduled catalog adoption inside the live Gateway registry scope, the same way the hot-reload refresh does. No new cache, manager or module sharing is added. Each registry keeps its own load and dispose lifecycle, and borrowing follows the existing #161267 contract.

Evidence

Trigger proven on origin/main 6070074. Runs were isolated Gateways with an external plugin used as the context engine, each held 60 s after ready, with scratch probes outside the repo:

  • Catalog refresh enabled: 8/8 runs captured and loaded the plugin a second time after ready. The probe at loadPreparedInboundPluginRegistry logged lender=false requestScope=false during applyRemoteModelCatalogUpdate, followed by remote model catalog applied.
  • Catalog refresh disabled (models.catalogRefresh.enabled: false): 3/3 runs had no second load.
  • Full stack of the second capture: buildSnapshotBatch → prepareWorkspacePluginRegistries → loadPreparedInboundPluginRegistry → loadAgentRuntimePluginRegistryHandle → loadOpenClawPlugins.
  • Cost on main with an 8k-file plugin: startup.maintenance.plugin-registry took 46.2 s and 57.7 s with event-loop max 45.2 s and 57.3 s, plus a 78 s post-ready reload in another run.

With this change. Same harness:

  • On 6070074 with this patch: 7/7 runs had 0 loads after ready. In each run the catalog was refreshed (status: updated) and applied, and the probe logged inbound lender=true requestScope=true.
  • On this PR's exact head versus its exact parent: these builds are newer than the current hosted catalog, so the runs serve the same hosted catalog with a newer generatedAt from a loopback models.catalogRefresh.url. Each run was held 60 s after ready, and the catalog was refreshed (status: updated) and applied in every run. The parent loaded the plugin a second time after ready in 5/5 runs; this head did so in 0/7 runs.

Lifecycle: on 6070074 with this patch, the catalog was adopted (borrowing the Gateway instance), then a config hot reload of the plugin (Plugin replacement applied) ran, then the Gateway stopped. Each instance evaluated once and was disposed exactly once (count=1), and no capture directories remained.

Tests:

  • New regression adopts scheduled remote catalogs inside the live Gateway registry scope fails without the production change (Expected the Gateway registry, received undefined) and passes with it.
  • server-startup-update-check.test.ts: 7 passed. update-startup-request-adoption.test.ts: 3 passed. oxlint on the changed files passes. codex review: clean.

Merge risk: two-way door. The change touches no persisted state, config or published contract, and a revert restores the scheduler's unscoped adoption. The blast radius is Gateways with external plugins when a hosted model catalog is adopted. Those catalog rebuilds now borrow Gateway instances under the accepted #161267 behavior.

@clawsweeper

clawsweeper Bot commented Oct 9, 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 gateway Gateway runtime size: XS labels Oct 9, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Run scheduled model catalog adoption within the live Gateway plugin registry scope so unchanged plugins reuse their existing instances.

Example: A running Gateway adopts a newer hosted model catalog with an external context-engine plugin installed.

  • Before: The reported parent runs load the plugin again after readiness in 5/5 runs.
  • After: The reported patched runs apply the catalog with no plugin loads after readiness in 7/7 runs.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong runtime evidence and a clean focused repair address one part of the broader linked capture-stall problem.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The inspected contributor evidence exercises scheduled catalog adoption in isolated real Gateways with an external context-engine plugin: catalogs apply successfully, and the repaired runs avoid the second plugin load. Lifecycle observations also cover replacement, disposal, and cleanup. The relevant repair is unchanged from the previously exercised head; the new merge head is not claimed as a separate runtime run. No stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: The Gateway becomes unresponsive shortly after startup when a model catalog update loads large external plugins again.
Reason: This restores established unchanged-plugin borrowing at a missed scheduler entry point. It repairs that trigger; the linked issue's initial-capture and explicit-reload stalls remain separate, and the existing Related reference is appropriate.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still lacks the scheduler connection to the established plugin borrowing owner. No actionable patch defect or unresolved product decision was found.

Priority: P1
Reviewed head: dcbaad990343a9ca5c13623bf87e7cbc55417f4f

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Gateway downloads model catalogs and prepares replacement model runtimes before publishing them. Its plugin registry scope identifies the live Gateway whose unchanged plugin instances those runtimes can borrow.

flowchart TD
 A[Gateway becomes ready] --> B[Scheduled catalog check]
 B --> C[New catalog available]
 C --> D[Live Gateway registry scope]
 D --> E[Prepare replacement model runtime]
 E --> F{Unchanged plugin and live owner?}
 F -->|Yes| G[Borrow existing instance]
 F -->|No| H[Load separate instance]
Loading

Technical review

Best possible solution:

Use the existing live-registry borrowing owner for scheduled adoption and retain the broader capture-performance investigation as separate work.

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

Yes: current main's missing registry scope explains the second capture, and the supplied parent Gateway runs consistently demonstrate that trigger. This review did not execute the runtime.

Is this the best way to solve the issue?

Yes: connecting scheduled adoption to the established borrowing owner matches hot reload and removes the missed scope without adding a competing cache or lifecycle.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +7, Tests +35. Total +42 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 8 1 +7
Tests 2 35 0 +35
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 43 1 +42

Root-cause cluster

Relationship: partial_overlap
Canonical: #160959
Summary: Scheduled catalog recapture is one trigger within the broader plugin-capture stall investigation.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Repeated external-plugin capture after readiness can stall Gateway requests and channel processing for tens of seconds or longer.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-09T01:07:50.382Z sha e88ce37 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T01:14:27.458Z sha e88ce37 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T01:42:41.562Z sha e88ce37 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T04:45:08.356Z sha e88ce37 :: needs maintainer review before merge. :: none

Reviewed October 9, 2026, 12:51 AM ET / 04:51 UTC (Revision 5).

@obviyus
obviyus marked this pull request as draft October 9, 2026 04:37
@obviyus
obviyus marked this pull request as ready for review October 9, 2026 04:37
@obviyus

obviyus commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus
obviyus merged commit 41b4607 into main Oct 9, 2026
108 checks passed
@obviyus
obviyus deleted the fix-catalog-refresh-recapture branch October 9, 2026 04:56
@obviyus

obviyus commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 41b4607.

Bug: after startup, the scheduled remote model catalog refresh rebuilt prepared runtimes with no Gateway registry scope. With no lender to borrow from, it copied and cold-loaded every external plugin a second time, which stalled the Gateway.

Fix: scheduled catalog adoption now runs inside the live Gateway registry scope, the same way config hot reload does. Prepared rebuilds borrow the unchanged Gateway plugin instances.

Proof: same hosted catalog applied in every run. The parent recaptured after ready in 5/5 runs, this change in 0/7. Each instance is still disposed exactly once through hot reload and stop. The new regression test fails without the fix. Full CI is green on the merged head.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…del catalog updates (openclaw#167544)

Related: openclaw#160959

## What Problem This Solves

Fixes: shortly after every Gateway start, the scheduled remote model catalog refresh copies every external plugin a second time and loads it cold. With a large plugin, this blocks the Gateway for as long as the startup capture did.

## User Impact

User impact: when the hosted model catalog is newer than the installed build (the normal case for released versions), adopting it no longer re-copies or re-evaluates external plugins. The Gateway stays responsive after startup. Prepared turns keep using the Gateway's unchanged plugin instances, as they already do after config hot reloads.

## Why This Change Was Made

openclaw#161267 made prepared model runtimes borrow unchanged plugin instances from the admitting Gateway. The lender is resolved from the Gateway registry scope of the work that triggers the rebuild. Hot reloads already run their prepared-runtime refresh inside that scope (`server-reload-hot.ts`).

The post-ready `update.remote-model-catalog` scheduler job calls `applyRemoteModelCatalogUpdate` with no registry scope. The prepared rebuild therefore finds no lender, and its inbound registry cold-loads every plugin. This change runs scheduled catalog adoption inside the live Gateway registry scope, the same way the hot-reload refresh does. No new cache, manager or module sharing is added. Each registry keeps its own load and dispose lifecycle, and borrowing follows the existing openclaw#161267 contract.

## Evidence

**Trigger proven on origin/main 618f4d2.** Runs were isolated Gateways with an external plugin used as the context engine, each held 60 s after `ready`, with scratch probes outside the repo:
- Catalog refresh enabled: 8/8 runs captured and loaded the plugin a second time after ready. The probe at `loadPreparedInboundPluginRegistry` logged `lender=false requestScope=false` during `applyRemoteModelCatalogUpdate`, followed by `remote model catalog applied`.
- Catalog refresh disabled (`models.catalogRefresh.enabled: false`): 3/3 runs had no second load.
- Full stack of the second capture: `buildSnapshotBatch → prepareWorkspacePluginRegistries → loadPreparedInboundPluginRegistry → loadAgentRuntimePluginRegistryHandle → loadOpenClawPlugins`.
- Cost on main with an 8k-file plugin: `startup.maintenance.plugin-registry` took 46.2 s and 57.7 s with event-loop max 45.2 s and 57.3 s, plus a 78 s post-ready reload in another run.

**With this change.** Same harness:
- On 618f4d2 with this patch: 7/7 runs had 0 loads after ready. In each run the catalog was refreshed (`status: updated`) and applied, and the probe logged `inbound lender=true requestScope=true`.
- On this PR's exact head versus its exact parent: these builds are newer than the current hosted catalog, so the runs serve the same hosted catalog with a newer `generatedAt` from a loopback `models.catalogRefresh.url`. Each run was held 60 s after ready, and the catalog was refreshed (`status: updated`) and applied in every run. The parent loaded the plugin a second time after ready in 5/5 runs; this head did so in 0/7 runs.

**Lifecycle:** on 618f4d2 with this patch, the catalog was adopted (borrowing the Gateway instance), then a config hot reload of the plugin (`Plugin replacement applied`) ran, then the Gateway stopped. Each instance evaluated once and was disposed exactly once (`count=1`), and no capture directories remained.

**Tests:**
- New regression `adopts scheduled remote catalogs inside the live Gateway registry scope` fails without the production change (Expected the Gateway registry, received `undefined`) and passes with it.
- `server-startup-update-check.test.ts`: 7 passed. `update-startup-request-adoption.test.ts`: 3 passed. oxlint on the changed files passes. `codex review`: clean.

No overlap with Pash/Sarah changes.

**Merge risk:** two-way door. The change touches no persisted state, config or published contract, and a revert restores the scheduler's unscoped adoption. The blast radius is Gateways with external plugins when a hosted model catalog is adopted. Those catalog rebuilds now borrow Gateway instances under the accepted openclaw#161267 behavior.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa pushed a commit that referenced this pull request Oct 10, 2026
…del catalog updates (#167544)

Related: #160959

## What Problem This Solves

Fixes: shortly after every Gateway start, the scheduled remote model catalog refresh copies every external plugin a second time and loads it cold. With a large plugin, this blocks the Gateway for as long as the startup capture did.

## User Impact

User impact: when the hosted model catalog is newer than the installed build (the normal case for released versions), adopting it no longer re-copies or re-evaluates external plugins. The Gateway stays responsive after startup. Prepared turns keep using the Gateway's unchanged plugin instances, as they already do after config hot reloads.

## Why This Change Was Made

#161267 made prepared model runtimes borrow unchanged plugin instances from the admitting Gateway. The lender is resolved from the Gateway registry scope of the work that triggers the rebuild. Hot reloads already run their prepared-runtime refresh inside that scope (`server-reload-hot.ts`).

The post-ready `update.remote-model-catalog` scheduler job calls `applyRemoteModelCatalogUpdate` with no registry scope. The prepared rebuild therefore finds no lender, and its inbound registry cold-loads every plugin. This change runs scheduled catalog adoption inside the live Gateway registry scope, the same way the hot-reload refresh does. No new cache, manager or module sharing is added. Each registry keeps its own load and dispose lifecycle, and borrowing follows the existing #161267 contract.

## Evidence

**Trigger proven on origin/main 6070074.** Runs were isolated Gateways with an external plugin used as the context engine, each held 60 s after `ready`, with scratch probes outside the repo:
- Catalog refresh enabled: 8/8 runs captured and loaded the plugin a second time after ready. The probe at `loadPreparedInboundPluginRegistry` logged `lender=false requestScope=false` during `applyRemoteModelCatalogUpdate`, followed by `remote model catalog applied`.
- Catalog refresh disabled (`models.catalogRefresh.enabled: false`): 3/3 runs had no second load.
- Full stack of the second capture: `buildSnapshotBatch → prepareWorkspacePluginRegistries → loadPreparedInboundPluginRegistry → loadAgentRuntimePluginRegistryHandle → loadOpenClawPlugins`.
- Cost on main with an 8k-file plugin: `startup.maintenance.plugin-registry` took 46.2 s and 57.7 s with event-loop max 45.2 s and 57.3 s, plus a 78 s post-ready reload in another run.

**With this change.** Same harness:
- On 6070074 with this patch: 7/7 runs had 0 loads after ready. In each run the catalog was refreshed (`status: updated`) and applied, and the probe logged `inbound lender=true requestScope=true`.
- On this PR's exact head versus its exact parent: these builds are newer than the current hosted catalog, so the runs serve the same hosted catalog with a newer `generatedAt` from a loopback `models.catalogRefresh.url`. Each run was held 60 s after ready, and the catalog was refreshed (`status: updated`) and applied in every run. The parent loaded the plugin a second time after ready in 5/5 runs; this head did so in 0/7 runs.

**Lifecycle:** on 6070074 with this patch, the catalog was adopted (borrowing the Gateway instance), then a config hot reload of the plugin (`Plugin replacement applied`) ran, then the Gateway stopped. Each instance evaluated once and was disposed exactly once (`count=1`), and no capture directories remained.

**Tests:**
- New regression `adopts scheduled remote catalogs inside the live Gateway registry scope` fails without the production change (Expected the Gateway registry, received `undefined`) and passes with it.
- `server-startup-update-check.test.ts`: 7 passed. `update-startup-request-adoption.test.ts`: 3 passed. oxlint on the changed files passes. `codex review`: clean.

No overlap with Pash/Sarah changes.

**Merge risk:** two-way door. The change touches no persisted state, config or published contract, and a revert restores the scheduler's unscoped adoption. The blast radius is Gateways with external plugins when a hosted model catalog is adopted. Those catalog rebuilds now borrow Gateway instances under the accepted #161267 behavior.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 41b4607)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS 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