Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(core): drop discovery failures for a replaced endpoint
  • Loading branch information
rekram1-node committed Nov 13, 2026
commit 1056dc8e9c2e2da818325249472ff8b8051493f0
27 changes: 16 additions & 11 deletions packages/core/src/plugin/provider/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,20 @@ export function createLocalProviderPlugin<Discovered>(input: {

// Keep the last successful inventory through transient outages instead of flickering model availability.
// Only a configured endpoint is expected to answer, and it is reported once per outage.
const attempt = refresh().pipe(
Effect.catch((cause) => {
if (!source.current.explicit || loaded.failing) return Effect.void
loaded.failing = true
return Effect.logWarning(`failed to discover ${input.name} models`, {
baseURL: source.current.baseURL,
cause,
})
}),
)
// A reload doesn't wait for the attempt in flight, so a failure for a replaced source is dropped.
const attempt = Effect.suspend(() => {
const current = source.current
return refresh().pipe(
Effect.catch((cause) => {
if (current !== source.current || !current.explicit || loaded.failing) return Effect.void
loaded.failing = true
return Effect.logWarning(`failed to discover ${input.name} models`, {
baseURL: current.baseURL,
cause,
})
}),
)
})
yield* attempt.pipe(Effect.repeat(Schedule.spaced(interval)), Effect.forkScoped)
// Event handlers start discovery without waiting on it, so a slow endpoint doesn't hold up the next event.
const background = yield* FiberSet.make()
Expand Down Expand Up @@ -197,7 +201,8 @@ function createClient(
return {
root,
apiKey,
get: (path: string) => http.execute(auth(HttpClientRequest.get(endpoint(path)))).pipe(Effect.timeout(requestTimeout)),
get: (path: string) =>
http.execute(auth(HttpClientRequest.get(endpoint(path)))).pipe(Effect.timeout(requestTimeout)),
getJson: <A, I>(path: string, schema: Schema.Codec<A, I>) =>
http
.execute(auth(HttpClientRequest.get(endpoint(path))))
Expand Down
61 changes: 60 additions & 1 deletion packages/core/test/plugin/provider-vllm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { make, VLLMPlugin } from "@opencode/core/plugin/provider/vllm"
import { Provider } from "@opencode/core/provider"
import { Document, Event, Info } from "@opencode/schema/config"
import { describe, expect } from "bun:test"
import { Duration, Effect, Layer, Schema } from "effect"
import { Duration, Effect, Layer, Logger, Schema } from "effect"
import { TestClock } from "effect/testing"
import { eventually } from "../lib/eventually"
import { testEffect } from "../lib/effect"
Expand Down Expand Up @@ -142,6 +142,65 @@ describe("VLLMPlugin", () => {
),
)

it.effect("does not report a replaced endpoint's failure against the new one", () =>
Effect.acquireUseRelease(
Effect.sync(() => {
const arrived = Promise.withResolvers<void>()
const aborted = Promise.withResolvers<void>()
return {
arrived,
aborted,
slow: Bun.serve({
port: 0,
fetch: (request) => {
request.signal.addEventListener("abort", () => aborted.resolve())
arrived.resolve()
return new Promise<Response>(() => {})
},
}),
healthy: Bun.serve({
port: 0,
fetch: (request) =>
new URL(request.url).pathname === "/health"
? new Response()
: Response.json({ object: "list", data: [remoteModel("healthy-model")] }),
}),
}
}),
({ arrived, aborted, slow, healthy }) =>
Effect.gen(function* () {
const bus = yield* Bus.Service
const modelState = yield* Model.Service
const config = yield* Config.Test
const warnings: unknown[] = []
yield* config.setEntries([configuration({ baseURL: `${slow.url.origin}/v1` })])
yield* addPlugin(slow.url.origin).pipe(
Effect.provide(
Logger.layer([
Logger.make((entry) => {
if (entry.logLevel === "Warn") warnings.push(entry.message)
}),
]),
),
)
yield* Effect.promise(() => arrived.promise)

yield* config.setEntries([configuration({ baseURL: `${healthy.url.origin}/v1` })])
yield* bus.publish(Event.Updated, {})
yield* eventually(
modelState.get(Provider.ID.make("vllm"), Model.ID.make("healthy-model")),
(model) => model !== undefined,
)

// The request to the replaced endpoint is still open, and now times out.
yield* TestClock.adjust("15 seconds")
yield* Effect.promise(() => aborted.promise)
expect(warnings).toEqual([])
}),
({ slow, healthy }) => Effect.promise(() => Promise.all([slow.stop(true), healthy.stop(true)])),
),
)

it.live("refreshes inventory while retaining the last success through transient failures", () =>
Effect.acquireUseRelease(
Effect.sync(() => {
Expand Down
Loading