Skip to content

fix(models): show newly authenticated providers after a config reload - #134922

Closed
Yigtwxx wants to merge 1 commit into
openclaw:mainfrom
Yigtwxx:fix/catalog-stale-owner-map-config-advance
Closed

Yigtwxx wants to merge 1 commit into
openclaw:mainfrom
Yigtwxx:fix/catalog-stale-owner-map-config-advance

Conversation

@Yigtwxx

@Yigtwxx Yigtwxx commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Related: #134361

What Problem This Solves

Fixes an issue where an operator who runs models auth login and then triggers any ordinary gateway config reload is still shown the pre-login model catalog in /models and models.list. The catalog is marked stale by the auth change, but the refresh that is supposed to consume that flag on the next explicit browse silently does not run, so the newly authenticated provider's models never appear until the gateway restarts.

This is the exact failure #134361 shipped to fix; it comes back whenever a model-neutral runtime-config commit lands between the login and the browse.

Why This Change Was Made

#134361 added ownersBySnapshot, a WeakMap from a published snapshot to its owner, so refreshStalePreparedModelRuntimeCatalog can find the owner holding catalogStale without scanning every owner. publishPreparedModelRuntimeOwnerSnapshot is its only writer.

advancePreparedModelRuntimeOwnerConfig assigns owner.snapshot directly, bypassing that writer:

owner.snapshot = stampPreparedModelRuntimeSnapshotConfig(owner.snapshot, config);

stampPreparedModelRuntimeSnapshotConfig returns Object.freeze({ ...snapshot, config }), a new object identity, in exactly the case that reaches this line. The map keeps pointing at the retired snapshot, the snapshot readers now receive is absent from it, and the lookup returns undefined. catalogStale is untouched by the advance, so the flag stays set while the code that consumes it can no longer resolve its owner.

Both callers are live gateway paths: advancePreparedModelRuntimeConfig runs from gateway/server-reload-managed.ts on every model-neutral runtime-config commit, and updateOwnersForScopedRefresh advances every owner outside a scoped refresh.

The fix routes that assignment through the writer, and the writer now carries a comment stating it is the only permitted assignment site, so a future owner.snapshot = elsewhere is visibly out of contract. It is behaviour-preserving for every path that does not take a config advance: the previous owner scan read owner.snapshot at call time, which is what the map now reflects.

User Impact

After authenticating a new provider, an explicit model browse refreshes the catalog as intended even if a config reload happened in between. Nothing else changes: the refresh still runs only on an explicit read that opts in, and owners that never take a config advance behave exactly as before.

Evidence

Regression test added to src/agents/prepared-model-runtime.reload-auth.test.ts: publish, apply a profileSetChanged auth mutation, advance the config stamp in place, then refresh from the snapshot readers now hold.

The measurement that motivated it, counting runPreparedModelCatalogWorker invocations across two arms that differ only by the advancePreparedModelRuntimeConfig({}) call:

without config advance with config advance
main worker x1, ["authenticated-model"] worker x0, undefined
this branch worker x1, ["authenticated-model"] worker x1, ["authenticated-model"]

End to end through loadPreparedModelCatalogOwnerSnapshot({ readOnly: true, refreshFullCatalog: true }) the same split shows up as reaching materializeRequestedModelCatalog versus returning entries: [] without ever attempting the refresh.

The new test is load-bearing. Reverting only the prepared-model-runtime.owner.ts change and rerunning the file:

Tests  1 failed | 15 passed (16)
x keeps a stale catalog reachable after a model-neutral config stamp advance

With the change applied, all 16 pass:

node scripts/run-vitest.mjs run --config test/vitest/vitest.agents-core.config.ts \
  src/agents/prepared-model-runtime.reload-auth.test.ts
Test Files  1 passed (1)
     Tests  16 passed (16)

Local gates, all clean against origin/main:

oxlint -c .oxlintrc.json <changed files>          exit 0
oxfmt --check <changed files>                     All matched files use the correct format.
check-max-lines-ratchet.mts --base origin/main    max-lines ratchet OK: 873 grandfathered suppressions.
check-assertion-safety-ratchet.mts --base origin/main
                                                  assertion SAFETY ratchet OK: 4130 files, 12735 grandfathered assertions.
check-deadcode-exports.mts                        Knip production unused-export scan passed with 0 entries.

