Skip to content

fix(control-ui): use catalog names in model picker - #59831

Closed
Mule-ME wants to merge 8 commits into
openclaw:mainfrom
Mule-ME:fix/control-ui-model-names
Closed

Mule-ME wants to merge 8 commits into
openclaw:mainfrom
Mule-ME:fix/control-ui-model-names

Conversation

@Mule-ME

@Mule-ME Mule-ME commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: the Control UI chat model picker ignores friendly name values from models.list and can restore slash-containing model ids against the wrong provider when modelProvider is already present separately.
  • Why it matters: users see raw model-id · provider labels instead of readable names, and models like nvidia/moonshotai/kimi-k2.5 can jump to the wrong provider after refresh.
  • What changed: the picker/default label now prefer catalog name, slash-containing model ids remain provider-qualified on restore, and duplicate friendly names are disambiguated with · provider.
  • What did NOT change (scope boundary): this PR does not add full alias support from agents.defaults.models, and it does not change the backend model catalog payload.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Root Cause / Regression History (if applicable)

  • Root cause: the picker built labels from raw qualified values instead of catalog display metadata, and the restore path treated slash-containing model strings as already qualified even when modelProvider was provided separately.
  • Missing detection / guardrail: there was no unit coverage for friendly-name rendering, duplicate-name disambiguation, or nested slash-containing ids paired with a separate provider.
  • Prior context (git blame, prior PR, issue, or refactor if known): reported in Bug: Control UI Model Display and Selection Issues #58835 against the built-in Control UI; the gateway already exposed name in models.list, but the chat picker path did not use it.
  • Why this regressed now: this appears to be longstanding UI behavior rather than a newly introduced regression.
  • If unknown, what was ruled out: ruled out missing name data for the reproduced cases; the issue is in Control UI rendering and restore logic.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file:
    • ui/src/ui/chat-model-ref.test.ts
    • ui/src/ui/chat-model-select-state.test.ts
  • Scenario the test should lock in:
    • picker labels use catalog name
    • slash-containing model ids stay provider-qualified when restored from session/default state
    • duplicate friendly names stay distinguishable with · provider
  • Why this is the smallest reliable guardrail: the bug lives in local picker/label resolution logic and can be covered deterministically without booting the full gateway/UI stack.
  • Existing test that already covers this (if any): none before this PR
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

  • The chat model picker now shows friendly catalog names from models.list.
  • The default model label uses the same display logic.
  • Models with slash-containing ids keep the correct provider-qualified value after refresh.
  • If two entries share the same friendly name, the picker appends · provider to keep them distinct.

Diagram (if applicable)

Before:
[user opens picker] -> [raw "model-id · provider" labels]
[user selects nvidia/moonshotai/kimi-k2.5] -> [refresh] -> [wrong provider mapping possible]

After:
[user opens picker] -> [friendly catalog name]
[user selects nvidia/moonshotai/kimi-k2.5] -> [refresh] -> [provider-qualified value preserved]

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (No)
  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: local OpenClaw main, built-in Control UI
  • Model/provider: nvidia/moonshotai/kimi-k2.5 and other catalog-backed models
  • Integration/channel (if any): none
  • Relevant config (redacted): model catalog entries with id, name, and provider

Steps

  1. Start the gateway and open the built-in Control UI.
  2. Open the chat model picker and inspect the displayed labels.
  3. Select a slash-containing model id, then refresh or reload the session state.

Expected

  • Friendly catalog names are shown in the picker.
  • Provider-qualified slash-containing model ids remain stable after refresh.

Actual

  • Before this change, the picker showed raw model-id · provider labels.
  • Before this change, slash-containing ids could be restored against the wrong provider.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

  • Verified scenarios:
    • rebuilt the Control UI and confirmed the picker shows friendly catalog names
    • confirmed the default label uses the same display logic
    • confirmed slash-containing model ids remain provider-qualified after refresh
  • Edge cases checked:
    • duplicate friendly names across providers
    • nested slash-containing ids
    • fallback to raw formatting when no catalog match exists
  • What you did not verify:
    • full alias support from agents.defaults.models
    • other Control UI surfaces outside the chat model picker

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

  • Risk: duplicate friendly names could become visually ambiguous.
    • Mitigation: append · provider only when duplicate visible names exist in the catalog.
  • Risk: the original issue also mentions alias support, which this PR does not fully implement.
    • Mitigation: scope is called out explicitly; this PR is limited to name display and provider-qualified persistence.

