Skip to content

Commit f6e8a0e

Browse files
fix(server): match OpenCode version-probe timeouts exactly
A non-timeout launch failure was classified as a timeout when binaryPath contained "version probe timed out", so the last ready snapshot was kept. The merge now requires the provider message to equal the exact timeout text, including its duration label. Fixes #11080. Verification: vp test run apps/server/src/provider/Layers/ProviderRegistry.test.ts apps/server/src/provider/Layers/OpenCodeProvider.test.ts Test Files 2 passed (2) Tests 79 passed (79) Duration 3.18s Model: Grok 4.7 via Cursor cloud agent Co-authored-by: maco <[email protected]>
1 parent c37210d commit f6e8a0e

3 files changed

Lines changed: 118 additions & 10 deletions

File tree

‎apps/server/src/provider/Layers/OpenCodeProvider.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ const formatOpenCodeVersionProbeTimeout = (duration: Duration.Duration): string
6363
return `${millis} millis`;
6464
};
6565

66+
const OPENCODE_CLI_HEALTH_CHECK_FAILURE = "Failed to execute OpenCode CLI health check";
67+
68+
/** Text before the duration label in the exact `--version` timeout message. */
69+
export const OPENCODE_VERSION_PROBE_TIMEOUT_MESSAGE_PREFIX = `${OPENCODE_CLI_HEALTH_CHECK_FAILURE}: OpenCode CLI version probe timed out after `;
70+
71+
/** Detail text for a `--version` probe that reached its cap. */
72+
const openCodeVersionProbeTimeoutDetail = (timeoutLabel: string): string =>
73+
`OpenCode CLI version probe timed out after ${timeoutLabel}.`;
74+
75+
/**
76+
* Exact provider message for that timeout. Snapshot merging must compare this
77+
* with `===`; a launch error that only contains the phrase is a different failure.
78+
*/
79+
export const openCodeVersionProbeTimeoutMessage = (timeoutLabel: string): string =>
80+
`${OPENCODE_VERSION_PROBE_TIMEOUT_MESSAGE_PREFIX}${timeoutLabel}.`;
81+
6682
const parseOpenCodeVersionProbeTimeout = (
6783
raw: string | undefined,
6884
): Duration.Duration | undefined => {
@@ -210,7 +226,7 @@ function formatOpenCodeProbeError(input: {
210226
const failureLabel =
211227
input.phase === "inventory"
212228
? "Failed to load OpenCode provider inventory"
213-
: "Failed to execute OpenCode CLI health check";
229+
: OPENCODE_CLI_HEALTH_CHECK_FAILURE;
214230
return {
215231
installed: true,
216232
message: detail ? `${failureLabel}: ${detail}` : `${failureLabel}.`,
@@ -536,7 +552,7 @@ export const checkOpenCodeProviderStatus = Effect.fn("checkOpenCodeProviderStatu
536552
orElse: () =>
537553
Effect.fail(
538554
new OpenCodeProbeError({
539-
detail: `OpenCode CLI version probe timed out after ${versionProbeTimeoutLabel}.`,
555+
detail: openCodeVersionProbeTimeoutDetail(versionProbeTimeoutLabel),
540556
}),
541557
),
542558
}),

‎apps/server/src/provider/Layers/ProviderRegistry.test.ts‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,65 @@ it.layer(Layer.mergeAll(TestNodeServices, ServerSettingsModule.layerTest(), Test
973973
assert.deepStrictEqual(merged.skills, previousProvider.skills);
974974
assert.equal(merged.message, timedOutProvider.message);
975975
assert.equal(merged.checkedAt, timedOutProvider.checkedAt);
976+
977+
for (const message of [
978+
"Failed to execute OpenCode CLI health check: OpenCode CLI version probe timed out after 1 second.",
979+
"Failed to execute OpenCode CLI health check: OpenCode CLI version probe timed out after 60 seconds.",
980+
"Failed to execute OpenCode CLI health check: OpenCode CLI version probe timed out after 1500 millis.",
981+
]) {
982+
const variant = mergeProviderSnapshot(previousProvider, { ...timedOutProvider, message });
983+
assert.equal(variant.status, "ready", message);
984+
assert.equal(variant.version, previousProvider.version, message);
985+
assert.deepStrictEqual(variant.auth, previousProvider.auth, message);
986+
}
987+
});
988+
989+
it("does not treat a launch failure that only contains the timeout phrase as a version-probe timeout", () => {
990+
const previousProvider = {
991+
instanceId: ProviderInstanceId.make("opencode"),
992+
driver: ProviderDriverKind.make("opencode"),
993+
status: "ready",
994+
enabled: true,
995+
installed: true,
996+
auth: { status: "authenticated", type: "opencode" },
997+
checkedAt: "2026-07-17T00:00:00.000Z",
998+
version: "1.18.19",
999+
models: [
1000+
{
1001+
slug: "github/gpt-5",
1002+
name: "GPT-5",
1003+
isCustom: false,
1004+
capabilities: null,
1005+
},
1006+
],
1007+
slashCommands: [],
1008+
skills: [],
1009+
} as const satisfies ServerProvider;
1010+
const binaryPath = "/opt/version probe timed out/opencode";
1011+
const messages = [
1012+
`Failed to execute OpenCode CLI health check: Failed to execute '${binaryPath} --version': spawn ${binaryPath} ENOENT`,
1013+
"version probe timed out",
1014+
"Failed to execute OpenCode CLI health check: OpenCode CLI version probe timed out after 4 seconds. See the binary path.",
1015+
"Note: Failed to execute OpenCode CLI health check: OpenCode CLI version probe timed out after 4 seconds.",
1016+
"Failed to execute OpenCode CLI health check: OpenCode CLI version probe timed out after 4 seconds",
1017+
];
1018+
1019+
for (const message of messages) {
1020+
const failedProvider = {
1021+
...previousProvider,
1022+
status: "error",
1023+
auth: { status: "unknown" },
1024+
checkedAt: "2026-07-17T00:01:00.000Z",
1025+
version: null,
1026+
models: [],
1027+
message,
1028+
} satisfies ServerProvider;
1029+
const merged = mergeProviderSnapshot(previousProvider, failedProvider);
1030+
assert.equal(merged.status, "error", message);
1031+
assert.equal(merged.version, null, message);
1032+
assert.deepStrictEqual(merged.auth, { status: "unknown" }, message);
1033+
assert.equal(merged.message, message);
1034+
}
9761035
});
9771036

9781037
it("does not keep last-known-good OpenCode state without a ready versioned snapshot", () => {

‎apps/server/src/provider/Layers/ProviderRegistry.ts‎

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ import {
5656
import type { ProviderInstance } from "../ProviderDriver.ts";
5757
import { makeManualOnlyProviderMaintenanceCapabilities } from "../providerMaintenance.ts";
5858
import type { ProviderSnapshotSource } from "../builtInProviderCatalog.ts";
59+
import {
60+
OPENCODE_VERSION_PROBE_TIMEOUT_MESSAGE_PREFIX,
61+
openCodeVersionProbeTimeoutMessage,
62+
} from "./OpenCodeProvider.ts";
5963

6064
const loadProviders = (
6165
providerSources: ReadonlyArray<ProviderSnapshotSource>,
@@ -173,15 +177,44 @@ const mergeProviderModels = (
173177
: mergedModels;
174178
};
175179

176-
// Matches the detail produced by `checkOpenCodeProviderStatus`.
177-
const OPENCODE_VERSION_PROBE_TIMEOUT_MARKER = "version probe timed out";
180+
// Labels `formatOpenCodeVersionProbeTimeout` can emit: "1 second", "N seconds",
181+
// or "N millis" when the cap is not a whole number of seconds.
182+
const OPENCODE_VERSION_PROBE_TIMEOUT_LABEL = /^(?:1 second|[1-9]\d* seconds|[1-9]\d* millis)$/;
178183

179-
const isOpenCodeVersionProbeTimeout = (provider: ServerProvider): boolean =>
180-
provider.driver === ProviderDriverKind.make("opencode") &&
181-
provider.installed &&
182-
provider.status === "error" &&
183-
provider.version === null &&
184-
(provider.message?.includes(OPENCODE_VERSION_PROBE_TIMEOUT_MARKER) ?? false);
184+
/**
185+
* Duration label inside the exact `--version` timeout message. A launch
186+
* failure whose text merely contains "version probe timed out" — including a
187+
* configured `binaryPath` with that phrase — does not match.
188+
*/
189+
const readOpenCodeVersionProbeTimeoutLabel = (message: string | undefined): string | undefined => {
190+
if (
191+
message === undefined ||
192+
!message.startsWith(OPENCODE_VERSION_PROBE_TIMEOUT_MESSAGE_PREFIX) ||
193+
!message.endsWith(".")
194+
) {
195+
return undefined;
196+
}
197+
const label = message.slice(OPENCODE_VERSION_PROBE_TIMEOUT_MESSAGE_PREFIX.length, -1);
198+
if (!OPENCODE_VERSION_PROBE_TIMEOUT_LABEL.test(label)) {
199+
return undefined;
200+
}
201+
return message === openCodeVersionProbeTimeoutMessage(label) ? label : undefined;
202+
};
203+
204+
const isOpenCodeVersionProbeTimeout = (provider: ServerProvider): boolean => {
205+
const label = readOpenCodeVersionProbeTimeoutLabel(provider.message);
206+
if (label === undefined) {
207+
return false;
208+
}
209+
const OPENCODE_VERSION_PROBE_TIMEOUT_MARKER = openCodeVersionProbeTimeoutMessage(label);
210+
return (
211+
provider.driver === ProviderDriverKind.make("opencode") &&
212+
provider.installed &&
213+
provider.status === "error" &&
214+
provider.version === null &&
215+
provider.message === OPENCODE_VERSION_PROBE_TIMEOUT_MARKER
216+
);
217+
};
185218

186219
/**
187220
* A slow OpenCode `--version` must not mark a provider Unavailable after it

0 commit comments

Comments
 (0)