Skip to content

Commit c0f26a8

Browse files
author
Kevin Rajan
committed
[muse] fix(server): bound OpenCode text generation with 180s timeout
A wedged local OpenCode server could park session.create / session.prompt forever: runOpenCodeJson had no timeout while every other text-generation provider (Claude, Codex, Cursor, Grok, Antigravity) bounds its call at 180s. The single sequential title-regeneration worker would then stall and stop all future title regeneration. Wrap the network portion of runOpenCodeJson in Effect.timeoutOption(OPENCODE_TIMEOUT_MS) and map expiry to TextGenerationError("OpenCode request timed out."), mirroring the Claude provider's timeout shape. Authored with AI assistance (Muse, Meta's Muse Spark) under the contributor's direction. The contributor reviewed the diff and ran the focused tests before opening this PR.
1 parent d15210c commit c0f26a8

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎apps/server/src/textGeneration/OpenCodeTextGeneration.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
33
import { it } from "@effect/vitest";
44
import * as Duration from "effect/Duration";
55
import * as Effect from "effect/Effect";
6+
import * as Fiber from "effect/Fiber";
67
import * as Layer from "effect/Layer";
78
import * as Schema from "effect/Schema";
89
import * as TestClock from "effect/testing/TestClock";
@@ -612,5 +613,30 @@ it.layer(OpenCodeTextGenerationExistingServerTestLayer)(
612613
}),
613614
).pipe(Effect.provide(TestClock.layer())),
614615
);
616+
it.effect("fails with a timeout error when the OpenCode server never answers", () =>
617+
withOpenCodeTextGeneration(DEFAULT_OPENCODE_SETTINGS, (textGeneration) =>
618+
Effect.gen(function* () {
619+
// The SDK promise never settles: the server accepted the session
620+
// but the prompt call is wedged.
621+
runtimeMock.state.promptResult = new Promise(() => {}) as unknown as NonNullable<
622+
typeof runtimeMock.state.promptResult
623+
>;
624+
625+
const child = yield* textGeneration
626+
.generateCommitMessage(DEFAULT_COMMIT_MESSAGE_INPUT)
627+
.pipe(Effect.forkChild);
628+
// Spin until the wedged prompt call is in flight, so the clock
629+
// adjustment below cannot run before the timeout is armed.
630+
while (runtimeMock.state.promptUrls.length === 0) {
631+
yield* Effect.yieldNow;
632+
}
633+
yield* TestClock.adjust(181_000);
634+
const error = yield* Fiber.join(child).pipe(Effect.flip);
635+
expect(error).toBeInstanceOf(TextGenerationError);
636+
expect(error.operation).toBe("generateCommitMessage");
637+
expect(error.detail).toContain("timed out");
638+
}),
639+
).pipe(Effect.provide(TestClock.layer())),
640+
);
615641
},
616642
);

‎apps/server/src/textGeneration/OpenCodeTextGeneration.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as Effect from "effect/Effect";
2+
import * as Option from "effect/Option";
23
import * as Schema from "effect/Schema";
34

45
import {
@@ -29,6 +30,10 @@ import {
2930
import * as OpenCodeRuntime from "../provider/opencodeRuntime.ts";
3031
import * as OpenCodeServerOwner from "../provider/OpenCodeServerOwner.ts";
3132

33+
// Matches the other text-generation providers: a wedged OpenCode server
34+
// must not hold the caller forever.
35+
const OPENCODE_TIMEOUT_MS = 180_000;
36+
3237
const OpenCodeTextGenerationOperation = Schema.Literals([
3338
"generateCommitMessage",
3439
"generatePrContent",
@@ -332,6 +337,19 @@ export const makeOpenCodeTextGeneration = Effect.fn("makeOpenCodeTextGeneration"
332337
.pipe(Effect.flatMap(runAgainstServer), Effect.scoped)
333338
: serverOwner.withServer(runAgainstServer);
334339
const rawOutput = yield* serverOutput.pipe(
340+
Effect.timeoutOption(OPENCODE_TIMEOUT_MS),
341+
Effect.flatMap(
342+
Option.match({
343+
onNone: () =>
344+
Effect.fail(
345+
new TextGenerationError({
346+
operation: input.operation,
347+
detail: "OpenCode request timed out.",
348+
}),
349+
),
350+
onSome: (value) => Effect.succeed(value),
351+
}),
352+
),
335353
Effect.catchTags({
336354
OpenCodeRuntimeError: (cause) =>
337355
Effect.fail(

0 commit comments

Comments
 (0)