Skip to content

Commit 083f6d6

Browse files
wpfleger96npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
andauthored
fix(desktop): surface model discovery failures in agent config UI (#2246)
Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
1 parent 50f4412 commit 083f6d6

7 files changed

Lines changed: 342 additions & 13 deletions

‎desktop/src/features/agents/AGENTS.md‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,15 @@ with a TypeScript lookup table or an id comparison in a component.
5353
6. **One canonical behavior, disclosure presets for visibility.** Behavior
5454
flags were deliberately killed in #2148 (`CANONICAL_CONFIG_BEHAVIORS`).
5555
Surface differences are expressed via the `disclosure` preset, not new
56-
boolean props.
56+
boolean props. **Exception:** `onboarding-essential` hides happy-path
57+
helper copy (provider/model descriptions) but a non-null model-discovery
58+
status always bypasses the preset and renders the status line — enforced
59+
via `shouldShowModelStatusMessage()` (`AgentConfigFields.tsx`).
60+
Additionally, a successful discovery response that yields no usable options
61+
(`supportsSwitching:false` or empty model list) synthesizes a warning status
62+
via `synthesizeEmptyDiscoveryStatus()` and is intentionally **not cached**
63+
so that closing → reopening the dialog re-runs discovery after the user
64+
installs or signs into the CLI (`isCacheableDiscoveryResponse()`).
5765
7. **Onboarding setup detects readiness; it does not select defaults.** The
5866
setup page derives visible and ready harnesses from the runtime catalog and
5967
only offers install or sign-in actions. The following defaults page is the
@@ -66,7 +74,11 @@ with a TypeScript lookup table or an id comparison in a component.
6674
- `lib/agentConfigCore.test.mjs` — field model per harness × scope, clearing
6775
policy. Update when the capability model changes.
6876
- `ui/agentConfigFieldsContract.test.mjs` — canonical behaviors + disclosure
69-
presets. If this fails, you probably reintroduced a per-surface flag.
77+
presets + `shouldShowModelStatusMessage` status-bypass rule. If this fails,
78+
you probably reintroduced a per-surface flag or broke the status-bypass.
79+
- `ui/usePersonaModelDiscovery.test.mjs` — `synthesizeEmptyDiscoveryStatus`,
80+
`isCacheableDiscoveryResponse`, `deriveModelDiscoveryPending`. If the
81+
"reopen to retry" copy becomes inert again, these tests will catch it.
7082
- `desktop/tests/e2e/onboarding-agent-defaults.spec.ts` — onboarding behavior
7183
acceptance coverage for readiness, failure states, defaults, navigation, and
7284
persistence races.

‎desktop/src/features/agents/ui/AgentConfigFields.tsx‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ export function resolveDisclosure(disclosure: "full" | "onboarding-essential") {
110110
} as const;
111111
}
112112

