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
6 changes: 5 additions & 1 deletion packages/cli/src/acp/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,11 @@ async function loadCatalog(client: OpenCodeClient, cwd: string): Promise<Catalog
client.skill.list({ location }),
])
const models = modelResult.data.filter((model) => model.enabled)
const defaultModel = defaultResult.data ?? models[0]
const preferred = defaultResult.data
// Parallel reads can straddle initialization; select only from this model list.
const defaultModel = preferred
? models.find((model) => model.providerID === preferred.providerID && model.id === preferred.id)
: models[0]
const agents = agentResult.data.filter((agent) => agent.mode !== "subagent" && !agent.hidden)
const defaultAgent = agents.find((agent) => agent.mode === "primary") ?? agents[0]
if (defaultModel && defaultAgent) {
Expand Down
36 changes: 36 additions & 0 deletions packages/cli/test/acp/service-directory.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, test } from "bun:test"
import type { McpServer, SessionConfigOption } from "@agentclientprotocol/sdk"
import { makeACPFixture, makeSession, secondModel } from "./service-fixture"
import { flattenSelectOptions, requireSelectOption } from "./subprocess"

describe("acp service directory behavior", () => {
test("creates sessions from a catalog shared by concurrent callers in the same cwd", async () => {
Expand Down Expand Up @@ -72,6 +73,41 @@ describe("acp service directory behavior", () => {
])
})

test.each(["empty", "missing the default"])(
"retries when the model list is %s but the default is ready",
async (initial) => {
await using fixture = makeACPFixture({
fetch(request, context) {
if (
request.path === "/api/model" &&
context.requests.filter((request) => request.path === "/api/model").length === 1
) {
return Response.json({
location: {
directory: "/workspace",
project: { id: "global", directory: "/workspace", canonical: "/workspace" },
},
data: initial === "empty" ? [] : [secondModel],
})
}
if (request.method === "POST" && request.path === "/api/session") {
return Response.json({ data: makeSession("ses_ready") })
}
return undefined
},
})

const session = await fixture.service.newSession({ cwd: "/workspace", mcpServers: [] })
const model = requireSelectOption(session.configOptions, "model")
const choices = flattenSelectOptions(model).map((option) => option.value)

expect(choices).toContain("test/second-model")
expect(choices).toContain("test/test-model")
expect(model.currentValue).toBe("test/test-model")
expect(fixture.requests.filter((request) => request.path === "/api/model")).toHaveLength(2)
},
)

test("does not cache a failed catalog load", async () => {
let modelCalls = 0
await using fixture = makeACPFixture({
Expand Down
Loading