Skip to content

Commit 3346049

Browse files
rekram1-nodeexe.dev user
andauthored
fix(core): time out the Console config request after five seconds (#62404)
Co-authored-by: exe.dev user <exedev@anton.exe.xyz>
1 parent e9540d3 commit 3346049

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎packages/core/src/plugin/provider/opencode.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,9 @@ function fetchConfig(http: HttpClient.HttpClient, value: Credential.Key | Creden
548548
}),
549549
),
550550
Effect.scoped,
551+
// A Console that accepts the connection but never answers would otherwise hold the load, including the one at
552+
// startup, indefinitely. A timeout is a transient failure, which `SharedCache` retries.
553+
Effect.timeout(Duration.seconds(5)),
551554
)
552555
}
553556

‎packages/core/test/plugin/provider-opencode.test.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { LLMClient, RequestExecutor } from "@opencode/ai/route"
44
import { Document, Event, Info } from "@opencode/schema/config"
55
import { ConfigPolicy } from "@opencode/schema/config/policy"
66
import { Money } from "@opencode/schema/money"
7-
import { Effect, Layer, Schema, Stream } from "effect"
7+
import { Effect, Fiber, Layer, Schema, Stream } from "effect"
88
import { TestClock } from "effect/testing"
99
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http"
1010
import { Agent } from "@opencode/core/agent"
@@ -1103,6 +1103,30 @@ describe("OpencodePlugin", () => {
11031103
),
11041104
)
11051105

1106+
it.effect("activates when the Console accepts the config request but never answers", () =>
1107+
Effect.gen(function* () {
1108+
const credentials = yield* Credential.Service
1109+
const integrations = yield* Integration.Service
1110+
const state = { requests: 0 }
1111+
const hanging = {
1112+
fetch: () => {
1113+
state.requests++
1114+
return new Promise<Response>(() => {})
1115+
},
1116+
}
1117+
yield* credentials.create({
1118+
integrationID: Integration.ID.make("opencode"),
1119+
value: Credential.Key.make({ type: "key", key: "secret", metadata: { server: "https://console.example" } }),
1120+
})
1121+
const activation = yield* addPlugin().pipe(inProcess(hanging), Effect.forkChild({ startImmediately: true }))
1122+
// Four attempts of 5 seconds each, with 1, 2 and 4 seconds of backoff between them.
1123+
yield* TestClock.adjust("1 second").pipe(Effect.repeat({ times: 29 }))
1124+
yield* Fiber.join(activation)
1125+
expect(state.requests).toBe(4)
1126+
expect((yield* integrations.get(Integration.ID.make("opencode")))?.connections).toHaveLength(1)
1127+
}),
1128+
)
1129+
11061130
it.effect("reports a Console session rejected before its token expires as signed out", () =>
11071131
Effect.acquireUseRelease(
11081132
Effect.sync(() => {

0 commit comments

Comments
 (0)