Skip to content

Commit 4a17135

Browse files
fix(opencode): stop timing out OpenCode 2 model reads before activation answers
On a busy host a cold OpenCode 2.2.7 took about 14 seconds to answer a model read with its plugin-activation 503, and about 9 seconds for the first successful read. Any fixed per-request timeout in the catalog reader turned those reads into an empty list, so the activation retry never ran. Drop the reader's timeout: the loader's activation deadline bounds the first read and its settle budget bounds the rest, and the per-project read keeps its own settle budget. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 636a46b commit 4a17135

2 files changed

Lines changed: 20 additions & 22 deletions

File tree

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,6 @@ describe("loadOpenCode2Catalog", () => {
9595
}),
9696
);
9797

98-
it.effect("lists no models yet when the model list does not answer", () =>
99-
Effect.gen(function* () {
100-
const fiber = yield* Effect.forkChild(
101-
readCatalog({ "/api/provider": PROVIDERS_BODY }, ["/api/model"]),
102-
);
103-
yield* TestClock.adjust("8 seconds");
104-
105-
assert.deepStrictEqual(yield* Fiber.join(fiber), []);
106-
}),
107-
);
108-
10998
// regression: #17424 only the provider list is optional; a model-list failure fails the read
11099
it.effect("fails the read when the model list fails", () =>
111100
Effect.gen(function* () {
@@ -119,14 +108,16 @@ describe("loadOpenCode2Catalog", () => {
119108
}),
120109
);
121110

122-
// regression: #30251 a cold OpenCode 2 holds each model read 5 seconds, then 503s until plugins activate
111+
// regression: #30251 a busy cold OpenCode 2 holds each model read past 5 seconds, then 503s
123112
it.effect("lists models once OpenCode 2 finishes activating its plugins", () =>
124113
Effect.gen(function* () {
125114
const activatedAt = (yield* Clock.currentTimeMillis) + 60_000;
115+
// Timings measured from OpenCode 2.2.7 on a CPU-throttled cold start.
126116
const listModels = Effect.gen(function* () {
127-
const remaining = activatedAt - (yield* Clock.currentTimeMillis);
128-
if (remaining <= 0) return MODELS_BODY;
129-
yield* Effect.sleep("5050 millis");
117+
if ((yield* Clock.currentTimeMillis) >= activatedAt) {
118+
return yield* Effect.as(Effect.sleep("9 seconds"), MODELS_BODY);
119+
}
120+
yield* Effect.sleep("14 seconds");
130121
return { status: 503, body: PLUGINS_ACTIVATING_BODY };
131122
});
132123
const load = yield* makeOpenCode2ModelLoader(
@@ -138,4 +129,16 @@ describe("loadOpenCode2Catalog", () => {
138129
assert.strictEqual((yield* Fiber.join(fiber)).length, 2);
139130
}),
140131
);
132+
133+
it.effect("lists no models once a model list that never answers reaches the deadline", () =>
134+
Effect.gen(function* () {
135+
const load = yield* makeOpenCode2ModelLoader(
136+
readCatalog({ "/api/provider": PROVIDERS_BODY }, ["/api/model"]),
137+
);
138+
const fiber = yield* Effect.forkChild(load);
139+
yield* TestClock.adjust("2 minutes");
140+
141+
assert.deepStrictEqual(yield* Fiber.join(fiber), []);
142+
}),
143+
);
141144
});

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import type { OpenCode2Model } from "./status.ts";
66

77
// Cold catalogs take seconds; model reads already retry empty catalogs.
88
const PROVIDER_NAME_TIMEOUT = "3 seconds";
9-
// Bounds the request alone (server start has its own bounds); a slow list reads as not listed yet.
10-
// OpenCode holds a read 5 seconds for plugin activation before its 503, which must win this race.
11-
const MODEL_LIST_TIMEOUT = "8 seconds";
129

1310
const listProviders = (client: OpenCodeClient, directory: string) =>
1411
client.provider.list({ location: { directory } }).pipe(
@@ -23,10 +20,8 @@ const readCatalog = <E>(
2320
): Effect.Effect<ReadonlyArray<OpenCode2Model>, OpenCodeRuntime.OpenCodeRuntimeError> =>
2421
Effect.all(
2522
{
26-
models: client.model.list({ location: { directory } }).pipe(
27-
Effect.timeoutOption(MODEL_LIST_TIMEOUT),
28-
Effect.map((list) => (list._tag === "Some" ? list.value.data : [])),
29-
),
23+
// Callers bound the read: a busy host can hold it past OpenCode's own activation wait.
24+
models: client.model.list({ location: { directory } }).pipe(Effect.map((list) => list.data)),
3025
providers,
3126
},
3227
{ concurrency: "unbounded" },

0 commit comments

Comments
 (0)