The owner-by-snapshot map added in openclaw#134361 keys on snapshot identity, and
publishPreparedModelRuntimeOwnerSnapshot is its only writer.
advancePreparedModelRuntimeOwnerConfig assigned owner.snapshot directly, and the
config stamp mints a new frozen snapshot, so the map kept pointing at the retired
one. The catalogStale flag survived the advance while the lookup that consumes it
no longer resolved its owner, and the next explicit browse served the pre-login
catalog.

Route that assignment through the writer so the index moves with the stamp, and
say on the writer that it is the only permitted assignment site.
@Yigtwxx
Yigtwxx requested a review from a team as a code owner September 1, 2026 06:25
@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Sep 1, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 1, 2026
@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 1, 2026, 3:03 AM ET / 07:03 UTC.

ClawSweeper review

What this changes

The PR routes a config-stamped prepared runtime snapshot through the canonical publisher so an explicit model browse can refresh providers authenticated before a gateway config reload.

Regression provenance

Possible regression — probable (reviewed change; known regression link). No predecessor PR is attributed.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 4 items remain

The patch is a correct owner-boundary repair: it restores the snapshot-to-owner index after an in-place config stamp. Keep this PR open for a redacted real gateway run, because the supplied validation is focused mocked-test evidence rather than after-fix operator behavior.

Priority: P1
Reviewed head: 8ba95e2c3e872b2be83a7092c2877e0dd588dd6e

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch and focused regression coverage are solid, but an external contributor’s evidence remains mock-only for this user-visible recovery path.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The changed production owner is the prepared runtime snapshot index; supplied terminal output covers a mocked catalog worker and focused owner test, but no real gateway run shows authentication, config reload, and explicit model browse producing the refreshed catalog. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The changed production owner is the prepared runtime snapshot index; supplied terminal output covers a mocked catalog worker and focused owner test, but no real gateway run shows authentication, config reload, and explicit model browse producing the refreshed catalog. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 7 items Current-main defect: The current-main-equivalent owner code indexes snapshots by object identity, while config stamping creates a frozen copied snapshot and the advance path directly replaces owner.snapshot without updating that index.
Introduced repair: The PR replaces the bypassing assignment with the existing publisher, which removes the old key and registers the newly stamped snapshot identity.
Consumer and explicit-read boundary: Stale refresh first resolves the owner by exact snapshot identity and returns without discovery when absent; catalog materialization invokes it only for read-only requests that explicitly request a full refresh.
Findings None None.
Security None None.

How this fits together

Prepared model-runtime snapshots supply model catalogs to gateway, CLI, and channel browse requests. Authentication marks a catalog stale; an explicit browse resolves the snapshot owner and refreshes that catalog without making normal agent runs wait for provider discovery.

flowchart LR
  A[Provider authentication] --> B[Catalog marked stale]
  B --> C[Prepared runtime owner]
  C --> D[Config reload stamps snapshot]
  D --> E[Snapshot owner lookup]
  E --> F[Explicit model browse]
  F --> G[Refreshed catalog]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The changed production owner is the prepared runtime snapshot index; supplied terminal output covers a mocked catalog worker and focused owner test, but no real gateway run shows authentication, config reload, and explicit model browse producing the refreshed catalog. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The supplied after-fix evidence is a mocked focused suite; it does not show an authenticated provider, ordinary gateway reload, and explicit browse succeeding together in a real gateway.
  • Resolve merge risk (P1) - Production changes are +8/−2 (net +6); the added canonical publisher call and invariant comment are justified by the identity-index update, but this small growth should remain limited to that path.
  • Complete next step (P2) - The remaining gate is contributor-owned real behavior proof, not a mechanical repair for an automated work lane.
Agent review details

Security

None.

PR surface

Source +6, Tests +46. Total +52 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 8 2 +6
Tests 1 46 0 +46
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 54 2 +52

Review metrics

Metric Value Why it matters
Production versus test delta production +8/−2 (net +6); tests +46/−0 The production change reuses the sole snapshot publisher to preserve WeakMap identity indexing; the test adds the previously uncovered auth-stale × config-stamp sequence.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the canonical publisher call, then demonstrate on an isolated gateway that provider login followed by an ordinary config reload makes the provider appear on the next explicit model browse without exposing credentials.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the canonical publisher call, then demonstrate on an isolated gateway that provider login followed by an ordinary config reload makes the provider appear on the next explicit model browse without exposing credentials.

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

