@devries-cameron20 / t3code Mirror · read-only / commits / de6830f1da
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 07:00 UTC

fix(opencode): OpenCode 1.x text generation gives up after 3 minutes like every other runner (#28372)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Victor Vogel committed Nov 1, 2026 at 16:05 UTC de6830f1daba7c993b97fc356fd045a5f021cabe
2 files changed +56 -1
packages/provider-opencode/src/server/textGeneration.test.ts
+44 -1
@@ -248,9 +248,24 @@ const advanceIdleClock = Effect.gen(function* () {
248 });
249
250 it.layer(layerOpenCodeTextGenerationTest)("OpenCodeTextGeneration", (it) => {
251 - it.effect("cancels an in-flight session creation before prompting", () =>
251 + it.effect("cancels or times out an in-flight session creation before prompting", () =>
252 withOpenCodeTextGeneration(EXISTING_SERVER_OPENCODE_SETTINGS, (textGeneration) =>
253 Effect.gen(function* () {
254 + const timedOut = yield* Deferred.make<AbortSignal | undefined>();
255 + runtimeMock.state.onSessionCreate = (signal) => {
256 + Deferred.doneUnsafe(timedOut, Effect.succeed(signal));
257 + return new Promise<never>(() => {});
258 + };
259 + const timedOutFiber = yield* textGeneration
260 + .generateCommitMessage(DEFAULT_COMMIT_MESSAGE_INPUT)
261 + .pipe(Effect.forkChild);
262 + const timedOutSignal = yield* Deferred.await(timedOut);
263 + yield* TestClock.adjust(Duration.minutes(3));
264 + const timeoutError = yield* Fiber.join(timedOutFiber).pipe(Effect.flip);
265 + expect(timeoutError).toBeInstanceOf(TextGenerationError);
266 + expect(timeoutError.detail).toBe("OpenCode did not finish generating in time.");
267 + expect(timedOutSignal?.aborted).toBe(true);
268 +
269 const started = yield* Deferred.make<AbortSignal | undefined>();
270 runtimeMock.state.onSessionCreate = (signal) => {
271 Deferred.doneUnsafe(started, Effect.succeed(signal));
@@ -368,6 +383,34 @@ it.layer(layerOpenCodeTextGenerationTest)("OpenCodeTextGeneration", (it) => {
383 ),
384 );
385
386 + it.effect("gives up and aborts the session when a prompt never settles", () =>
387 + withOpenCodeTextGeneration(DEFAULT_OPENCODE_SETTINGS, (textGeneration) =>
388 + Effect.gen(function* () {
389 + const started = yield* Deferred.make<AbortSignal | undefined>();
390 + let sessionAborts = 0;
391 + runtimeMock.state.onPrompt = (signal) => {
392 + Deferred.doneUnsafe(started, Effect.succeed(signal));
393 + return new Promise<never>(() => {});
394 + };
395 + runtimeMock.state.onAbort = () => {
396 + sessionAborts += 1;
397 + return Promise.reject(new Error("abort observed"));
398 + };
399 + const fiber = yield* textGeneration
400 + .generateCommitMessage(DEFAULT_COMMIT_MESSAGE_INPUT)
401 + .pipe(Effect.forkChild);
402 + const signal = yield* Deferred.await(started);
403 + yield* TestClock.adjust(Duration.minutes(3));
404 +
405 + const error = yield* Fiber.join(fiber).pipe(Effect.flip);
406 + expect(error).toBeInstanceOf(TextGenerationError);
407 + expect(error.detail).toBe("OpenCode did not finish generating in time.");
408 + expect(signal?.aborted).toBe(true);
409 + expect(sessionAborts).toBe(1);
410 + }),
411 + ),
412 + );
413 +
414 it.effect("uses an environment-only password for a locally spawned server", () =>
415 withOpenCodeTextGeneration(
416 DEFAULT_OPENCODE_SETTINGS,
packages/provider-opencode/src/server/textGeneration.ts
+12
@@ -10,6 +10,8 @@ import * as TextGenerationOperations from "@t3tools/provider-core/server/textGen
10 import * as OpenCodeRuntime from "./OpenCodeRuntime.ts";
11 import * as OpenCodeServerOwner from "./OpenCodeServerOwner.ts";
12
13 +const GENERATION_TIMEOUT = "3 minutes";
14 +
15 const OpenCodeTextGenerationOperation = Schema.Literals([
16 "generateCommitMessage",
17 "generatePrContent",
@@ -339,6 +341,16 @@ export const makeOpenCodeTextGeneration = Effect.fn("makeOpenCodeTextGeneration"
341 .pipe(Effect.flatMap(runAgainstServer), Effect.scoped)
342 : serverOwner.withServer(runAgainstServer);
343 const rawOutput = yield* serverOutput.pipe(
344 + Effect.timeoutOrElse({
345 + duration: GENERATION_TIMEOUT,
346 + orElse: () =>
347 + Effect.fail(
348 + new TextGenerationError({
349 + operation: input.operation,
350 + detail: "OpenCode did not finish generating in time.",
351 + }),
352 + ),
353 + }),
354 Effect.catchTags({
355 OpenCodeRuntimeError: (cause) =>
356 Effect.fail(