Skip to content

Commit 631fa1f

Browse files
committed
fix(gui): address discovery and helper review blockers
1 parent e711de3 commit 631fa1f

7 files changed

Lines changed: 159 additions & 17 deletions

File tree

‎gui/src/pages/ClaudeCode.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface ClaudeCodeState {
1919
autoCompactWindow: number | null;
2020
injectAgents: boolean;
2121
smallFastModel: string;
22+
tierModels?: { haiku?: string };
2223
effectiveModelEnv: Record<string, string>;
2324
available: string[];
2425
aliases: { id: string; display_name: string }[];
@@ -103,14 +104,17 @@ export function AutoConnectSetting({
103104

104105
export function SmallFastModelSetting({
105106
value,
107+
tierHaikuModel,
106108
options,
107109
onChange,
108110
}: {
109111
value: string;
112+
tierHaikuModel?: string;
110113
options: SelectOption[];
111114
onChange: (value: string) => void;
112115
}) {
113116
const t = useT();
117+
const effectiveHelperModel = tierHaikuModel ?? value;
114118
return (
115119
<>
116120
<div className="h-section">{t("claude.smallFastModel")}</div>
@@ -124,8 +128,8 @@ export function SmallFastModelSetting({
124128
label={t("claude.smallFastModel")}
125129
style={{ maxWidth: 420 }}
126130
/>
127-
{value === "" && (
128-
<p className="notice-warn" role="note" style={{ marginTop: 8 }}>
131+
{effectiveHelperModel === "" && (
132+
<p className="notice-warn" role="status" style={{ marginTop: 8 }}>
129133
{t("claude.smallFastModelNativeWarning")}
130134
</p>
131135
)}
@@ -379,6 +383,7 @@ export default function ClaudeCode({ apiBase }: { apiBase: string }) {
379383

380384
<SmallFastModelSetting
381385
value={state.smallFastModel}
386+
tierHaikuModel={state.tierModels?.haiku}
382387
options={modelOptions}
383388
onChange={smallFastModel => setState({ ...state, smallFastModel })}
384389
/>

‎gui/src/pages/Models.tsx‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ export default function Models({ apiBase }: { apiBase: string }) {
745745
const shown = limit[provider] ?? PAGE;
746746
const visible = sorted.slice(0, shown);
747747
const remaining = filtered.length - visible.length;
748+
const discoveryFailure = liveModels && discovery?.status === "failed" ? discovery : undefined;
748749
const allOn = rows.length > 0 && rows.every(m => !disabled.has(m.namespaced));
749750
const allOff = rows.length > 0 && rows.every(m => disabled.has(m.namespaced));
750751
const bulkToggle = (enable: boolean) => {
@@ -759,6 +760,15 @@ export default function Models({ apiBase }: { apiBase: string }) {
759760
<IconChevron style={{ width: 14, height: 14, color: "var(--muted)", transform: isCollapsed ? "none" : "rotate(90deg)", transition: "transform .12s" }} />
760761
<span className="text-body font-semibold">{provider}</span>
761762
{isNative && <span className="muted mono text-caption" style={{ padding: "1px 6px", border: "1px solid var(--border)", borderRadius: "var(--radius-pill)" }}>{t("models.nativeGroupLabel")}</span>}
763+
{discoveryFailure && (
764+
<span
765+
className="badge badge-amber"
766+
role="status"
767+
title={discoveryFailureReason(t, discoveryFailure)}
768+
>
769+
{t("models.discoveryFailedBadge")}
770+
</span>
771+
)}
762772
<span className="muted mono text-label">{t("models.active", { active: activeCount, total: rows.length })}</span>
763773
<div style={{ flex: 1 }} />
764774
<div className="row" onClick={e => e.stopPropagation()} style={{ gap: 6 }}>
@@ -797,7 +807,9 @@ export default function Models({ apiBase }: { apiBase: string }) {
797807
{!isCollapsed && (
798808
<div style={{ padding: "6px 12px" }}>
799809
{isNative && <p className="muted text-label" style={{ margin: "2px 0 6px" }}>{t("models.nativeHint")}</p>}
800-
{rows.length === 0 && <EmptyProviderHint liveModels={liveModels} discovery={discovery} />}
810+
{rows.length === 0 && (
811+
<EmptyProviderHint liveModels={liveModels} discovery={discovery} showFailureBadge={false} />
812+
)}
801813
{rows.length > PAGE / 2 && (
802814
<input
803815
className="input"
@@ -1136,17 +1148,19 @@ function discoveryFailureReason(
11361148
export function EmptyProviderHint({
11371149
liveModels,
11381150
discovery,
1151+
showFailureBadge = true,
11391152
}: {
11401153
liveModels: boolean;
11411154
discovery?: ProviderDiscoverySummary;
1155+
showFailureBadge?: boolean;
11421156
}) {
11431157
const t = useT();
11441158
const failed = liveModels && discovery?.status === "failed" ? discovery : undefined;
11451159
return (
11461160
<div className="row muted text-label leading-body" role="status" style={{ alignItems: "flex-start", gap: 8, padding: "6px 0" }}>
11471161
<IconInfo width={15} height={15} aria-hidden="true" style={{ flexShrink: 0, marginTop: 2 }} />
11481162
<span>
1149-
{failed && <><span className="badge badge-amber">{t("models.discoveryFailedBadge")}</span>{" "}</>}
1163+
{failed && showFailureBadge && <><span className="badge badge-amber">{t("models.discoveryFailedBadge")}</span>{" "}</>}
11501164
{failed
11511165
? `${discoveryFailureReason(t, failed)} `
11521166
: `${t(liveModels ? "models.emptyDiscovery" : "models.emptyDiscoveryDisabled")} `}

‎gui/tests/claude-code-background-helper.test.tsx‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,38 @@ import { renderToStaticMarkup } from "react-dom/server";
33
import { LanguageProvider } from "../src/i18n/provider";
44
import { SmallFastModelSetting } from "../src/pages/ClaudeCode";
55

6-
let previousLanguage: unknown;
6+
let originalLanguageDescriptor: PropertyDescriptor | undefined;
77

88
beforeEach(() => {
9-
previousLanguage = (globalThis.navigator as { language?: unknown } | undefined)?.language;
9+
originalLanguageDescriptor = Object.getOwnPropertyDescriptor(globalThis.navigator, "language");
1010
Object.defineProperty(globalThis.navigator, "language", {
1111
configurable: true,
1212
value: "en-US",
1313
});
1414
});
1515

1616
afterEach(() => {
17-
Object.defineProperty(globalThis.navigator, "language", {
18-
configurable: true,
19-
value: previousLanguage,
20-
});
17+
if (originalLanguageDescriptor) {
18+
Object.defineProperty(globalThis.navigator, "language", originalLanguageDescriptor);
19+
} else {
20+
delete (globalThis.navigator as { language?: string }).language;
21+
}
2122
});
2223

2324
const options = [
2425
{ value: "", label: "Let Claude Code choose (native model)" },
2526
{ value: "gemini/gemini-3-flash", label: "gemini/gemini-3-flash" },
2627
];
2728

28-
function renderSetting(value: string): string {
29+
function renderSetting(value: string, tierHaikuModel?: string): string {
2930
return renderToStaticMarkup(
3031
<LanguageProvider>
31-
<SmallFastModelSetting value={value} options={options} onChange={() => {}} />
32+
<SmallFastModelSetting
33+
value={value}
34+
tierHaikuModel={tierHaikuModel}
35+
options={options}
36+
onChange={() => {}}
37+
/>
3238
</LanguageProvider>,
3339
);
3440
}
@@ -39,13 +45,21 @@ test("unset background helper explains native selection and Sonnet cost", () =>
3945
expect(html).toContain("background work such as chat summaries and topic detection");
4046
expect(html).toContain("native Sonnet model");
4147
expect(html).toContain("may incur charges from your native provider");
42-
expect(html).toContain('role="note"');
48+
expect(html).toContain('role="status"');
49+
});
50+
51+
test("tier Haiku override is the effective helper and hides the native warning", () => {
52+
const html = renderSetting("", "mock/tier-haiku");
53+
expect(html).toContain("Let Claude Code choose (native model)");
54+
expect(html).toContain("background work such as chat summaries and topic detection");
55+
expect(html).not.toContain("native Sonnet model");
56+
expect(html).not.toContain('role="status"');
4357
});
4458

4559
test("selected background helper keeps the neutral description and hides the native warning", () => {
4660
const html = renderSetting("gemini/gemini-3-flash");
4761
expect(html).toContain("gemini/gemini-3-flash");
4862
expect(html).toContain("background work such as chat summaries and topic detection");
4963
expect(html).not.toContain("native Sonnet model");
50-
expect(html).not.toContain('role="note"');
64+
expect(html).not.toContain('role="status"');
5165
});

‎gui/tests/models-empty-provider.test.tsx‎

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { afterEach, beforeEach, expect, test } from "bun:test";
2+
import { Window } from "happy-dom";
23
import http2 from "node:http2";
4+
import { act } from "react";
5+
import type { Root } from "react-dom/client";
36
import { renderToStaticMarkup } from "react-dom/server";
47
import { LanguageProvider } from "../src/i18n/provider";
5-
import { EmptyProviderHint } from "../src/pages/Models";
8+
import Models, { EmptyProviderHint } from "../src/pages/Models";
69
import type { ProviderDiscoverySummary } from "../src/models-groups";
710
import { gatherRoutedModels } from "../../src/codex/catalog";
811
import {
@@ -44,6 +47,7 @@ function renderHint(liveModels: boolean, discovery?: ProviderDiscoverySummary):
4447
async function providerDto(
4548
provider: string,
4649
adapter: "openai-chat" | "cursor" = "openai-chat",
50+
liveModels = true,
4751
): Promise<Record<string, unknown>> {
4852
const requestUrl = new URL("http://127.0.0.1/api/providers");
4953
const response = await handleManagementAPI(
@@ -54,6 +58,7 @@ async function providerDto(
5458
[provider]: {
5559
adapter,
5660
baseUrl: adapter === "cursor" ? "https://api2.cursor.sh" : "https://api.example.test/v1",
61+
liveModels,
5762
models: [],
5863
},
5964
},
@@ -63,6 +68,76 @@ async function providerDto(
6368
return providers[0] ?? {};
6469
}
6570

71+
test("Models page keeps the discovery-failure badge visible with fallback rows", async () => {
72+
const domGlobals = ["document", "window", "localStorage", "IS_REACT_ACT_ENVIRONMENT"] as const;
73+
const previousDescriptors = Object.fromEntries(
74+
domGlobals.map(key => [key, Object.getOwnPropertyDescriptor(globalThis, key)]),
75+
) as Record<(typeof domGlobals)[number], PropertyDescriptor | undefined>;
76+
const testWindow = new Window({ url: "http://localhost/" });
77+
const container = testWindow.document.createElement("div");
78+
testWindow.document.body.append(container);
79+
let root: Root | undefined;
80+
81+
Object.defineProperties(globalThis, {
82+
document: { configurable: true, value: testWindow.document },
83+
window: { configurable: true, value: testWindow },
84+
localStorage: { configurable: true, value: testWindow.localStorage },
85+
IS_REACT_ACT_ENVIRONMENT: { configurable: true, value: true },
86+
});
87+
globalThis.fetch = (async (input) => {
88+
const url = String(input);
89+
if (url.endsWith("/api/models")) {
90+
return Response.json([{
91+
provider: "fallback-provider",
92+
id: "configured-fallback",
93+
namespaced: "fallback-provider/configured-fallback",
94+
disabled: false,
95+
}]);
96+
}
97+
if (url.endsWith("/api/providers")) {
98+
return Response.json([{
99+
name: "fallback-provider",
100+
liveModels: true,
101+
models: ["configured-fallback"],
102+
discovery: { status: "failed", reason: "http", httpStatus: 401 },
103+
}]);
104+
}
105+
if (url.endsWith("/api/provider-context-caps")) return Response.json({ caps: {} });
106+
if (url.endsWith("/api/combos")) return Response.json([]);
107+
return new Response(null, { status: 404 });
108+
}) as typeof fetch;
109+
110+
try {
111+
const { createRoot } = await import("react-dom/client");
112+
await act(async () => {
113+
root = createRoot(container);
114+
root.render(
115+
<LanguageProvider>
116+
<Models apiBase="http://localhost" />
117+
</LanguageProvider>,
118+
);
119+
});
120+
await act(async () => {
121+
await new Promise(resolve => testWindow.setTimeout(resolve, 0));
122+
await Promise.resolve();
123+
});
124+
125+
expect(container.textContent).toContain("fallback-provider/configured-fallback");
126+
expect(container.querySelector(".badge.badge-amber")?.textContent).toContain("Discovery failed");
127+
expect(container.textContent).not.toContain("No models were discovered");
128+
} finally {
129+
if (root) {
130+
await act(async () => root?.unmount());
131+
}
132+
testWindow.close();
133+
for (const key of domGlobals) {
134+
const descriptor = previousDescriptors[key];
135+
if (descriptor) Object.defineProperty(globalThis, key, descriptor);
136+
else delete (globalThis as Record<string, unknown>)[key];
137+
}
138+
}
139+
});
140+
66141
async function withCursorDiscoveryServer<T>(
67142
status: number,
68143
run: (baseUrl: string) => Promise<T>,
@@ -302,6 +377,30 @@ test("successful discovery clears every prior failure reason", async () => {
302377
expect(await providerDto(provider)).not.toHaveProperty("discovery");
303378
});
304379

380+
test("static catalog paths clear stale discovery failures and omit them from the API", async () => {
381+
for (const adapter of ["openai-chat", "cursor"] as const) {
382+
const provider = `static-${adapter}`;
383+
markProviderDiscoveryFailed(provider, { reason: "http", httpStatus: 401 });
384+
expect(await providerDto(provider, adapter, false)).not.toHaveProperty("discovery");
385+
386+
const models = await gatherRoutedModels({
387+
modelCacheTtlMs: 0,
388+
providers: {
389+
[provider]: {
390+
adapter,
391+
baseUrl: adapter === "cursor" ? "https://api2.cursor.sh" : "https://api.example.test/v1",
392+
liveModels: false,
393+
models: ["configured-fallback"],
394+
},
395+
},
396+
});
397+
398+
expect(models.map(model => model.id)).toEqual(["configured-fallback"]);
399+
expect(getProviderDiscoveryStatus(provider)).toBeUndefined();
400+
expect(await providerDto(provider, adapter, false)).not.toHaveProperty("discovery");
401+
}
402+
});
403+
305404
test("empty static provider explains that live discovery is disabled", () => {
306405
const html = renderHint(false);
307406
expect(html).toContain("Live model discovery is off");

‎src/codex/catalog/provider-fetch.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { atomicWriteFile, expandUserPath, getConfigDir, websocketsEnabled } from
66
import { CODEX_CONFIG_PATH, CODEX_MODELS_CACHE_PATH, DEFAULT_CATALOG_PATH, readRootTomlString, resolveCodexConfigPath } from "../paths";
77
import {
88
clearModelCache,
9+
clearProviderDiscoveryStatus,
910
DEFAULT_MODEL_CACHE_TTL_MS,
1011
getFreshCached,
1112
getStaleCached,
@@ -246,7 +247,11 @@ export async function fetchProviderModels(name: string, prov: OcxProviderConfig,
246247
: models
247248
);
248249
if (prov.adapter === "cursor") {
249-
if (prov.liveModels === false || !apiKey) return configured;
250+
if (prov.liveModels === false) {
251+
clearProviderDiscoveryStatus(name);
252+
return configured;
253+
}
254+
if (!apiKey) return configured;
250255
// Cursor uses a bespoke GetUsableModels RPC (not /models), returning the full effort-suffixed
251256
// variants this PLAN can use. Keep the base-model UX (the request builder appends the effort
252257
// suffix) but filter the static seed to the bases the account actually has — so models not on the
@@ -280,6 +285,7 @@ export async function fetchProviderModels(name: string, prov: OcxProviderConfig,
280285
return configured;
281286
}
282287
if (prov.liveModels === false) {
288+
clearProviderDiscoveryStatus(name);
283289
return configured;
284290
}
285291
const fresh = getFreshCached(name, ttlMs);

‎src/codex/model-cache.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ export function markProviderDiscoveryFailed(
6363
discoveryStatus.set(provider, { status: "failed", ...failure });
6464
}
6565

66+
export function clearProviderDiscoveryStatus(provider: string): void {
67+
discoveryStatus.delete(provider);
68+
}
69+
6670
export function getProviderDiscoveryStatus(provider: string): ProviderModelDiscoveryStatus | undefined {
6771
return discoveryStatus.get(provider);
6872
}

‎src/server/management/provider-routes.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export async function handleProviderRoutes(ctx: ManagementContext): Promise<Resp
7979
authMode: p.authMode,
8080
disabled: p.disabled === true,
8181
codexAccountMode: providerCodexAccountMode(name, p),
82-
discovery: getProviderDiscoveryStatus(name),
82+
discovery: p.liveModels === false ? undefined : getProviderDiscoveryStatus(name),
8383
})));
8484
}
8585

0 commit comments

Comments
 (0)