Skip to content

fix(models): report hosted catalogs pending a Gateway restart - #141885

Merged
obviyus merged 1 commit into
mainfrom
refactor/hosted-residual-delivery
Sep 8, 2026
Merged

obviyus merged 1 commit into
mainfrom
refactor/hosted-residual-delivery

Conversation

@obviyus

@obviyus obviyus commented Sep 8, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

A running Gateway could miss restart guidance when another process downloaded a newer catalog and the next scheduled refresh reported fresh or unchanged.

Why This Change Was Made

The startup snapshot retains its generation. A read-only check compares completed refresh data with the active snapshot and stored eligible bundle, reporting one notice per source/generation and rejecting superseded results. Failed inspection retains the remaining refresh interval.

User Impact

Operators receive restart guidance for externally downloaded catalogs without repeated notices. Inspection does not activate new rows or prices; no configuration or persistent state is added.

Evidence

Matched Gateway and CLI sequences reproduced the missing notice and produced one after the fix while both Gateways stayed healthy. Focused overlay and scheduling tests covered fresh/unchanged results, source races, cancellation, and inspection-error delay. Required CI passed all final controls. These source executions do not establish a newly compiled package or provider inference.

@obviyus obviyus self-assigned this Sep 8, 2026
@clawsweeper

clawsweeper Bot commented Sep 8, 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: M maintainer Maintainer-authored PR labels Sep 8, 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 8, 2026
@clawsweeper

clawsweeper Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 8, 2026, 1:58 AM ET / 05:58 UTC.

ClawSweeper review

What this changes

The Gateway detects downloaded model catalogs awaiting restart, suppresses repeated notices, and preserves retry timing when catalog inspection fails.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still misses restart notices after another process downloads a catalog. No blocking correctness or security findings were identified.

Priority: P2
Reviewed head: b2fa7d42fd27375cb2b2f343a45a3a67cdc0aac6

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and no identified blocking defects.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository State identifies MEMBER authorship, so the external proof gate does not apply. The body reports matching source Gateway/CLI runs showing one candidate restart notice; this review inspected source and tests but did not independently inspect runtime traces.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository State identifies MEMBER authorship, so the external proof gate does not apply. The body reports matching source Gateway/CLI runs showing one candidate restart notice; this review inspected source and tests but did not independently inspect runtime traces.
Evidence reviewed 8 items Current main still needs the repair: At the fetched main revision, createGatewayUpdateCheck logs restart guidance only for status updated; fresh and unchanged results cannot announce another process's download. The overlay still preserves the startup snapshot.
Inspection preserves activation ownership: The new check validates current configuration, compares the active generation, and reads the compatible stored bundle without replacing the startup snapshot. Gateway kernel initialization captures that snapshot before bootstrap yields.
Scheduling and race coverage: Read the added updated/fresh/unchanged cases, source-change race, inspection-error retry, and overlay lifetime assertions alongside existing cancellation controls. The scheduler retains nextCheckInMs before inspection and rejects stopped work before logging. Tests were inspected, not executed.
Findings None None.
Security None None.

How this fits together

The hosted model catalog supplies model metadata and prices through a shared SQLite store. The Gateway retains its startup snapshot; background checks notify operators when eligible downloaded data requires a restart.

flowchart TD
  A[Hosted catalog] --> B[CLI or background refresh]
  B --> C[Shared catalog store]
  C --> D[Pending update inspection]
  E[Gateway startup snapshot] --> D
  F[Current catalog settings] --> D
  D --> G[Restart notice or no notice]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +46, Tests +276, Docs +5. Total +327 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 77 31 +46
Tests 2 276 0 +276
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 358 31 +327

Review metrics

None.

Technical review

Best possible solution:

Keep catalog activation tied to process restart while deriving restart guidance from the eligible stored generation and the held startup snapshot.

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

Yes, from source: hold a Gateway startup snapshot, download a newer catalog through another process, then let the Gateway receive fresh or unchanged. Current main omits the restart notice; no local runtime reproduction was executed.

Is this the best way to solve the issue?

Yes. The patch extends the existing overlay and scheduler owners while retaining snapshot lifetime, compatibility filtering, and cancellation behavior.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: Repairs missing operator guidance for pending catalog updates without changing active model behavior.
  • 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: Repository State identifies MEMBER authorship, so the external proof gate does not apply. The body reports matching source Gateway/CLI runs showing one candidate restart notice; this review inspected source and tests but did not independently inspect runtime traces.

Evidence

