Skip to content

Commit a73249c

Browse files
fix(ui): clarify active model context in picker (#124207)
* fix(ui): show active model context budget * fix(ui): simplify compact model label * fix(ui): preserve provider when matching context budget * fix(ui): hide stale context during model switches --------- Co-authored-by: fuller-stack-dev <[email protected]>
1 parent e68f3d8 commit a73249c

5 files changed

Lines changed: 238 additions & 16 deletions

File tree

‎ui/src/i18n/locales/en.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5203,6 +5203,7 @@ export const en: TranslationMap = {
52035203
fastHelp: "Fast responses finish sooner and can use more of your usage limits.",
52045204
speedUnsupported: "Speed control is not supported for this model.",
52055205
contextWindow: "{count} context",
5206+
contextActiveAndMax: "{active} active · {maximum} max",
52065207
chatOnly: "Chat only",
52075208
chatOnlyHelp:
52085209
"This model can chat, but it cannot use tools. Choose another model for files, commands, web, or media tasks.",

‎ui/src/pages/chat/chat-view.test.ts‎

Lines changed: 181 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5518,7 +5518,7 @@ describe("chat model controls", () => {
55185518
expect(container.querySelector('[data-chat-model-provider-group="moonshotai"]')).toBeNull();
55195519
});
55205520

5521-
it("shows model context size inline without a redundant tooltip", () => {
5521+
it("keeps active context in picker details without crowding the compact trigger", () => {
55225522
const { state } = createChatHeaderState({
55235523
model: "gpt-5.6-sol",
55245524
modelProvider: "openai",
@@ -5528,21 +5528,187 @@ describe("chat model controls", () => {
55285528
name: "GPT-5.6 Sol",
55295529
provider: "openai",
55305530
contextWindow: 1_050_000,
5531+
agentRuntime: { id: "openclaw", source: "model" },
55315532
},
55325533
],
55335534
});
5535+
state.sessionsResult = createSessionsResultFromRows([
5536+
{
5537+
key: "main",
5538+
kind: "direct",
5539+
updatedAt: 1,
5540+
model: "gpt-5.6-sol",
5541+
modelProvider: "openai",
5542+
agentRuntime: { id: "openclaw", source: "model" },
5543+
contextTokens: 1_000_000,
5544+
},
5545+
]);
55345546
const container = renderModelControls(state);
55355547
const modelOption = container.querySelector<HTMLButtonElement>(
55365548
'[data-chat-model-option="openai/gpt-5.6-sol"]',
55375549
);
55385550

5539-
expect(modelOption?.querySelector(".chat-controls__model-option-meta")?.textContent).toBe("1M");
5540-
expect(
5541-
getChatModelSelect(container).querySelector(".chat-controls__trigger-meta")?.textContent,
5542-
).toBe("1M");
5551+
expect(modelOption?.querySelector(".chat-controls__model-option-meta")?.textContent).toBe(
5552+
"1M active · 1M max · OpenClaw",
5553+
);
5554+
expect(modelOption?.textContent).not.toContain("700k");
5555+
expect(getChatModelSelect(container).querySelector(".chat-controls__trigger-meta")).toBeNull();
55435556
expect(modelOption?.closest("openclaw-tooltip")).toBeNull();
55445557
});
55455558

5559+
it("uses the default selection runtime for an implicit Codex model", () => {
5560+
const { state } = createChatHeaderState({
5561+
model: "gpt-5.6-sol",
5562+
modelProvider: "openai",
5563+
models: [
5564+
{
5565+
id: "gpt-5.6-sol",
5566+
name: "GPT-5.6 Sol",
5567+
provider: "openai",
5568+
contextWindow: 1_050_000,
5569+
},
5570+
],
5571+
});
5572+
state.sessionsResult = createSessionsResultFromRows([
5573+
{
5574+
key: "main",
5575+
kind: "direct",
5576+
updatedAt: 1,
5577+
model: "gpt-5.6-sol",
5578+
modelProvider: "openai",
5579+
agentRuntime: { id: "codex", source: "implicit" },
5580+
contextTokens: 1_000_000,
5581+
},
5582+
]);
5583+
state.sessionsResult.defaults = {
5584+
modelProvider: "openai",
5585+
model: "gpt-5.6-sol",
5586+
contextTokens: 1_000_000,
5587+
agentRuntime: { id: "codex", source: "implicit" },
5588+
};
5589+
5590+
const container = renderModelControls(state);
5591+
const modelOption = container.querySelector<HTMLButtonElement>(
5592+
'[data-chat-model-option="openai/gpt-5.6-sol"]',
5593+
);
5594+
5595+
expect(modelOption?.querySelector(".chat-controls__model-option-meta")?.textContent).toBe(
5596+
"1M active · 1M max",
5597+
);
5598+
expect(modelOption?.textContent).not.toContain("700k");
5599+
});
5600+
5601+
it("rejects stale active context after an implicit default runtime change", () => {
5602+
const { state } = createChatHeaderState({
5603+
model: "gpt-5.6-sol",
5604+
modelProvider: "openai",
5605+
models: [
5606+
{
5607+
id: "gpt-5.6-sol",
5608+
name: "GPT-5.6 Sol",
5609+
provider: "openai",
5610+
contextWindow: 1_050_000,
5611+
},
5612+
],
5613+
});
5614+
state.sessionsResult = createSessionsResultFromRows([
5615+
{
5616+
key: "main",
5617+
kind: "direct",
5618+
updatedAt: 1,
5619+
model: "gpt-5.6-sol",
5620+
modelProvider: "openai",
5621+
agentRuntime: { id: "openclaw", source: "session" },
5622+
contextTokens: 272_000,
5623+
},
5624+
]);
5625+
state.sessionsResult.defaults = {
5626+
modelProvider: "openai",
5627+
model: "gpt-5.6-sol",
5628+
contextTokens: 1_000_000,
5629+
agentRuntime: { id: "codex", source: "implicit" },
5630+
};
5631+
5632+
const container = renderModelControls(state);
5633+
const modelOption = container.querySelector<HTMLButtonElement>(
5634+
'[data-chat-model-option="openai/gpt-5.6-sol"]',
5635+
);
5636+
5637+
expect(modelOption?.querySelector(".chat-controls__model-option-meta")?.textContent).toBe("1M");
5638+
expect(modelOption?.textContent).not.toContain("272k active");
5639+
});
5640+
5641+
it.each([
5642+
{
5643+
name: "a pending same-model switch",
5644+
modelSwitching: true,
5645+
sessionRuntimeId: "codex",
5646+
optionRuntimeId: "codex",
5647+
},
5648+
{
5649+
name: "a different session runtime",
5650+
modelSwitching: false,
5651+
sessionRuntimeId: "openclaw",
5652+
optionRuntimeId: "codex",
5653+
},
5654+
{
5655+
name: "missing session runtime provenance",
5656+
modelSwitching: false,
5657+
sessionRuntimeId: undefined,
5658+
optionRuntimeId: "codex",
5659+
},
5660+
{
5661+
name: "missing catalog runtime provenance",
5662+
modelSwitching: false,
5663+
sessionRuntimeId: "codex",
5664+
optionRuntimeId: undefined,
5665+
},
5666+
])(
5667+
"does not pair a stale session budget with $name",
5668+
({ modelSwitching, optionRuntimeId, sessionRuntimeId }) => {
5669+
const { state } = createChatHeaderState({
5670+
model: "gpt-5.6-sol",
5671+
modelProvider: "openai",
5672+
models: [
5673+
{
5674+
id: "gpt-5.6-sol",
5675+
name: "GPT-5.6 Sol",
5676+
provider: "openai",
5677+
contextWindow: 1_050_000,
5678+
...(optionRuntimeId
5679+
? { agentRuntime: { id: optionRuntimeId, source: "model" as const } }
5680+
: {}),
5681+
},
5682+
],
5683+
});
5684+
state.sessionsResult = createSessionsResultFromRows([
5685+
{
5686+
key: "main",
5687+
kind: "direct",
5688+
updatedAt: 1,
5689+
model: "gpt-5.6-sol",
5690+
modelProvider: "openai",
5691+
...(sessionRuntimeId
5692+
? { agentRuntime: { id: sessionRuntimeId, source: "session" as const } }
5693+
: {}),
5694+
contextTokens: 272_000,
5695+
},
5696+
]);
5697+
5698+
const container = renderModelControls(state, {
5699+
modelOverrides: { main: "openai/gpt-5.6-sol" },
5700+
modelSwitching,
5701+
});
5702+
const selectedModelOption = container.querySelector<HTMLButtonElement>(
5703+
'[data-chat-model-option="openai/gpt-5.6-sol"]',
5704+
);
5705+
5706+
expect(
5707+
selectedModelOption?.querySelector(".chat-controls__model-option-meta")?.textContent,
5708+
).toBe(optionRuntimeId ? "1M · Codex" : "1M");
5709+
},
5710+
);
5711+
55465712
it("synthesizes a selectable row for a persisted override missing from the catalog", () => {
55475713
const { state } = createChatHeaderState({
55485714
model: "gpt-5.2-retired",
@@ -5785,18 +5951,21 @@ describe("chat model controls", () => {
57855951
});
57865952
});
57875953

5788-
it("uses the session provider for slash-containing raw model ids without metadata", () => {
5954+
it("uses the session provider for slash-containing raw model ids", () => {
57895955
const { state } = createChatHeaderState();
57905956
state.chatModelCatalog = [
57915957
{
57925958
id: "google/gemma-4-26b-a4b-it",
57935959
name: "Gemma 4",
57945960
provider: "google",
5961+
agentRuntime: { id: "openclaw", source: "implicit" },
57955962
},
57965963
{
57975964
id: "google/gemma-4-26b-a4b-it",
57985965
name: "Gemma 4",
57995966
provider: "openrouter",
5967+
contextWindow: 1_000_000,
5968+
agentRuntime: { id: "openclaw", source: "implicit" },
58005969
},
58015970
];
58025971
state.sessionsResult = createSessionsListResult({
@@ -5805,6 +5974,11 @@ describe("chat model controls", () => {
58055974
defaultsModel: "google/gemma-4-26b-a4b-it",
58065975
defaultsProvider: "openrouter",
58075976
});
5977+
state.sessionsResult.sessions[0]!.agentRuntime = {
5978+
id: "openclaw",
5979+
source: "implicit",
5980+
};
5981+
state.sessionsResult.sessions[0]!.contextTokens = 272_000;
58085982
const container = renderModelControls(state);
58095983

58105984
const providerButtons = Array.from(
@@ -5821,7 +5995,7 @@ describe("chat model controls", () => {
58215995
expect(
58225996
container.querySelector<HTMLElement>('[data-chat-model-provider-group="openrouter"]')
58235997
?.textContent,
5824-
).toContain("Gemma 4");
5998+
).toContain("272k active · 1M max");
58255999
});
58266000

58276001
it("uses a unique catalog provider before an unrelated stale session hint", () => {

‎ui/src/pages/chat/components/chat-model-controls.ts‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import { html } from "lit";
33
import type { ModelCatalogEntry, SessionsListResult } from "../../../api/types.ts";
44
import { t } from "../../../i18n/index.ts";
5-
import { normalizeChatModelProviderId } from "../../../lib/chat/model-ref.ts";
5+
import {
6+
normalizeChatModelProviderId,
7+
resolvePreferredServerChatModelValue,
8+
} from "../../../lib/chat/model-ref.ts";
69
import {
710
resolveChatFastModeSelectState,
811
resolveChatModelSelectState,
@@ -272,6 +275,44 @@ export function renderChatModelControls(props: ChatModelControlsProps) {
272275
!explicitOverride && currentOverride.trim().toLowerCase() === defaultModel.trim().toLowerCase()
273276
? ""
274277
: currentOverride;
278+
const activeModelOption =
279+
pickerValue === ""
280+
? modelOptions.find((option) => option.isDefault)
281+
: modelOptions.find((option) => option.value === pickerValue);
282+
const activeSessionModel = activeSession?.model
283+
? resolveChatModelCatalogEntry(
284+
resolvePreferredServerChatModelValue(
285+
activeSession.model,
286+
activeSession.modelProvider,
287+
props.modelCatalog,
288+
),
289+
props.modelCatalog,
290+
)
291+
: undefined;
292+
const activeOptionModel = activeModelOption
293+
? resolveChatModelCatalogEntry(activeModelOption.value, props.modelCatalog)
294+
: undefined;
295+
const activeSessionRuntime = activeSession?.agentRuntime?.id.trim().toLowerCase();
296+
const activeOptionRuntime = (
297+
activeOptionModel?.agentRuntime?.id ??
298+
(activeModelOption?.isDefault ? props.sessionsResult?.defaults?.agentRuntime?.id : undefined)
299+
)
300+
?.trim()
301+
.toLowerCase();
302+
const activeRuntimeMatches =
303+
Boolean(activeSessionRuntime) && activeSessionRuntime === activeOptionRuntime;
304+
// Missing or mismatched current-selection provenance cannot bind the cached
305+
// session window. Even matching provenance is useful only after the switch settles.
306+
if (
307+
!props.modelSwitching &&
308+
activeModelOption &&
309+
activeSession?.contextTokens &&
310+
activeRuntimeMatches &&
311+
activeSessionModel !== undefined &&
312+
activeSessionModel === activeOptionModel
313+
) {
314+
activeModelOption.contextTokens = activeSession.contextTokens;
315+
}
275316
const lockedModelLabel =
276317
props.modelSelectionRuntimeId?.trim().toLowerCase() === "codex"
277318
? t("chat.selectors.nativeCodexModel")

‎ui/src/pages/chat/components/chat-model-picker-options.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { formatContextTokenCapacity } from "../../../lib/format.ts";
1111
export type ChatModelPickerOption = {
1212
agentRuntimeId?: string;
1313
commitValue: string;
14+
contextTokens?: number;
1415
contextWindow?: number;
1516
disabled?: boolean;
1617
isDefault: boolean;
@@ -20,6 +21,18 @@ export type ChatModelPickerOption = {
2021
value: string;
2122
};
2223

24+
function formatModelContextMeta(option: ChatModelPickerOption): string {
25+
const active = option.contextTokens;
26+
const maximum = option.contextWindow;
27+
if (active && maximum && active !== maximum) {
28+
return t("chat.modelControls.contextActiveAndMax", {
29+
active: formatContextTokenCapacity(active),
30+
maximum: formatContextTokenCapacity(maximum),
31+
});
32+
}
33+
return maximum ? formatContextTokenCapacity(maximum) : "";
34+
}
35+
2336
export type ChatModelPickerTargetGroup = {
2437
id: string;
2538
label: string;
@@ -74,7 +87,7 @@ export function renderChatModelPickerOption(params: {
7487
(params.entry.isDefault && params.selectedModelValue === "");
7588
const modelLabel = formatModelLabel(params.entry);
7689
const modelMeta = [
77-
params.entry.contextWindow ? formatContextTokenCapacity(params.entry.contextWindow) : "",
90+
formatModelContextMeta(params.entry),
7891
params.entry.supportsTools === false ? t("chat.modelControls.chatOnly") : "",
7992
params.entry.agentRuntimeId ? formatAgentRuntimeLabel(params.entry.agentRuntimeId) : "",
8093
params.entry.disabled ? t("modelSetup.candidates.signInNeeded") : "",

‎ui/src/pages/chat/components/chat-model-picker.ts‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { icons } from "../../../components/icons.ts";
44
import "../../../components/tooltip.ts";
55
import { providerDisplayLabel } from "../../../components/provider-icon.ts";
66
import { t } from "../../../i18n/index.ts";
7-
import { formatContextTokenCapacity } from "../../../lib/format.ts";
87
import {
98
renderChatModelPickerOption,
109
renderChatModelPickerTargetOption,
@@ -301,9 +300,6 @@ export function renderChatModelPicker(params: ChatModelPickerParams) {
301300
]
302301
.filter(Boolean)
303302
.join(" · ");
304-
const triggerMeta = activeModelOption?.contextWindow
305-
? formatContextTokenCapacity(activeModelOption.contextWindow)
306-
: "";
307303
const providerGroups = new Map<string, ChatModelPickerOption[]>();
308304
for (const option of params.modelOptions) {
309305
const existing = providerGroups.get(option.provider);
@@ -422,9 +418,6 @@ export function renderChatModelPicker(params: ChatModelPickerParams) {
422418
<span class="chat-controls__inline-select-label">
423419
${params.triggerStatusLabel ?? params.triggerModelLabel}
424420
</span>
425-
${params.triggerStatusLabel || !triggerMeta
426-
? nothing
427-
: html`<span class="chat-controls__trigger-meta">${triggerMeta}</span>`}
428421
</summary>
429422
<wa-popup data-anchored-overlay>
430423
<div

0 commit comments

Comments
 (0)