The best way to control Claude Code, Codex and more from any computer or phone
fix(opencode): OpenCode 2 threads see T3 Code's MCP tools on their first turn (#35084)
Julius Marminge committed
Nov 12, 2026 at 02:39 UTC
bf13d60e830afcebe6f5ae7285f2e927e001a8b3
2 files changed
+39
-18
apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts
+33
-18
@@ -4150,26 +4150,37 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
4150
promptAccepted,
4151
event("session.execution.succeeded", { sessionID: SESSION }),
4152
];
4153
+ const prompts: Array<unknown> = [];
4154
// Idle Location eviction drops OpenCode's runtime MCP servers without a reconnect.
4154
- const { runtime, thread } = yield* resumed([
4155
- add,
4156
- reply("mcp.add", null),
4157
- ...turn,
4158
- add,
4159
- reply("mcp.add", { status: 500, body: { message: "MCP unavailable" } }),
4160
- out("session.instructions.entry.put", {
4161
- sessionID: SESSION,
4162
- key: "t3-code",
4163
- value: buildRuntimeInstructions({ harness: "OpenCode", model: bigPickle.model }),
4164
- }),
4165
- reply("session.instructions.entry.put", null),
4166
- ...turn,
4167
- out("mcp.remove", { server, "location[directory]": WORK }),
4168
- reply("mcp.remove", null),
4169
- ]);
4155
+ const { runtime, thread } = yield* resumed(
4156
+ [
4157
+ add,
4158
+ reply("mcp.add", null),
4159
+ ...turn,
4160
+ add,
4161
+ reply("mcp.add", { status: 500, body: { message: "MCP unavailable" } }),
4162
+ out("session.instructions.entry.put", {
4163
+ sessionID: SESSION,
4164
+ key: "t3-code",
4165
+ value: buildRuntimeInstructions({ harness: "OpenCode", model: bigPickle.model }),
4166
+ }),
4167
+ reply("session.instructions.entry.put", null),
4168
+ ...turn,
4169
+ out("mcp.remove", { server, "location[directory]": WORK }),
4170
+ reply("mcp.remove", null),
4171
+ ],
4172
+ { onPrompt: (input) => prompts.push(input) },
4173
+ );
4174
for (let index = 0; index < 2; index++) {
4175
const terminal = yield* terminalOf(runtime).pipe(Effect.forkScoped);
4172
- yield* runtime.startTurn(turnInput(thread));
4176
+ const started = yield* runtime.startTurn(turnInput(thread)).pipe(Effect.forkScoped);
4177
+ // OpenCode before 2.2.6 loads a newly added server's tools after a debounce.
4178
+ if (index === 0) {
4179
+ yield* TestClock.adjust("249 millis");
4180
+ assert.lengthOf(prompts, 0, "prompted before OpenCode loaded the new MCP server's tools");
4181
+ yield* TestClock.adjust("1 millis");
4182
+ }
4183
+ yield* Fiber.join(started);
4184
assert.equal((yield* Fiber.join(terminal))?.status, "completed");
4185
}
4186
}).pipe(Effect.scoped),
@@ -4230,7 +4241,11 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
4241
runtimePolicy: policy(),
4242
});
4243
const terminal = yield* terminalOf(runtime).pipe(Effect.forkScoped);
4233
- yield* runtime.startTurn({ ...turnInput(thread), threadId: child });
4244
+ const started = yield* runtime
4245
+ .startTurn({ ...turnInput(thread), threadId: child })
4246
+ .pipe(Effect.forkScoped);
4247
+ yield* TestClock.adjust("250 millis");
4248
+ yield* Fiber.join(started);
4249
assert.equal((yield* Fiber.join(terminal))?.status, "completed");
4250
yield* runtime.unloadThread!({ providerThread: thread });
4251
}).pipe(Effect.scoped),
packages/provider-opencode/src/server/v2/adapter.ts
+6
@@ -592,6 +592,7 @@ const RECONNECT_WAIT = "30 seconds";
592
const LOST_BACKGROUND =
593
"T3 Code lost its connection to OpenCode while this subagent ran, so its result is not shown.";
594
const INVENTORY_TIMEOUT = "5 seconds";
595
+const MCP_TOOL_RELOAD_SETTLE = "250 millis";
596
const ACTIVE_CHECK_TIMEOUT = "5 seconds";
597
// Other failures may still have admitted the prompt.
598
const CLEAR_PROMPT_REJECTIONS: ReadonlySet<string> = new Set([
@@ -4060,6 +4061,7 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
4061
// Re-adding an unchanged config keeps its existing connection.
4062
let mcpAvailable = false;
4063
if (wanted !== undefined) {
4064
+ const fresh = state.mcp === undefined;
4065
mcpAvailable = yield* client.mcp
4066
.add({
4067
server: name,
@@ -4081,6 +4083,10 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
4083
),
4084
);
4085
if (mcpAvailable) state.mcp = wanted;
4086
+ // Before 2.2.6, OpenCode loads a new server's tools 100 ms after it connects, and a prompt sent sooner lacks them.
4087
+ if (mcpAvailable && fresh && compareSemverVersions(connection.version, "2.2.6") < 0) {
4088
+ yield* Effect.sleep(MCP_TOOL_RELOAD_SETTLE);
4089
+ }
4090
}
4091
const instructions = [
4092
buildRuntimeInstructions({ harness: "OpenCode", model: turnInput.modelSelection.model }),