What I checked:

  • Current main still needs the repair: At the fetched main revision, createGatewayUpdateCheck logs restart guidance only for status updated; fresh and unchanged results cannot announce another process's download. The overlay still preserves the startup snapshot. (src/infra/update-startup.ts:1515, b1264739e360)
  • Inspection preserves activation ownership: The new check validates current configuration, compares the active generation, and reads the compatible stored bundle without replacing the startup snapshot. Gateway kernel initialization captures that snapshot before bootstrap yields. (src/model-catalog/remote-overlay.ts:85, b2fa7d42fd27)
  • Scheduling and race coverage: Read the added updated/fresh/unchanged cases, source-change race, inspection-error retry, and overlay lifetime assertions alongside existing cancellation controls. The scheduler retains nextCheckInMs before inspection and rejects stopped work before logging. Tests were inspected, not executed. (src/infra/update-startup.test.ts:3013, b2fa7d42fd27)
  • Captured behavior evidence: The supplied complete PR body reports matched baseline/candidate source Gateway runs with a separate models refresh --json download: baseline omitted the notice and candidate emitted one. It explicitly identifies packaged build-stamp fixture input and limits its claims. Raw runtime traces were not supplied; the authoritative Repository State identifies MEMBER authorship, so ordinary external-contributor proof is not required. (b2fa7d42fd27)
  • Area history and routing: Current-main history records Ayaan Zaidi's catalog snapshot work and Peter Steinberger's update lifecycle and state work. Exact-line blame could not complete because a historical blob was unavailable; these are routing candidates, not verified introduction attribution. (src/model-catalog/remote-overlay.ts, 21dc7d5d7b6c)
  • Security and storage boundary: The diff adds an in-memory generation field and read-only inspection, without changing persisted formats, transport authorization, dependencies, or plugin APIs. Existing catalog validation continues stripping remote endpoint and header overrides. (packages/model-catalog-core/src/remote-catalog-bundle.ts:210, b2fa7d42fd27)

Likely related people:

  • Ayaan Zaidi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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-08T05:34:34.439Z sha b2fa7d4 :: needs maintainer review before merge. :: none

@obviyus

obviyus commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

landpr-approve-admin-merge
pr: 141885
head: b2fa7d4
scope: owner-review

@obviyus
obviyus merged commit d69d981 into main Sep 8, 2026
191 checks passed
@obviyus
obviyus deleted the refactor/hosted-residual-delivery branch September 8, 2026 06:03
@obviyus

obviyus commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as d69d981.

Proof: A separate real CLI process downloaded a hosted catalog while the Gateway kept its startup snapshot. The baseline gave no restart notice; the candidate logged the pending generation at the next scheduled check. Both stayed healthy and exited normally.

  • Bug: Cached fresh or unchanged results hid restart guidance after another process downloaded the catalog.
  • Fix: The existing update owner compares the eligible stored source/generation with the startup snapshot and suppresses repeated or superseded notices. Inspection leaves active rows and prices unchanged.
  • Validation: Exact-head required CI passed, including the final inspection-error retry control, source-change/cancellation controls and all overlay cases. Fresh local review is tier B with no findings or security concerns.
  • Authority: The exact-head approval waived only the procedural owner-review hold; correctness, proof, security, CI and server requirements remained.

Public proof used the actual source entrypoints with a named retained build-stamp data fixture. It does not claim a newly compiled package, provider inference or a repeat of the earlier recovery/pricing campaign. All owned proof consumers and observers are stopped; worktrees and evidence are preserved.

obviyus added a commit that referenced this pull request Sep 8, 2026
…41927)

## What Problem This Solves

Operators can see a stored credential with `static` health while `models status --check` exits 1 because route readiness is unknown. The reference currently omits that result. The FAQ also recommends unscoped status immediately after agent-specific login guidance, which can inspect a different model selection.

## Why This Change Was Made

The model CLI reference now distinguishes inventory, credential sources, profile health, model-route issues, and runtime availability. It documents check exit codes and command-resolution failures, and links chat-session inspection to the existing `/model status` guidance. The FAQ uses an explicit agent and links to this canonical explanation.

Hosted refresh now has its own section, preserving the distinction between downloading metadata and activating it after a Gateway restart. The FAQ's obsolete numeric picker was already corrected by #139232 and remains unchanged.

## User Impact

Operators can inspect the intended agent, understand an indeterminate result without treating it as rejected credentials, and distinguish a catalog download from authentication or live activation. No product behavior, model-selection policy, auth policy, or configuration changes.

## Evidence