113+
/**
114+
* Determines whether the status line beneath the Model field should render.
115+
*
116+
* Discovery warnings bypass the `onboarding-essential` preset so that a
117+
* first-run failure is never silently invisible. On the happy path
118+
* (`status === null`) the status line stays hidden in onboarding, keeping
119+
* the page clean.
120+
*/
121+
export function shouldShowModelStatusMessage(
122+
showDescriptions: boolean,
123+
status: { message: string; tone: string } | null,
124+
): boolean {
125+
return showDescriptions || status !== null;
126+
}
127+
113128
export type AgentConfigFieldsProps = {
114129
bakedEnv: BakedEnvEntry[];
115130
selectedRuntime: AcpRuntimeCatalogEntry | undefined;
@@ -682,7 +697,10 @@ export function AgentConfigFields({
682697
labelClassName={fieldLabelClassName}
683698
selectClassName={selectClassName}
684699
showCustomModelOption={showCustomModelOption}
685-
showStatusMessage={showDescriptions}
700+
showStatusMessage={shouldShowModelStatusMessage(
701+
showDescriptions,
702+
modelDiscoveryStatus,
703+
)}
686704
testId="global-agent-model"
687705
useCustomSelect={useCustomSelect}
688706
useChevronIcon={useChevronSelectIcon}

‎desktop/src/features/agents/ui/agentConfigControls.test.mjs‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import assert from "node:assert/strict";
22
import test from "node:test";
33

4-
import { resolveDefaultModelLabel } from "./agentConfigControls.tsx";
4+
import {
5+
MODEL_NO_MODELS_VALUE,
6+
appendNoModelsSentinel,
7+
resolveDefaultModelLabel,
8+
} from "./agentConfigControls.tsx";
59

610
test("uses the harness-discovered default model label for an unset model", () => {
711
assert.equal(
@@ -38,3 +42,27 @@ test("an explicit inherited default label wins over harness discovery", () => {
3842
"Default model (team-model)",
3943
);
4044
});
45+
46+
// ── appendNoModelsSentinel ─────────────────────────────────────────────────────
47+
48+
test("appendNoModelsSentinel_emptyOptionsDiscoveryFinished_addsDisabledRow", () => {
49+
const options = appendNoModelsSentinel([], false);
50+
assert.equal(options.length, 1);
51+
assert.equal(options[0].disabled, true);
52+
assert.equal(options[0].label, "No models found");
53+
assert.equal(options[0].value, MODEL_NO_MODELS_VALUE);
54+
});
55+
56+
test("appendNoModelsSentinel_emptyOptionsDiscoveryLoading_doesNotAddRow", () => {
57+
const options = appendNoModelsSentinel([], true);
58+
assert.equal(options.length, 0);
59+
});
60+
61+
test("appendNoModelsSentinel_nonEmptyOptionsDiscoveryFinished_doesNotAddRow", () => {
62+
const options = appendNoModelsSentinel(
63+
[{ label: "Default model", value: "" }],
64+
false,
65+
);
66+
assert.equal(options.length, 1);
67+
assert.equal(options[0].label, "Default model");
68+
});

‎desktop/src/features/agents/ui/agentConfigControls.tsx‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,34 @@ import {
2626
import { MODEL_DISCOVERY_LOADING_VALUE } from "./usePersonaModelDiscovery";
2727
import type { PersonaModelDiscoveryStatus } from "./personaModelDiscoveryStatus";
2828

29+
export const MODEL_NO_MODELS_VALUE = "__no_models__";
30+
2931
export type AgentDropdownOption = {
3032
disabled?: boolean;
3133
label: React.ReactNode;
3234
value: string;
3335
};
3436

37+
/**
38+
* Ensures an opened model dropdown never renders as a blank white bar.
39+
* When `options` is empty and discovery has finished, appends a single
40+
* disabled "No models found" sentinel row in place. Returns `options`
41+
* for convenient chaining in tests.
42+
*/
43+
export function appendNoModelsSentinel(
44+
options: AgentDropdownOption[],
45+
loading: boolean,
46+
): AgentDropdownOption[] {
47+
if (options.length === 0 && !loading) {
48+
options.push({
49+
disabled: true,
50+
label: "No models found",
51+
value: MODEL_NO_MODELS_VALUE,
52+
});
53+
}
54+
return options;
55+
}
56+
3557
function optionTestId(testId: string | undefined, value: string) {
3658
if (!testId) return undefined;
3759
return `${testId}-option-${value || "empty"}`;
@@ -422,6 +444,10 @@ export function AgentModelField({
422444
? [{ label: "Custom model...", value: CUSTOM_MODEL_DROPDOWN_VALUE }]
423445
: []),
424446
];
447+
// An opened dropdown must never show a blank popover. When all the above
448+
// yields an empty list and discovery has finished, add a disabled sentinel
449+
// row so the user sees "No models found" instead of a bare white bar.
450+
appendNoModelsSentinel(modelOptions, modelDiscoveryLoading);
425451
const stableSelectedModelLabel =
426452
keepSelectedModelValueLabel &&
427453
modelSelectValue === trimmedModel &&

‎desktop/src/features/agents/ui/agentConfigFieldsContract.test.mjs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import test from "node:test";
2121
import {
2222
CANONICAL_CONFIG_BEHAVIORS,
2323
resolveDisclosure,
24+
shouldShowModelStatusMessage,
2425
} from "./AgentConfigFields.tsx";
2526

2627
test("canonical behaviors: onboarding's values are the only behavior", () => {
@@ -57,3 +58,28 @@ test("onboarding-essential hides power tools but never the effort field", () =>
5758
showUnavailableEffortOptions: false,
5859
});
5960
});
61+
62+
// ── shouldShowModelStatusMessage ──────────────────────────────────────────────
63+
// The onboarding-essential preset sets showDescriptions=false. Discovery
64+
// warnings must bypass the preset so first-run failures are never invisible.
65+
66+
test("shouldShowModelStatusMessage_fullDisclosure_nullStatus_showsMessage", () => {
67+
// Full disclosure always shows the status line regardless of status.
68+
assert.equal(shouldShowModelStatusMessage(true, null), true);
69+
});
70+
71+
test("shouldShowModelStatusMessage_onboardingPreset_nullStatus_hidesMessage", () => {
72+
// Happy path: no status → status line hidden in onboarding.
73+
const { showDescriptions } = resolveDisclosure("onboarding-essential");
74+
assert.equal(shouldShowModelStatusMessage(showDescriptions, null), false);
75+
});
76+
77+
test("shouldShowModelStatusMessage_onboardingPreset_warningStatus_showsMessage", () => {
78+
// Discovery failure → status line surfaces even in onboarding-essential.
79+
const { showDescriptions } = resolveDisclosure("onboarding-essential");
80+
const warning = {
81+
message: "Claude Code reported no models.",
82+
tone: "warning",
83+
};
84+
assert.equal(shouldShowModelStatusMessage(showDescriptions, warning), true);
85+
});

‎desktop/src/features/agents/ui/usePersonaModelDiscovery.test.mjs‎

Lines changed: 149 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import assert from "node:assert/strict";
22
import test from "node:test";
33

4-
import { getDiscoveredPersonaModelOptions } from "./usePersonaModelDiscovery.ts";
4+
import {
5+
deriveModelDiscoveryPending,
6+
getDiscoveredPersonaModelOptions,
7+
isCacheableDiscoveryResponse,
8+
synthesizeEmptyDiscoveryStatus,
9+
} from "./usePersonaModelDiscovery.ts";
510

611
function response(overrides = {}) {
712
return {
@@ -110,3 +115,146 @@ test("returns null when discovery is unsupported or empty", () => {
110115
);
111116
assert.equal(getDiscoveredPersonaModelOptions(null, ""), null);
112117
});
118+
119+
// ── synthesizeEmptyDiscoveryStatus ────────────────────────────────────────────
120+
121+
test("synthesizeEmptyDiscoveryStatus_emptyModels_producesWarningStatus", () => {
122+
const status = synthesizeEmptyDiscoveryStatus(
123+
response({ models: [], agentName: "Claude Code" }),
124+
"",
125+
);
126+
assert.equal(status?.tone, "warning");
127+
assert.match(status?.message ?? "", /Claude Code/);
128+
assert.match(status?.message ?? "", /reported no models/);
129+
});
130+
131+
test("synthesizeEmptyDiscoveryStatus_supportsSwitchingFalse_producesWarningStatus", () => {
132+
const status = synthesizeEmptyDiscoveryStatus(
133+
response({
134+
supportsSwitching: false,
135+
models: [{ id: "gpt-4", name: "GPT-4", description: null }],
136+
agentName: "Codex",
137+
}),
138+
"",
139+
);
140+
assert.equal(status?.tone, "warning");
141+
assert.match(status?.message ?? "", /Codex/);
142+
});
143+
144+
test("synthesizeEmptyDiscoveryStatus_withUsableModels_returnsNull", () => {
145+
assert.equal(
146+
synthesizeEmptyDiscoveryStatus(
147+
response({
148+
models: [
149+
{ id: "claude-sonnet-5", name: "Claude Sonnet 5", description: null },
150+
],
151+
agentName: "Claude Code",
152+
}),
153+
"",
154+
),
155+
null,
156+
);
157+
});
158+
159+
test("synthesizeEmptyDiscoveryStatus_emptyAgentName_usesGenericFallback", () => {
160+
const status = synthesizeEmptyDiscoveryStatus(
161+
response({ models: [], agentName: "" }),
162+
"",
163+
);
164+
assert.equal(status?.tone, "warning");
165+
assert.match(status?.message ?? "", /This agent/);
166+
});
167+
168+
// ── isCacheableDiscoveryResponse ──────────────────────────────────────────────
169+
170+
test("isCacheableDiscoveryResponse_withUsableModels_returnsTrue", () => {
171+
assert.equal(
172+
isCacheableDiscoveryResponse(
173+
response({
174+
models: [
175+
{ id: "claude-sonnet-5", name: "Claude Sonnet 5", description: null },
176+
],
177+
}),
178+
"",
179+
),
180+
true,
181+
);
182+
});
183+
184+
test("isCacheableDiscoveryResponse_emptyModels_returnsFalse", () => {
185+
// An empty-result response must not be cached so close→reopen retries
186+
// discovery after the user installs or signs into the CLI.
187+
assert.equal(
188+
isCacheableDiscoveryResponse(response({ models: [] }), ""),
189+
false,
190+
);
191+
});
192+
193+
test("isCacheableDiscoveryResponse_supportsSwitchingFalse_returnsFalse", () => {
194+
assert.equal(
195+
isCacheableDiscoveryResponse(
196+
response({
197+
supportsSwitching: false,
198+
models: [{ id: "gpt-4", name: "GPT-4", description: null }],
199+
}),
200+
"",
201+
),
202+
false,
203+
);
204+
});
205+
206+
// ── deriveModelDiscoveryPending ────────────────────────────────────────────────
207+
208+
test("deriveModelDiscoveryPending_stillLoading_isTrue", () => {
209+
assert.equal(
210+
deriveModelDiscoveryPending({
211+
modelDiscoveryLoading: true,
212+
modelDiscoveryKey: "key",
213+
activeModelDiscoveryData: null,
214+
activeModelDiscoveryStatus: null,
215+
}),
216+
true,
217+
);
218+
});
219+
220+
test("deriveModelDiscoveryPending_keySetDataNullStatusNull_isTrue", () => {
221+
// A key is set but neither data nor status has arrived yet → still pending.
222+
assert.equal(
223+
deriveModelDiscoveryPending({
224+
modelDiscoveryLoading: false,
225+
modelDiscoveryKey: "key",
226+
activeModelDiscoveryData: null,
227+
activeModelDiscoveryStatus: null,
228+
}),
229+
true,
230+
);
231+
});
232+
233+
test("deriveModelDiscoveryPending_resolvedEmptyResponse_isNotPending", () => {
234+
// A resolved-but-empty response sets data non-null and status to a warning.
235+
// Neither condition for pending is met — the hook must not spin forever.
236+
const emptyResponse = response({ models: [] });
237+
const warningStatus = { message: "no models", tone: "warning" };
238+
assert.equal(
239+
deriveModelDiscoveryPending({
240+
modelDiscoveryLoading: false,
241+
modelDiscoveryKey: "key",
242+
activeModelDiscoveryData: emptyResponse,
243+
activeModelDiscoveryStatus: warningStatus,
244+
}),
245+
false,
246+
);
247+
});
248+
249+
test("deriveModelDiscoveryPending_noKey_isNotPending", () => {
250+
// key=null means discovery is not expected (e.g. dialog closed).
251+
assert.equal(
252+
deriveModelDiscoveryPending({
253+
modelDiscoveryLoading: false,
254+
modelDiscoveryKey: null,
255+
activeModelDiscoveryData: null,
256+
activeModelDiscoveryStatus: null,
257+
}),
258+
false,
259+
);
260+
});

0 commit comments

Comments
 (0)