Skip to content

fix(config): warn when configured model primary is not in catalog - #40355

Closed
dsantoreis wants to merge 1 commit into
openclaw:mainfrom
dsantoreis:fix/39811-model-config-validation
Closed

dsantoreis wants to merge 1 commit into
openclaw:mainfrom
dsantoreis:fix/39811-model-config-validation

Conversation

@dsantoreis

Copy link
Copy Markdown
Contributor

Summary

When a user sets agents.defaults.model.primary or agents.list[].model to a model name that does not exist in the runtime catalog (e.g. openai-codex/gpt-5.4-codex before the Codex provider ships it), the config is accepted silently. Every cron job and heartbeat then fails at runtime with FailoverError: Unknown model, and the user has no indication why without reading raw error logs.

This adds a lightweight validation pass that checks configured model primaries against the loaded model catalog and surfaces warnings through openclaw doctor. Warnings, not errors, because forward-compat model names are intentional and the model may appear later.

What changed

  • collectModelConfigWarnings(config, catalog) in src/config/validation.ts: iterates agents.defaults.model.primary and each agents.list[].model, resolves them through the existing resolveModelRefFromString path, and returns ConfigValidationIssue[] when any ref is absent from the catalog.
  • src/commands/doctor.ts: loads the model catalog once and calls collectModelConfigWarnings. Reuses the same catalog instance for the existing hooks.gmail.model check to avoid a redundant loadModelCatalog call.

What did NOT change

No runtime behavior, no config schema, no model resolution logic, no failover paths. This is purely an advisory check surfaced through doctor.

Linked Issues

Validation

pnpm vitest run src/config/validation.model-warnings.test.ts  # 6/6 pass
pnpm build                                                     # clean
pnpm check                                                     # clean

Tests

6 targeted tests in src/config/validation.model-warnings.test.ts:

  • valid model in catalog produces no warning
  • unknown default model primary triggers warning
  • string-form model config triggers warning
  • unknown per-agent model triggers warning
  • no model configured produces no warning
  • empty catalog still warns (cannot validate)

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: S labels Mar 8, 2026
@greptile-apps

greptile-apps Bot commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a lightweight advisory validation pass — collectModelConfigWarnings in src/config/validation.ts — that compares configured model primaries against the loaded model catalog and surfaces any mismatches as warnings through openclaw doctor. The implementation is clean, well-tested, and correctly reuses a single loadModelCatalog call in doctor.ts instead of making two separate calls.

Findings:

  • Test name contradicts assertion in src/config/validation.model-warnings.test.ts (line 62): The test is titled "returns no warnings with an empty catalog" but its assertion is expect(warnings).toHaveLength(1). The inline comment confirms the opposite intent ("still warn"). This is a documentation bug that should be corrected to avoid misleading future contributors.
  • The fallback model entries are not checked, only primary. This is consistent with the PR description.
  • No runtime behaviour, schema, or failover paths are affected; this is purely an advisory doctor check as described.

Confidence Score: 4/5

  • Safe to merge after correcting the misleading test name, which contradicts its own assertion.
  • The implementation logic is correct, well-isolated, and carries no runtime risk. The only issue is a test whose description says "returns no warnings" while the body asserts one warning exists — a clear documentation bug that should be fixed before merging to avoid future confusion and potential regressions.
  • src/config/validation.model-warnings.test.ts — the final test case has a contradictory name and assertion.

Last reviewed commit: 31c52ea

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 31c52ea7de

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/config/validation.ts Resolved
@dsantoreis

This comment was marked as spam.

@dsantoreis

This comment was marked as spam.

@dsantoreis

This comment was marked as spam.

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@clawsweeper

clawsweeper Bot commented Apr 26, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep open: current main still lacks a generic warning for invalid configured agent model refs, and this focused PR remains useful, but the current head is not merge-ready because it can miss the linked bad-config case, warn on valid alias configs, omit fallbacks, print unsanitized config text, and lacks real doctor output proof.

Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

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

Yes, source-reproducible. Current main accepts agent model refs structurally and only has catalog-backed doctor validation for hooks.gmail.model, while the linked issue shows the invalid-model failure mode remains active.

Is this the best way to solve the issue?

No, not as written. Advisory validation is the right direction, but this implementation needs runtime-equivalent resolution, trusted catalog semantics, fallback coverage, sanitizer handling, and real doctor-output proof.

Security review:

