The best way to control Claude Code, Codex and more from any computer or phone
fix(opencode): sessions open through OpenCode 2 after an in-place upgrade from 1.x (#27779)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 2, 2026 at 18:30 UTC
503488d7a3926537d1d13f763f69b8e12458d7b3
3 files changed
+49
-5
packages/provider-opencode/src/server/driver.test.ts
+41
-1
@@ -6,7 +6,12 @@ import * as NodePath from "node:path";
6
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
7
import * as NodeServices from "@effect/platform-node/NodeServices";
8
import { assert, it } from "@effect/vitest";
9
-import { DEFAULT_SERVER_SETTINGS, ProviderInstanceId } from "@t3tools/contracts";
9
+import {
10
+ DEFAULT_SERVER_SETTINGS,
11
+ ProviderInstanceId,
12
+ ProviderSessionId,
13
+ ThreadId,
14
+} from "@t3tools/contracts";
15
import type { OpenCodeSettings } from "../settings.ts";
16
import * as HostProcess from "@t3tools/shared/HostProcess";
17
import * as Deferred from "effect/Deferred";
@@ -575,4 +580,39 @@ it.layer(layerUpdate)("OpenCodeDriver updates", (it) => {
580
assert.isNull(v2.update);
581
}).pipe(Effect.scoped),
582
);
583
+
584
+ it.effect(
585
+ "opens sessions through OpenCode 2 after the binary is upgraded in place from 1.x",
586
+ () =>
587
+ Effect.gen(function* () {
588
+ versionOutput.current = "1.18.18\n";
589
+ const instance = yield* create({}, noHttp);
590
+ // Let the startup status check claim the refresh permit, then wait behind it so it
591
+ // cannot probe after the upgrade below.
592
+ yield* Effect.yieldNow;
593
+ yield* instance.snapshot.refresh;
594
+ serverStarts.length = 0;
595
+ const openSession = instance.orchestrationAdapter
596
+ .openSession({
597
+ threadId: ThreadId.make("thread-upgraded"),
598
+ providerSessionId: ProviderSessionId.make("session-upgraded"),
599
+ modelSelection: { instanceId: instance.instanceId, model: "opencode/big-pickle" },
600
+ runtimePolicy: { runtimeMode: "full-access", interactionMode: "default", cwd: null },
601
+ })
602
+ .pipe(Effect.scoped, Effect.flip);
603
+
604
+ yield* openSession;
605
+ assert.deepStrictEqual(serverStarts, ["connect"], "1.x opens through the 1.x adapter");
606
+
607
+ versionOutput.current = "opencode v2.2.4\n";
608
+ serverStarts.length = 0;
609
+ yield* openSession;
610
+ assert.notInclude(
611
+ serverStarts,
612
+ "connect",
613
+ "after upgrading to 2.x, the next session must not open through the 1.x adapter",
614
+ );
615
+ assert.include(serverStarts, "start", "the OpenCode 2 adapter starts its server");
616
+ }).pipe(Effect.scoped),
617
+ );
618
});
packages/provider-opencode/src/server/versionProbe.test.ts
+4
-3
@@ -160,9 +160,9 @@ describe("OpenCode version probe", () => {
160
}),
161
);
162
163
- it.effect("remembers a probed runtime but never a failure", () =>
163
+ it.effect("remembers a probed 2.x runtime but re-probes 1.x and failures", () =>
164
Effect.gen(function* () {
165
- const outputs = ["", "opencode v2.0.18\n", "1.18.32\n"];
165
+ const outputs = ["", "opencode v2.0.18\n", "1.18.32\n", "1.18.32\n"];
166
let calls = 0;
167
const runtime = {
168
runOpenCodeCommand: () => {
@@ -190,8 +190,9 @@ describe("OpenCode version probe", () => {
190
assert.strictEqual((yield* probe.get).generation, "v2");
191
assert.strictEqual(calls, 2);
192
assert.strictEqual((yield* probe.refresh).generation, "v1");
193
- assert.strictEqual((yield* probe.get).generation, "v1");
193
assert.strictEqual(calls, 3);
194
+ assert.strictEqual((yield* probe.get).generation, "v1");
195
+ assert.strictEqual(calls, 4);
196
}),
197
);
198
});
packages/provider-opencode/src/server/versionProbe.ts
+4
-1
@@ -172,11 +172,14 @@ export const probeOpenCodeRuntime = (
172
? probeOpenCodeServer(settings.serverUrl, settings.serverPassword)
173
: probeOpenCodeBinary(settings.binaryPath, environment);
174
175
+// Only 2.x is kept: 1.x can be upgraded in place while T3 runs, and 2.x converts the shared
176
+// database, so going back is unsupported.
177
export const makeOpenCodeRuntimeProbe = <E>(probe: Effect.Effect<ProbedOpenCode, E>) =>
178
Effect.map(
179
Cache.makeWith(() => probe, {
180
capacity: 1,
179
- timeToLive: (exit) => (Exit.isSuccess(exit) ? Duration.infinity : Duration.zero),
181
+ timeToLive: (exit) =>
182
+ Exit.isSuccess(exit) && exit.value.generation === "v2" ? Duration.infinity : Duration.zero,
183
}),
184
(cache) => ({
185
get: Cache.get(cache, undefined),