Skip to content

Commit f24bd8a

Browse files
authored
fix(ui): use session-key equivalence for active-row lookups in model/thinking/fast-mode paths (#124020)
Six sites strict-compared row.key === sessionKey while the sibling locked check already used areUiSessionKeysEquivalent (#104045 upgraded only the model path). In alias/transition windows (pre-hello legacy 'main' vs canonical agent:main:main) the optimistic thinking/fast-mode row patch found no row — the click produced no immediate visible change — and the display resolvers missed the active row, falling back to agent defaults. All lookups now go through the equivalence helper the rest of the flow uses.
1 parent ab8d7db commit f24bd8a

4 files changed

Lines changed: 39 additions & 7 deletions

File tree

‎ui/src/lib/chat/model-select-state.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,25 @@ describe("chat-model-select-state", () => {
122122
});
123123
});
124124

125+
it("finds the active row across the legacy main alias window", () => {
126+
// Pre-hello (or legacy-alias) states select "main" while the row list
127+
// already carries the canonical agent:main:main key; a strict compare
128+
// missed the row and the picker fell back to the agent default.
129+
const sessionsResult = createSessionsListResult({
130+
model: "gpt-5.3-codex",
131+
modelProvider: "openai",
132+
});
133+
const session = expectDefined(sessionsResult.sessions[0], "alias fixture row");
134+
sessionsResult.sessions[0] = { ...session, key: "agent:main:main" };
135+
const value = resolveChatModelOverrideValue(
136+
createChatModelState({
137+
chatModelCatalog: DEFAULT_CHAT_MODEL_CATALOG,
138+
sessionsResult,
139+
}),
140+
);
141+
expect(value).toBe("openai/gpt-5.3-codex");
142+
});
143+
125144
it("uses the server-qualified value when the active session provider is present", () => {
126145
const state = createChatModelState({
127146
chatModelCatalog: createModelCatalog(DEEPSEEK_CHAT_MODEL),

‎ui/src/lib/chat/model-select-state.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
SessionsListResult,
77
} from "../../api/types.ts";
88
import { t } from "../../i18n/index.ts";
9+
import { areUiSessionKeysEquivalent } from "../sessions/session-key.ts";
910
import {
1011
buildCatalogDisplayLookup,
1112
buildChatModelOptionFromLookup,
@@ -72,7 +73,9 @@ type ChatFastModeSelectStateInput = {
7273
const FAST_MODE_PROVIDER_IDS = new Set(["anthropic", "minimax", "minimax-portal", "openai", "xai"]);
7374

7475
function resolveActiveSessionRow(state: ChatModelSelectStateInput) {
75-
return state.sessionsResult?.sessions?.find((row) => row.key === state.sessionKey);
76+
return state.sessionsResult?.sessions?.find((row) =>
77+
areUiSessionKeysEquivalent(row.key, state.sessionKey),
78+
);
7679
}
7780

7881
export function resolveChatModelOverrideValue(state: ChatModelSelectStateInput): string {
@@ -304,7 +307,9 @@ function hasCatalogProviderMetadata(value: string, catalog: ModelCatalogEntry[])
304307
export function resolveChatFastModeSelectState(
305308
input: ChatFastModeSelectStateInput,
306309
): ChatFastModeSelectState {
307-
const activeRow = input.sessionsResult?.sessions?.find((row) => row.key === input.sessionKey);
310+
const activeRow = input.sessionsResult?.sessions?.find((row) =>
311+
areUiSessionKeysEquivalent(row.key, input.sessionKey),
312+
);
308313
const activeProvider = normalizeChatModelProviderId(activeRow?.modelProvider ?? "") || null;
309314
const defaultProvider =
310315
normalizeChatModelProviderId(input.sessionsResult?.defaults?.modelProvider ?? "") || null;

‎ui/src/lib/chat/thinking.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
normalizeThinkLevel,
55
resolveThinkingDefaultForModelCore,
66
} from "../../../../src/auto-reply/thinking.shared.js";
7-
// Control UI module implements thinking behavior.
87
import type {
98
GatewaySessionRow,
109
GatewayThinkingLevelOption,
@@ -13,6 +12,8 @@ import type {
1312
} from "../../api/types.ts";
1413
import { pushUniqueTrimmedSelectOption } from "../select-options.ts";
1514
import { sessionModelMatchesDefaults } from "../session-model-defaults.ts";
15+
// Control UI module implements thinking behavior.
16+
import { areUiSessionKeysEquivalent } from "../sessions/session-key.ts";
1617

1718
type ThinkingSessionDefaults = SessionsListResult["defaults"] | undefined;
1819

@@ -216,7 +217,10 @@ export function resolveChatThinkingSelectState(params: {
216217
sessionsResult: SessionsListResult | null;
217218
}): ChatThinkingSelectState {
218219
const session =
219-
params.session ?? params.sessionsResult?.sessions?.find((row) => row.key === params.sessionKey);
220+
params.session ??
221+
params.sessionsResult?.sessions?.find((row) =>
222+
areUiSessionKeysEquivalent(row.key, params.sessionKey),
223+
);
220224
const persisted = session?.thinkingLevel;
221225
const currentOverride =
222226
typeof persisted === "string" && persisted.trim()

‎ui/src/pages/chat/chat-session.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ function patchSessionRow(
331331
host.sessionsResult = {
332332
...current,
333333
sessions: current.sessions.map((row) =>
334-
row.key === sessionKey ? Object.assign({}, row, patch) : row,
334+
areUiSessionKeysEquivalent(row.key, sessionKey) ? Object.assign({}, row, patch) : row,
335335
),
336336
};
337337
}
@@ -344,7 +344,9 @@ export function switchChatFastMode(
344344
if (!host.client || !host.connected) {
345345
return Promise.resolve(false);
346346
}
347-
const activeRow = host.sessionsResult?.sessions?.find((row) => row.key === targetSessionKey);
347+
const activeRow = host.sessionsResult?.sessions?.find((row) =>
348+
areUiSessionKeysEquivalent(row.key, targetSessionKey),
349+
);
348350
const previousFastMode = activeRow?.fastMode;
349351
const previousEffectiveFastMode = activeRow?.effectiveFastMode;
350352
const next: FastMode | undefined =
@@ -478,7 +480,9 @@ export function switchChatThinkingLevel(
478480
if (!host.client || !host.connected) {
479481
return Promise.resolve(false);
480482
}
481-
const activeRow = host.sessionsResult?.sessions?.find((row) => row.key === targetSessionKey);
483+
const activeRow = host.sessionsResult?.sessions?.find((row) =>
484+
areUiSessionKeysEquivalent(row.key, targetSessionKey),
485+
);
482486
const previousThinkingLevel = activeRow?.thinkingLevel;
483487
const normalizedNext =
484488
(normalizeThinkLevel(nextThinkingLevel) ?? nextThinkingLevel.trim()) || undefined;

0 commit comments

Comments
 (0)