Skip to content

Commit 8eb7680

Browse files
author
npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67d
committed
fix(desktop): stop the create-agent provider config probe from erasing keystrokes
The WhereToRunSection probe effect depended on the whole run draft, so every keystroke in a provider config field re-fired the effect, re-probed the provider binary, and — because each probe result is a fresh object — kept re-probing in a loop for as long as the dialog sat on a provider. Each resolution then reset providerConfig to schema defaults, erasing whatever the user had typed. Fields without a schema default (the Kubernetes 'Kubeconfig context') read as completely dead. Fix: - Probe once per provider selection, keyed on the provider's stable binary path — not the draft, not the provider object (a providers-query refresh must not reprobe an unchanged selection). - Resolve with latest-state semantics via useEffectEvent + a new applyProbeResult helper that merges schema defaults BENEATH the current providerConfig, so a probe landing after the user typed can never clobber in-flight input. Tests: - unit: applyProbeResult merge semantics (defaults under typed values, user-cleared fields stay cleared, schema-less results). - e2e (new where-to-run-config.spec.ts, red-first verified against the unfixed component): typing sticks + exactly one probe per selection, probe-gated form render with a slow probe, provider->local->provider reset. Mock bridge gains backendProviders / backendProviderProbeResult / backendProviderProbeDelayMs seams. Reported by Tyler in buzz-remote-agents (channel 29414326, thread db76677a): could not type into the Kubeconfig context field. Co-authored-by: npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67d <011987e296fd5006292d2f930b574be47c7801048d1983c46c425d3c95f0cffd@buzz.block.builderlab.xyz> Signed-off-by: npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67d <011987e296fd5006292d2f930b574be47c7801048d1983c46c425d3c95f0cffd@buzz.block.builderlab.xyz>
1 parent 318fbf8 commit 8eb7680

7 files changed

Lines changed: 321 additions & 23 deletions

