-
Notifications
You must be signed in to change notification settings - Fork 6.5k
feat(server): detect OpenCode 1.x or 2.x per instance and route by it #14239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
juliusmarminge
merged 4 commits into
t3code/codex-turn-mapping
from
v2/oc2-1-runtime-probe
Oct 1, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cb6447c
feat(server): detect OpenCode 1.x or 2.x per instance and route by it
juliusmarminge f6db235
fix(server): keep OpenCode 2 off every 1.x path and harden the versio…
juliusmarminge 554f0b9
fix(server): keep a configured OpenCode URL's path and query when pro…
juliusmarminge fa8d700
refactor(server): import the OpenCode driver's Effect services as nam…
juliusmarminge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import * as NodeServices from "@effect/platform-node/NodeServices"; | ||
| import { assert, it } from "@effect/vitest"; | ||
| import { ProviderInstanceId, type OpenCodeSettings } from "@t3tools/contracts"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Fiber from "effect/Fiber"; | ||
| import * as Layer from "effect/Layer"; | ||
| import * as TestClock from "effect/testing/TestClock"; | ||
| import { HttpClient } from "effect/unstable/http"; | ||
|
|
||
| import * as BackgroundPolicy from "../../background/BackgroundPolicy.ts"; | ||
| import * as ServerConfig from "../../config.ts"; | ||
| import * as IdAllocator from "../../orchestration-v2/IdAllocator.ts"; | ||
| import * as ServerSettings from "../../serverSettings.ts"; | ||
| import * as ProviderEventLoggers from "../Layers/ProviderEventLoggers.ts"; | ||
| import * as OpenCodeRuntime from "../opencodeRuntime.ts"; | ||
| import { OPENCODE_2_UNSUPPORTED_MESSAGE } from "../opencodeVersionProbe.ts"; | ||
| import { OpenCodeDriver } from "./OpenCodeDriver.ts"; | ||
|
|
||
| const serverStarts: Array<string> = []; | ||
| const reachedServer = (operation: string) => | ||
| Effect.sync(() => serverStarts.push(operation)).pipe( | ||
| Effect.andThen( | ||
| Effect.fail( | ||
| new OpenCodeRuntime.OpenCodeRuntimeError({ | ||
| operation, | ||
| detail: "reached a 1.x server path", | ||
| }), | ||
| ), | ||
| ), | ||
| ); | ||
| // Reports OpenCode 2 from `--version`; any attempt to reach a server is recorded and refused. | ||
| const openCode2Runtime = { | ||
| runOpenCodeCommand: () => Effect.succeed({ stdout: "opencode v2.0.18\n", stderr: "", code: 0 }), | ||
| startOpenCodeServerProcess: () => reachedServer("start"), | ||
| connectToOpenCodeServer: () => reachedServer("connect"), | ||
| } as unknown as OpenCodeRuntime.OpenCodeRuntimeShape; | ||
|
|
||
| const layer = Layer.mergeAll( | ||
| ServerConfig.layerTest(process.cwd(), { prefix: "t3-opencode-driver-" }), | ||
| IdAllocator.layer, | ||
| ServerSettings.layerTest(), | ||
| Layer.mock(BackgroundPolicy.BackgroundPolicy)({}), | ||
| Layer.succeed( | ||
| ProviderEventLoggers.ProviderEventLoggers, | ||
| ProviderEventLoggers.NoOpProviderEventLoggers, | ||
| ), | ||
| Layer.succeed(OpenCodeRuntime.OpenCodeRuntime, openCode2Runtime), | ||
| ).pipe(Layer.provideMerge(NodeServices.layer)); | ||
|
|
||
| const create = (config: Partial<OpenCodeSettings>, http: HttpClient.HttpClient) => | ||
| OpenCodeDriver.create({ | ||
| instanceId: ProviderInstanceId.make("opencode-test"), | ||
| displayName: undefined, | ||
| environment: [], | ||
| enabled: true, | ||
| config: { ...OpenCodeDriver.defaultConfig(), ...config }, | ||
| }).pipe(Effect.provideService(HttpClient.HttpClient, http)); | ||
|
|
||
| const noHttp = HttpClient.make(() => Effect.die("A local binary must not be probed over HTTP")); | ||
|
|
||
| it.layer(layer)("OpenCodeDriver runtime selection", (it) => { | ||
| it.effect("refuses OpenCode 2 on every path that would start a 1.x server", () => | ||
| Effect.gen(function* () { | ||
| serverStarts.length = 0; | ||
| const instance = yield* create({}, noHttp); | ||
|
|
||
| const workspace = yield* Effect.flip(instance.snapshotForCwd!(process.cwd())); | ||
| assert.strictEqual( | ||
| (workspace.cause as { readonly detail?: string }).detail, | ||
| OPENCODE_2_UNSUPPORTED_MESSAGE, | ||
| ); | ||
| const title = yield* Effect.flip( | ||
| instance.textGeneration.generateThreadTitle({ | ||
| cwd: process.cwd(), | ||
| message: "hello", | ||
| modelSelection: { instanceId: instance.instanceId, model: "opencode/big-pickle" }, | ||
| }), | ||
| ); | ||
| assert.strictEqual(title.detail, OPENCODE_2_UNSUPPORTED_MESSAGE); | ||
| assert.deepStrictEqual(serverStarts, []); | ||
| }).pipe(Effect.scoped), | ||
| ); | ||
|
|
||
| it.effect("answers capability reads without waiting on an unreachable server", () => | ||
| Effect.gen(function* () { | ||
| const hang = HttpClient.make(() => Effect.never); | ||
| const instance = yield* create({ serverUrl: "http://127.0.0.1:9" }, hang); | ||
|
|
||
| // No probe has succeeded yet, and the server never answers: the 1.x default applies. | ||
| const capabilities = yield* instance.orchestrationAdapter | ||
| .getCapabilities() | ||
| .pipe(Effect.forkChild); | ||
| yield* Effect.yieldNow; | ||
| assert.isDefined(capabilities.pollUnsafe()); | ||
| yield* Fiber.join(capabilities); | ||
| }).pipe(Effect.scoped, Effect.provide(TestClock.layer())), | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.