- Source audit at `8e47d6998abdd916d66f5245c3d3f31f02c682b6` covers CLI registration, status output and exit-code selection, credential-source/health owners, and hosted refresh.
- Reused the actual isolated `models status --agent work --json --check` observation at `4e402dda9e0ee8c8a5b01e39d7ccd61ccf6d40ad`: stored exec reference retained, profile `static`, route `indeterminate`, exit 1, and no execution of the stored reference. The relevant status/health/overview/config-loading source is unchanged at the documentation baseline.
- Reused the completed hosted refresh proof from #141885: a separate CLI download produces a Gateway restart notice without activating rows or prices. No new runtime, provider request, or credential access was needed for this docs-only change.
- `pnpm docs:list`, changed-file `oxfmt --check`, `node scripts/check-docs-mdx.mjs docs/cli/models.md docs/help/faq-models.md`, the glossary check against the pinned baseline, and `git diff --check` pass.
- Full link/anchor audits check 9,427 candidate links and 9,424 baseline links. Both report the same 39 pre-existing missing ClawHub mirror links; all three new links pass. The local external documentation mirror is unavailable. No product build or typecheck ran locally.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 9, 2026
…aw#141885)

## What Problem This Solves

A running Gateway can miss a catalog restart notice when another process runs `openclaw models refresh`. Its next scheduled check reports `fresh` or `unchanged`, although the downloaded catalog differs from the Gateway's process-start snapshot.

## Why This Change Was Made

The startup snapshot now retains its generation. One read-only check compares the completed refresh's source and generation with the active snapshot and the currently stored eligible bundle. The existing update lifecycle reports a pending restart once per observed source/generation, rejects superseded results, and retains the remaining cache interval when inspection fails.

This replaces the download-status-only notice branch. Validation, scheduling, cancellation and snapshot ownership stay with their existing owners; no new timer, persistent state or configuration is introduced.

## User Impact

Operators receive restart guidance for a newer catalog downloaded by another process. Repeated checks do not repeat the same notice. Inspection does not activate rows or prices, and stopped or superseded work cannot publish stale guidance.

## Evidence

- On current-main source `4e2ceb3345e372edb6a124de1fa02eb0140c186f`, two focused cases reached the held startup snapshot and failed because `fresh` and `unchanged` checks logged no restart notice. Three existing timing/cancellation controls passed.
- Matched actual source Gateway and CLI sequences reproduced the missing baseline notice and produced one candidate notice after a separate `models refresh --json` download. Both Gateways remained healthy, exited normally and joined their consumers. These isolated source runs used retained packaged build-stamp data as an explicit fixture input; they are not claims of a newly compiled package or provider inference.
- Twelve overlay checks and the first five scheduler checks passed. The source-change race control also passed. A later inspection-error control exposed a retry-delay issue; retaining the refresh's remaining interval before inspection fixes it, and required CI confirmed that control.
- Focused lint and formatting pass. [Required CI](https://github.com/openclaw/openclaw/actions/runs/34190821325) passed. Actual verbose logs confirm the final retry-delay control, source-change control, updated/fresh/unchanged cases and all twelve overlay cases. CI tested merge `acc3bfbaec90714ca3f6d9599ffbafd33f6eed20`; all five candidate file blobs match this PR head.

Existing hosted row/pricing lifetime and recovery proof remains at its original identities. This does not claim uninterrupted service, repeat the earlier recovery campaign, or close broader native/auth publication obligations.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 9, 2026
…enclaw#141927)

## What Problem This Solves

Operators can see a stored credential with `static` health while `models status --check` exits 1 because route readiness is unknown. The reference currently omits that result. The FAQ also recommends unscoped status immediately after agent-specific login guidance, which can inspect a different model selection.

## Why This Change Was Made

The model CLI reference now distinguishes inventory, credential sources, profile health, model-route issues, and runtime availability. It documents check exit codes and command-resolution failures, and links chat-session inspection to the existing `/model status` guidance. The FAQ uses an explicit agent and links to this canonical explanation.

Hosted refresh now has its own section, preserving the distinction between downloading metadata and activating it after a Gateway restart. The FAQ's obsolete numeric picker was already corrected by openclaw#139232 and remains unchanged.

## User Impact

Operators can inspect the intended agent, understand an indeterminate result without treating it as rejected credentials, and distinguish a catalog download from authentication or live activation. No product behavior, model-selection policy, auth policy, or configuration changes.

## Evidence

- Source audit at `968f4df72cfee029db29d5d21962bb835fb212be` covers CLI registration, status output and exit-code selection, credential-source/health owners, and hosted refresh.
- Reused the actual isolated `models status --agent work --json --check` observation at `4e402dda9e0ee8c8a5b01e39d7ccd61ccf6d40ad`: stored exec reference retained, profile `static`, route `indeterminate`, exit 1, and no execution of the stored reference. The relevant status/health/overview/config-loading source is unchanged at the documentation baseline.
- Reused the completed hosted refresh proof from openclaw#141885: a separate CLI download produces a Gateway restart notice without activating rows or prices. No new runtime, provider request, or credential access was needed for this docs-only change.
- `pnpm docs:list`, changed-file `oxfmt --check`, `node scripts/check-docs-mdx.mjs docs/cli/models.md docs/help/faq-models.md`, the glossary check against the pinned baseline, and `git diff --check` pass.
- Full link/anchor audits check 9,427 candidate links and 9,424 baseline links. Both report the same 39 pre-existing missing ClawHub mirror links; all three new links pass. The local external documentation mirror is unavailable. No product build or typecheck ran locally.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Oct 1, 2026
…8000)

