Skip to content

Commit 37bc962

Browse files
wpfleger96npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
andauthored
fix(desktop): always start agents and hide unavailable mesh (#1860)
Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
1 parent ab5cbc3 commit 37bc962

13 files changed

Lines changed: 195 additions & 229 deletions

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ type AgentDefinitionDialogProps = {
8585
onSubmit: (
8686
input: CreatePersonaInput | UpdatePersonaInput,
8787
) => Promise<unknown>;
88-
/** Rendered in the footer’s left slot. */
89-
createFooterSlot?: React.ReactNode;
9088
/** Rendered below the form fields in create mode only ("Where to run"). */
9189
createRunSection?: React.ReactNode;
9290
/** Extra create-mode submit gate (e.g. incomplete provider config). */
@@ -115,7 +113,6 @@ export function AgentDefinitionDialog({
115113
runtimesLoading = false,
116114
onOpenChange,
117115
onSubmit,
118-
createFooterSlot,
119116
createRunSection,
120117
createSubmitBlocked = false,
121118
createRunOnMesh = false,
@@ -661,7 +658,7 @@ export function AgentDefinitionDialog({
661658
title={title}
662659
footer={
663660
<div className="flex w-full items-center justify-between gap-3">
664-
<div className="flex min-h-9 items-center">{createFooterSlot}</div>
661+
<div className="flex min-h-9 items-center" />
665662

666663
<div className="flex items-center gap-2">
667664
<Button

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

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ import type {
66
ManagedAgent,
77
UpdatePersonaInput,
88
} from "@/shared/api/types";
9-
import { Switch } from "@/shared/ui/switch";
109
import type { BackendIntent } from "../lib/instanceInputForDefinition";
11-
import {
12-
definitionCreateDialogState,
13-
intentForStartToggle,
14-
type AgentCreateIntent,
15-
} from "./agentCreateIntent";
10+
import type { AgentCreateIntent } from "./agentCreateIntent";
1611
import type { EditAgentFocusTarget } from "@/features/agents/openEditAgentEvent";
12+
import { useMeshAvailability } from "@/features/mesh-compute/hooks/useMeshAvailability";
1713
import { AgentInstanceEditDialog } from "./AgentInstanceEditDialog";
1814
import { createPersonaDialogState } from "./personaDialogState";
1915
import { AgentDefinitionDialog } from "./AgentDefinitionDialog";
@@ -79,10 +75,11 @@ type AgentDialogProps =
7975
/**
8076
* Unified entry point (Phase 1B.2/1B.3b/1B.3c): routes an intent to the form
8177
* that owns it. The definition family renders AgentDefinitionDialog — create
82-
* mode adds a "start after create" toggle, definition-edit passes the caller's
83-
* PersonaDialogState-derived props through unchanged (edit/duplicate/import).
84-
* instance-edit renders AgentInstanceEditDialog (persistent mount + `open`
85-
* toggle — its reset lifecycle is keyed on [open, agent.pubkey]).
78+
* mode always starts the agent and includes a WhereToRunSection;
79+
* definition-edit passes the caller's PersonaDialogState-derived props
80+
* through unchanged (edit/duplicate/import). instance-edit renders
81+
* AgentInstanceEditDialog (persistent mount + `open` toggle — its reset
82+
* lifecycle is keyed on [open, agent.pubkey]).
8683
*/
8784
export function AgentDialog(props: AgentDialogProps) {
8885
if (props.mode === "instance-edit") {
@@ -112,47 +109,44 @@ function AgentCreateDialogRouter({
112109
runtimesLoading,
113110
onSubmitDefinition,
114111
}: AgentDialogCreateProps) {
115-
const [startAfterCreate, setStartAfterCreate] = React.useState(true);
116112
const [runDraft, setRunDraft] = React.useState(emptyWhereToRunDraft);
117-
// Stable identity across toggle flips — AgentDefinitionDialog re-initializes its
118-
// fields whenever `initialValues` changes.
113+
const { availability: meshAvailability } = useMeshAvailability();
114+
const meshUnavailable =
115+
meshAvailability != null && !meshAvailability.available;
116+
// The cleanup effect below resets the persisted draft after this render. The
117+
// submit path must not wait for that effect: it uses the local fallback
118+
// immediately when a selected mesh target disappears.
119+
const effectiveRunDraft =
120+
meshUnavailable && runDraft.runOn === "mesh"
121+
? emptyWhereToRunDraft
122+
: runDraft;
123+
// Persist the fallback after the synchronous guard has made the render safe.
124+
// This cleanup keeps a future availability recovery from restoring an invalid
125+
// mesh selection.
126+
React.useEffect(() => {
127+
if (meshUnavailable && runDraft.runOn === "mesh") {
128+
setRunDraft(emptyWhereToRunDraft);
129+
}
130+
}, [meshUnavailable, runDraft.runOn]);
119131
const initialValues = React.useMemo(
120132
() => createPersonaDialogState().initialValues,
121133
[],
122134
);
123135

124-
const copy = definitionCreateDialogState(startAfterCreate);
136+
const copy = createPersonaDialogState();
125137

126138
return (
127139
<AgentDefinitionDialog
128-
createFooterSlot={
129-
<label
130-
className="flex cursor-pointer items-center gap-2 text-sm text-muted-foreground"
131-
htmlFor="agent-dialog-start-toggle"
132-
>
133-
<Switch
134-
checked={startAfterCreate}
135-
data-testid="agent-dialog-start-toggle"
136-
disabled={isDefinitionPending}
137-
id="agent-dialog-start-toggle"
138-
onCheckedChange={setStartAfterCreate}
139-
/>
140-
Start agent after creation
141-
</label>
142-
}
143140
createRunSection={
144-
// "Where to run" is instance state: with the start toggle off no
145-
// instance exists, so the section disappears instead of dangling.
146-
startAfterCreate ? (
147-
<WhereToRunSection
148-
draft={runDraft}
149-
isPending={isDefinitionPending}
150-
onDraftChange={setRunDraft}
151-
/>
152-
) : null
141+
<WhereToRunSection
142+
draft={runDraft}
143+
isPending={isDefinitionPending}
144+
meshAvailability={meshAvailability}
145+
onDraftChange={setRunDraft}
146+
/>
153147
}
154-
createSubmitBlocked={!canSubmitWhereToRun(runDraft, startAfterCreate)}
155-
createRunOnMesh={startAfterCreate && runDraft.runOn === "mesh"}
148+
createSubmitBlocked={!canSubmitWhereToRun(effectiveRunDraft)}
149+
createRunOnMesh={effectiveRunDraft.runOn === "mesh"}
156150
description={copy.description}
157151
error={definitionError}
158152
initialValues={initialValues}
@@ -161,8 +155,8 @@ function AgentCreateDialogRouter({
161155
onSubmit={async (input) => {
162156
const submitted = await onSubmitDefinition(
163157
input,
164-
intentForStartToggle(startAfterCreate),
165-
resolveBackendIntent(runDraft, startAfterCreate),
158+
"definition_start",
159+
resolveBackendIntent(effectiveRunDraft),
166160
);
167161
if (submitted) {
168162
onOpenChange(false);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function AgentsView() {
6363
// biome-ignore lint/correctness/useExhaustiveDependencies: mount-only shortcut subscription; openUnifiedCreate only calls stable setState-backed callbacks
6464
React.useEffect(() => {
6565
// The app-wide "create agent" shortcut routes to the unified definition
66-
// flow (B5): one create path, with the start-after-create toggle on.
66+
// flow (B5): one create path, always starting the agent after creation.
6767
if (consumePendingOpenCreateAgent()) {
6868
openUnifiedCreate();
6969
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as React from "react";
44
import { useBackendProvidersQuery } from "@/features/agents/hooks";
55
import { RelayMeshAgentSection } from "@/features/mesh-compute/ui/RelayMeshAgentSection";
66
import { probeBackendProvider } from "@/shared/api/tauri";
7+
import type { MeshAvailability } from "@/shared/api/tauriMesh";
78

89
import { ProviderConfigFields } from "./ProviderConfigFields";
910
import { emptyWhereToRunDraft, type WhereToRunDraft } from "./whereToRunIntent";
@@ -16,11 +17,9 @@ import { emptyWhereToRunDraft, type WhereToRunDraft } from "./whereToRunIntent";
1617
* (`resolveBackendIntent`) and gates the submit button
1718
* (`canSubmitWhereToRun`).
1819
*
19-
* Only rendered while the start-after-create toggle is ON — "where to run"
20-
* is instance state, and with the toggle off no instance exists. The parent
21-
* discards the draft at submit when the toggle is off (the stale-intent
22-
* guard), so a selection made before toggling off can never silently ride
23-
* a definition-only create.
20+
* Always rendered in the create flow — agents are always started after
21+
* creation. The parent owns the availability-flip guard so visibility and the
22+
* submit path share one snapshot; this section only renders that snapshot.
2423
*
2524
* Honest-copy note: unlike the legacy create dialog, the mesh preset never
2625
* overwrites the definition's fields — only the minted instance carries the
@@ -30,10 +29,12 @@ import { emptyWhereToRunDraft, type WhereToRunDraft } from "./whereToRunIntent";
3029
export function WhereToRunSection({
3130
draft,
3231
isPending,
32+
meshAvailability,
3333
onDraftChange,
3434
}: {
3535
draft: WhereToRunDraft;
3636
isPending: boolean;
37+
meshAvailability: MeshAvailability | null;
3738
onDraftChange: (next: WhereToRunDraft) => void;
3839
}) {
3940
const backendProvidersQuery = useBackendProvidersQuery();
@@ -174,6 +175,7 @@ export function WhereToRunSection({
174175
{!isProviderMode ? (
175176
<>
176177
<RelayMeshAgentSection
178+
availability={meshAvailability}
177179
current={{
178180
// The definition's own fields are never overwritten by the mesh
179181
// preset — only the minted instance carries it — so the override
Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import assert from "node:assert/strict";
22
import test from "node:test";
33

4-
import {
5-
definitionCreateDialogState,
6-
intentForStartToggle,
7-
resolveCreateIntent,
8-
} from "./agentCreateIntent.ts";
9-
import { createPersonaDialogState } from "./personaDialogState.ts";
4+
import { resolveCreateIntent } from "./agentCreateIntent.ts";
105

116
test("resolveCreateIntent defaults to quick-start for un-migrated callers", () => {
127
// PersonaDialog's duplicate path calls handleSubmit without an intent until
@@ -19,25 +14,3 @@ test("resolveCreateIntent passes explicit intents through", () => {
1914
assert.equal(resolveCreateIntent("definition"), "definition");
2015
assert.equal(resolveCreateIntent("definition_start"), "definition_start");
2116
});
22-
23-
test("intentForStartToggle maps the toggle to definition-family intents", () => {
24-
assert.equal(intentForStartToggle(true), "definition_start");
25-
assert.equal(intentForStartToggle(false), "definition");
26-
});
27-
28-
test("toggle-on dialog copy is exactly the legacy create copy", () => {
29-
assert.deepEqual(
30-
definitionCreateDialogState(true),
31-
createPersonaDialogState(),
32-
);
33-
});
34-
35-
test("toggle-off dialog copy differs only in description", () => {
36-
const legacy = createPersonaDialogState();
37-
const definitionOnly = definitionCreateDialogState(false);
38-
assert.equal(definitionOnly.title, legacy.title);
39-
assert.equal(definitionOnly.submitLabel, legacy.submitLabel);
40-
assert.deepEqual(definitionOnly.initialValues, legacy.initialValues);
41-
assert.notEqual(definitionOnly.description, legacy.description);
42-
assert.match(definitionOnly.description, /without starting/);
43-
});
Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
import {
2-
createPersonaDialogState,
3-
type PersonaDialogState,
4-
} from "./personaDialogState";
5-
61
/**
72
* What the user is creating from the unified create dialog.
83
*
@@ -23,30 +18,3 @@ export function resolveCreateIntent(
2318
): AgentCreateIntent {
2419
return intent ?? "definition_start";
2520
}
26-
27-
/** Maps the "Start agent after create" toggle to a definition-family intent. */
28-
export function intentForStartToggle(
29-
startAfterCreate: boolean,
30-
): AgentCreateIntent {
31-
return startAfterCreate ? "definition_start" : "definition";
32-
}
33-
34-
/**
35-
* Dialog copy for the definition-family create dialog. The toggle-on copy is
36-
* derived from `createPersonaDialogState` so it cannot drift from the legacy
37-
* create flow it replaces.
38-
*/
39-
export function definitionCreateDialogState(
40-
startAfterCreate: boolean,
41-
): PersonaDialogState {
42-
const legacy = createPersonaDialogState();
43-
if (startAfterCreate) {
44-
return legacy;
45-
}
46-
47-
return {
48-
...legacy,
49-
description:
50-
"Create an agent without starting it. You can start it from its card at any time.",
51-
};
52-
}

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -241,36 +241,6 @@ test("localMode_gate_bypassed_for_meshMode", () => {
241241
);
242242
});
243243

244-
test("localMode_gate_active_when_mesh_selected_but_startAfterCreate_off", () => {
245-
// Regression: when a user selects relay-mesh then turns off "Start agent
246-
// after creation", the run draft is hidden and the backend intent is
247-
// discarded — the saved definition has no mesh backing. The submit gate
248-
// must require provider/model in this case.
249-
//
250-
// AgentDialog.tsx computes: createRunOnMesh = startAfterCreate && runDraft.runOn === "mesh"
251-
// With startAfterCreate=false that evaluates to false regardless of runDraft,
252-
// so computeLocalModeGate receives useMesh:false and must enforce the gate.
253-
const result = computeLocalModeGate({
254-
envVars: {},
255-
isProviderMode: false,
256-
model: "",
257-
provider: "",
258-
runtimeId: "buzz-agent",
259-
useMesh: false, // = startAfterCreate(false) && runDraft.runOn("mesh")
260-
});
261-
262-
assert.equal(
263-
result.satisfied,
264-
false,
265-
"gate must NOT be bypassed when startAfterCreate is off, even if runDraft was set to mesh",
266-
);
267-
assert.deepEqual(
268-
result.missingNormalizedFields,
269-
["provider", "model"],
270-
"both provider and model must be flagged as missing for the stale-mesh path",
271-
);
272-
});
273-
274244
// ── IMPORTANT 2: requiredEnvKeys surfaces correctly ───────────────────────
275245

276246
test("localMode_requiredEnvKeys_surfaces_anthropicKey", () => {

0 commit comments

Comments
 (0)