@greptile-apps

greptile-apps Bot commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes two related bugs in the Control UI chat model picker: (1) raw model-id · provider labels were shown instead of the friendly name from the model catalog, and (2) slash-containing model IDs (e.g. nvidia/moonshotai/kimi-k2.5) could be misidentified as already-qualified values when modelProvider was present separately, leading to wrong provider mapping on restore.

Changes:

  • resolvePreferredServerChatModel now treats trimmedModel as "raw" (catalog-lookup) rather than "qualified" (pass-through) when a separate provider is supplied, fixing the slash-containing ID restore bug.
  • New helpers (formatRawCatalogLabel, hasCatalogNameCollision, formatCatalogEntryDisplay, formatCatalogChatModelDisplay) build picker labels from the catalog's name field, with · provider disambiguation when two entries share the same friendly name.
  • buildChatModelOption now accepts a catalog argument (defaulting to [entry]) to enable the disambiguation check.
  • chat-model-select-state.ts passes the full catalog to buildChatModelOption and uses formatCatalogChatModelDisplay for dynamically-added options (currentOverride, defaultModel) and the defaultLabel.
  • New unit tests cover all three scenarios: friendly-name labels, nested-slash-id restore, and duplicate-name disambiguation.

Minor observations:

  • hasCatalogNameCollision performs an O(n) scan per call; called O(n) times in buildChatModelOptions yields O(n²) total — acceptable for typical catalog sizes but worth noting if the catalog ever grows large.
  • label ?? trimmed in addOption won't catch an empty-string label; || trimmed would be marginally more defensive (no functional impact today).

Confidence Score: 4/5

  • Safe to merge — changes are UI-only, well-scoped, and all edge cases are covered by new unit tests.
  • The core bug fixes (provider-qualified restore and catalog-name labels) are logically correct and backed by targeted unit tests. No backend, API, or security surfaces are touched. The two comments are both P2 style observations with no runtime impact at typical catalog sizes.
  • No files require special attention — chat-model-ref.ts contains all the new logic and its tests cover the key scenarios.

Comments Outside Diff (1)

  1. ui/src/ui/chat-model-select-state.ts, line 64-75 (link)

    P2 ?? trimmed won't catch an empty-string label

    label ?? trimmed only falls back when label is null or undefined. If formatCatalogChatModelDisplay were to return "" for some input (e.g. a catalog entry with a blank name and empty id), the option would render with an empty visible label.

    The current implementation of formatCatalogChatModelDisplay can't actually produce "" for a non-empty value (it always falls through to formatChatModelDisplay), so this is not a bug today. But || trimmed would make the fallback robust against that edge case and would document the intent more clearly:

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: ui/src/ui/chat-model-select-state.ts
    Line: 64-75
    
    Comment:
    **`?? trimmed` won't catch an empty-string label**
    
    `label ?? trimmed` only falls back when `label` is `null` or `undefined`. If `formatCatalogChatModelDisplay` were to return `""` for some input (e.g. a catalog entry with a blank `name` and empty `id`), the option would render with an empty visible label.
    
    The current implementation of `formatCatalogChatModelDisplay` can't actually produce `""` for a non-empty `value` (it always falls through to `formatChatModelDisplay`), so this is not a bug today. But `|| trimmed` would make the fallback robust against that edge case and would document the intent more clearly:
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: ui/src/ui/chat-model-ref.ts
Line: 149-168

Comment:
**O(n²) collision detection per catalog build**

`hasCatalogNameCollision` iterates the full catalog for every entry, and `buildChatModelOptions` calls it once per catalog entry via `formatCatalogEntryDisplay`. For a catalog with _n_ entries, this is O(n²) per picker open.

For typical model catalogs this is harmless, but a single pre-pass that groups entries by lowercase name would reduce this to O(n):

```ts
// one-time pass: names that appear more than once
const collisionNames = new Set<string>();
const seen = new Map<string, string>(); // lowerName → qualifiedValue
for (const e of catalog) {
  const lowerName = e.name.trim().toLowerCase();
  if (!lowerName) continue;
  const qualified = buildQualifiedChatModelValue(e.id, e.provider).toLowerCase();
  if (seen.has(lowerName) && seen.get(lowerName) !== qualified) {
    collisionNames.add(lowerName);
  } else {
    seen.set(lowerName, qualified);
  }
}
```

