Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function pendingBase(
prompt: "",
linkedIssues: [],
linkedPR: null,
agentId: null,
...overrides,
};
}
Expand Down Expand Up @@ -121,9 +122,12 @@ describe("buildForkAgentLaunch", () => {
expect(build).toBeNull();
});

test("prompt-only → terminal launch via default agent (claude)", async () => {
test("selected claude agent → terminal launch", async () => {
const build = await buildForkAgentLaunch({
pending: pendingBase({ prompt: "refactor the auth middleware" }),
pending: pendingBase({
prompt: "refactor the auth middleware",
agentId: "claude",
}),
attachments: undefined,
agentConfigs,
});
Expand All @@ -140,6 +144,7 @@ describe("buildForkAgentLaunch", () => {
const build = await buildForkAgentLaunch({
pending: pendingBase({
prompt: "do it",
agentId: "claude",
linkedIssues: [
{
source: "internal",
Expand All @@ -158,7 +163,7 @@ describe("buildForkAgentLaunch", () => {

test("attachments produce disk-ready bytes + matching names", async () => {
const build = await buildForkAgentLaunch({
pending: pendingBase({ prompt: "fix" }),
pending: pendingBase({ prompt: "fix", agentId: "claude" }),
attachments: [
{
data: "data:text/plain;base64,AQID", // [1,2,3]
Expand All @@ -178,21 +183,19 @@ describe("buildForkAgentLaunch", () => {
});

test("chat agent → chat launch with initialPrompt + files", async () => {
const chatOnlyConfigs = agentConfigs.map((c) =>
c.id === "superset-chat"
? { ...c, enabled: true }
: { ...c, enabled: false },
);
const build = await buildForkAgentLaunch({
pending: pendingBase({ prompt: "help me refactor" }),
pending: pendingBase({
prompt: "help me refactor",
agentId: "superset-chat",
}),
attachments: [
{
data: "data:text/plain;base64,AQID",
mediaType: "text/plain",
filename: "logs.txt",
},
],
agentConfigs: chatOnlyConfigs,
agentConfigs,
});
expect(build?.kind).toBe("chat");
if (build?.kind !== "chat") throw new Error("wrong kind");
Expand All @@ -207,10 +210,28 @@ describe("buildForkAgentLaunch", () => {
test("disabled agent → null", async () => {
const disabled = agentConfigs.map((c) => ({ ...c, enabled: false }));
const build = await buildForkAgentLaunch({
pending: pendingBase({ prompt: "hi" }),
pending: pendingBase({ prompt: "hi", agentId: "claude" }),
attachments: undefined,
agentConfigs: disabled,
});
expect(build).toBeNull();
});

test("agentId null → null (no user selection, no launch)", async () => {
const build = await buildForkAgentLaunch({
pending: pendingBase({ prompt: "hi", agentId: null }),
attachments: undefined,
agentConfigs,
});
expect(build).toBeNull();
});

test('agentId "none" → null (explicit opt-out)', async () => {
const build = await buildForkAgentLaunch({
pending: pendingBase({ prompt: "hi", agentId: "none" }),
attachments: undefined,
agentConfigs,
});
expect(build).toBeNull();
});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { isTerminalAgentDefinition } from "@superset/shared/agent-catalog";
import {
type AgentDefinitionId,
isTerminalAgentDefinition,
} from "@superset/shared/agent-catalog";
import {
buildPromptCommandFromAgentConfig,
getCommandFromAgentConfig,
getFallbackAgentId,
indexResolvedAgentConfigs,
type ResolvedAgentConfig,
} from "@superset/shared/agent-settings";
Expand Down Expand Up @@ -40,7 +42,7 @@ export interface ResolvedPrContent {
export interface BuildForkAgentLaunchInputs {
pending: Pick<
PendingWorkspaceRow,
"projectId" | "prompt" | "linkedIssues" | "linkedPR"
"projectId" | "prompt" | "linkedIssues" | "linkedPR" | "agentId"
>;
attachments: LoadedAttachment[] | undefined;
agentConfigs: ResolvedAgentConfig[];
Expand Down Expand Up @@ -124,7 +126,7 @@ export type PendingLaunchBuild =
export async function buildForkAgentLaunch(
inputs: BuildForkAgentLaunchInputs,
): Promise<PendingLaunchBuild | null> {
const agentId = getFallbackAgentId(inputs.agentConfigs);
const agentId = resolveAgentId(inputs.pending.agentId, inputs.agentConfigs);
if (!agentId) return null;

const agentConfig = indexResolvedAgentConfigs(inputs.agentConfigs).get(
Expand Down Expand Up @@ -162,6 +164,17 @@ export async function buildForkAgentLaunch(
return buildChatLaunch(spec, agentConfig);
}

function resolveAgentId(
selected: string | null,
configs: ResolvedAgentConfig[],
): AgentDefinitionId | null {
if (!selected || selected === "none") return null;
const match = indexResolvedAgentConfigs(configs).get(
selected as AgentDefinitionId,
);
return match?.enabled ? match.id : null;
}

// ---------------------------------------------------------------------------
// Terminal launch assembly
// ---------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function makePending(
runSetupScript: true,
terminalLaunch: null,
chatLaunch: null,
agentId: null,
...overrides,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ export interface DispatchForkLaunchInputs {
workspaceId: string;
pending: Pick<
PendingWorkspaceRow,
"projectId" | "prompt" | "linkedIssues" | "linkedPR" | "hostTarget"
| "projectId"
| "prompt"
| "linkedIssues"
| "linkedPR"
| "hostTarget"
| "agentId"
>;
loadedAttachments: LoadedAttachment[] | undefined;
agentConfigs: ResolvedAgentConfig[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export function PromptGroup({
});

// ── Submit (fork) ────────────────────────────────────────────────
const createWorkspace = useSubmitWorkspace(projectId);
const createWorkspace = useSubmitWorkspace(projectId, selectedAgent);
const handleSubmit = useCallback(
(files: SubmitAttachment[] = []) => {
if (needsSetup) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useCallback } from "react";
import { storeAttachments } from "renderer/lib/pending-attachment-store";
import { useCollections } from "renderer/routes/_authenticated/providers/CollectionsProvider";
import { useDashboardNewWorkspaceDraft } from "../../../../../DashboardNewWorkspaceDraftContext";
import type { WorkspaceCreateAgent } from "../../types";
import { resolveNames } from "./resolveNames";

export interface SubmitAttachment {
Expand All @@ -24,7 +25,10 @@ export interface SubmitAttachment {
* the library clears provider state + revokes blob URLs *before*
* invoking onSubmit, so the ref is stale by the time we'd see it.
*/
export function useSubmitWorkspace(projectId: string | null) {
export function useSubmitWorkspace(
projectId: string | null,
selectedAgent: WorkspaceCreateAgent,
) {
const navigate = useNavigate();
const { closeAndResetDraft, draft } = useDashboardNewWorkspaceDraft();
const collections = useCollections();
Expand Down Expand Up @@ -83,6 +87,7 @@ export function useSubmitWorkspace(projectId: string | null) {
linkedPR: draft.linkedPR,
hostTarget: draft.hostTarget,
attachmentCount: files.length,
agentId: selectedAgent,
status: "creating",
error: null,
workspaceId: null,
Expand All @@ -93,6 +98,13 @@ export function useSubmitWorkspace(projectId: string | null) {
closeAndResetDraft();
void navigate({ to: `/pending/${pendingId}` as string });
},
[closeAndResetDraft, collections, draft, navigate, projectId],
[
closeAndResetDraft,
collections,
draft,
navigate,
projectId,
selectedAgent,
],
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ export const pendingWorkspaceSchema = z.object({
linkedIssues: z.array(pendingLinkedIssueSchema).default([]),
linkedPR: pendingLinkedPRSchema.nullable().default(null),
attachmentCount: z.number().int().default(0),
// User-selected agent from the modal. `"none"` = user explicitly chose not
// to launch; any other string = `AgentDefinitionId`; null = legacy rows
// (predating this field), treated as "use fallback".
agentId: z.string().nullable().default(null),
Comment on lines +188 to +191
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Schema comment contradicts actual runtime behavior

The comment says null is "treated as 'use fallback'" but resolveAgentId does the opposite — !selected (which is true for null) immediately returns null, skipping the launch entirely. A legacy row with agentId: null and a prompt will show the "Workspace created but no agent launched" warning toast, not fall back to Claude as the comment implies. The comment should reflect the actual no-op semantics.

Suggested change
// User-selected agent from the modal. `"none"` = user explicitly chose not
// to launch; any other string = `AgentDefinitionId`; null = legacy rows
// (predating this field), treated as "use fallback".
agentId: z.string().nullable().default(null),
// User-selected agent from the modal. `"none"` = user explicitly chose not
// to launch; any other string = `AgentDefinitionId`; null = legacy rows
// (predating this field), treated as no-op (launch is skipped).
agentId: z.string().nullable().default(null),
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/renderer/routes/_authenticated/providers/CollectionsProvider/dashboardSidebarLocal/schema.ts
Line: 188-191

Comment:
**Schema comment contradicts actual runtime behavior**

The comment says `null` is "treated as 'use fallback'" but `resolveAgentId` does the opposite — `!selected` (which is true for `null`) immediately returns `null`, skipping the launch entirely. A legacy row with `agentId: null` and a prompt will show the "Workspace created but no agent launched" warning toast, not fall back to Claude as the comment implies. The comment should reflect the actual no-op semantics.

```suggestion
	// User-selected agent from the modal. `"none"` = user explicitly chose not
	// to launch; any other string = `AgentDefinitionId`; null = legacy rows
	// (predating this field), treated as no-op (launch is skipped).
	agentId: z.string().nullable().default(null),
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +188 to +191
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Comment contradicts actual null-handling behavior.

The comment states null = legacy rows (predating this field), treated as "use fallback", but downstream resolveAgentId in buildForkAgentLaunch.ts returns null when selected is null, which causes buildForkAgentLaunch to return null (no launch). This matches the PR's stated behavior ("existing in-flight pending rows with null agentId … no-op the launch rather than crashing") but directly contradicts "use fallback" in this schema comment.

Recommend aligning the comment with the actual no-op behavior so future maintainers don't expect a fallback resolution path.

📝 Proposed comment fix
-	// User-selected agent from the modal. `"none"` = user explicitly chose not
-	// to launch; any other string = `AgentDefinitionId`; null = legacy rows
-	// (predating this field), treated as "use fallback".
+	// User-selected agent from the modal. `"none"` = user explicitly chose not
+	// to launch; any other string = `AgentDefinitionId`; null = legacy rows
+	// (predating this field) — treated the same as `"none"` (no-op launch on
+	// retry) rather than falling back to a default agent.
 	agentId: z.string().nullable().default(null),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// User-selected agent from the modal. `"none"` = user explicitly chose not
// to launch; any other string = `AgentDefinitionId`; null = legacy rows
// (predating this field), treated as "use fallback".
agentId: z.string().nullable().default(null),
// User-selected agent from the modal. `"none"` = user explicitly chose not
// to launch; any other string = `AgentDefinitionId`; null = legacy rows
// (predating this field) — treated the same as `"none"` (no-op launch on
// retry) rather than falling back to a default agent.
agentId: z.string().nullable().default(null),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@apps/desktop/src/renderer/routes/_authenticated/providers/CollectionsProvider/dashboardSidebarLocal/schema.ts`
around lines 188 - 191, The schema comment for agentId is misleading: instead of
saying "null = legacy rows ... treated as 'use fallback'", update the comment to
state that null indicates legacy/in-flight rows that should be treated as a
no-op (no launch) because resolveAgentId returns null and buildForkAgentLaunch
will return null; reference the agentId field in this file and the
resolveAgentId and buildForkAgentLaunch functions so maintainers understand the
actual downstream behavior.


// fork + checkout (irrelevant for adopt — worktree already exists).
runSetupScript: z.boolean().default(true),
Expand Down
Loading