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,