From e98eb5e7552d922442ce0ed6f4a6dc6955dc16fc Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sun, 6 Dec 2026 04:16:43 +0800 Subject: [PATCH] fix(agents): start a new task with the agent the composer shows after its agent was removed (#8289) After the selected agent was removed, the composer fell back to the first agent but Start still sent the removed id and failed with "unknown agent". Start and option changes now resolve the agent like the composer. --- .../agents/composerSubmission.test.tsx | 10 +++++++++ src/features/agents/store.ts | 21 ++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/features/agents/composerSubmission.test.tsx b/src/features/agents/composerSubmission.test.tsx index 4533037562..bfd588138e 100644 --- a/src/features/agents/composerSubmission.test.tsx +++ b/src/features/agents/composerSubmission.test.tsx @@ -160,6 +160,16 @@ const paths = [ { name: "new task", key: HOME, send: () => startTask(), mock: backend.create }, ]; +describe("new task agent", () => { + it("starts with the agent the composer shows when the draft names a removed agent", async () => { + updateDraft({ provider: "removed-agent" }); + updateComposer(HOME, { ...emptyDraft(), text: "hello" }); + backend.create.mockResolvedValueOnce(ok(task("created"))); + await startTask(); + expect(backend.create).toHaveBeenCalledWith(expect.objectContaining({ provider: "codex" })); + }); +}); + describe.each(paths)("$name acknowledgement", (path) => { function begin() { const response = deferred(); diff --git a/src/features/agents/store.ts b/src/features/agents/store.ts index 7cba4677a1..be834f4f75 100644 --- a/src/features/agents/store.ts +++ b/src/features/agents/store.ts @@ -483,11 +483,8 @@ export function draftModelSettings( } export function setDraftOption(id: string, value: string) { - const { draft, providers } = useAgents.getState(); - const config = draftConfig( - providers.find((p) => p.id === draft.provider), - draft, - ); + const { draft } = useAgents.getState(); + const config = draftConfig(selectedProvider(), draft); const model = config.find((o) => o.category === "model")?.current; const target = config.find((o) => o.id === id); if (model && target && isPerModelOption(target)) { @@ -1601,15 +1598,15 @@ export async function startTask( projectRoot: string | null = null, worktreePath?: string | null, ): Promise { - const { draft, providers } = useAgents.getState(); + const { draft } = useAgents.getState(); const composer = composerDraft(HOME); if (!canSend(composer)) return; const started = generation; const command = shellCommand(composer); - const options = draftConfig( - providers.find((p) => p.id === draft.provider), - draft, - ); + // The agent the composer shows: a draft naming a removed agent falls back to the first one. + const provider = selectedProvider(); + const providerId = provider?.id ?? draft.provider; + const options = draftConfig(provider, draft); if ( options.some( (o) => @@ -1620,7 +1617,7 @@ export async function startTask( ) return; const model = options.find((o) => o.category === "model")?.current; - const defaults = providerDefaults(draft.provider); + const defaults = providerDefaults(providerId); const config = options.flatMap((o) => { // An untouched Codex tier inherits the runtime's default; explicit Off must still be sent. const value = @@ -1636,7 +1633,7 @@ export async function startTask( commands.agentCreate({ projectRoot, prompt: promptOf(HOME, composer), - provider: draft.provider, + provider: providerId, config, isolation, base: isolation === "worktree" && !reusedWorktree ? draft.base : null,