@devries-cameron20 / t3code-1 / commits / 5d0de82dcb
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(opencode): OpenCode 1.x text generation deletes its scratch session (#28294)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Victor Vogel committed Nov 1, 2026 at 16:03 UTC 5d0de82dcb43856553de0b66486994daeba99cf2
2 files changed +43 -6
packages/provider-opencode/src/server/textGeneration.test.ts
+37 -6
@@ -28,7 +28,7 @@ const runtimeMock = {
28 authHeaders: [] as Array<string | null>,
29 closeCalls: [] as string[],
30 sessionCreateCalls: 0,
31 - abortCalls: [] as string[],
31 + sessionCalls: [] as string[],
32 onSessionCreate: undefined as ((signal?: AbortSignal) => Promise<never>) | undefined,
33 onPrompt: undefined as
34 | ((signal?: AbortSignal) => Promise<{ data: { parts: ReadonlyArray<unknown> } }>)
@@ -49,7 +49,7 @@ const runtimeMock = {
49 this.state.authHeaders.length = 0;
50 this.state.closeCalls.length = 0;
51 this.state.sessionCreateCalls = 0;
52 - this.state.abortCalls.length = 0;
52 + this.state.sessionCalls.length = 0;
53 this.state.onSessionCreate = undefined;
54 this.state.onPrompt = undefined;
55 this.state.onAbort = undefined;
@@ -121,10 +121,14 @@ const OpenCodeRuntimeTestDouble: OpenCodeRuntime.OpenCodeRuntime["Service"] = {
121 input: { readonly sessionID: string },
122 options?: { readonly signal?: AbortSignal },
123 ) => {
124 - runtimeMock.state.abortCalls.push(input.sessionID);
124 + runtimeMock.state.sessionCalls.push(`abort ${input.sessionID}`);
125 if (runtimeMock.state.onAbort) return runtimeMock.state.onAbort(options?.signal);
126 return { data: true };
127 },
128 + delete: async (input: { readonly sessionID: string }) => {
129 + runtimeMock.state.sessionCalls.push(`delete ${input.sessionID}`);
130 + return { data: true };
131 + },
132 prompt: async (
133 input: { readonly parts: ReadonlyArray<unknown> },
134 options?: { readonly signal?: AbortSignal },
@@ -262,7 +266,7 @@ it.layer(layerOpenCodeTextGenerationTest)("OpenCodeTextGeneration", (it) => {
266 expect(Exit.isFailure(exit) && Cause.hasInterruptsOnly(exit.cause)).toBe(true);
267 expect(signal?.aborted).toBe(true);
268 expect(runtimeMock.state.promptUrls).toEqual([]);
265 - expect(runtimeMock.state.abortCalls).toEqual([]);
269 + expect(runtimeMock.state.sessionCalls).toEqual([]);
270 }),
271 ),
272 );
@@ -298,7 +302,10 @@ it.layer(layerOpenCodeTextGenerationTest)("OpenCodeTextGeneration", (it) => {
302 expect(Exit.isFailure(exit) && Cause.hasInterruptsOnly(exit.cause)).toBe(true);
303 expect(signal?.aborted).toBe(true);
304 expect(otherSignal?.aborted).toBe(false);
301 - expect(runtimeMock.state.abortCalls).toEqual(["cancelled-session"]);
305 + expect(runtimeMock.state.sessionCalls).toEqual([
306 + "abort cancelled-session",
307 + "delete cancelled-session",
308 + ]);
309 expect(runtimeMock.state.closeCalls).toEqual([]);
310
311 otherReply.resolve({
@@ -312,7 +319,11 @@ it.layer(layerOpenCodeTextGenerationTest)("OpenCodeTextGeneration", (it) => {
319 "http://127.0.0.1:4301",
320 "http://127.0.0.1:4301",
321 ]);
315 - expect(runtimeMock.state.abortCalls).toEqual(["cancelled-session"]);
322 + expect(runtimeMock.state.sessionCalls).toEqual([
323 + "abort cancelled-session",
324 + "delete cancelled-session",
325 + "delete other-session",
326 + ]);
327 expect(runtimeMock.state.closeCalls).toEqual([]);
328 }),
329 ),
@@ -397,6 +408,22 @@ it.layer(layerOpenCodeTextGenerationTest)("OpenCodeTextGeneration", (it) => {
408 textPartCount: 1,
409 });
410 expect(error.cause).not.toHaveProperty("cause");
411 + expect(runtimeMock.state.sessionCalls).toEqual(["delete http://127.0.0.1:4301/session"]);
412 + }),
413 + ),
414 + );
415 +
416 + it.effect("deletes the session when the prompt request rejects", () =>
417 + withOpenCodeTextGeneration(DEFAULT_OPENCODE_SETTINGS, (textGeneration) =>
418 + Effect.gen(function* () {
419 + runtimeMock.state.promptRequestError = new Error("prompt transport failed");
420 +
421 + const error = yield* textGeneration
422 + .generateCommitMessage(DEFAULT_COMMIT_MESSAGE_INPUT)
423 + .pipe(Effect.flip);
424 +
425 + expect(error.detail).toBe("OpenCode session.prompt request failed.");
426 + expect(runtimeMock.state.sessionCalls).toEqual(["delete http://127.0.0.1:4301/session"]);
427 }),
428 ),
429 );
@@ -484,6 +511,10 @@ it.layer(layerOpenCodeTextGenerationExistingServerTest)(
511 });
512
513 expect(runtimeMock.state.startCalls).toEqual([]);
514 + expect(runtimeMock.state.sessionCalls).toEqual([
515 + "delete http://127.0.0.1:9999/session",
516 + "delete http://127.0.0.1:9999/session",
517 + ]);
518 expect(runtimeMock.state.promptUrls).toEqual([
519 "http://127.0.0.1:9999",
520 "http://127.0.0.1:9999",
packages/provider-opencode/src/server/textGeneration.ts
+6
@@ -211,6 +211,11 @@ export const makeOpenCodeTextGeneration = Effect.fn("makeOpenCodeTextGeneration"
211 cwd: input.cwd,
212 });
213 }
214 + yield* Effect.addFinalizer(() =>
215 + OpenCodeRuntime.runOpenCodeSdk("session.delete", (signal) =>
216 + client.session.delete({ sessionID: session.data.id }, { signal }),
217 + ).pipe(Effect.timeout("5 seconds"), Effect.ignore({ log: "Warn" })),
218 + );
219 const selectedAgent = getModelSelectionStringOptionValue(input.modelSelection, "agent");
220 const selectedVariant = getModelSelectionStringOptionValue(input.modelSelection, "variant");
221 const promptContext = {
@@ -275,6 +280,7 @@ export const makeOpenCodeTextGeneration = Effect.fn("makeOpenCodeTextGeneration"
280 }
281 return rawText;
282 },
283 + Effect.scoped,
284 Effect.catchTags({
285 OpenCodeTextGenerationSessionRequestError: (cause) =>
286 Effect.fail(