Skip to content

Commit 9cf9539

Browse files
chore: Omit the Model control when an optional-model harness has nothing to select (#2262)
Signed-off-by: Moe Jangda <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 659e6a8 commit 9cf9539

9 files changed

Lines changed: 449 additions & 61 deletions

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,34 @@ with a TypeScript lookup table or an id comparison in a component.
6868
sole onboarding surface that chooses and persists `preferred_runtime`.
6969
`onboarding-agent-defaults.spec.ts` is the acceptance gate for anything
7070
touching this flow or the shared renderer.
71+
8. **Omit the Model control only after a confirmed successful empty
72+
discovery on an optional-model harness.** When the field model marks model
73+
as `acpNative` (Claude Code / Codex), `shouldRenderModelControl` hides the
74+
picker while discovery is in flight and after IPC resolves with no usable
75+
options (`modelDiscoverySuccessfulEmpty` / `isSuccessfulEmptyDiscovery`).
76+
A thrown or unavailable discovery keeps the control so #2246 failure UI can
77+
render, and must not heal/clear persisted model or effort. Full disclosure
78+
still shows the control when Custom model is available. Required-model
79+
harnesses always keep the field. Gate: `defaults hides model when optional
80+
harness has empty discovery` (and the failed-discovery counterpart) in
81+
`onboarding-agent-defaults.spec.ts`.
7182

7283
## The tests that enforce this
7384

7485
- `lib/agentConfigCore.test.mjs` — field model per harness × scope, clearing
7586
policy. Update when the capability model changes.
7687
- `ui/agentConfigFieldsContract.test.mjs` — canonical behaviors + disclosure
77-
presets + `shouldShowModelStatusMessage` status-bypass rule. If this fails,
78-
you probably reintroduced a per-surface flag or broke the status-bypass.
88+
presets + `shouldShowModelStatusMessage` status-bypass +
89+
`shouldRenderModelControl` (successful-empty omit vs failure keep). If this
90+
fails, you probably reintroduced a per-surface flag or conflated empty with
91+
failed discovery.
7992
- `ui/usePersonaModelDiscovery.test.mjs` — `synthesizeEmptyDiscoveryStatus`,
80-
`isCacheableDiscoveryResponse`, `deriveModelDiscoveryPending`. If the
81-
"reopen to retry" copy becomes inert again, these tests will catch it.
93+
`isCacheableDiscoveryResponse`, `deriveModelDiscoveryPending`,
94+
`isSuccessfulEmptyDiscovery`. If the "reopen to retry" copy becomes inert
95+
again, these tests will catch it.
8296
- `desktop/tests/e2e/onboarding-agent-defaults.spec.ts` — onboarding behavior
83-
acceptance coverage for readiness, failure states, defaults, navigation, and
84-
persistence races.
97+
acceptance coverage for readiness, failure states, defaults, navigation,
98+
successful-empty vs failed optional-model discovery, and persistence races.
8599
- Rust: `runtime_metadata_env_vars` tests pin spawn-time key application.
86100

87101
## Keep this file true

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

Lines changed: 113 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,41 @@ export function shouldShowModelStatusMessage(
125125
return showDescriptions || status !== null;
126126
}
127127

128+
/**
129+
* Whether the Model control should render given discovery state.
130+
*
131+
* Optional-model harnesses (Claude Code / Codex, `acpNative`) omit the control
132+
* while discovery is in flight and after a **confirmed successful empty**
133+
* catalog (IPC resolved, no usable options) — there is nothing useful to pick.
134+
* Discovery failures / unavailable runtimes keep the control so #2246 failure
135+
* UI can render. Full disclosure still shows the control when Custom model is
136+
* available. Required-model harnesses always render the control.
137+
*/
138+
export function shouldRenderModelControl({
139+
discoveredModelOptions,
140+
modelDiscoveryLoading,
141+
modelDiscoverySuccessfulEmpty,
142+
modelIsOptional,
143+
showCustomModelOption,
144+
}: {
145+
discoveredModelOptions: readonly { id: string }[] | null;
146+
modelDiscoveryLoading: boolean;
147+
/** True only when discovery IPC resolved with a response that yielded no options. */
148+
modelDiscoverySuccessfulEmpty: boolean;
149+
modelIsOptional: boolean;
150+
showCustomModelOption: boolean;
151+
}): boolean {
152+
if (!modelIsOptional) return true;
153+
if (modelDiscoveryLoading) return false;
154+
const hasExplicitModel = (discoveredModelOptions ?? []).some(
155+
(option) => option.id.trim().length > 0,
156+
);
157+
if (hasExplicitModel) return true;
158+
if (showCustomModelOption) return true;
159+
// Omit only on confirmed successful empty — not on failure/unavailable.
160+
return !modelDiscoverySuccessfulEmpty;
161+
}
162+
128163
export type AgentConfigFieldsProps = {
129164
bakedEnv: BakedEnvEntry[];
130165
selectedRuntime: AcpRuntimeCatalogEntry | undefined;
@@ -277,6 +312,7 @@ export function AgentConfigFields({
277312
discoveredModelOptions,
278313
modelDiscoveryLoading,
279314
modelDiscoveryStatus,
315+
modelDiscoverySuccessfulEmpty,
280316
} = usePersonaModelDiscovery({
281317
envVars: config.env_vars,
282318
isCustomProviderEditing: isCustomProvider,
@@ -285,6 +321,18 @@ export function AgentConfigFields({
285321
provider: providerForDiscovery,
286322
selectedRuntime,
287323
});
324+
const modelControlVisible = shouldRenderModelControl({
325+
discoveredModelOptions: dependentFieldsDisabled
326+
? null
327+
: discoveredModelOptions,
328+
modelDiscoveryLoading: dependentFieldsDisabled
329+
? false
330+
: modelDiscoveryLoading,
331+
modelDiscoverySuccessfulEmpty:
332+
!dependentFieldsDisabled && modelDiscoverySuccessfulEmpty,
333+
modelIsOptional,
334+
showCustomModelOption,
335+
});
288336

289337
// Mount-time healing policy: onboarding page 4 edits the root config during
290338
// first-run (no higher layers to inherit from), so acting on open is safe
@@ -353,16 +401,23 @@ export function AgentConfigFields({
353401
// the old harness. In onboarding, heal that stale value as soon as the new
354402
// harness catalog proves it is unsupported; otherwise a Codex id like
355403
// `gpt-5.5[low]` appears as a Claude Code custom model.
404+
// Also clear when the Model control is omitted after a confirmed successful
405+
// empty catalog — never while discovery failed/unavailable (transient
406+
// failures must not erase saved model/effort).
356407
React.useEffect(() => {
357408
if (!healOnMount) return;
358409
const currentModel = (config.model ?? "").trim();
359410
if (currentModel.length === 0) return;
360-
if (modelDiscoveryLoading || discoveredModelOptions === null) return;
361-
if (
362-
discoveredModelOptions.some((option) => option.id.trim() === currentModel)
363-
) {
364-
return;
365-
}
411+
if (modelDiscoveryLoading) return;
412+
413+
const catalogMiss =
414+
discoveredModelOptions !== null &&
415+
!discoveredModelOptions.some(
416+
(option) => option.id.trim() === currentModel,
417+
);
418+
const omittedAfterSuccessfulEmpty =
419+
modelIsOptional && !modelControlVisible && modelDiscoverySuccessfulEmpty;
420+
if (!catalogMiss && !omittedAfterSuccessfulEmpty) return;
366421

367422
const nextEnvVars = { ...config.env_vars };
368423
if (effortPersistenceKey) delete nextEnvVars[effortPersistenceKey];
@@ -371,7 +426,10 @@ export function AgentConfigFields({
371426
}, [
372427
config,
373428
discoveredModelOptions,
429+
modelControlVisible,
374430
modelDiscoveryLoading,
431+
modelDiscoverySuccessfulEmpty,
432+
modelIsOptional,
375433
onConfigChange,
376434
onCustomModelEditingChange,
377435
healOnMount,
@@ -659,53 +717,55 @@ export function AgentConfigFields({
659717
</div>
660718
) : null}
661719

662-
{/* Model field */}
663-
<div className={showDescriptions ? fieldClassName : undefined}>
664-
<AgentModelField
665-
allowDefaultModel={fallbackModel !== null}
666-
defaultModelLabel={
667-
fallbackModel ? `Default model (${fallbackModel})` : undefined
668-
}
669-
disableSelectDuringDiscovery={disableModelSelectDuringDiscovery}
670-
disabled={dependentFieldsDisabled}
671-
discoveredModelOptions={
672-
dependentFieldsDisabled ? null : discoveredModelOptions
673-
}
674-
globalModel={fallbackModel ?? undefined}
675-
id="global-agent-model"
676-
isCustomModelEditing={isCustomModelEditing}
677-
isRequired={
678-
showRequiredIndicators &&
679-
!modelIsOptional &&
680-
fallbackModel === null &&
681-
!dependentFieldsDisabled
682-
}
683-
keepSelectedModelValueLabel
684-
model={dependentFieldsDisabled ? "" : (config.model ?? "")}
685-
modelDiscoveryLoading={
686-
dependentFieldsDisabled ? false : modelDiscoveryLoading
687-
}
688-
modelDiscoveryStatus={
689-
dependentFieldsDisabled ? null : modelDiscoveryStatus
690-
}
691-
onIsCustomModelEditingChange={onCustomModelEditingChange}
692-
onModelChange={handleModelChange}
693-
placeholderClassName={placeholderClassName}
694-
placeholder="Select a model"
695-
provider={providerForDiscovery}
696-
fieldClassName={unstyled ? fieldClassName : undefined}
697-
labelClassName={fieldLabelClassName}
698-
selectClassName={selectClassName}
699-
showCustomModelOption={showCustomModelOption}
700-
showStatusMessage={shouldShowModelStatusMessage(
701-
showDescriptions,
702-
modelDiscoveryStatus,
703-
)}
704-
testId="global-agent-model"
705-
useCustomSelect={useCustomSelect}
706-
useChevronIcon={useChevronSelectIcon}
707-
/>
708-
</div>
720+
{/* Model field — omitted only after confirmed successful empty discovery */}
721+
{modelControlVisible ? (
722+
<div className={showDescriptions ? fieldClassName : undefined}>
723+
<AgentModelField
724+
allowDefaultModel={fallbackModel !== null}
725+
defaultModelLabel={
726+
fallbackModel ? `Default model (${fallbackModel})` : undefined
727+
}
728+
disableSelectDuringDiscovery={disableModelSelectDuringDiscovery}
729+
disabled={dependentFieldsDisabled}
730+
discoveredModelOptions={
731+
dependentFieldsDisabled ? null : discoveredModelOptions
732+
}
733+
globalModel={fallbackModel ?? undefined}
734+
id="global-agent-model"
735+
isCustomModelEditing={isCustomModelEditing}
736+
isRequired={
737+
showRequiredIndicators &&
738+
!modelIsOptional &&
739+
fallbackModel === null &&
740+
!dependentFieldsDisabled
741+
}
742+
keepSelectedModelValueLabel
743+
model={dependentFieldsDisabled ? "" : (config.model ?? "")}
744+
modelDiscoveryLoading={
745+
dependentFieldsDisabled ? false : modelDiscoveryLoading
746+
}
747+
modelDiscoveryStatus={
748+
dependentFieldsDisabled ? null : modelDiscoveryStatus
749+
}
750+
onIsCustomModelEditingChange={onCustomModelEditingChange}
751+
onModelChange={handleModelChange}
752+
placeholderClassName={placeholderClassName}
753+
placeholder="Select a model"
754+
provider={providerForDiscovery}
755+
fieldClassName={unstyled ? fieldClassName : undefined}
756+
labelClassName={fieldLabelClassName}
757+
selectClassName={selectClassName}
758+
showCustomModelOption={showCustomModelOption}
759+
showStatusMessage={shouldShowModelStatusMessage(
760+
showDescriptions,
761+
dependentFieldsDisabled ? null : modelDiscoveryStatus,
762+
)}
763+
testId="global-agent-model"
764+
useCustomSelect={useCustomSelect}
765+
useChevronIcon={useChevronSelectIcon}
766+
/>
767+
</div>
768+
) : null}
709769

710770
{/* Thinking / Effort */}
711771
{effortFieldVisible ? (

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export function AgentDropdownSelect({
6363
ariaRequired,
6464
className,
6565
disabled = false,
66+
emptyOptionsLabel = "No options available",
6667
id,
6768
onValueChange,
6869
options,
@@ -77,6 +78,8 @@ export function AgentDropdownSelect({
7778
ariaRequired?: boolean;
7879
className?: string;
7980
disabled?: boolean;
81+
/** Shown when the option list is empty (not a search filter miss). */
82+
emptyOptionsLabel?: string;
8083
id: string;
8184
onValueChange: (value: string) => void;
8285
options: readonly AgentDropdownOption[];
@@ -184,8 +187,15 @@ export function AgentDropdownSelect({
184187
/>
185188
</div>
186189
) : null}
187-
{showSearch && filteredOptions.length === 0 ? (
188-
<p className="px-3 py-2 text-sm text-foreground/55">No matches</p>
190+
{filteredOptions.length === 0 ? (
191+
<p
192+
className="px-3 py-2 text-sm text-foreground/55"
193+
data-testid={testId ? `${testId}-empty` : undefined}
194+
>
195+
{showSearch && query.trim().length > 0
196+
? "No matches"
197+
: emptyOptionsLabel}
198+
</p>
189199
) : null}
190200
{filteredOptions.map((option) => {
191201
const selected = option.value === value;
@@ -470,6 +480,7 @@ export function AgentModelField({
470480
ariaRequired={isRequired}
471481
className={selectClassName}
472482
disabled={selectDisabled}
483+
emptyOptionsLabel="Couldn't load models"
473484
id={id}
474485
onValueChange={handleModelSelectChange}
475486
options={modelOptions}

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

Lines changed: 92 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+
shouldRenderModelControl,
2425
shouldShowModelStatusMessage,
2526
} from "./AgentConfigFields.tsx";
2627

@@ -83,3 +84,94 @@ test("shouldShowModelStatusMessage_onboardingPreset_warningStatus_showsMessage",
8384
};
8485
assert.equal(shouldShowModelStatusMessage(showDescriptions, warning), true);
8586
});
87+
88+
// ── shouldRenderModelControl ──────────────────────────────────────────────────
89+
// Optional-model harnesses omit the control only after a confirmed successful
90+
// empty catalog. Failures keep the control so #2246 status UI can render.
91+
92+
test("optional model control hides while loading", () => {
93+
assert.equal(
94+
shouldRenderModelControl({
95+
discoveredModelOptions: null,
96+
modelDiscoveryLoading: true,
97+
modelDiscoverySuccessfulEmpty: false,
98+
modelIsOptional: true,
99+
showCustomModelOption: false,
100+
}),
101+
false,
102+
"optional + loading must hide the control",
103+
);
104+
});
105+
106+
test("optional model control hides after successful empty discovery", () => {
107+
assert.equal(
108+
shouldRenderModelControl({
109+
discoveredModelOptions: null,
110+
modelDiscoveryLoading: false,
111+
modelDiscoverySuccessfulEmpty: true,
112+
modelIsOptional: true,
113+
showCustomModelOption: false,
114+
}),
115+
false,
116+
"optional + successful empty + no custom must hide the control",
117+
);
118+
});
119+
120+
test("optional model control stays visible on discovery failure", () => {
121+
assert.equal(
122+
shouldRenderModelControl({
123+
discoveredModelOptions: null,
124+
modelDiscoveryLoading: false,
125+
modelDiscoverySuccessfulEmpty: false,
126+
modelIsOptional: true,
127+
showCustomModelOption: false,
128+
}),
129+
true,
130+
"optional + failed/unavailable discovery must keep the control",
131+
);
132+
});
133+
134+
test("optional model control shows when explicit models are available", () => {
135+
assert.equal(
136+
shouldRenderModelControl({
137+
discoveredModelOptions: [
138+
{ id: "", label: "Default model" },
139+
{ id: "claude-sonnet-4", label: "Claude Sonnet 4" },
140+
],
141+
modelDiscoveryLoading: false,
142+
modelDiscoverySuccessfulEmpty: false,
143+
modelIsOptional: true,
144+
showCustomModelOption: false,
145+
}),
146+
true,
147+
"explicit models must show the control",
148+
);
149+
});
150+
151+
test("full disclosure keeps Custom escape hatch when discovery is empty", () => {
152+
assert.equal(
153+
shouldRenderModelControl({
154+
discoveredModelOptions: null,
155+
modelDiscoveryLoading: false,
156+
modelDiscoverySuccessfulEmpty: true,
157+
modelIsOptional: true,
158+
showCustomModelOption: true,
159+
}),
160+
true,
161+
"full disclosure keeps Custom escape hatch when discovery is empty",
162+
);
163+
});
164+
165+
test("required-model harnesses always keep the control", () => {
166+
assert.equal(
167+
shouldRenderModelControl({
168+
discoveredModelOptions: null,
169+
modelDiscoveryLoading: false,
170+
modelDiscoverySuccessfulEmpty: true,
171+
modelIsOptional: false,
172+
showCustomModelOption: false,
173+
}),
174+
true,
175+
"required-model harnesses always keep the control",
176+
);
177+
});

0 commit comments

Comments
 (0)