@devries-cameron20 / t3code-1 / commits / 200a373fbd
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(opencode): keep streamed reply text after an event stream reconnect (#23591)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Victor Vogel committed Oct 30, 2026 at 15:54 UTC 200a373fbde4a41dd70c4d075a993fb079df14f4
2 files changed +56 -2
apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts
+43
@@ -2265,6 +2265,49 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
2265 }).pipe(Effect.scoped),
2266 );
2267
2268 + it.effect("continues a reply still streaming at reconnect from the text already shown", () =>
2269 + Effect.gen(function* () {
2270 + const delta = (text: string) =>
2271 + event("session.text.delta", {
2272 + sessionID: SESSION,
2273 + assistantMessageID: "msg_assistant_gap",
2274 + ordinal: 0,
2275 + delta: text,
2276 + });
2277 + const { runtime, thread } = yield* resumed([
2278 + out("session.prompt", { sessionID: SESSION, id: PROMPT_ID, text: "<any>" }),
2279 + promptAccepted,
2280 + delta("Sent before the stream dropped"),
2281 + // OpenCode saves a block's text only when the block ends.
2282 + ...reconnected({ [SESSION]: { type: "running" } }, undefined, {
2283 + content: [{ type: "text", text: "" }],
2284 + finish: undefined,
2285 + }),
2286 + ...openRequests([]),
2287 + delta(" and after it came back."),
2288 + event("session.execution.succeeded", { sessionID: SESSION }),
2289 + ]);
2290 + const events = yield* runtime.events.pipe(
2291 + Stream.takeUntil((event) => event.type === "turn.terminal"),
2292 + Stream.runCollect,
2293 + Effect.forkScoped,
2294 + );
2295 + yield* runtime.startTurn(turnInput(thread));
2296 + const collected = yield* Fiber.join(events);
2297 + const texts = collected.flatMap((event) =>
2298 + event.type === "turn_item.updated" && event.turnItem.type === "assistant_message"
2299 + ? [event.turnItem.text]
2300 + : [],
2301 + );
2302 + assert.deepEqual(texts, [
2303 + "Sent before the stream dropped",
2304 + "Sent before the stream dropped",
2305 + "Sent before the stream dropped and after it came back.",
2306 + "Sent before the stream dropped and after it came back.",
2307 + ]);
2308 + }).pipe(Effect.scoped),
2309 + );
2310 +
2311 it.effect("shows a permission asked while the stream was down, and answers it", () =>
2312 Effect.gen(function* () {
2313 const { runtime, thread } = yield* resumed(
packages/provider-opencode/src/server/v2/adapter.ts
+13 -2
@@ -2493,10 +2493,21 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
2493 for (const message of recent.toReversed()) {
2494 if (message.type !== "assistant" || state.active !== turn) continue;
2495 const ordinals = { text: 0, reasoning: 0 };
2496 - for (const part of message.content) {
2496 + for (const [index, part] of message.content.entries()) {
2497 if (part.type === "text" || part.type === "reasoning") {
2498 const block = { assistantMessageID: message.id, ordinal: ordinals[part.type]++ };
2499 - yield* emitText(state, turn, block, part.type, () => part.text, true);
2499 + // OpenCode saves a block's text only when the block ends, so the last block of a
2500 + // response still streaming stays open and keeps the text that already arrived.
2501 + const open =
2502 + message.time.streamed === undefined && index === message.content.length - 1;
2503 + yield* emitText(
2504 + state,
2505 + turn,
2506 + block,
2507 + part.type,
2508 + (text) => (open && !part.text.startsWith(text) ? text : part.text),
2509 + !open,
2510 + );
2511 continue;
2512 }
2513 if (part.type !== "tool") continue;