Then `formatCatalogEntryDisplay` would just do a `Set.has()` lookup instead of rescanning the catalog.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: ui/src/ui/chat-model-select-state.ts
Line: 64-75

Comment:
**`?? trimmed` won't catch an empty-string label**

`label ?? trimmed` only falls back when `label` is `null` or `undefined`. If `formatCatalogChatModelDisplay` were to return `""` for some input (e.g. a catalog entry with a blank `name` and empty `id`), the option would render with an empty visible label.

The current implementation of `formatCatalogChatModelDisplay` can't actually produce `""` for a non-empty `value` (it always falls through to `formatChatModelDisplay`), so this is not a bug today. But `|| trimmed` would make the fallback robust against that edge case and would document the intent more clearly:

```suggestion
    options.push({ value: trimmed, label: label || trimmed });
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "test(control-ui): cover model picker nam..." | Re-trigger Greptile

Comment thread ui/src/ui/chat-model-ref.ts Resolved

@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: 9a11091ece

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ui/src/ui/chat-model-ref.ts Resolved

@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: b5e9b6918f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ui/src/ui/chat-model-ref.ts Resolved
@Mulualem-E

Copy link
Copy Markdown

Before: raw model-id · provider labels, and some models could restore to the wrong provider.
Screenshot 2026-04-02 at 21 41 27

After: friendly names in the picker, with provider-qualified refs preserved after refresh.
Screenshot 2026-04-02 at 19 36 53

@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: bbdd12dcc2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ui/src/ui/chat-model-ref.ts Outdated

const overrideResolution = resolveChatModelOverride(
createChatModelOverride(trimmedModel),
trimmedProvider ? { kind: "raw", value: trimmedModel } : createChatModelOverride(trimmedModel),

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.

P2 Badge Preserve qualified model when provider is stale

Forcing trimmedModel through { kind: "raw" } whenever modelProvider is present regresses qualified values when the provider is stale or mismatched. Fresh evidence: even with the new guard on lines 109-113, resolvePreferredServerChatModel("openai/gpt-5-mini", "zai", catalog) now falls through to resolveServerChatModelValue and returns zai/openai/gpt-5-mini instead of preserving the already-qualified model. This can surface invalid picker/default values after refresh for sessions that carry a qualified model string plus an outdated modelProvider.

Useful? React with 👍 / 👎.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: L and removed size: M labels Apr 3, 2026

@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: 928551fdd2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ui/src/ui/chat-model-ref.ts Outdated
Comment on lines +121 to +124
if (trimmedProvider) {
return {
value: resolveServerChatModelValue(trimmedModel, trimmedProvider),
source: trimmedModel.toLowerCase().startsWith(`${trimmedProvider.toLowerCase()}/`)

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.

P2 Badge Preserve qualified model when provider is stale

When modelProvider is present, this branch always trusts it and skips catalog/qualified resolution, so a stale provider can corrupt already-qualified model refs. For example, resolvePreferredServerChatModel("openai/gpt-5-mini", "zai", catalog) now flows through resolveServerChatModelValue and yields zai/openai/gpt-5-mini instead of preserving openai/gpt-5-mini. That can surface invalid picker/default values after refresh and propagate a provider/model pair the backend does not recognize.

Useful? React with 👍 / 👎.

@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: 884ca6346c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +1066 to +1070
if (storedProviderOverride) {
const providerPrefix = `${storedProviderOverride.toLowerCase()}/`;
const normalizedModel = storedModelOverride.toLowerCase().startsWith(providerPrefix)
? storedModelOverride.slice(storedProviderOverride.length + 1).trim() || storedModelOverride
: storedModelOverride;

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.

P2 Badge Keep parsing overrides when providerOverride is present

This new early-return path skips parseModelRef whenever providerOverride exists, so stored overrides no longer get provider-specific normalization/canonicalization. In practice, legacy rows like providerOverride: "openrouter", modelOverride: "claude-sonnet-4-6" (or stale qualified values with a mismatched provider) now resolve to raw, potentially invalid provider/model pairs instead of the normalized ref that pre-change code produced. Because resolveSessionModelRef is used by runtime session resolution paths, this can surface wrong model refs for existing sessions after upgrade.

Useful? React with 👍 / 👎.

@Mule-ME

Mule-ME commented Apr 5, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #61382. Closing this one to keep review on the cleaner replacement PR.

@Mule-ME Mule-ME closed this Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui gateway Gateway runtime size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants