Skip to content

Commit 0b30d07

Browse files
atishpatelWorkerBeeGPTclaude
committed
fix(agents): require the visible provider for runtime-less definitions
Address wesbillman's blocking review: the Customize provider gate keyed off runtimeSupportsLlmProviderSelection(runtime), which is false for a blank runtime. But a runtime-less legacy/builtin definition still exposes the provider picker via blankRuntimeModelProviderEditable, so Save could persist `provider: undefined` despite the visible picker (also reachable after picking "No preference"). Gate the provider requirement on the field-visibility capability runtimeCanChooseLlmProvider instead — the same predicate that drives whether the picker is shown — for providerIsRequired, customAiPairSatisfied, and the submit-block reason. Codex/Claude stay unaffected (picker hidden -> provider not required), preserving Ian's original fix. Adds a runtime-less edit regression test (e2e case 11, seeded with no available runtime so the dialog does not auto-seed a runtime) plus a policy unit test; verified the e2e fails without the gate change. Co-authored-by: Atish Patel <[email protected]> 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 08fdefa commit 0b30d07

4 files changed

Lines changed: 180 additions & 17 deletions

File tree

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -416,25 +416,31 @@ export function AgentDefinitionDialog({
416416
secretEnvVar: topLevelSecretEnvVar,
417417
value: apiKeyValue,
418418
} = apiKeyFieldState;
419-
// Provider required-ness is a static property of the runtime — it does not
420-
// change based on whether the field is currently filled. Using the dynamic
421-
// missingNormalizedFields check would flip the asterisk off once a value is
422-
// selected, which is incoherent (required means required, not "required until
423-
// 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.
424427
const providerIsRequired =
425-
aiConfigurationMode === "custom" &&
426-
runtimeSupportsLlmProviderSelection(runtime);
428+
aiConfigurationMode === "custom" && runtimeCanChooseLlmProvider;
427429
const modelFieldVisible =
428430
runtime.trim().length > 0 || blankRuntimeModelProviderEditable;
429431
// Customize pins a complete provider/model pair. Shared compute's concrete
430432
// automatic-routing value is the only valid non-model-id choice.
431433
const isExplicitModelRequired = aiConfigurationMode === "custom";
432-
// Codex/Claude hide the provider picker (they drive their own provider), so
433-
// Customize must not require a provider there — only Buzz Agent/Goose do.
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.
434440
const customAiPairSatisfied = agentAiConfigurationModeSatisfied(
435441
aiConfigurationMode,
436442
{ provider, model },
437-
runtimeSupportsLlmProviderSelection(runtime),
443+
runtimeCanChooseLlmProvider,
438444
);
439445
const isCreateMode = Boolean(initialValues && !("id" in initialValues));
440446
const selectedRuntimeIsAvailable =
@@ -474,7 +480,7 @@ export function AgentDefinitionDialog({
474480
localModeMissingFields: localModeGate.missingNormalizedFields,
475481
localModeMissingEnvKeys: localModeGate.missingEnvKeys,
476482
customAiPairSatisfied,
477-
runtimeNeedsProviderSelection: runtimeSupportsLlmProviderSelection(runtime),
483+
runtimeNeedsProviderSelection: runtimeCanChooseLlmProvider,
478484
customProviderEmpty: provider.trim().length === 0,
479485
customModelEmpty: model.trim().length === 0,
480486
});

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,30 @@ test("Buzz Agent/Goose Customize still requires both provider and model", () =>
9191
);
9292
});
9393

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+
94118
test("Defaults clears provider and model together", () => {
95119
assert.deepEqual(
96120
agentAiConfigurationPairForMode({

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ export function agentAiConfigurationPairForMode({
3333
/**
3434
* Whether a Customize (explicit) AI pair is complete enough to submit.
3535
*
36-
* `needsProviderSelection` mirrors `runtimeSupportsLlmProviderSelection`:
37-
* Buzz Agent / Goose expose a provider picker and require both provider and
38-
* model, while Codex / Claude drive their own provider and hide the field, so
39-
* requiring a provider there would gate Save on a value the user can never set
40-
* (the create/edit "Save stays disabled" regression). It defaults to `true` so
41-
* existing callers keep the provider+model requirement.
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.
4245
*/
4346
export function agentAiConfigurationModeSatisfied(
4447
mode: AgentAiConfigurationMode,

‎desktop/tests/e2e/global-agent-config-screenshots.spec.ts‎

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,41 @@ const CATALOG_WITH_CODEX = [
127127
},
128128
];
129129

130+
// A catalog where every runtime is unavailable (not installed). With nothing
131+
// available, getDefaultPersonaRuntime returns null, so the definition dialog's
132+
// runtime auto-seed effect is a no-op and a runtime-less definition keeps its
133+
// empty runtime — the precondition for blankRuntimeModelProviderEditable.
134+
const CATALOG_NONE_AVAILABLE = [
135+
{
136+
id: "buzz-agent",
137+
label: "Buzz Agent",
138+
avatar_url: "",
139+
availability: "not_installed",
140+
command: "buzz-agent",
141+
binary_path: null,
142+
default_args: [],
143+
mcp_command: "buzz-dev-mcp",
144+
install_hint: "Ships with the Buzz desktop app.",
145+
install_instructions_url: "https://github.com/block/buzz",
146+
can_auto_install: false,
147+
underlying_cli_path: null,
148+
},
149+
{
150+
id: "goose",
151+
label: "Goose",
152+
avatar_url: "",
153+
availability: "not_installed",
154+
command: "goose",
155+
binary_path: null,
156+
default_args: [],
157+
mcp_command: null,
158+
install_hint: "Install Goose to use this runtime.",
159+
install_instructions_url: "https://github.com/block/goose",
160+
can_auto_install: false,
161+
underlying_cli_path: null,
162+
},
163+
];
164+
130165
test.describe("global agent config screenshots", () => {
131166
test.use({ viewport: { width: 1280, height: 900 } });
132167

@@ -465,4 +500,99 @@ test.describe("global agent config screenshots", () => {
465500
path: `${SHOTS}/10-edit-codex-custom-model-save-enabled-no-reason.png`,
466501
});
467502
});
503+
504+
// Shot 11: the inverse of Ian's fix, and wesbillman's blocking review point.
505+
// A runtime-LESS legacy/builtin definition (no runtime, but a saved model)
506+
// still EXPOSES the provider picker via blankRuntimeModelProviderEditable, so
507+
// an empty provider must keep Save DISABLED. The gate must key off the field's
508+
// visibility (runtimeCanChooseLlmProvider), not the raw runtime capability —
509+
// otherwise Save persists `provider: undefined` despite the visible picker.
510+
// A global provider/model default keeps localMode satisfied, so the ONLY thing
511+
// that can block Save here is the Customize-pair provider gate (step 7), which
512+
// is exactly what this regression pins.
513+
test("11-edit-runtime-less-provider-required-save-blocked", async ({
514+
page,
515+
}) => {
516+
const PERSONA_ID = "persona-runtime-less-edit-e2e";
517+
await installMockBridge(page, {
518+
// No runtime is available, so getDefaultPersonaRuntime returns null and
519+
// the dialog does NOT auto-seed a runtime on open — the runtime-less
520+
// definition stays runtime-less, which is the only state where
521+
// blankRuntimeModelProviderEditable exposes the provider picker.
522+
acpRuntimesCatalog: CATALOG_NONE_AVAILABLE,
523+
// Global defaults satisfy localMode, so any block is the pair gate alone.
524+
globalAgentConfig: {
525+
provider: "anthropic",
526+
model: "claude-opus-4-5",
527+
env_vars: { ANTHROPIC_API_KEY: "sk-ant-global-value" },
528+
},
529+
managedAgents: [
530+
{
531+
pubkey: TEST_IDENTITIES.tyler.pubkey,
532+
name: "Legacy Editor",
533+
personaId: PERSONA_ID,
534+
status: "stopped",
535+
channelNames: ["agents"],
536+
},
537+
],
538+
personas: [
539+
{
540+
id: PERSONA_ID,
541+
displayName: "Legacy Editor",
542+
systemPrompt: "You are the runtime-less edit-mode e2e persona.",
543+
// Runtime-less definition with a saved model and NO provider — the
544+
// picker is editable-without-runtime, so the provider stays required.
545+
runtime: null,
546+
model: "claude-opus-4-5",
547+
provider: null,
548+
},
549+
],
550+
});
551+
552+
// Agents view → persona-grouped agent card → Edit quick action.
553+
await page.goto("/");
554+
await page.getByTestId("open-agents-view").click();
555+
const agentButton = page.getByRole("button", {
556+
name: "Legacy Editor agent profile",
557+
});
558+
await expect(agentButton).toBeVisible({ timeout: 10_000 });
559+
await agentButton.click();
560+
await expect(page.getByTestId("user-profile-panel")).toBeVisible({
561+
timeout: 10_000,
562+
});
563+
await page.getByTestId("user-profile-edit-agent").click();
564+
565+
// Confirm the real EDIT dialog, seeded from the persona.
566+
await expect(page.getByTestId("persona-dialog")).toBeVisible({
567+
timeout: 10_000,
568+
});
569+
await expect(page.locator("#persona-display-name")).toHaveValue(
570+
"Legacy Editor",
571+
);
572+
await expect(page.getByTestId("persona-dialog-submit")).toHaveText(
573+
/Save changes/,
574+
);
575+
576+
// The provider picker IS visible (runtime-less editable definition) …
577+
await expect(page.locator("#persona-llm-provider")).toBeVisible({
578+
timeout: 10_000,
579+
});
580+
// … so the empty provider must block Save …
581+
await expect(page.getByTestId("persona-dialog-submit")).toBeDisabled({
582+
timeout: 10_000,
583+
});
584+
// … and the reason must be the Customize-pair provider gate, not the
585+
// global-defaults gate (which would say "Settings → AI defaults").
586+
const reason = page.getByTestId("persona-dialog-submit-reason");
587+
await expect(reason).toBeVisible({ timeout: 10_000 });
588+
await expect(reason).toContainText("Select a provider");
589+
await expect(reason).not.toContainText("Settings → AI defaults");
590+
591+
await waitForAnimations(page);
592+
593+
const dialog = page.getByRole("dialog");
594+
await dialog.screenshot({
595+
path: `${SHOTS}/11-edit-runtime-less-provider-required-save-blocked.png`,
596+
});
597+
});
468598
});

0 commit comments

Comments
 (0)