Related: #140086, #141885, #156535, #157838

## What Problem This Solves

A running Gateway doesn't see a newly downloaded hosted model catalog until it restarts. This PR publishes each accepted catalog through the existing prepared-runtime owner, without a restart. Model rows and their prices switch together as one generation, which keeps the invariant from #140086.

## User Impact

- Compatible downloads are adopted at the Gateway's background catalog check, or after an explicit `models.list` refresh. That refresh returns the currently accepted rows right away and runs adoption afterward.
- A turn admitted on catalog N keeps N's rows and prices until it finishes. New turns use N+1. Rows and prices are never mixed.
- A concurrent auth or config publication no longer postpones adoption to the next scheduled check (up to 6 h). Adoption waits for that publication to settle, then retries, up to 3 attempts.
- An owner whose build failed or timed out ends the adoption instead of waiting on unbounded work. Gateway shutdown cancels an adoption that is still preparing.
- Malformed, schema-invalid, too-new (`minVersion`) and older catalogs are rejected, and the previously accepted catalog stays in use.
- Changing `models.catalogRefresh.url` no longer needs a restart: the previous source's catalog stops applying, and the mirror's catalog is adopted at the next catalog check.

**Bad-catalog exposure:** with live apply, a *valid but wrong* published catalog reaches running Gateways at their next catalog check (at most every 6 h) or on the next explicit `models.list` refresh. It no longer waits for a restart. Recovery uses existing mechanisms only:
- Republish a corrected catalog with a newer `generatedAt`; Gateways adopt it the same way.
- Operators can set `models.catalogRefresh.enabled: false`, which withdraws remote rows and prices without a restart (covered by the Gateway integration test).

This PR adds no new kill switch, config option or env knob.

### Compatibility

