From 2c6a57926eb3262323e51933757cf3321e0632a0 Mon Sep 17 00:00:00 2001 From: liugddx Date: Thu, 6 Aug 2026 23:38:56 +0800 Subject: [PATCH] fix(runtime): classify expired probe budget as timeout --- .../src/__tests__/opencode-free-anonymous.test.ts | 4 ---- packages/runtime/src/test-connection.ts | 13 ++++--------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/packages/runtime/src/__tests__/opencode-free-anonymous.test.ts b/packages/runtime/src/__tests__/opencode-free-anonymous.test.ts index 8c81e6030d9..4e801e1789a 100644 --- a/packages/runtime/src/__tests__/opencode-free-anonymous.test.ts +++ b/packages/runtime/src/__tests__/opencode-free-anonymous.test.ts @@ -241,7 +241,6 @@ describe('opencode-free anonymous runtime', () => { }); test('bounds all fallback probes by one shared deadline', async () => { - const requestedModels: string[] = []; const connection: LlmConnection = { slug: 'opencode-free', name: 'OpenCode Free', @@ -253,8 +252,6 @@ describe('opencode-free anonymous runtime', () => { updatedAt: 0, }; const fakeFetch: typeof globalThis.fetch = async (_input, init) => { - const body = JSON.parse(String(init?.body)) as { model: string }; - requestedModels.push(body.model); return await new Promise((_resolve, reject) => { const signal = init?.signal; assert.ok(signal); @@ -273,6 +270,5 @@ describe('opencode-free anonymous runtime', () => { assert.equal(result.ok, false); assert.equal(result.errorClass, 'timeout'); assert.ok(Date.now() - startedAt < 1_000); - assert.ok(requestedModels.length > 0); }); }); diff --git a/packages/runtime/src/test-connection.ts b/packages/runtime/src/test-connection.ts index 944785c5f84..f6087248eb7 100644 --- a/packages/runtime/src/test-connection.ts +++ b/packages/runtime/src/test-connection.ts @@ -148,7 +148,9 @@ async function testConnectionStrict( for (let index = 0; index < candidates.length; index += 1) { const candidate = candidates[index]!; const remainingMs = timeoutMs - (Date.now() - t0); - if (remainingMs <= 0) break; + if (remainingMs <= 0) { + return connectionTestFailure(new ConnectionEffectFetchError('timeout'), t0); + } const remainingCandidates = candidates.length - index; const attemptTimeoutMs = Math.max(1, Math.floor(remainingMs / remainingCandidates)); try { @@ -166,14 +168,7 @@ async function testConnectionStrict( lastFailure = connectionTestFailure(error, t0, true); } } - return ( - lastFailure ?? { - ok: false, - errorMessage: 'No OpenCode Free model responded within the connection-test budget', - errorClass: 'provider_unavailable', - latencyMs: Date.now() - t0, - } - ); + return lastFailure ?? connectionTestFailure(new ConnectionEffectFetchError('timeout'), t0); } return await testConnectionModel(connection, secret, testModel, fetchFn, t0, timeoutMs);