Skip to content

Commit 87dc4dc

Browse files
atishpatelWorkerBeeGPTclaude
authored
fix(agents): explain why Create/Save is disabled and fix Codex/Claude gate (#2050)
Signed-off-by: Atish Patel <[email protected]> Co-authored-by: WorkerBeeGPT <c5c455215c2506cb8ba776518cec804af62d3a0526e32d496a22072e395042b9@buzz> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
1 parent 79598bd commit 87dc4dc

8 files changed

Lines changed: 803 additions & 23 deletions

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

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
emptyPersonaBehaviorDraft,
3232
personaBehaviorDraftValid,
3333
} from "./personaBehaviorDraft";
34+
import { personaSubmitBlock } from "./personaSubmitBlock";
3435
import {
3536
AUTO_MODEL_DROPDOWN_VALUE,
3637
AUTO_PROVIDER_DROPDOWN_VALUE,
@@ -415,22 +416,31 @@ export function AgentDefinitionDialog({
415416
secretEnvVar: topLevelSecretEnvVar,
416417
value: apiKeyValue,
417418
} = apiKeyFieldState;
418-
// Provider required-ness is a static property of the runtime — it does not
419-
// change based on whether the field is currently filled. Using the dynamic
420-
// missingNormalizedFields check would flip the asterisk off once a value is
421-
// selected, which is incoherent (required means required, not "required until
422-
// satisfied"). runtimeSupportsLlmProviderSelection is the authoritative gate.
419+
// Provider required-ness is a static property of the field's visibility — it
420+
// does not change based on whether the field is currently filled. Using the
421+
// dynamic missingNormalizedFields check would flip the asterisk off once a
422+
// value is selected, which is incoherent (required means required, not
423+
// "required until satisfied"). runtimeCanChooseLlmProvider is the authoritative
424+
// gate: it tracks exactly when the provider picker is shown (Buzz Agent/Goose,
425+
// plus runtime-less legacy/builtin definitions), so the required marker never
426+
// drifts from whether Save actually needs a provider.
423427
const providerIsRequired =
424-
aiConfigurationMode === "custom" &&
425-
runtimeSupportsLlmProviderSelection(runtime);
428+
aiConfigurationMode === "custom" && runtimeCanChooseLlmProvider;
426429
const modelFieldVisible =
427430
runtime.trim().length > 0 || blankRuntimeModelProviderEditable;
428431
// Customize pins a complete provider/model pair. Shared compute's concrete
429432
// automatic-routing value is the only valid non-model-id choice.
430433
const isExplicitModelRequired = aiConfigurationMode === "custom";
434+
// Gate the provider requirement on the field's actual visibility, not the raw
435+
// runtime capability. Codex/Claude hide the provider picker (they drive their
436+
// own provider), so Customize must not require a provider there. But a
437+
// runtime-less legacy/builtin definition still exposes the picker via
438+
// blankRuntimeModelProviderEditable, so it must keep requiring a provider —
439+
// otherwise Save could persist `provider: undefined` despite the visible field.
431440
const customAiPairSatisfied = agentAiConfigurationModeSatisfied(
432441
aiConfigurationMode,
433442
{ provider, model },
443+
runtimeCanChooseLlmProvider,
434444
);
435445
const isCreateMode = Boolean(initialValues && !("id" in initialValues));
436446
const selectedRuntimeIsAvailable =
@@ -452,6 +462,29 @@ export function AgentDefinitionDialog({
452462
customAiPairSatisfied &&
453463
!isAvatarUploadPending;
454464

465+
// Derive the single, deterministic reason the action is disabled from the
466+
// same gate outputs that feed canSubmit — no policy is recomputed here.
467+
// Precedence mirrors canSubmit's term order, so the reason is `null` exactly
468+
// when the form can be submitted (transient Saving/Uploading states aside).
469+
const submitBlockReason = personaSubmitBlock({
470+
isPending,
471+
isAvatarUploadPending,
472+
displayNameEmpty: displayName.trim().length === 0,
473+
isCreateMode,
474+
runtimeChosen: runtime.trim().length > 0,
475+
runtimeAvailable: selectedRuntimeIsAvailable,
476+
createBackendBlocked: createSubmitBlocked,
477+
allowlistEmpty: !personaBehaviorDraftValid(behaviorDraft),
478+
aiConfigurationMode,
479+
localModeSatisfied,
480+
localModeMissingFields: localModeGate.missingNormalizedFields,
481+
localModeMissingEnvKeys: localModeGate.missingEnvKeys,
482+
customAiPairSatisfied,
483+
runtimeNeedsProviderSelection: runtimeCanChooseLlmProvider,
484+
customProviderEmpty: provider.trim().length === 0,
485+
customModelEmpty: model.trim().length === 0,
486+
});
487+
455488
// Merge global env as the base layer so credential keys satisfied via global
456489
// config are available to model discovery — same rationale as in AgentInstanceEditDialog.
457490
const envVarsForDiscovery = React.useMemo(
@@ -700,7 +733,16 @@ export function AgentDefinitionDialog({
700733
title={title}
701734
footer={
702735
<div className="flex w-full items-center justify-between gap-3">
703-
<div className="flex min-h-9 items-center" />
736+
<div className="flex min-h-9 items-center">
737+
{submitBlockReason ? (
738+
<p
739+
className="text-2xs text-muted-foreground"
740+
data-testid="persona-dialog-submit-reason"
741+
>
742+
{submitBlockReason}
743+
</p>
744+
) : null}
745+
</div>
704746

705747
<div className="flex items-center gap-2">
706748
<Button

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,71 @@ test("Customize requires a complete explicit pair", () => {
5050
);
5151
});
5252

53+
test("Codex/Claude Customize needs only a model, not the hidden provider", () => {
54+
// needsProviderSelection=false → the intentionally hidden provider must not
55+
// gate Save (the create/edit "Save stays disabled" regression).
56+
assert.equal(
57+
agentAiConfigurationModeSatisfied(
58+
"custom",
59+
{ provider: "", model: "gpt-5-codex" },
60+
false,
61+
),
62+
true,
63+
);
64+
// Still needs a model even when the provider is hidden.
65+
assert.equal(
66+
agentAiConfigurationModeSatisfied(
67+
"custom",
68+
{ provider: "", model: "" },
69+
false,
70+
),
71+
false,
72+
);
73+
});
74+
75+
test("Buzz Agent/Goose Customize still requires both provider and model", () => {
76+
assert.equal(
77+
agentAiConfigurationModeSatisfied(
78+
"custom",
79+
{ provider: "", model: "llama" },
80+
true,
81+
),
82+
false,
83+
);
84+
assert.equal(
85+
agentAiConfigurationModeSatisfied(
86+
"custom",
87+
{ provider: "databricks_v2", model: "llama" },
88+
true,
89+
),
90+
true,
91+
);
92+
});
93+
94+
test("runtime-less editable definition still requires the visible provider", () => {
95+
// A legacy/builtin definition with no runtime but a saved model exposes the
96+
// provider picker (runtimeCanChooseLlmProvider === true), so the dialog passes
97+
// needsProviderSelection=true here. An empty provider must NOT satisfy the
98+
// pair — otherwise Save persists `provider: undefined` despite the visible
99+
// picker (wesbillman's blocking review point).
100+
assert.equal(
101+
agentAiConfigurationModeSatisfied(
102+
"custom",
103+
{ provider: "", model: "claude-opus-4-5" },
104+
true,
105+
),
106+
false,
107+
);
108+
assert.equal(
109+
agentAiConfigurationModeSatisfied(
110+
"custom",
111+
{ provider: "anthropic", model: "claude-opus-4-5" },
112+
true,
113+
),
114+
true,
115+
);
116+
});
117+
53118
test("Defaults clears provider and model together", () => {
54119
assert.deepEqual(
55120
agentAiConfigurationPairForMode({

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,27 @@ export function agentAiConfigurationPairForMode({
3030
};
3131
}
3232

33+
/**
34+
* Whether a Customize (explicit) AI pair is complete enough to submit.
35+
*
36+
* `needsProviderSelection` reflects whether the provider picker is actually
37+
* shown to the user: Buzz Agent / Goose expose it (and runtime-less legacy /
38+
* builtin definitions do too), so both provider and model are required, while
39+
* Codex / Claude drive their own provider and hide the field, so requiring a
40+
* provider there would gate Save on a value the user can never set (the
41+
* create/edit "Save stays disabled" regression). Callers should pass the
42+
* field-visibility capability (`runtimeCanChooseLlmProvider`), not the raw
43+
* runtime capability, so the gate never diverges from the visible picker. It
44+
* defaults to `true` so existing callers keep the provider+model requirement.
45+
*/
3346
export function agentAiConfigurationModeSatisfied(
3447
mode: AgentAiConfigurationMode,
3548
pair: AgentAiConfigurationPair,
49+
needsProviderSelection = true,
3650
) {
37-
return (
38-
mode === "defaults" ||
39-
(pair.provider.trim().length > 0 && pair.model.trim().length > 0)
40-
);
51+
if (mode === "defaults") {
52+
return true;
53+
}
54+
const providerOk = !needsProviderSelection || pair.provider.trim().length > 0;
55+
return providerOk && pair.model.trim().length > 0;
4156
}
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import { personaSubmitBlock } from "./personaSubmitBlock.ts";
5+
6+
/** A fully valid, submittable form: personaSubmitBlock returns null. */
7+
function submittable(overrides = {}) {
8+
return {
9+
isPending: false,
10+
isAvatarUploadPending: false,
11+
displayNameEmpty: false,
12+
isCreateMode: true,
13+
runtimeChosen: true,
14+
runtimeAvailable: true,
15+
createBackendBlocked: false,
16+
allowlistEmpty: false,
17+
aiConfigurationMode: "defaults",
18+
localModeSatisfied: true,
19+
localModeMissingFields: [],
20+
localModeMissingEnvKeys: [],
21+
customAiPairSatisfied: true,
22+
runtimeNeedsProviderSelection: true,
23+
customProviderEmpty: false,
24+
customModelEmpty: false,
25+
...overrides,
26+
};
27+
}
28+
29+
test("a valid form has no disabled reason", () => {
30+
assert.equal(personaSubmitBlock(submittable()), null);
31+
});
32+
33+
test("missing name is reported first", () => {
34+
assert.equal(
35+
personaSubmitBlock(submittable({ displayNameEmpty: true })),
36+
"Enter a name for this agent.",
37+
);
38+
});
39+
40+
test("Buzz Agent + Use AI defaults with no global provider/model names the fix", () => {
41+
const reason = personaSubmitBlock(
42+
submittable({
43+
aiConfigurationMode: "defaults",
44+
localModeSatisfied: false,
45+
localModeMissingFields: ["provider", "model"],
46+
}),
47+
);
48+
assert.match(reason, /global AI defaults are incomplete/);
49+
assert.match(reason, /a provider and a model/);
50+
assert.match(reason, /Settings → AI defaults/);
51+
});
52+
53+
test("incomplete defaults also names missing credential keys", () => {
54+
const reason = personaSubmitBlock(
55+
submittable({
56+
localModeSatisfied: false,
57+
localModeMissingFields: [],
58+
localModeMissingEnvKeys: ["ANTHROPIC_API_KEY"],
59+
}),
60+
);
61+
assert.match(reason, /a value for ANTHROPIC_API_KEY/);
62+
});
63+
64+
test("the reason disappears once the blocking input is corrected", () => {
65+
const blocked = submittable({
66+
localModeSatisfied: false,
67+
localModeMissingFields: ["provider", "model"],
68+
});
69+
assert.notEqual(personaSubmitBlock(blocked), null);
70+
// Correct the blocking input: defaults now resolve.
71+
const corrected = {
72+
...blocked,
73+
localModeSatisfied: true,
74+
localModeMissingFields: [],
75+
};
76+
assert.equal(personaSubmitBlock(corrected), null);
77+
});
78+
79+
test("create mode requires a chosen, available runtime", () => {
80+
assert.equal(
81+
personaSubmitBlock(submittable({ runtimeChosen: false })),
82+
"Choose where this agent runs.",
83+
);
84+
assert.equal(
85+
personaSubmitBlock(submittable({ runtimeAvailable: false })),
86+
"The selected runtime isn't available on this machine.",
87+
);
88+
});
89+
90+
test("runtime gates do not apply in edit mode", () => {
91+
assert.equal(
92+
personaSubmitBlock(
93+
submittable({ isCreateMode: false, runtimeChosen: false }),
94+
),
95+
null,
96+
);
97+
});
98+
99+
test("empty allowlist is reported (create and edit)", () => {
100+
const reason = personaSubmitBlock(
101+
submittable({ isCreateMode: false, allowlistEmpty: true }),
102+
);
103+
assert.match(reason, /allowed sender/);
104+
});
105+
106+
test("Customize with an empty pair but satisfied global fallback points at the pair", () => {
107+
const reason = personaSubmitBlock(
108+
submittable({
109+
aiConfigurationMode: "custom",
110+
localModeSatisfied: true,
111+
customAiPairSatisfied: false,
112+
customProviderEmpty: true,
113+
customModelEmpty: true,
114+
}),
115+
);
116+
assert.match(reason, /Select a provider and a model/);
117+
assert.match(reason, /Use AI defaults/);
118+
});
119+
120+
test("Customize on Codex/Claude asks only for a model, never a provider", () => {
121+
const reason = personaSubmitBlock(
122+
submittable({
123+
aiConfigurationMode: "custom",
124+
customAiPairSatisfied: false,
125+
runtimeNeedsProviderSelection: false,
126+
customProviderEmpty: true,
127+
customModelEmpty: true,
128+
}),
129+
);
130+
assert.match(reason, /Select a model/);
131+
assert.doesNotMatch(reason, /provider/);
132+
});
133+
134+
test("precedence: a missing name outranks incomplete AI defaults", () => {
135+
assert.equal(
136+
personaSubmitBlock(
137+
submittable({
138+
displayNameEmpty: true,
139+
localModeSatisfied: false,
140+
localModeMissingFields: ["provider", "model"],
141+
}),
142+
),
143+
"Enter a name for this agent.",
144+
);
145+
});
146+
147+
test("in-flight save/upload shows no reason (the button label communicates it)", () => {
148+
assert.equal(
149+
personaSubmitBlock(
150+
submittable({ isPending: true, displayNameEmpty: true }),
151+
),
152+
null,
153+
);
154+
assert.equal(
155+
personaSubmitBlock(submittable({ isAvatarUploadPending: true })),
156+
null,
157+
);
158+
});

0 commit comments

Comments
 (0)