No config keys, defaults, types, validation, stored rows, protocol or SDK contracts change. The only config-surface change is the `models.catalogRefresh.url` help text, which drops the stale "Changes apply after a Gateway restart" sentence, and its regenerated config-doc baseline hash. Existing configs validate unchanged and need no Doctor migration (maintainer confirmation: #158000 (comment)). Startup behavior is unchanged. Upgrade impact for existing installs: an accepted download activates at the next catalog check instead of the next restart.

## Why This Change Was Made

- `prepared-model-runtime.configured-refresh.ts` builds a complete candidate generation of the configured owners under the new catalog. One serialized commit then publishes rows, the accepted bundle, the pricing context and the reply-dispatch projection together.
- Adoption re-reads the stored catalog until the config it read under is still current, so a stale caller can't cancel a current adoption.
- Each preparation attempt has its own abort signal. A config advance restarts only the attempt; a newer catalog or shutdown ends the whole adoption, including pricing preparation.
- Between attempts, adoption waits only on publication gates: a pending replacement or an owner's pending publication.
- Adopted owners install the same plugin-retirement recovery as configured publication (#161267). After commit, a lost Gateway plugin loan republishes them through the normal recovery. Before commit, it restarts the adoption attempt, and the commit refuses any candidate whose plugin generation retired.

### Why downloads were restart-only, and what this keeps

Restart-only activation was a mechanism, not the goal. #140086 chose it to stop rows and prices from different catalog versions mixing, and #157838 was merged as "the prerequisite for applying new remote catalogs without a Gateway restart (rows and prices must switch together)". This PR is that follow-up. Every requirement those PRs set still holds:

| Original requirement | Source | How it holds here |
|---|---|---|
| Rows and prices from one catalog version; never mixed across reloads or new requests | #140086 | One serialized commit publishes owners, bundle, pricing context and dispatch; pricing contexts are keyed by the exact accepted catalog. Integration test: new rows appear only with new prices |
| Admitted work keeps its pair | #140086, #157838 | Runs carry their plugin generation's catalog; usage operations capture one pricing context. Integration test and live proof: the in-flight turn keeps the old price |
| Startup absence is a real state (no downloaded rows without prices) | #140086 | Absence → catalog goes through the same atomic commit; overlay absence tests unchanged |
| Worker replacement inherits the host's accepted pair, not a later download | #140086 | The commit updates the inherited pair; later workers and a worker-exit recovery keep it (overlay and integration tests) |
| Current enablement and source URL still gate eligibility | #140086, #156535 | Checked on every read and before adoption, including the default-install v1 fallback; disablement withdraws rows and prices together (integration test) |
| Bad or superseded downloads never replace the active pair | #140086, #141885 | Compatibility, `minVersion`, revision and `generatedAt` checks; stale reads can't cancel a current adoption (regression test) |
| Failed catalog checks retry at the remaining fresh interval, not a full TTL | #141885 | Unchanged scheduler behavior; the deleted notice test's retry case is restored for failed adoption (fails if the retry falls back to the full TTL) |
| Operators learn when a downloaded catalog is not yet active | #141885 | No longer needed: downloads activate at the next check. The restart notice and its tests are removed; `models refresh` says when a running Gateway applies the update |
| Billing-route prices switch with their rows | #156535 | `upstreamPricing` and `providerPricing` are part of the accepted catalog pair |

## Evidence

**Regressions.** Each fails with its fix reverted and passes with it:
- *Retries a scheduled adoption when its pending auth owner settles.* Runs through the real Gateway update scheduler. Reverted, it logs `remote model catalog check superseded; deferred to the next check`.
- *Does not let a read under a superseded config cancel the current adoption.* Reverted, both calls end `superseded`.
- *Ends adoption instead of joining a timed-out owner build.* Reverted, adoption never settles.
- *Does not hold Gateway shutdown on an adoption's pricing preparation.* Reverted, shutdown waits on the held preparation until the test times out.
- *Recovers adopted owners when their borrowed Gateway plugin retires after commit / before commit.* Without the recovery, both fail: `Prepared model runtime plugin generation retired` and `prepared reply dispatch runtime owner was not published`.
- *Uses the remaining stored TTL after a fresh startup check when adoption fails.* With the retry reverted to the full TTL, the second check doesn't run.

**Suites:**

| Suite | Result |
|---|---|
| `prepared-model-runtime.remote-publication.test.ts` | 10/10 |
| Gateway integration (`models-list.remote-catalog`) | v1 and v2 pass. Config and auth churn during preparation end `published` on the settled owners. Also covers retained admitted runs, rejected and stale bundles, worker replacement and disablement |
| `prepared-model-runtime*`, `server-plugin-reload*`, `update-startup`, and all PR-touched test files | pass |
| `tsgo:core`, all `tsgo:test:src` shards | pass |
| oxlint and oxfmt on changed files; `config:docs:check`, `config:schema:check`; max-lines, assertion-safety and test-timeout-race ratchets | pass |

Tests wait on owned completion signals (`withinTest`), not wall-clock deadlines.

**Live proof** on an isolated Gateway built from `cb8c9197fdc` (no provider mocks). Later commits add plugin-retirement recovery for adopted owners, covered by the regression tests above, and rebases onto `main`. It used a real OpenAI key through `openai/gpt-4.1-mini`, and the build stamp was set before the real catalog's publication date. A client polled `models.list` back to back over one WebSocket for the whole run (1023 polls, no errors). One Gateway process (PID unchanged) and no restart:
1. The stored catalog was seeded with an older revision of the real `catalog.openclaw.ai` v2 catalog: generated 2 days earlier, `gpt-4.1-mini` priced ×10, plus one extra kimi row. `models.list` listed the extra row, and a turn priced **$4.00 / $16.00 per M** input/output.
2. `openclaw models refresh` downloaded the real catalog (`updated`, 1039 models). The listed rows didn't change for the next 7.1 s, and a turn in that window still priced **$4.00 / $16.00 per M**: a download stays inactive until the Gateway adopts it.
3. A long turn was admitted on the older catalog, then `models.list {refresh:true}` returned the older rows (extra kimi row still listed) and started adoption. The new catalog was visible 0.9 s later, while the long turn was still running: the extra kimi row was gone.
4. The in-flight turn finished at **$4.00 / $16.00 per M** (older rows and prices). The next turn priced **$0.40 / $1.60 per M** (real catalog).
5. `models.catalogRefresh.url` was moved to a local mirror of the real catalog through `config.patch`, and the mirror's catalog was adopted without a restart. The mirror then served malformed JSON: `models refresh` failed with `SyntaxError`, the model list was unchanged, and the next turn still priced $0.40 / $1.60 per M.

**Model picker during republication (also on `main`).** Right after the new generation commits, `models.list` shows the new generation's configured and static rows until its full catalog loads, then the full list. In the live run this lasted 109 ms. The same poller against a `main` build shows the same window after a `models.*` config reload (20 → 6 → 16 rows for about 350 ms), so this PR adds a new trigger for an existing behavior. It doesn't change it. The short list comes from the new generation, so rows and prices stay paired.

**Published-driver upgrade cells.** Candidate tarball built from a fresh clone at `6f682c7944e` with the canonical Docker packaging script and no build-time overrides. sha256 `46d881a0…ef0ad`; embedded commit `6f682c7944e2`, version 2026.9.7. `6f682c7944e` already includes the shutdown-cancellation and pricing-deadline commits. The current head the current head differs from it only by rebases onto `main`: `main` had moved the scheduled catalog check into `update-startup-catalog.ts`, and this PR's adoption call moved there unchanged (`git range-diff` shows no other production change; a `remoteCatalog: null` test-fixture field moved to main's relocated `cli-compaction.test-support.ts`).

| Driver → candidate | Scenario | Result |
|---|---|---|
| `[email protected]` | base | passed (930 s); updater outcome success, no recovery |
| `[email protected]` | plugin-deps-cleanup | passed (923 s); updater outcome success, no recovery |
| `[email protected]` (latest) | base | passed (813 s); updater outcome success, no recovery |

In every cell:
- Migration, post-Doctor config validation, survival, plugin-dependency cleanup and runtime-deps repair checks passed.
- The candidate Gateway logged ready, then its catalog check fetched and saved the hosted catalog about 0.2 s after starting. The hosted catalog is older than the candidate's build stamp, so adoption ends `unchanged`, which isn't logged. After a 300 s settlement window, `/readyz` (`ready:true`, nothing failing) and a Gateway `status` RPC passed, and the Gateway shut down cleanly.
- To show a logged terminal outcome, each cell was repeated with a loopback mirror serving a newer copy of the same catalog. Each check logged `remote model catalog applied` about 0.26 s after it started, followed by `/readyz` and `status` passing.

Not run: `[email protected]` plugin-deps-cleanup. At the previous head it failed inside the 2026.9.7 driver's retained-runtime verification (`Retained runtime entry does not reference its inventoried file: dist/a2ui-…mjs`), identically for a merge-base control package with none of this PR's commits.

Harness note for the 2026.9.7 cell: unchanged, the upgrade harness can't run against 2026.9.7. It seeds the retired `tools.toolSearch {mode:"code"}` setting, which 2026.9.7 rejects. The 2026.9.7 cell used the harness's existing Tool Search "absent" mode, a one-line local change that skips only that seed and its check. The 2026.9.6 cells used the unchanged harness.

**CI:** fully green on the final head ([run 36818367970](https://github.com/openclaw/openclaw/actions/runs/36818367970)). Earlier heads hit failures that reproduce on `main` in code this PR doesn't touch: `update-cli.target-schema` (main reproduction: #158000 (comment)), the type-suppression inventory, the Windows partition owner test and the Windows backup-rename test. Main has since fixed the last three. Config compatibility confirmation: #158000 (comment).

No overlap with Pash/Sarah changes.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
…nclaw#158000)

Related: openclaw#140086, openclaw#141885, openclaw#156535, openclaw#157838

## What Problem This Solves

A running Gateway doesn't see a newly downloaded hosted model catalog until it restarts. This PR publishes each accepted catalog through the existing prepared-runtime owner, without a restart. Model rows and their prices switch together as one generation, which keeps the invariant from openclaw#140086.

## User Impact

- Compatible downloads are adopted at the Gateway's background catalog check, or after an explicit `models.list` refresh. That refresh returns the currently accepted rows right away and runs adoption afterward.
- A turn admitted on catalog N keeps N's rows and prices until it finishes. New turns use N+1. Rows and prices are never mixed.
- A concurrent auth or config publication no longer postpones adoption to the next scheduled check (up to 6 h). Adoption waits for that publication to settle, then retries, up to 3 attempts.
- An owner whose build failed or timed out ends the adoption instead of waiting on unbounded work. Gateway shutdown cancels an adoption that is still preparing.
- Malformed, schema-invalid, too-new (`minVersion`) and older catalogs are rejected, and the previously accepted catalog stays in use.
- Changing `models.catalogRefresh.url` no longer needs a restart: the previous source's catalog stops applying, and the mirror's catalog is adopted at the next catalog check.

**Bad-catalog exposure:** with live apply, a *valid but wrong* published catalog reaches running Gateways at their next catalog check (at most every 6 h) or on the next explicit `models.list` refresh. It no longer waits for a restart. Recovery uses existing mechanisms only:
- Republish a corrected catalog with a newer `generatedAt`; Gateways adopt it the same way.
- Operators can set `models.catalogRefresh.enabled: false`, which withdraws remote rows and prices without a restart (covered by the Gateway integration test).

This PR adds no new kill switch, config option or env knob.

### Compatibility

No config keys, defaults, types, validation, stored rows, protocol or SDK contracts change. The only config-surface change is the `models.catalogRefresh.url` help text, which drops the stale "Changes apply after a Gateway restart" sentence, and its regenerated config-doc baseline hash. Existing configs validate unchanged and need no Doctor migration (maintainer confirmation: openclaw#158000 (comment)). Startup behavior is unchanged. Upgrade impact for existing installs: an accepted download activates at the next catalog check instead of the next restart.

## Why This Change Was Made

- `prepared-model-runtime.configured-refresh.ts` builds a complete candidate generation of the configured owners under the new catalog. One serialized commit then publishes rows, the accepted bundle, the pricing context and the reply-dispatch projection together.
- Adoption re-reads the stored catalog until the config it read under is still current, so a stale caller can't cancel a current adoption.
- Each preparation attempt has its own abort signal. A config advance restarts only the attempt; a newer catalog or shutdown ends the whole adoption, including pricing preparation.
- Between attempts, adoption waits only on publication gates: a pending replacement or an owner's pending publication.
- Adopted owners install the same plugin-retirement recovery as configured publication (openclaw#161267). After commit, a lost Gateway plugin loan republishes them through the normal recovery. Before commit, it restarts the adoption attempt, and the commit refuses any candidate whose plugin generation retired.

### Why downloads were restart-only, and what this keeps

Restart-only activation was a mechanism, not the goal. openclaw#140086 chose it to stop rows and prices from different catalog versions mixing, and openclaw#157838 was merged as "the prerequisite for applying new remote catalogs without a Gateway restart (rows and prices must switch together)". This PR is that follow-up. Every requirement those PRs set still holds:

| Original requirement | Source | How it holds here |
|---|---|---|
| Rows and prices from one catalog version; never mixed across reloads or new requests | openclaw#140086 | One serialized commit publishes owners, bundle, pricing context and dispatch; pricing contexts are keyed by the exact accepted catalog. Integration test: new rows appear only with new prices |
| Admitted work keeps its pair | openclaw#140086, openclaw#157838 | Runs carry their plugin generation's catalog; usage operations capture one pricing context. Integration test and live proof: the in-flight turn keeps the old price |
| Startup absence is a real state (no downloaded rows without prices) | openclaw#140086 | Absence → catalog goes through the same atomic commit; overlay absence tests unchanged |
| Worker replacement inherits the host's accepted pair, not a later download | openclaw#140086 | The commit updates the inherited pair; later workers and a worker-exit recovery keep it (overlay and integration tests) |
| Current enablement and source URL still gate eligibility | openclaw#140086, openclaw#156535 | Checked on every read and before adoption, including the default-install v1 fallback; disablement withdraws rows and prices together (integration test) |
| Bad or superseded downloads never replace the active pair | openclaw#140086, openclaw#141885 | Compatibility, `minVersion`, revision and `generatedAt` checks; stale reads can't cancel a current adoption (regression test) |
| Failed catalog checks retry at the remaining fresh interval, not a full TTL | openclaw#141885 | Unchanged scheduler behavior; the deleted notice test's retry case is restored for failed adoption (fails if the retry falls back to the full TTL) |
| Operators learn when a downloaded catalog is not yet active | openclaw#141885 | No longer needed: downloads activate at the next check. The restart notice and its tests are removed; `models refresh` says when a running Gateway applies the update |
| Billing-route prices switch with their rows | openclaw#156535 | `upstreamPricing` and `providerPricing` are part of the accepted catalog pair |

## Evidence

**Regressions.** Each fails with its fix reverted and passes with it:
- *Retries a scheduled adoption when its pending auth owner settles.* Runs through the real Gateway update scheduler. Reverted, it logs `remote model catalog check superseded; deferred to the next check`.
- *Does not let a read under a superseded config cancel the current adoption.* Reverted, both calls end `superseded`.
- *Ends adoption instead of joining a timed-out owner build.* Reverted, adoption never settles.
- *Does not hold Gateway shutdown on an adoption's pricing preparation.* Reverted, shutdown waits on the held preparation until the test times out.
- *Recovers adopted owners when their borrowed Gateway plugin retires after commit / before commit.* Without the recovery, both fail: `Prepared model runtime plugin generation retired` and `prepared reply dispatch runtime owner was not published`.
- *Uses the remaining stored TTL after a fresh startup check when adoption fails.* With the retry reverted to the full TTL, the second check doesn't run.

**Suites:**

| Suite | Result |
|---|---|
| `prepared-model-runtime.remote-publication.test.ts` | 10/10 |
| Gateway integration (`models-list.remote-catalog`) | v1 and v2 pass. Config and auth churn during preparation end `published` on the settled owners. Also covers retained admitted runs, rejected and stale bundles, worker replacement and disablement |
| `prepared-model-runtime*`, `server-plugin-reload*`, `update-startup`, and all PR-touched test files | pass |
| `tsgo:core`, all `tsgo:test:src` shards | pass |
| oxlint and oxfmt on changed files; `config:docs:check`, `config:schema:check`; max-lines, assertion-safety and test-timeout-race ratchets | pass |

Tests wait on owned completion signals (`withinTest`), not wall-clock deadlines.

**Live proof** on an isolated Gateway built from `cb8c9197fdc` (no provider mocks). Later commits add plugin-retirement recovery for adopted owners, covered by the regression tests above, and rebases onto `main`. It used a real OpenAI key through `openai/gpt-4.1-mini`, and the build stamp was set before the real catalog's publication date. A client polled `models.list` back to back over one WebSocket for the whole run (1023 polls, no errors). One Gateway process (PID unchanged) and no restart:
1. The stored catalog was seeded with an older revision of the real `catalog.openclaw.ai` v2 catalog: generated 2 days earlier, `gpt-4.1-mini` priced ×10, plus one extra kimi row. `models.list` listed the extra row, and a turn priced **$4.00 / $16.00 per M** input/output.
2. `openclaw models refresh` downloaded the real catalog (`updated`, 1039 models). The listed rows didn't change for the next 7.1 s, and a turn in that window still priced **$4.00 / $16.00 per M**: a download stays inactive until the Gateway adopts it.
3. A long turn was admitted on the older catalog, then `models.list {refresh:true}` returned the older rows (extra kimi row still listed) and started adoption. The new catalog was visible 0.9 s later, while the long turn was still running: the extra kimi row was gone.
4. The in-flight turn finished at **$4.00 / $16.00 per M** (older rows and prices). The next turn priced **$0.40 / $1.60 per M** (real catalog).
5. `models.catalogRefresh.url` was moved to a local mirror of the real catalog through `config.patch`, and the mirror's catalog was adopted without a restart. The mirror then served malformed JSON: `models refresh` failed with `SyntaxError`, the model list was unchanged, and the next turn still priced $0.40 / $1.60 per M.

**Model picker during republication (also on `main`).** Right after the new generation commits, `models.list` shows the new generation's configured and static rows until its full catalog loads, then the full list. In the live run this lasted 109 ms. The same poller against a `main` build shows the same window after a `models.*` config reload (20 → 6 → 16 rows for about 350 ms), so this PR adds a new trigger for an existing behavior. It doesn't change it. The short list comes from the new generation, so rows and prices stay paired.

**Published-driver upgrade cells.** Candidate tarball built from a fresh clone at `6f682c7944e` with the canonical Docker packaging script and no build-time overrides. sha256 `46d881a0…ef0ad`; embedded commit `6f682c7944e2`, version 2026.9.7. `6f682c7944e` already includes the shutdown-cancellation and pricing-deadline commits. The current head the current head differs from it only by rebases onto `main`: `main` had moved the scheduled catalog check into `update-startup-catalog.ts`, and this PR's adoption call moved there unchanged (`git range-diff` shows no other production change; a `remoteCatalog: null` test-fixture field moved to main's relocated `cli-compaction.test-support.ts`).

| Driver → candidate | Scenario | Result |
|---|---|---|
| `[email protected]` | base | passed (930 s); updater outcome success, no recovery |
| `[email protected]` | plugin-deps-cleanup | passed (923 s); updater outcome success, no recovery |
| `[email protected]` (latest) | base | passed (813 s); updater outcome success, no recovery |

In every cell:
- Migration, post-Doctor config validation, survival, plugin-dependency cleanup and runtime-deps repair checks passed.
- The candidate Gateway logged ready, then its catalog check fetched and saved the hosted catalog about 0.2 s after starting. The hosted catalog is older than the candidate's build stamp, so adoption ends `unchanged`, which isn't logged. After a 300 s settlement window, `/readyz` (`ready:true`, nothing failing) and a Gateway `status` RPC passed, and the Gateway shut down cleanly.
- To show a logged terminal outcome, each cell was repeated with a loopback mirror serving a newer copy of the same catalog. Each check logged `remote model catalog applied` about 0.26 s after it started, followed by `/readyz` and `status` passing.

Not run: `[email protected]` plugin-deps-cleanup. At the previous head it failed inside the 2026.9.7 driver's retained-runtime verification (`Retained runtime entry does not reference its inventoried file: dist/a2ui-…mjs`), identically for a merge-base control package with none of this PR's commits.

Harness note for the 2026.9.7 cell: unchanged, the upgrade harness can't run against 2026.9.7. It seeds the retired `tools.toolSearch {mode:"code"}` setting, which 2026.9.7 rejects. The 2026.9.7 cell used the harness's existing Tool Search "absent" mode, a one-line local change that skips only that seed and its check. The 2026.9.6 cells used the unchanged harness.

**CI:** fully green on the final head ([run 36818367970](https://github.com/openclaw/openclaw/actions/runs/36818367970)). Earlier heads hit failures that reproduce on `main` in code this PR doesn't touch: `update-cli.target-schema` (main reproduction: openclaw#158000 (comment)), the type-suppression inventory, the Windows partition owner test and the Windows backup-rename test. Main has since fixed the last three. Config compatibility confirmation: openclaw#158000 (comment).

No overlap with Pash/Sarah changes.

Co-authored-by: Ayaan Zaidi <[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 maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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