Skip to content

Commit 1574077

Browse files
only21milclaude
andcommitted
fix(opencode): OpenCode 1.x text generation gives up after 3 minutes like every other runner
The OpenCode 1.x runner awaited session.create and session.prompt with no deadline, so a stuck generation waited for Node fetch's 300 s default and then failed without aborting the server-side session. Put the OpenCode 2 runner's 3-minute timeout on the whole run. Timing out interrupts the in-flight prompt, so the existing session.abort runs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 15fe283 commit 1574077

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎packages/provider-opencode/src/server/textGeneration.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,34 @@ it.layer(layerOpenCodeTextGenerationTest)("OpenCodeTextGeneration", (it) => {
357357
),
358358
);
359359

360+
it.effect("gives up and aborts the session when a prompt never settles", () =>
361+
withOpenCodeTextGeneration(DEFAULT_OPENCODE_SETTINGS, (textGeneration) =>
362+
Effect.gen(function* () {
363+
const started = yield* Deferred.make<AbortSignal | undefined>();
364+
let sessionAborts = 0;
365+
runtimeMock.state.onPrompt = (signal) => {
366+
Deferred.doneUnsafe(started, Effect.succeed(signal));
367+
return new Promise<never>(() => {});
368+
};
369+
runtimeMock.state.onAbort = () => {
370+
sessionAborts += 1;
371+
return Promise.reject(new Error("abort observed"));
372+
};
373+
const fiber = yield* textGeneration
374+
.generateCommitMessage(DEFAULT_COMMIT_MESSAGE_INPUT)
375+
.pipe(Effect.forkChild);
376+
const signal = yield* Deferred.await(started);
377+
yield* TestClock.adjust(Duration.minutes(3));
378+
379+
const error = yield* Fiber.join(fiber).pipe(Effect.flip);
380+
expect(error).toBeInstanceOf(TextGenerationError);
381+
expect(error.detail).toBe("OpenCode did not finish generating in time.");
382+
expect(signal?.aborted).toBe(true);
383+
expect(sessionAborts).toBe(1);
384+
}),
385+
),
386+
);
387+
360388
it.effect("uses an environment-only password for a locally spawned server", () =>
361389
withOpenCodeTextGeneration(
362390
DEFAULT_OPENCODE_SETTINGS,

‎packages/provider-opencode/src/server/textGeneration.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import * as TextGenerationOperations from "@t3tools/provider-core/server/textGen
1010
import * as OpenCodeRuntime from "./OpenCodeRuntime.ts";
1111
import * as OpenCodeServerOwner from "./OpenCodeServerOwner.ts";
1212

13+
const GENERATION_TIMEOUT = "3 minutes";
14+
1315
const OpenCodeTextGenerationOperation = Schema.Literals([
1416
"generateCommitMessage",
1517
"generatePrContent",
@@ -333,6 +335,16 @@ export const makeOpenCodeTextGeneration = Effect.fn("makeOpenCodeTextGeneration"
333335
.pipe(Effect.flatMap(runAgainstServer), Effect.scoped)
334336
: serverOwner.withServer(runAgainstServer);
335337
const rawOutput = yield* serverOutput.pipe(
338+
Effect.timeoutOrElse({
339+
duration: GENERATION_TIMEOUT,
340+
orElse: () =>
341+
Effect.fail(
342+
new TextGenerationError({
343+
operation: input.operation,
344+
detail: "OpenCode did not finish generating in time.",
345+
}),
346+
),
347+
}),
336348
Effect.catchTags({
337349
OpenCodeRuntimeError: (cause) =>
338350
Effect.fail(

0 commit comments

Comments
 (0)