Skip to content
Open
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
74 changes: 67 additions & 7 deletions core/config/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
}

/** Only difference between intermediate and final configs is the `models` array */
async function intermediateToFinalConfig({
export async function intermediateToFinalConfig({
config,
ide,
ideSettings,
Expand Down Expand Up @@ -372,15 +372,75 @@
llmLogger,
config.completionOptions,
);
if (llm) {
if (llm.providerName === "free-trial") {
warnAboutFreeTrial = true;
} else {
tabAutocompleteModels.push(llm);
if (!llm) {
return;
}

if (llm.model === "AUTODETECT") {
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: AUTODETECT expansion logic is duplicated from the earlier config.models loop, and drift already exists between the two copies (e.g., the pre-existing CustomLLMClass shadowing bug in config.models is avoided here, but other behavioral differences like free-trial inline filtering remain). Extract a shared helper to prevent future regressions.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At core/config/load.ts, line 379:

<comment>AUTODETECT expansion logic is duplicated from the earlier `config.models` loop, and drift already exists between the two copies (e.g., the pre-existing CustomLLMClass shadowing bug in `config.models` is avoided here, but other behavioral differences like free-trial inline filtering remain). Extract a shared helper to prevent future regressions.</comment>

<file context>
@@ -372,15 +372,75 @@ async function intermediateToFinalConfig({
+            return;
+          }
+
+          if (llm.model === "AUTODETECT") {
+            try {
+              const modelNames = await llm.listModels();
</file context>

try {
const modelNames = await llm.listModels();
const detectedModels = await Promise.all(
modelNames.map(async (modelName) => {
return await llmFromDescription(
{
...desc,
model: modelName,
title: modelName,
isFromAutoDetect: true,
},
ide.readFile.bind(ide),
getUriFromPath,
uniqueId,
ideSettings,
llmLogger,
copyOf(config.completionOptions),
);
}),
);
for (const expandedLlm of detectedModels.filter(
(x) => typeof x !== "undefined",
) as BaseLLM[]) {
if (expandedLlm.providerName === "free-trial") {
warnAboutFreeTrial = true;
} else {
tabAutocompleteModels.push(expandedLlm);
}
}
} catch (e) {
console.warn("Error listing models: ", e);
}
} else if (llm.providerName === "free-trial") {
warnAboutFreeTrial = true;
} else {
tabAutocompleteModels.push(llm);
}
} else {
tabAutocompleteModels.push(new CustomLLMClass(desc));
const llm = new CustomLLMClass({
...desc,
options: { ...desc.options, logger: llmLogger } as any,
});
if (llm.model === "AUTODETECT") {
try {
const modelNames = await llm.listModels();
const expanded = modelNames.map(
(modelName) =>
new CustomLLMClass({
...desc,
options: {
...desc.options,
model: modelName,
logger: llmLogger,
isFromAutoDetect: true,
},
}),
);
tabAutocompleteModels.push(...expanded);
} catch (e) {
console.warn("Error listing models: ", e);
}
} else {
tabAutocompleteModels.push(llm);
}
}
}),
);
Expand Down Expand Up @@ -464,7 +524,7 @@
}
if (name === "llm") {
const llm = models.find((model) => model.title === params?.modelTitle);
if (!llm) {

Check warning on line 527 in core/config/load.ts

View workflow job for this annotation

GitHub Actions / core-checks

Unexpected negated condition
errors.push({
fatal: false,
message: `Unknown reranking model ${params?.modelTitle}`,
Expand Down Expand Up @@ -560,7 +620,7 @@
id: `continue-mcp-server-${index + 1}`,
name: `MCP Server`,
requestOptions: mergeConfigYamlRequestOptions(
server.transport.type !== "stdio"

Check warning on line 623 in core/config/load.ts

View workflow job for this annotation

GitHub Actions / core-checks

Unexpected negated condition
? server.transport.requestOptions
: undefined,
config.requestOptions,
Expand Down
204 changes: 204 additions & 0 deletions core/config/load.vitest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";

import { Config, IDE, IdeInfo, IdeSettings, ILLMLogger } from "..";
import { BaseLLM } from "../llm";

import { intermediateToFinalConfig } from "./load";

vi.mock("../llm", () => ({
BaseLLM: class {},
}));

vi.mock("../llm/llms", () => ({
LLMClasses: [],
llmFromDescription: vi.fn(),
}));

vi.mock("../llm/llms/CustomLLM", () => ({
default: class {
constructor(public _opts: any) {}
},
}));

vi.mock("../llm/llms/llm", () => ({
LLMReranker: class {
constructor(public _llm: any) {}
},
}));

vi.mock("../llm/llms/TransformersJsEmbeddingsProvider", () => ({
default: class {
providerName = "transformers.js";
},
}));

// Avoid pulling in @continuedev/fetch (CJS follow-redirects) via the legacy
// slash-command barrel — we don't exercise slash commands in these tests.
vi.mock("../commands/slash/built-in-legacy", () => ({
getLegacyBuiltInSlashCommandFromDescription: vi.fn(() => undefined),
}));

// Avoid pulling in @continuedev/terminal-security (CJS shell-quote) via the
// tools barrel — we don't exercise tool definitions in these tests.
vi.mock("../tools", () => ({
getBaseToolDefinitions: () => [],
serializeTool: (t: any) => t,
}));

vi.mock("../context/mcp/json/loadJsonMcpConfigs", () => ({
loadJsonMcpConfigs: vi.fn().mockResolvedValue({ errors: [], mcpServers: [] }),
}));

vi.mock("./loadContextProviders", () => ({
loadConfigContextProviders: vi.fn().mockReturnValue({
providers: [],
errors: [],
}),
}));

let llmFromDescriptionMock: ReturnType<typeof vi.fn>;

beforeAll(async () => {
const { llmFromDescription } = await import("../llm/llms");
llmFromDescriptionMock = llmFromDescription as ReturnType<typeof vi.fn>;
});

function makeFakeLlm(overrides: Partial<BaseLLM> & { model: string }): BaseLLM {
return {
model: overrides.model,
title: overrides.title ?? overrides.model,
providerName: overrides.providerName ?? "openai",
listModels: overrides.listModels ?? (async () => []),
isFromAutoDetect: overrides.isFromAutoDetect ?? false,
} as unknown as BaseLLM;
}

function makeArgs(config: Partial<Config>) {
const ide: IDE = {
getWorkspaceDirs: async () => [],
readFile: async () => "",
getIdeSettings: async () => ({}) as IdeSettings,
showToast: async () => undefined,
} as unknown as IDE;

const baseConfig: Config = {
models: [],
...config,
} as unknown as Config;

return {
config: baseConfig,
ide,
ideSettings: {} as IdeSettings,
ideInfo: { ideType: "jetbrains" } as IdeInfo,
uniqueId: "test-unique-id",
llmLogger: { log: vi.fn() } as unknown as ILLMLogger,
workOsAccessToken: undefined,
loadPromptFiles: false,
};
}

describe("intermediateToFinalConfig — tabAutocompleteModel AUTODETECT expansion", () => {
beforeEach(() => {
llmFromDescriptionMock.mockReset();
});

it("expands an AUTODETECT tabAutocompleteModel into the provider's real model list (regression for #12400)", async () => {
llmFromDescriptionMock.mockImplementation(async (desc: any) => {
if (desc.model === "AUTODETECT") {
return makeFakeLlm({
model: "AUTODETECT",
providerName: "openai",
listModels: async () => ["model-a", "model-b"],
});
}
return makeFakeLlm({
model: desc.model,
title: desc.title ?? desc.model,
providerName: "openai",
isFromAutoDetect: desc.isFromAutoDetect,
});
});

const { config: result } = await intermediateToFinalConfig(
makeArgs({
tabAutocompleteModel: {
title: "auto",
provider: "openai",
model: "AUTODETECT",
apiBase: "https://example.invalid/v1",
} as any,
}),
);

const autocomplete = result.modelsByRole.autocomplete;
expect(autocomplete).toHaveLength(2);
expect(autocomplete.every((m) => m.model !== "AUTODETECT")).toBe(true);
expect(autocomplete.map((m) => m.model).sort()).toEqual([
"model-a",
"model-b",
]);
expect(autocomplete.every((m) => m.isFromAutoDetect === true)).toBe(true);
});

it("uses the configured model unchanged when it is not AUTODETECT", async () => {
llmFromDescriptionMock.mockImplementation(async (desc: any) =>
makeFakeLlm({
model: desc.model,
title: desc.title ?? desc.model,
providerName: "openai",
}),
);

const { config: result } = await intermediateToFinalConfig(
makeArgs({
tabAutocompleteModel: {
title: "auto",
provider: "openai",
model: "qwen-7b",
apiBase: "https://example.invalid/v1",
} as any,
}),
);

const autocomplete = result.modelsByRole.autocomplete;
expect(autocomplete).toHaveLength(1);
expect(autocomplete[0].model).toBe("qwen-7b");
});

it("drops the AUTODETECT placeholder when listModels() rejects (does not leak it into autocomplete)", async () => {
llmFromDescriptionMock.mockImplementation(async (desc: any) => {
if (desc.model === "AUTODETECT") {
return makeFakeLlm({
model: "AUTODETECT",
providerName: "openai",
listModels: async () => {
throw new Error("listModels failed");
},
});
}
return makeFakeLlm({
model: desc.model,
title: desc.title ?? desc.model,
providerName: "openai",
});
});

const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});

const { config: result } = await intermediateToFinalConfig(
makeArgs({
tabAutocompleteModel: {
title: "auto",
provider: "openai",
model: "AUTODETECT",
apiBase: "https://example.invalid/v1",
} as any,
}),
);

expect(result.modelsByRole.autocomplete).toHaveLength(0);
expect(warnSpy).toHaveBeenCalled();
warnSpy.mockRestore();
});
});
Loading