Skip to content

Commit 5f6e5fd

Browse files
committed
fix(server): give slow OpenCode version probes more time
A cold wrapper around the OpenCode CLI can exceed the hardcoded four-second --version budget, which flips a healthy provider to Unavailable. Raise the probe timeout to ten seconds and cover a slow-but-successful probe with a test.
1 parent 5e6cc2b commit 5f6e5fd

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

‎apps/server/src/provider/Layers/OpenCodeProvider.test.ts‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const runtimeMock = {
3737
state: {
3838
runVersionError: null as Error | null,
3939
runVersionPending: false,
40+
runVersionDelayMs: null as number | null,
4041
versionStdout: DEFAULT_VERSION_STDOUT,
4142
inventoryError: null as Error | null,
4243
connectionError: null as Error | null,
@@ -56,6 +57,7 @@ const runtimeMock = {
5657
reset() {
5758
this.state.runVersionError = null;
5859
this.state.runVersionPending = false;
60+
this.state.runVersionDelayMs = null;
5961
this.state.versionStdout = DEFAULT_VERSION_STDOUT;
6062
this.state.inventoryError = null;
6163
this.state.connectionError = null;
@@ -128,7 +130,11 @@ const OpenCodeRuntimeTestDouble: OpenCodeRuntimeShape = {
128130
cause: runtimeMock.state.runVersionError,
129131
}),
130132
)
131-
: Effect.succeed({ stdout: runtimeMock.state.versionStdout, stderr: "", code: 0 }),
133+
: runtimeMock.state.runVersionDelayMs
134+
? Effect.sleep(runtimeMock.state.runVersionDelayMs).pipe(
135+
Effect.as({ stdout: runtimeMock.state.versionStdout, stderr: "", code: 0 }),
136+
)
137+
: Effect.succeed({ stdout: runtimeMock.state.versionStdout, stderr: "", code: 0 }),
132138
createOpenCodeSdkClient: (input) => {
133139
runtimeMock.state.sdkClientInputs.push(input);
134140
return {} as unknown as ReturnType<OpenCodeRuntimeShape["createOpenCodeSdkClient"]>;
@@ -230,18 +236,33 @@ it.layer(testLayer)("checkOpenCodeProviderStatus", (it) => {
230236
const probeFiber = yield* checkProvider(makeOpenCodeSettings()).pipe(Effect.forkChild);
231237

232238
yield* Effect.yieldNow;
233-
yield* TestClock.adjust("4 seconds");
239+
yield* TestClock.adjust("10 seconds");
234240
const snapshot = yield* Fiber.join(probeFiber);
235241

236242
NodeAssert.equal(snapshot.status, "error");
237243
NodeAssert.equal(snapshot.installed, true);
238244
NodeAssert.equal(
239245
snapshot.message,
240-
"Failed to execute OpenCode CLI health check: OpenCode CLI version probe timed out after 4 seconds.",
246+
"Failed to execute OpenCode CLI health check: OpenCode CLI version probe timed out after 10 seconds.",
241247
);
242248
}).pipe(Effect.provide(TestClock.layer())),
243249
);
244250

251+
it.effect("waits past the legacy four-second budget for a slow local CLI version probe", () =>
252+
Effect.gen(function* () {
253+
runtimeMock.state.runVersionDelayMs = 5_000;
254+
const probeFiber = yield* checkProvider(makeOpenCodeSettings()).pipe(Effect.forkChild);
255+
256+
yield* Effect.yieldNow;
257+
yield* TestClock.adjust("5 seconds");
258+
const snapshot = yield* Fiber.join(probeFiber);
259+
260+
NodeAssert.equal(snapshot.status, "warning");
261+
NodeAssert.equal(snapshot.installed, true);
262+
NodeAssert.equal(snapshot.version, "1.14.19");
263+
}).pipe(Effect.provide(TestClock.layer())),
264+
);
265+
245266
it.effect("emits OpenCode variant defaults so trait picker can resolve a visible selection", () =>
246267
Effect.gen(function* () {
247268
runtimeMock.state.inventory = {

‎apps/server/src/provider/Layers/OpenCodeProvider.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const OPENCODE_PRESENTATION = {
3232
displayName: "OpenCode",
3333
showInteractionModeToggle: false,
3434
} as const;
35-
const OPENCODE_VERSION_PROBE_TIMEOUT = "4 seconds";
35+
const OPENCODE_VERSION_PROBE_TIMEOUT = "10 seconds";
3636

3737
class OpenCodeProbeError extends Data.TaggedError("OpenCodeProbeError")<{
3838
readonly cause?: unknown;

0 commit comments

Comments
 (0)