File tree

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export default defineConfig({
132132
"**/harness-management.spec.ts",
133133
"**/harness-catalog-screenshots.spec.ts",
134134
"**/inline-custom-harness.spec.ts",
135+
"**/where-to-run-config.spec.ts",
135136
"**/huddle-transcription.spec.ts",
136137
],
137138
use: {

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

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { useBackendProvidersQuery } from "@/features/agents/hooks";
55
import { probeBackendProvider } from "@/shared/api/tauri";
66

77
import { ProviderConfigFields } from "./ProviderConfigFields";
8-
import { emptyWhereToRunDraft, type WhereToRunDraft } from "./whereToRunIntent";
8+
import {
9+
applyProbeResult,
10+
emptyWhereToRunDraft,
11+
type WhereToRunDraft,
12+
} from "./whereToRunIntent";
913

1014
/** Optional remote-backend selector. Buzz shared compute is an LLM provider, not a run destination. */
1115
export function WhereToRunSection({
@@ -26,32 +30,37 @@ export function WhereToRunSection({
2630
[backendProviders, draft.runOn],
2731
);
2832

33+
// Latest-state seam for probe resolution: an Effect Event always sees the
34+
// draft as it is *now*. Without this, the probe promise closes over the
35+
// draft from probe start, and anything typed while the probe was in flight
36+
// gets thrown away when it resolves (a second, subtler Typewriter Eraser).
37+
const applyProbe = React.useEffectEvent(
38+
(result: Awaited<ReturnType<typeof probeBackendProvider>>) => {
39+
onDraftChange(applyProbeResult(draft, result));
40+
},
41+
);
42+
43+
// Probe once per provider *selection*, keyed on the provider's stable
44+
// path — never on the draft. Depending on the draft made every keystroke
45+
// refire the probe, and each resolution reset providerConfig to schema
46+
// defaults, which erased what the user was typing (the Typewriter Eraser)
47+
// and spawned the provider binary in a loop for as long as the dialog was
48+
// open. Keying on the path (not the provider object) also keeps a
49+
// providers-query refresh from reprobing an unchanged selection.
50+
const selectedBinaryPath = isProviderMode
51+
? (selectedBackendProvider?.binaryPath ?? null)
52+
: null;
2953
React.useEffect(() => {
30-
if (!isProviderMode || !selectedBackendProvider) {
54+
if (!selectedBinaryPath) {
3155
setProbeError(null);
3256
return;
3357
}
3458
let cancelled = false;
3559
setProbeError(null);
36-
void probeBackendProvider(selectedBackendProvider.binaryPath)
60+
void probeBackendProvider(selectedBinaryPath)
3761
.then((result) => {
3862
if (cancelled) return;
39-
const defaults: Record<string, string> = {};
40-
const properties =
41-
(result.config_schema as Record<string, unknown> | undefined)
42-
?.properties ?? {};
43-
for (const [key, property] of Object.entries(properties) as [
44-
string,
45-
Record<string, unknown>,
46-
][]) {
47-
if (property.default != null)
48-
defaults[key] = String(property.default);
49-
}
50-
onDraftChange({
51-
...draft,
52-
probedProvider: result,
53-
providerConfig: defaults,
54-
});
63+
applyProbe(result);
5564
})
5665
.catch((error: unknown) => {
5766
if (!cancelled) {
@@ -61,7 +70,7 @@ export function WhereToRunSection({
6170
return () => {
6271
cancelled = true;
6372
};
64-
}, [draft, isProviderMode, onDraftChange, selectedBackendProvider]);
73+
}, [selectedBinaryPath]);
6574

6675
if (backendProviders.length === 0) return null;
6776

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
22
import test from "node:test";
33

44
import {
5+
applyProbeResult,
56
canSubmitWhereToRun,
67
emptyWhereToRunDraft,
78
providerConfigComplete,
@@ -59,3 +60,72 @@ test("provider draft resolves with coerced config values", () => {
5960
config: { region: "us", size: 3 },
6061
});
6162
});
63+
64+
// ── applyProbeResult: probe resolution must merge, not overwrite ─────────────
65+
//
66+
// Pins the seam that fixed the "Typewriter Eraser" (agent-create dialog's
67+
// provider config fields losing keystrokes): a probe resolution prefills
68+
// schema defaults *beneath* the user's in-flight config, never over it. The
69+
// effect in WhereToRunSection keys probing on the provider's binary path, so
70+
// the only probe writes that reach providerConfig are the ones pinned here.
71+
72+
const probeWithDefaults = {
73+
ok: true,
74+
config_schema: {
75+
properties: {
76+
context: { type: "string", title: "Kubeconfig context" },
77+
namespace: { type: "string", default: "buzz-agents-x1y2z3" },
78+
inactivity_seconds: { type: "number", default: 1800 },
79+
},
80+
required: ["namespace"],
81+
},
82+
};
83+
84+
const unprobedDraft = {
85+
...emptyWhereToRunDraft,
86+
runOn: "kubernetes",
87+
};
88+
89+
test("probe resolution prefills schema defaults on a fresh draft", () => {
90+
const next = applyProbeResult(unprobedDraft, probeWithDefaults);
91+
assert.equal(next.probedProvider, probeWithDefaults);
92+
assert.deepEqual(next.providerConfig, {
93+
namespace: "buzz-agents-x1y2z3",
94+
inactivity_seconds: "1800",
95+
});
96+
});
97+
98+
test("probe resolution keeps user-typed values over schema defaults", () => {
99+
const typed = {
100+
...unprobedDraft,
101+
providerConfig: { context: "prod-us-west", namespace: "my-ns" },
102+
};
103+
const next = applyProbeResult(typed, probeWithDefaults);
104+
assert.deepEqual(next.providerConfig, {
105+
context: "prod-us-west",
106+
namespace: "my-ns",
107+
inactivity_seconds: "1800",
108+
});
109+
});
110+
111+
test("probe resolution keeps a user-cleared field cleared", () => {
112+
// "" is a deliberate user state — coerceConfigValues drops empty numerics
113+
// and required-gating treats "" as incomplete; the probe must not undo it.
114+
const cleared = { ...unprobedDraft, providerConfig: { namespace: "" } };
115+
const next = applyProbeResult(cleared, probeWithDefaults);
116+
assert.equal(next.providerConfig.namespace, "");
117+
});
118+
119+
test("a schema-less probe result records the probe without touching config", () => {
120+
const typed = { ...unprobedDraft, providerConfig: { context: "abc" } };
121+
const next = applyProbeResult(typed, { ok: true });
122+
assert.deepEqual(next.providerConfig, { context: "abc" });
123+
assert.deepEqual(next.probedProvider, { ok: true });
124+
});
125+
126+
test("probe resolution preserves unrelated draft fields", () => {
127+
assert.equal(
128+
applyProbeResult(unprobedDraft, probeWithDefaults).runOn,
129+
"kubernetes",
130+
);
131+
});

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,35 @@ export const emptyWhereToRunDraft: WhereToRunDraft = {
1515
probedProvider: null,
1616
};
1717

18+
/**
19+
* Fold a completed probe into the draft the user has *now* — not the draft
20+
* that existed when the probe started. Schema defaults prefill only the keys
21+
* the user has not touched: anything already in `providerConfig` (typed while
22+
* the probe was in flight) wins over the default. Overwriting instead of
23+
* merging is the "Typewriter Eraser" bug — every probe resolution silently
24+
* erased in-flight keystrokes.
25+
*/
26+
export function applyProbeResult(
27+
current: WhereToRunDraft,
28+
result: BackendProviderProbeResult,
29+
): WhereToRunDraft {
30+
const defaults: Record<string, string> = {};
31+
const properties =
32+
(result.config_schema as Record<string, unknown> | undefined)?.properties ??
33+
{};
34+
for (const [key, property] of Object.entries(properties) as [
35+
string,
36+
Record<string, unknown>,
37+
][]) {
38+
if (property.default != null) defaults[key] = String(property.default);
39+
}
40+
return {
41+
...current,
42+
probedProvider: result,
43+
providerConfig: { ...defaults, ...current.providerConfig },
44+
};
45+
}
46+
1847
export function providerConfigComplete(draft: WhereToRunDraft): boolean {
1948
if (draft.runOn === "local") return true;
2049
if (!draft.probedProvider) return false;

‎desktop/src/testing/e2eBridge.ts‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,11 @@ type E2eConfig = {
507507
* returning a catalog.
508508
*/
509509
discoverAgentModelsError?: string;
510+
// Backend provider mocks for the create-agent "Run on" section. See
511+
// tests/helpers/bridge.ts:MockBridgeOptions for semantics.
512+
backendProviders?: Array<{ id: string; binaryPath: string }>;
513+
backendProviderProbeResult?: Record<string, unknown>;
514+
backendProviderProbeDelayMs?: number;
510515
};
511516
relayHttpUrl?: string;
512517
relayWsUrl?: string;
@@ -11064,9 +11069,22 @@ export function maybeInstallE2eTauriMocks() {
1106411069
activeConfig,
1106511070
);
1106611071
case "discover_backend_providers":
11067-
return [];
11068-
case "probe_backend_provider":
11069-
return { ok: false, error: "mock: no providers available" };
11072+
return activeConfig?.mock?.backendProviders ?? [];
11073+
case "probe_backend_provider": {
11074+
const probeDelayMs =
11075+
activeConfig?.mock?.backendProviderProbeDelayMs ?? 0;
11076+
if (probeDelayMs > 0) {
11077+
await new Promise((resolve) =>
11078+
window.setTimeout(resolve, probeDelayMs),
11079+
);
11080+
}
11081+
return (
11082+
activeConfig?.mock?.backendProviderProbeResult ?? {
11083+
ok: false,
11084+
error: "mock: no providers available",
11085+
}
11086+
);
11087+
}
1107011088
case "discover_managed_agent_prereqs":
1107111089
return handleDiscoverManagedAgentPrereqs(
1107211090
payload as Parameters<typeof handleDiscoverManagedAgentPrereqs>[0],
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/**
2+
* E2E spec for the create-agent "Run on" provider config fields.
3+
*
4+
* Pins the fix for the "Typewriter Eraser": WhereToRunSection's probe effect
5+
* used to depend on the whole draft, so every keystroke re-probed the
6+
* provider and every probe resolution reset providerConfig to schema
7+
* defaults — typing into a defaultless field (the k8s "Kubeconfig context")
8+
* looked completely dead, and the provider binary respawned in a loop.
9+
*
10+
* Covers:
11+
* - typing into a defaultless provider field sticks, and the provider is
12+
* probed exactly once for the selection (not once per keystroke)
13+
* - the config form is gated on probe resolution (no half-rendered form),
14+
* and defaults prefill exactly once when a slow probe lands
15+
* - switching provider → local → provider re-probes and resets cleanly
16+
*
17+
* The stale-closure merge on probe resolution (defaults beneath in-flight
18+
* typing) is unreachable through this UI because the fields render only
19+
* after the probe resolves; it is pinned at the unit level in
20+
* whereToRunIntent.test.mjs (applyProbeResult).
21+
*/
22+
import { expect, test } from "@playwright/test";
23+
24+
import { installMockBridge } from "../helpers/bridge";
25+
26+
type Page = import("@playwright/test").Page;
27+
28+
const PROVIDER = {
29+
id: "kubernetes",
30+
binaryPath: "/mock/buzz-backend-kubernetes",
31+
};
32+
33+
const PROBE_RESULT = {
34+
ok: true,
35+
name: "kubernetes",
36+
version: "0.0.0-mock",
37+
config_schema: {
38+
type: "object",
39+
properties: {
40+
context: {
41+
type: "string",
42+
title: "Kubeconfig context",
43+
description: "Context from your kubeconfig.",
44+
},
45+
namespace: {
46+
type: "string",
47+
title: "Namespace",
48+
default: "buzz-agents-mock01",
49+
},
50+
},
51+
required: ["namespace"],
52+
},
53+
};
54+
55+
async function probeInvocations(page: Page): Promise<number> {
56+
return page.evaluate(
57+
() =>
58+
(
59+
window as Window & { __BUZZ_E2E_COMMANDS__?: string[] }
60+
).__BUZZ_E2E_COMMANDS__?.filter(
61+
(command) => command === "probe_backend_provider",
62+
).length ?? 0,
63+
);
64+
}
65+
66+
/** Open the create-agent dialog and select the mocked provider in "Run on". */
67+
async function openCreateDialogOnProvider(page: Page) {
68+
await page.goto("/", { waitUntil: "domcontentloaded" });
69+
await page.getByTestId("open-agents-view").click();
70+
await page.getByTestId("new-agent-card").click();
71+
await page.getByRole("menuitem", { name: "Create agent" }).click();
72+
const dialog = page.getByTestId("persona-dialog");
73+
await expect(dialog).toBeVisible({ timeout: 10_000 });
74+
await dialog.locator("#agent-run-on").selectOption(PROVIDER.id);
75+
return dialog;
76+
}
77+
78+
test("typing into a defaultless provider field sticks and probes only once", async ({
79+
page,
80+
}) => {
81+
await installMockBridge(page, {
82+
backendProviders: [PROVIDER],
83+
backendProviderProbeResult: PROBE_RESULT,
84+
});
85+
const dialog = await openCreateDialogOnProvider(page);
86+
87+
const contextField = dialog.locator("#provider-cfg-context");
88+
await expect(contextField).toBeVisible({ timeout: 10_000 });
89+
// Defaults prefilled from the schema; context has none.
90+
await expect(dialog.locator("#provider-cfg-namespace")).toHaveValue(
91+
"buzz-agents-mock01",
92+
);
93+
await expect(contextField).toHaveValue("");
94+
95+
await contextField.pressSequentially("prod-us-west", { delay: 20 });
96+
await expect(contextField).toHaveValue("prod-us-west");
97+
98+
// One selection, one probe — keystrokes must not refire it.
99+
expect(await probeInvocations(page)).toBe(1);
100+
});
101+
102+
test("config fields render only after a slow probe resolves, with defaults", async ({
103+
page,
104+
}) => {
105+
// The fields are gated on the probe result (draft.probedProvider), which is
106+
// what makes mid-flight typing unreachable through the UI — the stale-probe
107+
// merge seam (applyProbeResult) is pinned at the unit level instead. This
108+
// spec holds the gate: no half-rendered form before the probe lands, and
109+
// defaults appear exactly once when it does.
110+
await installMockBridge(page, {
111+
backendProviders: [PROVIDER],
112+
backendProviderProbeResult: PROBE_RESULT,
113+
backendProviderProbeDelayMs: 1_000,
114+
});
115+
const dialog = await openCreateDialogOnProvider(page);
116+
117+
// Pre-resolution: the security warning is up, the form is not.
118+
await expect(dialog.getByText("will receive your agent")).toBeVisible();
119+
await expect(dialog.locator("#provider-cfg-context")).toHaveCount(0);
120+
121+
// Post-resolution: fields render with schema defaults prefilled.
122+
await expect(dialog.locator("#provider-cfg-context")).toBeVisible({
123+
timeout: 10_000,
124+
});
125+
await expect(dialog.locator("#provider-cfg-namespace")).toHaveValue(
126+
"buzz-agents-mock01",
127+
);
128+
expect(await probeInvocations(page)).toBe(1);
129+
});
130+
131+
test("provider → local → provider re-probes and resets the config", async ({
132+
page,
133+
}) => {
134+
await installMockBridge(page, {
135+
backendProviders: [PROVIDER],
136+
backendProviderProbeResult: PROBE_RESULT,
137+
});
138+
const dialog = await openCreateDialogOnProvider(page);
139+
140+
const contextField = dialog.locator("#provider-cfg-context");
141+
await expect(contextField).toBeVisible({ timeout: 10_000 });
142+
await contextField.fill("stale-value");
143+
144+
await dialog.locator("#agent-run-on").selectOption("local");
145+
await expect(contextField).toHaveCount(0);
146+
147+
await dialog.locator("#agent-run-on").selectOption(PROVIDER.id);
148+
await expect(dialog.locator("#provider-cfg-context")).toBeVisible({
149+
timeout: 10_000,
150+
});
151+
// Fresh selection = fresh draft: the stale value must not leak back.
152+
await expect(dialog.locator("#provider-cfg-context")).toHaveValue("");
153+
expect(await probeInvocations(page)).toBe(2);
154+
});

0 commit comments

Comments
 (0)