Repository navigation
fix(models): apply a changed catalog source at once without breaking turns - #202583
Conversation
…turns Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
…e reload Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR promptly reschedules catalog checks after source changes while preserving the update owner's async context. Example: A running Gateway switches catalogs to one describing together/zz-lab/zz-day0-live.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it addresses a source-supported catalog refresh gap through the existing scheduler, and no concrete introduced defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway config publication notifies the update scheduler, which downloads catalog metadata and invokes the prepared-runtime owner to publish matching model rows, prices, and reply dispatch. flowchart TD
A[Config publication] --> B[Update scheduler]
B --> C[Catalog refresh]
C --> D[Prepared runtime publication]
E[Gateway plugin inventory] --> D
D --> F[Model rows and prices]
D --> G[Reply dispatch]
Technical reviewBest possible solution: Keep source-change scheduling in the existing update owner and preserve its startup context without adding adoption retries or another scheduler. Do we have a high-confidence way to reproduce the issue? Current-main source directly shows that changing catalogRefresh does not re-arm the catalog job, and the earlier merged PR confirms this remaining limitation; no target code was executed during this review. Is this the best way to solve the issue? The patch fixes scheduling at its existing owner and preserves atomic publication, memory-pressure deferral, shutdown handling, and the intentional no-retry policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 918d83996b98. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +14, Tests +238, Docs +2. Total +254 across 4 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 20, 2026, 11:52 AM ET / 16:52 UTC. |
|
Landed as 4332e9a.
|
…turns (openclaw#202583) ## What Problem This Solves Changing `models.catalogRefresh.url` (or `.enabled`) on a running Gateway waited up to six hours for the next scheduled catalog check, so a model the new catalog describes stayed unlisted and its turns were priced at $0. The obvious fix, re-arming the catalog check from the config listener (part 3 of openclaw#202490, reverted), broke worse. The check ran inside the hot reload that published the config. The Gateway scheduler keeps the async context of whoever schedules a job, and the reload runs inside a plugin lifecycle operation with its own plugin cache, which retires when the reload ends. The catalog adoption then built its plugin generation from that short-lived inventory: - inventory retired during the build: `PluginInventoryRetiredError` ("check failed") or a rejected candidate ("superseded"), then a 6-hour wait; - inventory retired after the adoption committed: the published owner was retired with it, and every later turn failed with `UNAVAILABLE: prepared reply dispatch runtime owner was not published for main` until restart; - every later scheduled check chained from the same retired context and failed again. In the reverted branch this showed up as the 10-second retry failing with an `AbortError`. ## Timeline of one wedged run Probe build (main plus the naive re-check), one Gateway, URL change at t=10.49 s: | t (s) | Step | Source (main ab79858) | |---|---|---| | 10.49 | The `config.patch` reload runs in the plugin lifecycle lease, which installs an operation-scoped plugin cache | `gateway/config-reload.ts:1007`, `plugins/plugin-lifecycle-lease.ts:356` | | 10.498 | The runtime config is set and `sessionChanges.emit` fires inside that context. The update owner's listener re-arms the catalog check. `GatewayScheduler` snapshots the registrant's context | `config/runtime-snapshot.ts:272`, `infra/update-startup-scheduler.ts:90`, `infra/gateway-scheduler.ts:190` | | 10.499 / 10.504 | Reload commit marks prepared runtimes stale (R1), then its refresh supersedes R1 with R2 | `gateway/server-reload-hot.ts:280`, `:596` → `agents/prepared-model-runtime.ts:519` | | 11.197 | The fetch is done; the adoption waits for R2 | `agents/prepared-model-runtime.configured-refresh.ts:97-101` | | 11.271 | The reload commits R2 and reply dispatch publishes `main` (generation 5) | `agents/prepared-model-runtime.ts:580` | | 11.272 | The adoption claims generation 5 and builds candidates. Their plugin metadata belongs to the reload's operation cache | `configured-refresh.ts:256-298`, `plugins/plugin-cache.ts:315` | | 12.791 | The reload operation ends; its cache retires | `gateway/config-reload.ts:470`, `plugins/plugin-lifecycle-lease.ts:128` | | 14.336 | The adoption commits generation 6: "remote model catalog applied" | `configured-refresh.ts:363-373` | | after | Cache retirement retires the published owner (needs refresh, no plugin generation). No recovery runs, because it was not a Gateway loan | `agents/prepared-model-runtime.plugin-lifetime.ts:390`, `:407-425` | | 41.858 | Turn: owner mismatch → `UNAVAILABLE ... runtime owner was not published for main` | `agents/prepared-reply-dispatch-runtime.ts:179-188` | The stale mark and the pending replacement were not the cause. The adoption waited correctly for R2 and claimed fresh owners. What broke it was where the check ran, not when. ## Fix One owner: the update-check scheduler. - When `models.catalogRefresh` changes, the config listener re-arms the existing catalog check. It does not add a second scheduler. - Re-arms from the listener run in the update owner's own context, taken from `AsyncLocalStorage.snapshot()` at `start()`, not in the publishing reload's context. The catalog check and every later re-arm use the Gateway's plugin inventory, the same one the startup check uses. No change to the adoption, the stale mark or reply dispatch. The four symptom patches from openclaw#202490 (10-second superseded retry, `PluginInventoryRetiredError` → superseded, captured cancel signal, docs) stay reverted. None of them is needed, and none was added back. Accepted edge case: an unrelated model-affecting reload that lands while an adoption is building still defers that adoption to the next scheduled check, as on `main` (openclaw#168981 removed adoption retries on purpose). A further `catalogRefresh` change re-arms at once. ## Evidence Regression tests (`src/agents/prepared-model-runtime.catalog-source-change.test.ts`) run the real update owner, the real scheduler and the real adoption. The config notification fires inside a reload-style plugin operation, and each test retires that operation's inventory at the point where production failed. Explicit gates, no sleeps. | Case | main | main + naive re-check | this PR | |---|---|---|---| | reload operation ends during the build | red: no re-check | red: `superseded` | green | | reload operation ended before the check ran | red: no re-check | red: `Plugin inventory has retired; begin a new plugin operation.` | green | | reply dispatch after the operation ends | red: no re-check | red: `prepared reply dispatch runtime owner was not published for default` | green | | next scheduled check after the operation ends | red: no re-check | red: `superseded` | green | Real Gateway (isolated state, loopback catalog and Together mock, `cadence2`: Gateway running on catalog A, then the URL is changed to catalog C, which describes `together/zz-lab/zz-day0-live`): **This PR** (exact head `11ac3c2d`), 20 of 20 runs: the catalog was adopted 0.6–13.9 s after the URL change (host load average around 70), the new row was listed, every turn succeeded with a price, and no run showed `UNAVAILABLE`. | run | URL change → outcome (s) | catalog check | Together listing | turn | cost | UNAVAILABLE | |---|---|---|---|---|---|---| | 1 | 2.5 | remote model catalog applied | listed | ok | $0.00006 | no | | 2 | 2.1 | remote model catalog applied | listed | ok | $0.00006 | no | | 3 | 13.9 | remote model catalog applied | listed | ok | $0.00006 | no | | 4 | 1.8 | remote model catalog applied | listed | ok | $0.00006 | no | | 5 | 1.3 | remote model catalog applied | listed | ok | $0.00006 | no | | 6 | 2.9 | remote model catalog applied | listed | ok | $0.00006 | no | | 7 | 8.6 | remote model catalog applied | listed | ok | $0.00006 | no | | 8 | 5.0 | remote model catalog applied | listed | ok | $0.00006 | no | | 9 | 3.4 | remote model catalog applied | listed | ok | $0.00006 | no | | 10 | 3.5 | remote model catalog applied | listed | ok | $0.00006 | no | | 11 | 0.7 | remote model catalog applied | listed | ok | $0.00006 | no | | 12 | 0.7 | remote model catalog applied | listed | ok | $0.00006 | no | | 13 | 0.6 | remote model catalog applied | listed | ok | $0.00006 | no | | 14 | 0.9 | remote model catalog applied | listed | ok | $0.00006 | no | | 15 | 0.7 | remote model catalog applied | listed | ok | $0.00006 | no | | 16 | 0.7 | remote model catalog applied | listed | ok | $0.00006 | no | | 17 | 6.8 | remote model catalog applied | listed | ok | $0.00006 | no | | 18 | 0.8 | remote model catalog applied | listed | ok | $0.00006 | no | | 19 | 1.3 | remote model catalog applied | listed | ok | $0.00006 | no | | 20 | 1.1 | remote model catalog applied | listed | ok | $0.00006 | no | **main** (`ab798580`), 5 runs: no check after the URL change; the next check comes in 6 h. The row stayed unlisted and turns cost $0. | run | URL change → outcome (s) | catalog check | Together listing | turn | cost | UNAVAILABLE | |---|---|---|---|---|---|---| | 1 | - | no check within 120 s (next check in 6 h) | "NOT LISTED (count=2)" | ok | $0.00000 | no | | 2 | - | no check within 120 s (next check in 6 h) | "NOT LISTED (count=2)" | ok | $0.00000 | no | | 3 | - | no check within 120 s (next check in 6 h) | "NOT LISTED (count=2)" | ok | $0.00000 | no | | 4 | - | no check within 120 s (next check in 6 h) | "NOT LISTED (count=2)" | ok | $0.00000 | no | | 5 | - | no check within 120 s (next check in 6 h) | "NOT LISTED (count=2)" | ok | $0.00000 | no | **main + naive immediate re-check** (the reverted approach), 5 runs: 2 of 5 runs wedged every later turn; the other 3 deferred the change by 6 h. | run | URL change → outcome (s) | catalog check | Together listing | turn | cost | UNAVAILABLE | |---|---|---|---|---|---|---| | 1 | 0.7 | remote model catalog check failed | "NOT LISTED (count=2)" | ok | $0.00000 | no | | 2 | 1.7 | remote model catalog check superseded; deferred to the next check | "NOT LISTED (count=2)" | ok | $0.00000 | no | | 3 | 4.6 | remote model catalog applied | "NOT LISTED (count=0)" | failed | - | yes | | 4 | 3.6 | remote model catalog applied | "NOT LISTED (count=0)" | failed | - | yes | | 5 | 3.9 | remote model catalog check failed | "NOT LISTED (count=2)" | ok | $0.00000 | no | Live service PID and config hash were unchanged before and after every batch. Gates: `tsgo:core`, `tsgo:core:test`, `tsgo:test:root`, `tsgo:extensions:test`; oxlint and oxfmt on changed files; consumer suites (`update-startup*`, `server-startup-update-check`, `server-startup-post-attach`, `prepared-model-runtime`, `models-list.remote-catalog.integration`). Under host load, `models-list.remote-catalog.integration` timed out once and `update-startup.test.ts` failed once. Both pass on rerun, and on base. ## Merge danger and blast radius - New behavior: a `models.catalogRefresh` edit triggers one immediate catalog GET. - Config-driven re-arms of `update.check` also run in the update owner's context now, instead of the reload's. That is the same context as their startup and scheduled runs. - No config, schema, protocol, SDK or storage change. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Changing
models.catalogRefresh.url(or.enabled) on a running Gateway waited up to six hours for the next scheduled catalog check, so a model the new catalog describes stayed unlisted and its turns were priced at $0.The obvious fix, re-arming the catalog check from the config listener (part 3 of #202490, reverted), broke worse. The check ran inside the hot reload that published the config. The Gateway scheduler keeps the async context of whoever schedules a job, and the reload runs inside a plugin lifecycle operation with its own plugin cache, which retires when the reload ends. The catalog adoption then built its plugin generation from that short-lived inventory:
PluginInventoryRetiredError("check failed") or a rejected candidate ("superseded"), then a 6-hour wait;UNAVAILABLE: prepared reply dispatch runtime owner was not published for mainuntil restart;AbortError.Timeline of one wedged run
Probe build (main plus the naive re-check), one Gateway, URL change at t=10.49 s:
config.patchreload runs in the plugin lifecycle lease, which installs an operation-scoped plugin cachegateway/config-reload.ts:1007,plugins/plugin-lifecycle-lease.ts:356sessionChanges.emitfires inside that context. The update owner's listener re-arms the catalog check.GatewaySchedulersnapshots the registrant's contextconfig/runtime-snapshot.ts:272,infra/update-startup-scheduler.ts:90,infra/gateway-scheduler.ts:190gateway/server-reload-hot.ts:280,:596→agents/prepared-model-runtime.ts:519agents/prepared-model-runtime.configured-refresh.ts:97-101main(generation 5)agents/prepared-model-runtime.ts:580configured-refresh.ts:256-298,plugins/plugin-cache.ts:315gateway/config-reload.ts:470,plugins/plugin-lifecycle-lease.ts:128configured-refresh.ts:363-373agents/prepared-model-runtime.plugin-lifetime.ts:390,:407-425UNAVAILABLE ... runtime owner was not published for mainagents/prepared-reply-dispatch-runtime.ts:179-188The stale mark and the pending replacement were not the cause. The adoption waited correctly for R2 and claimed fresh owners. What broke it was where the check ran, not when.
Fix
One owner: the update-check scheduler.
models.catalogRefreshchanges, the config listener re-arms the existing catalog check. It does not add a second scheduler.AsyncLocalStorage.snapshot()atstart(), not in the publishing reload's context. The catalog check and every later re-arm use the Gateway's plugin inventory, the same one the startup check uses.No change to the adoption, the stale mark or reply dispatch. The four symptom patches from #202490 (10-second superseded retry,
PluginInventoryRetiredError→ superseded, captured cancel signal, docs) stay reverted. None of them is needed, and none was added back.Accepted edge case: an unrelated model-affecting reload that lands while an adoption is building still defers that adoption to the next scheduled check, as on
main(#168981 removed adoption retries on purpose). A furthercatalogRefreshchange re-arms at once.Evidence
Regression tests (
src/agents/prepared-model-runtime.catalog-source-change.test.ts) run the real update owner, the real scheduler and the real adoption. The config notification fires inside a reload-style plugin operation, and each test retires that operation's inventory at the point where production failed. Explicit gates, no sleeps.supersededPlugin inventory has retired; begin a new plugin operation.prepared reply dispatch runtime owner was not published for defaultsupersededReal Gateway (isolated state, loopback catalog and Together mock,
cadence2: Gateway running on catalog A, then the URL is changed to catalog C, which describestogether/zz-lab/zz-day0-live):This PR (exact head
11ac3c2d), 20 of 20 runs: the catalog was adopted 0.6–13.9 s after the URL change (host load average around 70), the new row was listed, every turn succeeded with a price, and no run showedUNAVAILABLE.main (
569c60bc), 5 runs: no check after the URL change; the next check comes in 6 h. The row stayed unlisted and turns cost $0.main + naive immediate re-check (the reverted approach), 5 runs: 2 of 5 runs wedged every later turn; the other 3 deferred the change by 6 h.
Live service PID and config hash were unchanged before and after every batch.
Gates:
tsgo:core,tsgo:core:test,tsgo:test:root,tsgo:extensions:test; oxlint and oxfmt on changed files; consumer suites (update-startup*,server-startup-update-check,server-startup-post-attach,prepared-model-runtime,models-list.remote-catalog.integration). Under host load,models-list.remote-catalog.integrationtimed out once andupdate-startup.test.tsfailed once. Both pass on rerun, and on base.Merge danger and blast radius
models.catalogRefreshedit triggers one immediate catalog GET.update.checkalso run in the update owner's context now, instead of the reload's. That is the same context as their startup and scheduled runs.