Yes, at the owner boundary: a profile-set auth mutation followed by a model-neutral config advance returns a new snapshot identity absent from the current-main WeakMap. The supplied focused regression transcript supports this path, though it was not independently executed in this read-only review.

Is this the best way to solve the issue?

Yes. Updating the existing sole snapshot publisher repairs the identity-index invariant at its owner rather than compensating in catalog readers or broadening discovery behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 32adfe7a8e12.

Labels

Label changes:

  • add P1: A successful provider-authentication flow can otherwise leave explicit model browsing silently stale until a gateway restart.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The changed production owner is the prepared runtime snapshot index; supplied terminal output covers a mocked catalog worker and focused owner test, but no real gateway run shows authentication, config reload, and explicit model browse producing the refreshed catalog. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P1: A successful provider-authentication flow can otherwise leave explicit model browsing silently stale until a gateway restart.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The changed production owner is the prepared runtime snapshot index; supplied terminal output covers a mocked catalog worker and focused owner test, but no real gateway run shows authentication, config reload, and explicit model browse producing the refreshed catalog. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Current-main defect: The current-main-equivalent owner code indexes snapshots by object identity, while config stamping creates a frozen copied snapshot and the advance path directly replaces owner.snapshot without updating that index. (src/agents/prepared-model-runtime.owner.ts:265, 32adfe7a8e12)
  • Introduced repair: The PR replaces the bypassing assignment with the existing publisher, which removes the old key and registers the newly stamped snapshot identity. (src/agents/prepared-model-runtime.owner.ts:268, 8ba95e2c3e87)
  • Consumer and explicit-read boundary: Stale refresh first resolves the owner by exact snapshot identity and returns without discovery when absent; catalog materialization invokes it only for read-only requests that explicitly request a full refresh. (src/agents/prepared-model-runtime.ts:380, 8ba95e2c3e87)
  • Gateway and browse callers: Gateway config commits advance non-read-only owners, while /models, CLI model listing, and the Gateway model-list flow request full catalog refreshes; auth-status deliberately does not. (src/gateway/server-reload-managed.ts:374, 8ba95e2c3e87)
  • Regression coverage: The added test covers the missing sequence: publish, mark the catalog stale after an auth-profile-set mutation, advance config, then refresh once and consume the stale flag. Existing tests cover explicit stale reads, concurrent refreshes, and immutable config stamping independently. (src/agents/prepared-model-runtime.reload-auth.test.ts:815, 8ba95e2c3e87)
  • Current-main and related-fix provenance: Fetched current main contains the PR base but not this head, and both changed file blobs are unchanged from the base, so main still has the direct-assignment defect. The related merged PR is main-only: no release tag contains its merge commit. (src/agents/prepared-model-runtime.owner.ts:259, d8f55fa4f9ea)

Likely related people:

  • obviyus: 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)
  • Marvinthebored: 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.

  • Add a redacted isolated-gateway trace showing provider authentication, an ordinary config reload, and the next explicit model browse listing the provider; do not expose tokens or private endpoints.
  • Update the PR body with that evidence; if a fresh review does not start automatically, ask a maintainer to comment @clawsweeper re-review.

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.

@Yigtwxx

Yigtwxx commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #135063, which landed the same owner-boundary repair on main.

Measured on origin/main: advancePreparedModelRuntimeOwnerConfig now publishes through publishPreparedModelRuntimeOwnerSnapshot, and that publisher performs the config stamp and the ownersBySnapshot move together — it stamps snapshot with owner.input.config, deletes the previous key, and registers the newly stamped identity. That keeps a config-stamped snapshot resolvable back to the owner holding the stale-catalog flag, which is the invariant this PR was restoring.

git merge origin/main on this branch conflicts only in src/agents/prepared-model-runtime.owner.ts, and the conflicting hunk is that same fix rather than unrelated drift. The only remaining delta here is the extra regression case, which is not enough to keep a separate PR open.

Thanks @steipete for picking the invariant up at the publisher instead of at the call site — moving the stamp inside the sole publication helper is the stronger placement, since every future publication path inherits the index update for free.

@Yigtwxx Yigtwxx closed this Sep 1, 2026
@Yigtwxx
Yigtwxx deleted the fix/catalog-stale-owner-map-config-advance branch September 1, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant