The best way to control Claude Code, Codex and more from any computer or phone
fix(server): bound OpenCode version probes (#8750)
Aditya Garud committed
Sep 2, 2026 at 13:12 UTC
4116db9807cb37b49d3db35c7a45301f5e851b01
3 files changed
+56
-10
apps/server/src/provider/Layers/OpenCodeProvider.test.ts
+33
-9
@@ -3,8 +3,10 @@ import * as NodeAssert from "node:assert/strict";
3
import * as NodeServices from "@effect/platform-node/NodeServices";
4
import { it } from "@effect/vitest";
5
import * as Effect from "effect/Effect";
6
+import * as Fiber from "effect/Fiber";
7
import * as Layer from "effect/Layer";
8
import * as Schema from "effect/Schema";
9
+import * as TestClock from "effect/testing/TestClock";
10
import { beforeEach } from "vite-plus/test";
11
12
import { OpenCodeSettings } from "@t3tools/contracts";
@@ -34,6 +36,7 @@ const DEFAULT_VERSION_STDOUT = "opencode 1.14.19\n";
36
const runtimeMock = {
37
state: {
38
runVersionError: null as Error | null,
39
+ runVersionPending: false,
40
versionStdout: DEFAULT_VERSION_STDOUT,
41
inventoryError: null as Error | null,
42
connectionError: null as Error | null,
@@ -52,6 +55,7 @@ const runtimeMock = {
55
},
56
reset() {
57
this.state.runVersionError = null;
58
+ this.state.runVersionPending = false;
59
this.state.versionStdout = DEFAULT_VERSION_STDOUT;
60
this.state.inventoryError = null;
61
this.state.connectionError = null;
@@ -114,15 +118,17 @@ const OpenCodeRuntimeTestDouble: OpenCodeRuntimeShape = {
118
};
119
}),
120
runOpenCodeCommand: () =>
117
- runtimeMock.state.runVersionError
118
- ? Effect.fail(
119
- new OpenCodeRuntimeError({
120
- operation: "runOpenCodeCommand",
121
- detail: runtimeMock.state.runVersionError.message,
122
- cause: runtimeMock.state.runVersionError,
123
- }),
124
- )
125
- : Effect.succeed({ stdout: runtimeMock.state.versionStdout, stderr: "", code: 0 }),
121
+ runtimeMock.state.runVersionPending
122
+ ? Effect.never
123
+ : runtimeMock.state.runVersionError
124
+ ? Effect.fail(
125
+ new OpenCodeRuntimeError({
126
+ operation: "runOpenCodeCommand",
127
+ detail: runtimeMock.state.runVersionError.message,
128
+ cause: runtimeMock.state.runVersionError,
129
+ }),
130
+ )
131
+ : Effect.succeed({ stdout: runtimeMock.state.versionStdout, stderr: "", code: 0 }),
132
createOpenCodeSdkClient: (input) => {
133
runtimeMock.state.sdkClientInputs.push(input);
134
return {} as unknown as ReturnType<OpenCodeRuntimeShape["createOpenCodeSdkClient"]>;
@@ -218,6 +224,24 @@ it.layer(testLayer)("checkOpenCodeProviderStatus", (it) => {
224
}),
225
);
226
227
+ it.effect("times out a hanging local CLI version probe", () =>
228
+ Effect.gen(function* () {
229
+ runtimeMock.state.runVersionPending = true;
230
+ const probeFiber = yield* checkProvider(makeOpenCodeSettings()).pipe(Effect.forkChild);
231
+
232
+ yield* Effect.yieldNow;
233
+ yield* TestClock.adjust("4 seconds");
234
+ const snapshot = yield* Fiber.join(probeFiber);
235
+
236
+ NodeAssert.equal(snapshot.status, "error");
237
+ NodeAssert.equal(snapshot.installed, true);
238
+ NodeAssert.equal(
239
+ snapshot.message,
240
+ "Failed to execute OpenCode CLI health check: OpenCode CLI version probe timed out after 4 seconds.",
241
+ );
242
+ }).pipe(Effect.provide(TestClock.layer())),
243
+ );
244
+
245
it.effect("emits OpenCode variant defaults so trait picker can resolve a visible selection", () =>
246
Effect.gen(function* () {
247
runtimeMock.state.inventory = {
apps/server/src/provider/Layers/OpenCodeProvider.ts
+11
-1
@@ -31,9 +31,10 @@ const OPENCODE_PRESENTATION = {
31
displayName: "OpenCode",
32
showInteractionModeToggle: false,
33
} as const;
34
+const OPENCODE_VERSION_PROBE_TIMEOUT = "4 seconds";
35
36
class OpenCodeProbeError extends Data.TaggedError("OpenCodeProbeError")<{
36
- readonly cause: unknown;
37
+ readonly cause?: unknown;
38
readonly detail: string;
39
}> {}
40
@@ -401,6 +402,15 @@ export const checkOpenCodeProviderStatus = Effect.fn("checkOpenCodeProviderStatu
402
Effect.mapError(
403
(cause) => new OpenCodeProbeError({ cause, detail: openCodeRuntimeErrorDetail(cause) }),
404
),
405
+ Effect.timeoutOrElse({
406
+ duration: OPENCODE_VERSION_PROBE_TIMEOUT,
407
+ orElse: () =>
408
+ Effect.fail(
409
+ new OpenCodeProbeError({
410
+ detail: `OpenCode CLI version probe timed out after ${OPENCODE_VERSION_PROBE_TIMEOUT}.`,
411
+ }),
412
+ ),
413
+ }),
414
),
415
);
416
if (versionExit._tag === "Failure") {
apps/server/src/provider/opencodeRuntime.ts
+12
@@ -563,11 +563,23 @@ const makeOpenCodeRuntime = Effect.gen(function* () {
563
const spawnCommand = yield* resolveCommand(input.binaryPath, input.args, input.environment);
564
const child = yield* spawner.spawn(
565
ChildProcess.make(spawnCommand.command, spawnCommand.args, {
566
+ detached: hostPlatform !== "win32",
567
shell: spawnCommand.shell,
568
...(input.cwd ? { cwd: input.cwd } : {}),
569
...(input.environment ? { env: input.environment } : { extendEnv: true }),
570
}),
571
);
572
+ const terminateCommandGroup =
573
+ hostPlatform === "win32"
574
+ ? child.kill({ killSignal: "SIGKILL" }).pipe(Effect.asVoid)
575
+ : Effect.sync(() => {
576
+ try {
577
+ process.kill(-Number(child.pid), "SIGKILL");
578
+ } catch {
579
+ // The command and its process group may already have exited.
580
+ }
581
+ });
582
+ yield* Effect.addFinalizer(() => terminateCommandGroup.pipe(Effect.ignore));
583
const collectOptions =
584
input.maxOutputBytes === undefined ? undefined : { maxBytes: input.maxOutputBytes };
585
const [stdout, stderr, code] = yield* Effect.all(