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.
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-12-06 04:16:43 +08:00
1 джерело c341799768
коміт e98eb5e755
2 files changed
+19 -12

No files matched your search

+10
Переглянути файл
@@ -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();
+9 -12
Переглянути файл
@@ -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<void> {
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,