Skip to content

Commit a6432ab

Browse files
authored
Fix harness default model states in onboarding (#2156)
1 parent e43b2d5 commit a6432ab

9 files changed

Lines changed: 420 additions & 56 deletions

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,36 @@ export function AgentConfigFields({
297297

298298
const currentEffortForAutoClear =
299299
config.env_vars[BUZZ_AGENT_THINKING_EFFORT] ?? "";
300+
301+
// When the selected harness changes outside this component (Back → setup
302+
// page → choose a different harness → Next), the saved model can belong to
303+
// the old harness. In onboarding, heal that stale value as soon as the new
304+
// harness catalog proves it is unsupported; otherwise a Codex id like
305+
// `gpt-5.5[low]` appears as a Claude Code custom model.
306+
React.useEffect(() => {
307+
if (!healOnMount) return;
308+
const currentModel = (config.model ?? "").trim();
309+
if (currentModel.length === 0) return;
310+
if (modelDiscoveryLoading || discoveredModelOptions === null) return;
311+
if (
312+
discoveredModelOptions.some((option) => option.id.trim() === currentModel)
313+
) {
314+
return;
315+
}
316+
317+
const nextEnvVars = { ...config.env_vars };
318+
delete nextEnvVars[BUZZ_AGENT_THINKING_EFFORT];
319+
onCustomModelEditingChange(false);
320+
onConfigChange({ ...config, env_vars: nextEnvVars, model: null });
321+
}, [
322+
config,
323+
discoveredModelOptions,
324+
modelDiscoveryLoading,
325+
onConfigChange,
326+
onCustomModelEditingChange,
327+
healOnMount,
328+
]);
329+
300330
// Orphan-model clearing follows the mount-time healing policy above: the
301331
// backend resolves provider and model independently across layers
302332
// (agent → definition → global), so a saved global model WITHOUT a global
@@ -452,6 +482,15 @@ export function AgentConfigFields({
452482
const { validValues: effortValid, defaultValue: effortDefault } =
453483
getProviderEffortConfig(effortProvider, config.model ?? "");
454484
const currentEffort = config.env_vars[BUZZ_AGENT_THINKING_EFFORT] ?? "";
485+
// Claude Code and Codex both have harness-native effort semantics that are
486+
// not represented by Buzz Agent's generic BUZZ_AGENT_THINKING_EFFORT env var:
487+
// Claude exposes ACP config option `effort`; Codex currently encodes effort
488+
// into model ids (e.g. `gpt-5.5[low]`). Hide the generic control until the
489+
// config core can render harness-native options honestly.
490+
const effortFieldVisible =
491+
showEffortField &&
492+
selectedRuntimeId !== "claude" &&
493+
selectedRuntimeId !== "codex";
455494

456495
const fieldClassName = unstyled ? "space-y-4" : "space-y-1.5 p-3";
457496
const blockClassName = unstyled ? "" : "p-3";
@@ -617,7 +656,7 @@ export function AgentConfigFields({
617656
</div>
618657

619658
{/* Thinking / Effort */}
620-
{showEffortField ? (
659+
{effortFieldVisible ? (
621660
<div className={blockClassName}>
622661
<EffortSelectField
623662
currentEffort={dependentFieldsDisabled ? "" : currentEffort}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import { resolveDefaultModelLabel } from "./agentConfigControls.tsx";
5+
6+
test("uses the harness-discovered default model label for an unset model", () => {
7+
assert.equal(
8+
resolveDefaultModelLabel({
9+
discoveredModelOptions: [
10+
{ id: "", label: "Default model (claude-sonnet-5)" },
11+
{ id: "claude-opus-4-8", label: "Claude Opus 4.8" },
12+
],
13+
isSharedCompute: false,
14+
}),
15+
"Default model (claude-sonnet-5)",
16+
);
17+
});
18+
19+
test("falls back to a generic harness default when discovery has no current model", () => {
20+
assert.equal(
21+
resolveDefaultModelLabel({
22+
discoveredModelOptions: [{ id: "", label: "Default model" }],
23+
isSharedCompute: false,
24+
}),
25+
"Default model",
26+
);
27+
});
28+
29+
test("an explicit inherited default label wins over harness discovery", () => {
30+
assert.equal(
31+
resolveDefaultModelLabel({
32+
defaultModelLabel: "Default model (team-model)",
33+
discoveredModelOptions: [
34+
{ id: "", label: "Default model (claude-sonnet-5)" },
35+
],
36+
isSharedCompute: false,
37+
}),
38+
"Default model (team-model)",
39+
);
40+
});

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

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,24 @@ export function RequiredFieldLabel({
230230
);
231231
}
232232

233+
export function resolveDefaultModelLabel({
234+
defaultModelLabel,
235+
discoveredModelOptions,
236+
globalModel,
237+
isSharedCompute,
238+
}: {
239+
defaultModelLabel?: string;
240+
discoveredModelOptions: readonly PersonaModelOption[] | null;
241+
globalModel?: string;
242+
isSharedCompute: boolean;
243+
}) {
244+
return (
245+
defaultModelLabel ??
246+
discoveredModelOptions?.find((option) => option.id.trim() === "")?.label ??
247+
(isSharedCompute ? "Default (auto)" : getDefaultLlmModelLabel(globalModel))
248+
);
249+
}
250+
233251
export function AgentModelField({
234252
disabled,
235253
discoveredModelOptions,
@@ -305,24 +323,32 @@ export function AgentModelField({
305323
}) {
306324
const trimmedModel = model.trim();
307325
const isSharedCompute = provider?.trim() === "relay-mesh";
326+
const discoveredDefaultOption = discoveredModelOptions?.find(
327+
(option) => option.id.trim() === "",
328+
);
308329

309-
// Buzz shared compute always has an automatic routing choice, even when
310-
// discovery is empty or returns only explicit live model ids.
330+
// Model discovery can report the harness's current/default model while the
331+
// persisted value remains empty ("let the harness choose"). Treat that as a
332+
// real, displayable option instead of a blank select state. Explicit labels
333+
// from a lower-precedence/baked default still win when present.
311334
const defaultOption: PersonaModelOption = {
312335
id: "",
313-
label:
314-
defaultModelLabel ??
315-
(isSharedCompute
316-
? "Default (auto)"
317-
: getDefaultLlmModelLabel(globalModel)),
336+
label: resolveDefaultModelLabel({
337+
defaultModelLabel,
338+
discoveredModelOptions,
339+
globalModel,
340+
isSharedCompute,
341+
}),
318342
};
319343
const discoveredWithoutDefault = (discoveredModelOptions ?? []).filter(
320344
(option) => option.id.trim() !== "",
321345
);
322346
const baseModelOptions = isSharedCompute
323347
? [defaultOption, ...discoveredWithoutDefault]
324348
: [
325-
...(allowDefaultModel ? [defaultOption] : []),
349+
...(allowDefaultModel || discoveredDefaultOption
350+
? [defaultOption]
351+
: []),
326352
...discoveredWithoutDefault,
327353
];
328354
const shouldShowPendingModelOption =
@@ -402,6 +428,16 @@ export function AgentModelField({
402428
trimmedModel.length > 0
403429
? trimmedModel
404430
: undefined;
431+
// While discovery is in flight with nothing selected, the closed field
432+
// reads "Loading models…" instead of a select-prompt — the field isn't
433+
// waiting on the user, it's waiting on the harness.
434+
const restingPlaceholder =
435+
modelDiscoveryLoading &&
436+
discoveredModelOptions === null &&
437+
trimmedModel.length === 0 &&
438+
!isCustomModelEditing
439+
? "Loading models..."
440+
: placeholder;
405441

406442
const modelSelect = useCustomSelect ? (
407443
<AgentDropdownSelect
@@ -411,7 +447,7 @@ export function AgentModelField({
411447
id={id}
412448
onValueChange={handleModelSelectChange}
413449
options={modelOptions}
414-
placeholder={placeholder}
450+
placeholder={restingPlaceholder}
415451
placeholderClassName={placeholderClassName}
416452
searchable
417453
selectedLabel={stableSelectedModelLabel}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import { getDiscoveredPersonaModelOptions } from "./usePersonaModelDiscovery.ts";
5+
6+
function response(overrides = {}) {
7+
return {
8+
agentName: "mock",
9+
agentVersion: "0.0.0",
10+
models: [],
11+
agentDefaultModel: null,
12+
selectedModel: null,
13+
supportsSwitching: true,
14+
...overrides,
15+
};
16+
}
17+
18+
test("merges the harness's own 'default' catalog entry into the canonical default row", () => {
19+
const options = getDiscoveredPersonaModelOptions(
20+
response({
21+
models: [
22+
{ id: "default", name: null, description: null },
23+
{ id: "claude-opus-4-8", name: null, description: null },
24+
{ id: "claude-sonnet-5", name: null, description: null },
25+
],
26+
}),
27+
"",
28+
);
29+
30+
// Exactly one default row (id ""), and no raw "default" entry remains.
31+
assert.deepEqual(
32+
options.map((option) => option.id),
33+
["", "claude-opus-4-8", "claude-sonnet-5"],
34+
);
35+
assert.equal(options[0].label, "Default model");
36+
});
37+
38+
test("default row shows the harness-reported current model when available", () => {
39+
const options = getDiscoveredPersonaModelOptions(
40+
response({
41+
agentDefaultModel: "gpt-5.5[high]",
42+
models: [
43+
{ id: "gpt-5.5", name: "GPT-5.5", description: null },
44+
{ id: "gpt-5.4", name: "GPT-5.4", description: null },
45+
],
46+
}),
47+
"",
48+
);
49+
50+
assert.equal(options[0].id, "");
51+
assert.equal(options[0].label, "Default model (gpt-5.5[high])");
52+
assert.deepEqual(
53+
options.slice(1).map((option) => option.id),
54+
["gpt-5.5", "gpt-5.4"],
55+
);
56+
});
57+
58+
test("the 'default' id match is case-insensitive and trimmed", () => {
59+
const options = getDiscoveredPersonaModelOptions(
60+
response({
61+
models: [
62+
{ id: " Default ", name: null, description: null },
63+
{ id: "claude-sonnet-5", name: null, description: null },
64+
],
65+
}),
66+
"",
67+
);
68+
69+
assert.deepEqual(
70+
options.map((option) => option.id),
71+
["", "claude-sonnet-5"],
72+
);
73+
});
74+
75+
test("explicit-model providers get no default row (no harness default entry)", () => {
76+
const options = getDiscoveredPersonaModelOptions(
77+
response({
78+
models: [
79+
{ id: "goose-claude-4-6-sonnet", name: null, description: null },
80+
],
81+
}),
82+
"anthropic",
83+
);
84+
85+
assert.deepEqual(
86+
options.map((option) => option.id),
87+
["goose-claude-4-6-sonnet"],
88+
);
89+
});
90+
91+
test("relay-mesh keeps its automatic routing default row", () => {
92+
const options = getDiscoveredPersonaModelOptions(
93+
response({
94+
models: [{ id: "llama-3", name: "Llama 3", description: null }],
95+
}),
96+
"relay-mesh",
97+
);
98+
99+
assert.equal(options[0].id, "");
100+
assert.equal(options[0].label, "Default (auto)");
101+
});
102+
103+
test("returns null when discovery is unsupported or empty", () => {
104+
assert.equal(
105+
getDiscoveredPersonaModelOptions(
106+
response({ supportsSwitching: false }),
107+
"",
108+
),
109+
null,
110+
);
111+
assert.equal(getDiscoveredPersonaModelOptions(null, ""), null);
112+
});

‎desktop/src/features/agents/ui/usePersonaModelDiscovery.ts‎

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,57 @@ function stableModelDiscoveryEnvKey(envVars: EnvVarsValue): string {
2525
);
2626
}
2727

28-
function getDiscoveredPersonaModelOptions(
28+
/**
29+
* True when a harness catalog entry is the harness's own "use my default"
30+
* row (e.g. Claude Code ships a literal `default` model id). Such entries
31+
* mean the same thing as leaving the model unset, so the UI merges them
32+
* into the single canonical default row instead of showing two rows for
33+
* one idea.
34+
*/
35+
function isHarnessDefaultModelEntry(model: { id: string }) {
36+
return model.id.trim().toLowerCase() === "default";
37+
}
38+
39+
export function getDiscoveredPersonaModelOptions(
2940
response: AgentModelsResponse | null,
3041
provider: string,
3142
): readonly PersonaModelOption[] | null {
3243
if (!response?.supportsSwitching || response.models.length === 0) {
3344
return null;
3445
}
3546

36-
const defaultModelOption = providerRequiresExplicitModel(provider)
37-
? []
38-
: [
39-
{
40-
id: "",
41-
label:
42-
provider === "relay-mesh"
43-
? "Default (auto)"
44-
: response.agentDefaultModel?.trim()
45-
? `Default model (${response.agentDefaultModel})`
46-
: "Default model",
47-
},
48-
];
47+
// One row per idea: the harness's own default catalog entry (if any) is
48+
// absorbed into the canonical default row. Selecting it keeps the stored
49+
// model unset — behaviorally identical, and it avoids two saved states
50+
// ("default" vs unset) that mean the same thing.
51+
const explicitModels = response.models.filter(
52+
(model) => !isHarnessDefaultModelEntry(model),
53+
);
54+
const harnessDefaultEntry = response.models.find(isHarnessDefaultModelEntry);
55+
const agentDefaultModel = response.agentDefaultModel?.trim();
56+
57+
const defaultModelOption =
58+
providerRequiresExplicitModel(provider) && harnessDefaultEntry === undefined
59+
? []
60+
: [
61+
{
62+
id: "",
63+
label:
64+
provider === "relay-mesh"
65+
? "Default (auto)"
66+
: agentDefaultModel
67+
? `Default model (${agentDefaultModel})`
68+
: "Default model",
69+
},
70+
];
71+
72+
if (explicitModels.length === 0 && defaultModelOption.length === 0) {
73+
return null;
74+
}
4975

5076
return [
5177
...defaultModelOption,
52-
...response.models.map((model) => ({
78+
...explicitModels.map((model) => ({
5379
id: model.id,
5480
label: model.name?.trim() || model.id,
5581
})),

0 commit comments

Comments
 (0)