mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 00:03:13 +03:00
fix(acp): detach new and resumed sessions when setup fails (#52558)
This commit is contained in:
committed by
GitHub
Unverified
parent
4cb56a829e
commit
4a2c024ea7
@@ -196,7 +196,10 @@ export function make(input: {
|
||||
}),
|
||||
)
|
||||
const attached = yield* input.sessions.attach(created, params.cwd, params.mcpServers)
|
||||
return { sessionId: attached.id, configOptions: yield* currentOptions(attached) }
|
||||
return yield* currentOptions(attached).pipe(
|
||||
Effect.map((configOptions) => ({ sessionId: attached.id, configOptions })),
|
||||
Effect.onError(() => input.sessions.detach(attached.id)),
|
||||
)
|
||||
}),
|
||||
loadSession: Effect.fnUntraced(function* (params) {
|
||||
const directories = yield* ACPDirectories.parse(params.cwd, params.additionalDirectories)
|
||||
@@ -248,7 +251,10 @@ export function make(input: {
|
||||
const session = yield* getSession(params.sessionId, params.cwd)
|
||||
yield* ACPDirectories.activate(input.client, session, directories)
|
||||
const attached = yield* input.sessions.attach(session, session.location.directory, params.mcpServers ?? [])
|
||||
return { configOptions: yield* currentOptions(attached) }
|
||||
return yield* currentOptions(attached).pipe(
|
||||
Effect.map((configOptions) => ({ configOptions })),
|
||||
Effect.onError(() => input.sessions.detach(attached.id)),
|
||||
)
|
||||
}),
|
||||
closeSession: Effect.fnUntraced(function* (params) {
|
||||
yield* input.turn.close(params.sessionId)
|
||||
|
||||
@@ -205,6 +205,39 @@ describe("acp session lifecycle over the wire", () => {
|
||||
).toMatchObject({ code: -32602, data: { sessionId: "ses_loaded" } })
|
||||
})
|
||||
|
||||
test("detaches sessions whose new or resume fails after attaching", async () => {
|
||||
// A model without a name forces a crash building config options after attach.
|
||||
await using acp = await startWire({
|
||||
fetch: (request) =>
|
||||
request.path === "/api/model"
|
||||
? Response.json({
|
||||
location: { directory: "/workspace", project: { id: "global", directory: "/workspace" } },
|
||||
data: [testModel, { ...secondModel, name: null }],
|
||||
})
|
||||
: undefined,
|
||||
})
|
||||
acp.server.sessions.set("ses_resumed", makeSession("ses_resumed"))
|
||||
await acp.initialize()
|
||||
const existing = new Set(acp.server.sessions.keys())
|
||||
|
||||
expect(await rpcError(acp.newSession())).toMatchObject({ code: -32603 })
|
||||
const created = acp.server.sessions.keys().find((id) => !existing.has(id))
|
||||
if (!created) throw new Error("session/new did not create a server session")
|
||||
expect(
|
||||
await rpcError(acp.request("session/resume", { cwd: "/workspace", sessionId: "ses_resumed", mcpServers: [] })),
|
||||
).toMatchObject({ code: -32603 })
|
||||
const failed = [created, "ses_resumed"]
|
||||
|
||||
expect(
|
||||
await Promise.all(
|
||||
failed.map((sessionId) =>
|
||||
rpcError(acp.request("session/set_config_option", { sessionId, configId: "mode", value: "plan" })),
|
||||
),
|
||||
),
|
||||
).toMatchObject(failed.map((sessionId) => ({ code: -32602, data: { sessionId } })))
|
||||
expect(acp.server.sessions.has(created)).toBe(true)
|
||||
})
|
||||
|
||||
test("lists server-backed pages for the requested cwd", async () => {
|
||||
await using acp = await startWire()
|
||||
Array.from({ length: 101 }, (_, index) =>
|
||||
|
||||
Reference in New Issue
Block a user