Security review needs attention: The diff introduces config-derived terminal output without routing warning paths and messages through the existing sanitizer path.

  • [low] Unsanitized model warning output — src/flows/doctor-health-contributions.ts:411
    Model refs in warning messages come from local config and are interpolated into note() output, so control characters or ANSI escapes could spoof doctor diagnostics.
    Confidence: 0.82

What I checked:

  • stale F-rated PR: PR was opened 2026-03-08T23:36:46Z, is older than 60 days, and the latest review rated it F.
  • proof blocker: real behavior proof is missing and proof tier is F, so this branch is not merge-ready without contributor follow-up.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • steipete: Current-main blame attributes the central doctor health, model catalog, model-selection, and configured-ref collector lines used in this review to Peter Steinberger's recent commit. (role: recent model/config and doctor surface contributor; confidence: high; commits: dd07fb400fc5; files: src/flows/doctor-health-contributions.ts, src/agents/model-catalog.ts, src/agents/model-selection-shared.ts)
  • shakkernerd: Commit d289e40 changed read-only model catalog behavior, adjacent to the trusted catalog semantics this PR needs. (role: adjacent model-catalog contributor; confidence: medium; commits: d289e400d5ff; files: src/agents/model-catalog.ts)
  • Takhoffman: Commit f328c21 added hot-reload model registration, which is adjacent to whether user-declared provider model rows count as trusted catalog evidence. (role: adjacent configured-model registration contributor; confidence: medium; commits: f328c2104675; files: src/agents/model-catalog.ts)
  • gumadeiras: The PR author explicitly requested review from this route, and adjacent history includes fallback-to-default model behavior relevant to the diagnostic policy. (role: requested review route / adjacent model-default reviewer; confidence: low; commits: a4c373935f61; files: src/commands/auth-choice.model-check.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against d7a078f1962b.

@openclaw-barnacle openclaw-barnacle Bot removed stale Marked as stale due to inactivity commands Command implementations labels Apr 27, 2026
Add collectModelConfigWarnings() to validation.ts that checks
agents.defaults.model.primary and agents.list[].model against the
model catalog. Returns warnings (not errors) to preserve forward
compatibility with models that may not be available yet.

Wire the check into the doctor health flow as a new
"doctor:model-config" contribution, sitting alongside the existing
hooks.gmail.model check. Reuses the model catalog loader.

6 targeted tests cover: valid model, unknown default primary,
string-form config, per-agent model, no model configured, and
empty catalog.

Closes openclaw#39811
@clawsweeper

clawsweeper Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge.

What this changes:

The PR adds a config-validation helper, a doctor health contribution, and tests to warn when agents.defaults.model.primary or agents.list[].model points to a model missing from the loaded catalog.

Maintainer follow-up before merge:

This is an active contributor PR with concrete review findings, but the remaining action is maintainer/product review of model-catalog semantics plus author follow-up, not a safe autonomous replacement or close action.

Review findings:

  • [P2] Validate against catalog rows that do not come from config — src/flows/doctor-health-contributions.ts:407
  • [P2] Resolve aliases before checking configured primaries — src/config/validation.ts:1341
  • [P3] Sanitize model warning text before printing it — src/flows/doctor-health-contributions.ts:411
Review details

Best possible solution:

Land a focused doctor or shared validation path that resolves model refs the same way runtime/model-picker paths do, distinguishes provider/runtime/static catalog rows from user-declared config rows when warning about unsupported models, keeps catalog inspection read-only where possible, sanitizes terminal output, and covers aliases plus the models.providers misconfiguration from the linked report. Leave broader fallback-user-notification behavior to its separate tracking item.

Full review comments:

  • [P2] Validate against catalog rows that do not come from config — src/flows/doctor-health-contributions.ts:407
    The new doctor check passes loadModelCatalog({ config: ctx.cfg }) into the warning helper, but that catalog appends models.providers.*.models from the same config. In the linked Model configuration accepts unvalidated model names, enabling silent misconfiguration #39811 reproduction, the bogus model is first added under models.providers.openai.models, so it will be present in this catalog and no warning is emitted even though runtime/provider calls can still fail. Use a catalog/source that distinguishes provider-discovered rows from user-declared config rows, or carry origin metadata into the check.
    Confidence: 0.88
  • [P2] Resolve aliases before checking configured primaries — src/config/validation.ts:1341
    collectModelConfigWarnings calls resolveModelRefFromString without cfg or an alias index, so a valid configured alias such as fast is parsed as anthropic/fast and warned as missing. Runtime and model-picker paths build agents.defaults.models aliases before resolving, so doctor would produce false positives for supported configs.
    Confidence: 0.9
  • [P3] Sanitize model warning text before printing it — src/flows/doctor-health-contributions.ts:411
    The warning message includes model identifiers derived from local config and is passed straight to note(). A model id containing ANSI or control characters can spoof doctor output; route the path/message through the existing terminal sanitizers before display.
    Confidence: 0.82

Overall correctness: patch is incorrect
Overall confidence: 0.86

Acceptance criteria:

  • pnpm test src/config/validation.model-warnings.test.ts src/commands/doctor-config-analysis.test.ts src/terminal/safe-text.test.ts
  • pnpm build
  • pnpm check:changed in Testbox before merge if code changes are accepted

What I checked:

  • current_main_no_generic_model_config_doctor_check: Search on current main found no collectModelConfigWarnings, runModelConfigHealth, doctor:model-config, or model-warning test surface for default/per-agent model config. (e46dccb35374)
  • doctor_only_checks_hooks_model: The current doctor model-catalog health contribution is scoped to hooks.gmail.model; no current main contribution validates agents.defaults.model or agents.list[].model. (src/flows/doctor-health-contributions.ts:358, e46dccb35374)
  • config_validate_is_schema_snapshot_only: openclaw config validate reports the schema/config snapshot as valid or invalid and does not add catalog-aware model validation. (src/cli/config-cli.ts:1478, e46dccb35374)
  • agent_model_schema_is_structural: AgentModelSchema accepts either a string or { primary, fallbacks, timeoutMs } object; it does not validate model refs against a runtime/provider catalog. (src/config/zod-schema.agent-model.ts:3, e46dccb35374)
  • catalog_includes_configured_provider_models: loadModelCatalog appends buildConfiguredModelCatalog({ cfg }), so a model listed under models.providers.*.models is treated as present in the loaded catalog even if the upstream provider does not actually support it. (src/agents/model-catalog.ts:209, e46dccb35374)
  • runtime_model_resolution_uses_alias_index: Current model resolution builds and passes a ModelAliasIndex from config before resolving configured defaults; a doctor check that calls resolveModelRefFromString without that index will not match runtime/model-picker behavior. (src/agents/model-selection-shared.ts:485, e46dccb35374)

Likely related people:

  • steipete: Local blame and GitHub path history show recent mainline work across the doctor health contribution, model-selection, model-catalog, and model config-check surfaces that this PR touches. (role: recent maintainer / central model and doctor surface owner candidate; confidence: high; commits: 34d11d57, 93d5cd10151f, aec5efed8d43; files: src/flows/doctor-health-contributions.ts, src/agents/model-selection-shared.ts, src/agents/model-catalog.ts)
  • shakkernerd: Recent path history includes read-only catalog and onboarding/configure cold-path work adjacent to how doctor should inspect model catalog state without unwanted side effects. (role: adjacent model-catalog/configure maintainer; confidence: medium; commits: d289e400d5ff, 2f81c5f5803d; files: src/agents/model-catalog.ts, src/commands/auth-choice.model-check.ts)
  • Takhoffman: Recent merged work added /models add hot-reload model registration, which is directly adjacent to whether user-declared models.providers rows should count as trusted catalog rows for this diagnostic. (role: adjacent configured-model registration contributor; confidence: medium; commits: f328c2104675; files: src/agents/model-catalog.ts)
  • gumadeiras: Path history shows review involvement on fallback-to-default model behavior, and the PR discussion explicitly requested review from this maintainer; this is routing evidence more than direct ownership of the proposed patch. (role: adjacent model-default reviewer / requested review route; confidence: low; commits: a4c373935f61; files: src/commands/auth-choice.model-check.ts)

Remaining risk / open question:

  • The branch discussion says alias and terminal-output feedback was addressed, but the current fetched PR diff still shows the unfixed implementation, so maintainers should verify whether the intended follow-up commits were lost during rebasing or force-pushing.
  • I did not execute the PR branch tests in this read-only review; the verdict is based on current main source, docs, GitHub diff/context, and history inspection.

Codex review notes: model gpt-5.5, reasoning high; reviewed against e46dccb35374.

@clawsweeper clawsweeper Bot added the P2 Normal backlog priority with limited blast radius. label May 16, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 16, 2026
@clawsweeper clawsweeper Bot added impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. and removed impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. labels May 17, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@clawsweeper

clawsweeper Bot commented May 23, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Model configuration accepts unvalidated model names, enabling silent misconfiguration

1 participant