Skip to content

Commit 8fada87

Browse files
committed
fix(server): keep OpenCode 1.x commands pending when listing them fails
1 parent c4e2392 commit 8fada87

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
@@ -20,6 +20,7 @@ import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEve
2020
import * as ProviderMaintenance from "@t3tools/provider-core/server/maintenanceResolver";
2121
import * as OpenCodeRuntime from "./OpenCodeRuntime.ts";
2222
import {
23+
OPENCODE_1_RESPONSES,
2324
OPENCODE_2_RESPONSES,
2425
OPENCODE_2_WORKSPACE_RESPONSES,
2526
replayOpenCodeServer,
@@ -112,6 +113,36 @@ it.layer(layer)("OpenCodeDriver runtime selection", (it) => {
112113
}).pipe(Effect.scoped),
113114
);
114115

116+
it.effect("keeps an OpenCode 1.x workspace's commands pending when listing them fails", () =>
117+
Effect.gen(function* () {
118+
const openCode1Runtime = {
119+
connectToOpenCodeServer: () =>
120+
Effect.succeed({
121+
url: "http://127.0.0.1:4096",
122+
version: "1.18.32",
123+
exitCode: null,
124+
external: true,
125+
}),
126+
createOpenCodeSdkClient: () => ({
127+
command: { list: () => Promise.reject(new Error("command.list failed")) },
128+
}),
129+
loadOpenCodeSkills: () =>
130+
Effect.succeed([{ name: "plum", location: "/work/.opencode/skills/plum/SKILL.md" }]),
131+
} as unknown as OpenCodeRuntime.OpenCodeRuntimeShape;
132+
const instance = yield* create(
133+
{ serverUrl: "http://127.0.0.1:4096", serverPassword: "secret" },
134+
replayOpenCodeServer(OPENCODE_1_RESPONSES, "secret"),
135+
).pipe(Effect.provideService(OpenCodeRuntime.OpenCodeRuntime, openCode1Runtime));
136+
137+
const workspace = yield* instance.snapshotForCwd!("/work");
138+
assert.deepStrictEqual(
139+
workspace.skills.map((skill) => skill.name),
140+
["plum"],
141+
);
142+
assert.strictEqual(workspace.slashCommandsPending, true);
143+
}).pipe(Effect.scoped),
144+
);
145+
115146
it.effect("answers capability reads without waiting on an unreachable server", () =>
116147
Effect.gen(function* () {
117148
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
@@ -405,10 +405,18 @@ export const OpenCodeDriver: ProviderDriver<OpenCodeSettings, OpenCodeDriverEnv>
405405
skills: openCodeRuntime.loadOpenCodeSkills(client),
406406
commands: OpenCodeRuntime.loadOpenCodeCommands(client).pipe(
407407
Effect.timeout("10 seconds"),
408-
Effect.orElseSucceed(() => []),
408+
Effect.option,
409409
),
410410
},
411411
{ concurrency: "unbounded" },
412+
).pipe(
413+
// A failed command lookup leaves the commands pending, so the
414+
// registry keeps the last known ones and rescans.
415+
Effect.map(({ skills, commands }) => ({
416+
skills,
417+
commands: Option.getOrElse(commands, () => []),
418+
slashCommandsPending: Option.isNone(commands),
419+
})),
412420
);
413421
const loadWorkspaceForCwd = (cwd: string) =>
414422
effectiveConfig.serverUrl.trim().length > 0
@@ -518,11 +526,11 @@ export const OpenCodeDriver: ProviderDriver<OpenCodeSettings, OpenCodeDriverEnv>
518526
snapshot.getSnapshot,
519527
loadWorkspaceForCwd(cwd).pipe(Effect.timeout("20 seconds")),
520528
]).pipe(
521-
Effect.map(([machineSnapshot, { skills, commands }]) => ({
529+
Effect.map(([machineSnapshot, { skills, commands, slashCommandsPending }]) => ({
522530
...machineSnapshot,
523531
skills: openCodeSkillsToServerProviderSkills(skills),
524532
slashCommands: openCodeCommandsToServerProviderSlashCommands(commands),
525-
slashCommandsPending: false,
533+
slashCommandsPending,
526534
})),
527535
Effect.mapError(
528536
(cause) =>

0 commit comments

Comments
 (0)