Skip to content

Commit 9ce3d80

Browse files
committed
fix(server): keep OpenCode 1.x commands pending when listing them fails
1 parent 4b03a8c commit 9ce3d80

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEve
2222
import * as ProviderMaintenance from "@t3tools/provider-core/server/maintenanceResolver";
2323
import * as OpenCodeRuntime from "./OpenCodeRuntime.ts";
2424
import {
25+
OPENCODE_1_RESPONSES,
2526
OPENCODE_2_RESPONSES,
2627
OPENCODE_2_WORKSPACE_RESPONSES,
2728
replayOpenCodeServer,
@@ -116,6 +117,36 @@ it.layer(layer)("OpenCodeDriver runtime selection", (it) => {
116117
}).pipe(Effect.scoped),
117118
);
118119

120+
it.effect("keeps an OpenCode 1.x workspace's commands pending when listing them fails", () =>
121+
Effect.gen(function* () {
122+
const openCode1Runtime = {
123+
connectToOpenCodeServer: () =>
124+
Effect.succeed({
125+
url: "http://127.0.0.1:4096",
126+
version: "1.18.32",
127+
exitCode: null,
128+
external: true,
129+
}),
130+
createOpenCodeSdkClient: () => ({
131+
command: { list: () => Promise.reject(new Error("command.list failed")) },
132+
}),
133+
loadOpenCodeSkills: () =>
134+
Effect.succeed([{ name: "plum", location: "/work/.opencode/skills/plum/SKILL.md" }]),
135+
} as unknown as OpenCodeRuntime.OpenCodeRuntime["Service"];
136+
const instance = yield* create(
137+
{ serverUrl: "http://127.0.0.1:4096", serverPassword: "secret" },
138+
replayOpenCodeServer(OPENCODE_1_RESPONSES, "secret"),
139+
).pipe(Effect.provideService(OpenCodeRuntime.OpenCodeRuntime, openCode1Runtime));
140+
141+
const workspace = yield* instance.snapshotForCwd!("/work");
142+
assert.deepStrictEqual(
143+
workspace.skills.map((skill) => skill.name),
144+
["plum"],
145+
);
146+
assert.strictEqual(workspace.slashCommandsPending, true);
147+
}).pipe(Effect.scoped),
148+
);
149+
119150
it.effect("answers capability reads without waiting on an unreachable server", () =>
120151
Effect.gen(function* () {
121152
const hang = HttpClient.make(() => Effect.never);

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,18 @@ export const OpenCodeDriver: ProviderDriver<
410410
skills: openCodeRuntime.loadOpenCodeSkills(client),
411411
commands: OpenCodeRuntime.loadOpenCodeCommands(client).pipe(
412412
Effect.timeout("10 seconds"),
413-
Effect.orElseSucceed(() => []),
413+
Effect.option,
414414
),
415415
},
416416
{ concurrency: "unbounded" },
417+
).pipe(
418+
// A failed command lookup leaves the commands pending, so the
419+
// registry keeps the last known ones and rescans.
420+
Effect.map(({ skills, commands }) => ({
421+
skills,
422+
commands: Option.getOrElse(commands, () => []),
423+
slashCommandsPending: Option.isNone(commands),
424+
})),
417425
);
418426
const loadWorkspaceForCwd = (cwd: string) =>
419427
effectiveConfig.serverUrl.trim().length > 0
@@ -524,11 +532,11 @@ export const OpenCodeDriver: ProviderDriver<
524532
snapshot.getSnapshot,
525533
loadWorkspaceForCwd(cwd).pipe(Effect.timeout("20 seconds")),
526534
]).pipe(
527-
Effect.map(([machineSnapshot, { skills, commands }]) => ({
535+
Effect.map(([machineSnapshot, { skills, commands, slashCommandsPending }]) => ({
528536
...machineSnapshot,
529537
skills: openCodeSkillsToServerProviderSkills(skills),
530538
slashCommands: openCodeCommandsToServerProviderSlashCommands(commands),
531-
slashCommandsPending: false,
539+
slashCommandsPending,
532540
})),
533541
Effect.mapError(
534542
(cause) =>

0 commit comments

Comments
 (0)