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, 22:00 UTC
fix(opencode): keep workspace commands retryable after probe timeouts (#19636)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Ibrahim Elkamali committed
Oct 20, 2026 at 08:09 UTC
78d095a8a5483ea8310c42d4035cec9231b8c8f0
2 files changed
+101
-8
packages/provider-opencode/src/server/driver.test.ts
+88
@@ -5,6 +5,7 @@ import * as NodePath from "node:path";
5
6
import * as NodeServices from "@effect/platform-node/NodeServices";
7
import { assert, it } from "@effect/vitest";
8
+import { createOpencodeClient } from "@opencode-ai/sdk/v2";
9
import { ProviderInstanceId } from "@t3tools/contracts";
10
import type { OpenCodeSettings } from "../settings.ts";
11
import * as HostProcess from "@t3tools/shared/HostProcess";
@@ -22,6 +23,7 @@ import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEve
23
import * as ProviderMaintenance from "@t3tools/provider-core/server/maintenanceResolver";
24
import * as OpenCodeRuntime from "./OpenCodeRuntime.ts";
25
import {
26
+ OPENCODE_1_RESPONSES,
27
OPENCODE_2_RESPONSES,
28
OPENCODE_2_WORKSPACE_RESPONSES,
29
replayOpenCodeServer,
@@ -70,6 +72,92 @@ const create = (config: Partial<OpenCodeSettings>, http: HttpClient.HttpClient)
72
73
const noHttp = HttpClient.make(() => Effect.die("A local binary must not be probed over HTTP"));
74
75
+const createOpenCode1WorkspaceDriver = (client: ReturnType<typeof createOpencodeClient>) =>
76
+ create(
77
+ { serverUrl: "http://127.0.0.1:4096" },
78
+ replayOpenCodeServer(OPENCODE_1_RESPONSES, ""),
79
+ ).pipe(
80
+ Effect.provide(
81
+ Layer.mock(OpenCodeRuntime.OpenCodeRuntime)({
82
+ connectToOpenCodeServer: () =>
83
+ Effect.succeed({
84
+ url: "http://127.0.0.1:4096",
85
+ version: "1.18.32",
86
+ exitCode: null,
87
+ external: true,
88
+ }),
89
+ createOpenCodeSdkClient: () => client,
90
+ loadOpenCodeSkills: () =>
91
+ Effect.succeed([
92
+ {
93
+ name: "workspace-skill",
94
+ location: "/work/.opencode/skills/workspace-skill/SKILL.md",
95
+ },
96
+ ]),
97
+ }),
98
+ ),
99
+ );
100
+
101
+it.layer(layer)("OpenCodeDriver 1.x workspace commands", (it) => {
102
+ it.effect("keeps skills and marks commands pending on a timed-out probe, then loads them", () =>
103
+ Effect.gen(function* () {
104
+ const requested = Promise.withResolvers<void>();
105
+ let ready = false;
106
+ const client = createOpencodeClient({
107
+ baseUrl: "http://127.0.0.1:4096",
108
+ throwOnError: true,
109
+ fetch: () => {
110
+ requested.resolve();
111
+ return ready
112
+ ? Promise.resolve(Response.json([{ name: "hello", hints: [] }]))
113
+ : new Promise<Response>(() => {});
114
+ },
115
+ });
116
+ const instance = yield* createOpenCode1WorkspaceDriver(client);
117
+ const probe = yield* instance.snapshotForCwd!("/work").pipe(Effect.forkChild);
118
+ yield* Effect.promise(() => requested.promise);
119
+ yield* TestClock.adjust("10 seconds");
120
+
121
+ const pending = yield* Fiber.join(probe);
122
+ assert.deepStrictEqual(
123
+ pending.skills.map((skill) => skill.name),
124
+ ["workspace-skill"],
125
+ );
126
+ assert.strictEqual(pending.slashCommandsPending, true);
127
+
128
+ ready = true;
129
+ const workspace = yield* instance.snapshotForCwd!("/work");
130
+ assert.deepStrictEqual(
131
+ workspace.slashCommands.map((command) => command.name),
132
+ ["compact", "hello"],
133
+ );
134
+ assert.strictEqual(workspace.slashCommandsPending, false);
135
+ }).pipe(Effect.scoped),
136
+ );
137
+
138
+ it.effect("keeps skills and defers command fallback to provider health on an SDK error", () =>
139
+ Effect.gen(function* () {
140
+ const client = createOpencodeClient({
141
+ baseUrl: "http://127.0.0.1:4096",
142
+ throwOnError: true,
143
+ fetch: () => Promise.resolve(Response.json({ message: "unavailable" }, { status: 500 })),
144
+ });
145
+ const instance = yield* createOpenCode1WorkspaceDriver(client);
146
+ const workspace = yield* instance.snapshotForCwd!("/work");
147
+
148
+ assert.deepStrictEqual(
149
+ workspace.slashCommands.map((command) => command.name),
150
+ ["compact"],
151
+ );
152
+ assert.deepStrictEqual(
153
+ workspace.skills.map((skill) => skill.name),
154
+ ["workspace-skill"],
155
+ );
156
+ assert.strictEqual(workspace.slashCommandsPending, undefined);
157
+ }).pipe(Effect.scoped),
158
+ );
159
+});
160
+
161
it.layer(layer)("OpenCodeDriver runtime selection", (it) => {
162
it.effect("never starts a 1.x server for an OpenCode 2 instance", () =>
163
Effect.gen(function* () {
packages/provider-opencode/src/server/driver.ts
+13
-8
@@ -378,19 +378,24 @@ export const OpenCodeDriver: ProviderDriver<
378
Effect.all(
379
{
380
skills: openCodeRuntime.loadOpenCodeSkills(client),
381
- commands: OpenCodeRuntime.loadOpenCodeCommands(client).pipe(
382
- Effect.timeout("10 seconds"),
383
- Effect.option,
381
+ commandInventory: OpenCodeRuntime.loadOpenCodeCommands(client).pipe(
382
+ Effect.timeoutOption("10 seconds"),
383
+ Effect.map((commands) => ({
384
+ commands: Option.getOrElse(commands, () => []),
385
+ slashCommandsPending: Option.isNone(commands),
386
+ })),
387
+ // SDK errors leave command discovery to the provider's health.
388
+ Effect.orElseSucceed(() => ({
389
+ commands: [],
390
+ slashCommandsPending: undefined,
391
+ })),
392
),
393
},
394
{ concurrency: "unbounded" },
395
).pipe(
388
- // Only a finished lookup is reported as complete. A failed one leaves
389
- // the flag unset, so the registry decides from the provider's health.
390
- Effect.map(({ skills, commands }) => ({
396
+ Effect.map(({ skills, commandInventory }) => ({
397
skills,
392
- commands: Option.getOrElse(commands, () => []),
393
- slashCommandsPending: Option.isSome(commands) ? false : undefined,
398
+ ...commandInventory,
399
})),
400
);
401
const loadWorkspaceForCwd = (cwd: string) =>