Skip to content

Commit fb900da

Browse files
committed
refactor(opencode): leave failed command lookups to the registry's health rule
Keeping OpenCode commands pending after a failed lookup on a healthy provider is a separate fix. Report only finished lookups as complete.
1 parent 7f4d0ef commit fb900da

2 files changed

Lines changed: 5 additions & 64 deletions

File tree

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

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ 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,
2625
OPENCODE_2_RESPONSES,
2726
OPENCODE_2_WORKSPACE_RESPONSES,
2827
replayOpenCodeServer,
@@ -117,64 +116,6 @@ it.layer(layer)("OpenCodeDriver runtime selection", (it) => {
117116
}).pipe(Effect.scoped),
118117
);
119118

120-
it.effect("keeps an OpenCode 2 workspace's commands pending when its scan never ends", () =>
121-
Effect.gen(function* () {
122-
const instance = yield* create(
123-
{ serverUrl: "http://127.0.0.1:4096", serverPassword: "secret" },
124-
replayOpenCodeServer(
125-
{
126-
...OPENCODE_2_RESPONSES,
127-
...OPENCODE_2_WORKSPACE_RESPONSES,
128-
"/api/command": {
129-
...OPENCODE_2_WORKSPACE_RESPONSES["/api/command"],
130-
body: '{"location":{"directory":"/work"},"data":[]}',
131-
},
132-
},
133-
"secret",
134-
),
135-
);
136-
137-
const scan = yield* instance.snapshotForCwd!("/work").pipe(Effect.forkChild);
138-
yield* TestClock.adjust("10 seconds");
139-
const workspace = yield* Fiber.join(scan);
140-
assert.includeMembers(
141-
workspace.skills.map((skill) => skill.name),
142-
["plum"],
143-
);
144-
assert.strictEqual(workspace.slashCommandsPending, true);
145-
}).pipe(Effect.scoped, Effect.provide(TestClock.layer())),
146-
);
147-
148-
it.effect("keeps an OpenCode 1.x workspace's commands pending when listing them fails", () =>
149-
Effect.gen(function* () {
150-
const openCode1Runtime = {
151-
connectToOpenCodeServer: () =>
152-
Effect.succeed({
153-
url: "http://127.0.0.1:4096",
154-
version: "1.18.32",
155-
exitCode: null,
156-
external: true,
157-
}),
158-
createOpenCodeSdkClient: () => ({
159-
command: { list: () => Promise.reject(new Error("command.list failed")) },
160-
}),
161-
loadOpenCodeSkills: () =>
162-
Effect.succeed([{ name: "plum", location: "/work/.opencode/skills/plum/SKILL.md" }]),
163-
} as unknown as OpenCodeRuntime.OpenCodeRuntime["Service"];
164-
const instance = yield* create(
165-
{ serverUrl: "http://127.0.0.1:4096", serverPassword: "secret" },
166-
replayOpenCodeServer(OPENCODE_1_RESPONSES, "secret"),
167-
).pipe(Effect.provideService(OpenCodeRuntime.OpenCodeRuntime, openCode1Runtime));
168-
169-
const workspace = yield* instance.snapshotForCwd!("/work");
170-
assert.deepStrictEqual(
171-
workspace.skills.map((skill) => skill.name),
172-
["plum"],
173-
);
174-
assert.strictEqual(workspace.slashCommandsPending, true);
175-
}).pipe(Effect.scoped),
176-
);
177-
178119
it.effect("answers capability reads without waiting on an unreachable server", () =>
179120
Effect.gen(function* () {
180121
const hang = HttpClient.make(() => Effect.never);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,12 @@ export const OpenCodeDriver: ProviderDriver<
415415
},
416416
{ concurrency: "unbounded" },
417417
).pipe(
418-
// A failed command lookup leaves the commands pending, so the
419-
// registry keeps the last known ones and rescans.
418+
// Only a finished lookup is reported as complete. A failed one leaves
419+
// the flag unset, so the registry decides from the provider's health.
420420
Effect.map(({ skills, commands }) => ({
421421
skills,
422422
commands: Option.getOrElse(commands, () => []),
423-
slashCommandsPending: Option.isNone(commands),
423+
slashCommandsPending: Option.isSome(commands) ? false : undefined,
424424
})),
425425
);
426426
const loadWorkspaceForCwd = (cwd: string) =>
@@ -526,8 +526,8 @@ export const OpenCodeDriver: ProviderDriver<
526526
skills: openCode2SkillsToServerProviderSkills(skills),
527527
slashCommands: openCode2CommandsToServerProviderSlashCommands(commands),
528528
// A finished scan lists at least the built-ins. None means it
529-
// timed out, so the registry keeps the last ones and rescans.
530-
slashCommandsPending: commands.length === 0,
529+
// timed out, so the registry decides from the provider's health.
530+
slashCommandsPending: commands.length > 0 ? false : undefined,
531531
})),
532532
),
533533
v1: Effect.all([

0 commit comments

Comments
 (0)