Repository navigation
[AI-assisted] fix(models-config): preserve existing models.json baseUrls on regen - #67893
Conversation
0d6f0fb to
b66a5ea
Compare
Greptile SummaryRemoves the Confidence Score: 5/5Safe to merge; the fix is targeted, the logic is correct, and the regression tests cover the exact failure path. All changed files are well-reasoned: the removal of explicitBaseUrlProviders is complete and consistent across merge.ts and plan.ts, test expectations are updated correctly, and a new end-to-end regression test locks in the preservation semantics. The only open item is a P2 style suggestion to add a comment in the runtime-snapshot test. No blocking issues exist. No files require special attention. Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/agents/models-config.runtime-source-snapshot.test.ts
Line: 317-326
Comment:
**Consider a clarifying comment on the preserved-baseUrl assertion**
After the fix, `ensureOpenClawModelsJson(secondCandidate)` rewrites `models.json` (triggered by the `headers` change) but keeps the `baseUrl` from the first write rather than adopting `secondCandidate`'s `"https://mirror.example/v1"`. That's correct, but the test was originally the primary place where "config baseUrl change propagates" was verified, so a future reader may be surprised to see line 324 asserting the old value. A one-line comment would make the intent clear:
```suggestion
// baseUrl is preserved from the first write; only headers change causes the rewrite.
await ensureOpenClawModelsJson(secondCandidate);
parsed = await readGeneratedModelsJson<{
providers: Record<
string,
{ baseUrl?: string; apiKey?: string; headers?: Record<string, string> }
>;
}>();
expect(parsed.providers.openai?.baseUrl).toBe("https://api.openai.com/v1");
expect(parsed.providers.openai?.apiKey).toBe("OPENAI_API_KEY"); // pragma: allowlist secret
expect(parsed.providers.openai?.headers?.["X-OpenClaw-Test"]).toBe("two");
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "test: distill models-config baseUrl regr..." | Re-trigger Greptile |
obviyus
left a comment
There was a problem hiding this comment.
Verified the merge-mode regression where regenerating models.json rewrote an existing provider baseUrl back to the config value, and confirmed the fix removes the explicit-baseUrl override so existing non-empty baseUrls persist unless the provider API surface changes.
Maintainer follow-up: distilled the new regression test setup, added one clarifying test comment for the preserved-baseUrl assertion, added the unreleased changelog entry, and resolved the current-head review thread.
Local gate: pnpm test src/agents/models-config.merge.test.ts src/agents/models-config.runtime-source-snapshot.test.ts src/agents/models-config.uses-first-github-copilot-profile-env-tokens.test.ts.
|
Landed on main. Thanks @lawrence3699. |
There was a problem hiding this comment.
Pull request overview
Fixes a merge-mode regression where regenerating an agent’s models.json would overwrite an existing non-empty provider baseUrl with the configured provider baseUrl, causing custom endpoints (e.g. OpenAI-compatible gateways without /v1) to be reset on restart.
Changes:
- Removed the “explicit config baseUrl wins” override so merge mode preserves an existing non-empty
models.jsonbaseUrl. - Updated merge logic/tests to preserve
baseUrlfrommodels.jsonunless the provider API surface changes. - Added/updated regression tests across merge, plan, and runtime snapshot layers; documented the fix in the changelog.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/agents/models-config.plan.ts | Removes explicit-baseUrl override plumbing so merge planning no longer forces config baseUrl over existing agent models.json. |
| src/agents/models-config.merge.ts | Updates baseUrl preservation logic to ignore “explicit config baseUrl” and preserve existing non-empty baseUrl when API surface matches. |
| src/agents/models-config.merge.test.ts | Adjusts merge precedence expectations and adds coverage for the restored semantics. |
| src/agents/models-config.uses-first-github-copilot-profile-env-tokens.test.ts | Adds a plan-level regression test ensuring merge regeneration yields noop when only config baseUrl differs from existing non-empty models.json baseUrl. |
| src/agents/models-config.runtime-source-snapshot.test.ts | Ensures runtime snapshot regeneration can still rewrite other fields (e.g. headers) without rewriting an existing baseUrl in merge mode. |
| CHANGELOG.md | Notes the user-visible behavior fix for merge-mode baseUrl preservation. |
…lawrence3699) * models-config: preserve existing models.json baseUrls * test: distill models-config baseUrl regression test * fix: preserve models.json baseUrls on regen (openclaw#67893) (thanks @lawrence3699) --------- Co-authored-by: lawrence3699 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…lawrence3699) * models-config: preserve existing models.json baseUrls * test: distill models-config baseUrl regression test * fix: preserve models.json baseUrls on regen (openclaw#67893) (thanks @lawrence3699) --------- Co-authored-by: lawrence3699 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…boot
Root cause: upstream v2026.4.15 openai-completions provider normalization
writes an extra trailing "/v1" to the blink provider baseUrl on first
persistence of /data/agents/main/agent/models.json:
"blink": { "baseUrl": "https://core.blink.new/api/v1/ai/v1", ... }
The openai-completions adapter then appends "/chat/completions", producing
https://core.blink.new/api/v1/ai/v1/chat/completions ← HTTP 404
Every LLM call fails with failoverReason=model_not_found. Agents appear
non-responsive even though the machine is healthy and the gateway /healthz
returns ok — the gateway just can't reach the upstream model.
Upstream PR openclaw#67893 "preserve models.json baseUrls on regen" (pulled in via
our v2026.4.15 merge) then locks the corrupted baseUrl forever across
restarts — it's preserved from disk even when the code wants to regenerate
it from buildBlinkProvider(). So the bug is fleet-wide and sticky.
Fix: the entrypoint now rewrites providers.blink.baseUrl to the canonical
${BLINK_APIS_URL}/api/v1/ai on every container start, unconditionally.
Breaks the preserve-lock specifically for blink without affecting any
other provider. Runs before the gateway starts, so the correct URL is in
place before any LLM call.
Verified end-to-end on clw_ji90uejs + 3 canary agents: LLM calls return
normally via direct WS and via the claw-manager SSE pipeline.
Pairs with scripts/claw/fix-blink-baseurl-all.sh in the parent repo for
bulk recovery of the currently-running fleet without waiting for the new
image to roll out.
…watcher The initial fix (6eb7983) only sanitized /data/agents/main/agent/models.json if the file already existed at entrypoint run time. On a fresh volume that is not true — OpenClaw gateway lazy-writes models.json during its own startup (after the entrypoint has already exec'd gosu node), and the upstream normalization bug writes a corrupted blink.baseUrl ".../api/v1/ai/v1" at that moment. Combined with openclaw#67893 preserve-baseUrl-on-regen, the corrupted value then persists forever — so every FIRST LLM call from a brand-new agent 404s, even on an image with the "fixed" entrypoint. Reproduction verified on clw_ji90uejs: rm /data/agents/main/agent/models.json + restart → gateway boots → models.json appears with "https://core.blink.new/api/v1/ai/v1" → first chat returns HTTP 404. Fix: the entrypoint now runs a background watcher (disowned, adopted by init) that polls for ~60s, invokes the sanitize helper as soon as models.json appears, and SIGHUPs the running gateway so it reloads the corrected config immediately. The synchronous steady-state sanitize from the previous commit is preserved for already-provisioned agents. Both paths share a single sanitize_models_json() helper so the rewrite logic lives in one place. Also: the helper now uses `ps -e -o pid=,comm=` to find the gateway process instead of `pgrep -x openclaw-gateway`. pgrep caps program-name match at 15 chars and openclaw-gateway is 16 chars, so pgrep was silently finding zero matches and never delivering SIGHUP. ps+awk has no such limit. End-to-end test plan after this ships: 1. Wait for :latest to rebuild and redeploy across the fleet. 2. Provision a new test agent (or `rm models.json && restart` an existing one to simulate a fresh volume). 3. Send a chat within the first 2 minutes of boot. Should respond normally, with models.json on disk holding the canonical baseUrl.
…lawrence3699) * models-config: preserve existing models.json baseUrls * test: distill models-config baseUrl regression test * fix: preserve models.json baseUrls on regen (openclaw#67893) (thanks @lawrence3699) --------- Co-authored-by: lawrence3699 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…lawrence3699) * models-config: preserve existing models.json baseUrls * test: distill models-config baseUrl regression test * fix: preserve models.json baseUrls on regen (openclaw#67893) (thanks @lawrence3699) --------- Co-authored-by: lawrence3699 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…lawrence3699) * models-config: preserve existing models.json baseUrls * test: distill models-config baseUrl regression test * fix: preserve models.json baseUrls on regen (openclaw#67893) (thanks @lawrence3699) --------- Co-authored-by: lawrence3699 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…lawrence3699) * models-config: preserve existing models.json baseUrls * test: distill models-config baseUrl regression test * fix: preserve models.json baseUrls on regen (openclaw#67893) (thanks @lawrence3699) --------- Co-authored-by: lawrence3699 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…lawrence3699) * models-config: preserve existing models.json baseUrls * test: distill models-config baseUrl regression test * fix: preserve models.json baseUrls on regen (openclaw#67893) (thanks @lawrence3699) --------- Co-authored-by: lawrence3699 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…lawrence3699) * models-config: preserve existing models.json baseUrls * test: distill models-config baseUrl regression test * fix: preserve models.json baseUrls on regen (openclaw#67893) (thanks @lawrence3699) --------- Co-authored-by: lawrence3699 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…lawrence3699) * models-config: preserve existing models.json baseUrls * test: distill models-config baseUrl regression test * fix: preserve models.json baseUrls on regen (openclaw#67893) (thanks @lawrence3699) --------- Co-authored-by: lawrence3699 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…lawrence3699) * models-config: preserve existing models.json baseUrls * test: distill models-config baseUrl regression test * fix: preserve models.json baseUrls on regen (openclaw#67893) (thanks @lawrence3699) --------- Co-authored-by: lawrence3699 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
Summary
models.jsonbaseUrlback to the config/provider value, so custom endpoints likehttps://api.kilo.ai/api/gatewayget forced back to/v1.models.jsonbaseUrl, and users editing custom provider endpoints lose those changes on restart.baseUrlvalues override non-empty agentmodels.jsonbaseUrlvalues; added regression tests at the merge, plan, and runtime-snapshot layers.models.mode: "replace"behavior is unchanged, and stalebaseUrlvalues still refresh when the provider API surface changes.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause (if applicable)
models.jsonmerge refactor added anexplicitBaseUrlProvidersoverride insrc/agents/models-config.merge.ts, which forced configmodels.providers.*.baseUrlto win even in merge mode.models.jsonfile.docs/concepts/models.mdanddocs/gateway/configuration-reference.mdalready say that a non-empty agentmodels.jsonbaseUrlshould win.Regression Test Plan (if applicable)
src/agents/models-config.uses-first-github-copilot-profile-env-tokens.test.tssrc/agents/models-config.merge.test.tssrc/agents/models-config.runtime-source-snapshot.test.tsmodels.json, an existing non-empty agentbaseUrlsurvives restart/regeneration unless the provider API surface changed.User-visible / Behavior Changes
baseUrlvalues already present in~/.openclaw/agents/<agentId>/agent/models.jsonnow survive gateway regeneration/restart again.Diagram (if applicable)
Security Impact (required)
Yes/No) NoYes/No) NoYes/No) NoYes/No) NoYes/No) NoYes, explain risk + mitigation:Repro + Verification
Environment
nvmkilocoderepro)models.mode: "merge",models.providers.kilocode.baseUrl: "https://api.kilo.ai/api/gateway/v1"Steps
baseUrlends in/v1.models.jsonentry for the same provider with a non-emptybaseUrlthat omits/v1.models.jsonvia the normal planning path (or restart the gateway).Expected
models.jsonbaseUrlstays unchanged in merge mode.Actual
baseUrlback to the config value with/v1.Evidence
Attach at least one:
Human Verification (required)
What you personally verified (not just CI), and how:
mergeWithExistingProviderSecretsandplanOpenClawModelsJsonWithDeps, then verified the updated tests and commit hook preserve the existingbaseUrlwhile still refreshing other fields.baseUrlvalues still refresh when the provider API surface changes; runtime-source-snapshot regeneration still updates refreshable headers under the same snapshot.Review Conversations
If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.
Compatibility / Migration
Yes/No) YesYes/No) NoYes/No) NoRisks and Mitigations
baseUrlupdates into an existing agentmodels.jsonwill now keep the existing value instead.models.mode: "replace"and API-surface mismatch handling still provide the explicit overwrite paths.AI Assistance
build, targetedtest, full pre-commitcheck)models.jsonbaseUrlback to the config value on restart, with concrete repro, minimal scope, and regression coverage.