Skip to content

Commit 90fa675

Browse files
only21milclaude
andcommitted
fix(opencode): keep the text already shown when the snapshot is empty
OpenCode 2 saves a text or reasoning block only when the block ends, so a reconnect backfill of a reply still streaming reads an empty part. Keep the live text unless the snapshot extends it, and pin the test to that shape. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 2581481 commit 90fa675

2 files changed

Lines changed: 26 additions & 13 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,22 +2205,26 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
22052205
}).pipe(Effect.scoped),
22062206
);
22072207

2208-
it.effect("continues a reply still streaming at reconnect from its recovered text", () =>
2208+
it.effect("continues a reply still streaming at reconnect from the text already shown", () =>
22092209
Effect.gen(function* () {
2210+
const delta = (text: string) =>
2211+
event("session.text.delta", {
2212+
sessionID: SESSION,
2213+
assistantMessageID: "msg_assistant_gap",
2214+
ordinal: 0,
2215+
delta: text,
2216+
});
22102217
const { runtime, thread } = yield* resumed([
22112218
out("session.prompt", { sessionID: SESSION, id: PROMPT_ID, text: "<any>" }),
22122219
promptAccepted,
2220+
delta("Sent before the stream dropped"),
2221+
// OpenCode saves a block's text only when the block ends.
22132222
...reconnected({ [SESSION]: { type: "running" } }, undefined, {
2214-
content: [{ type: "text", text: "Sent while the stream" }],
2223+
content: [{ type: "text", text: "" }],
22152224
finish: undefined,
22162225
}),
22172226
...openRequests([]),
2218-
event("session.text.delta", {
2219-
sessionID: SESSION,
2220-
assistantMessageID: "msg_assistant_gap",
2221-
ordinal: 0,
2222-
delta: " was down.",
2223-
}),
2227+
delta(" and after it came back."),
22242228
event("session.execution.succeeded", { sessionID: SESSION }),
22252229
]);
22262230
const events = yield* runtime.events.pipe(
@@ -2236,9 +2240,10 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
22362240
: [],
22372241
);
22382242
assert.deepEqual(texts, [
2239-
"Sent while the stream",
2240-
"Sent while the stream was down.",
2241-
"Sent while the stream was down.",
2243+
"Sent before the stream dropped",
2244+
"Sent before the stream dropped",
2245+
"Sent before the stream dropped and after it came back.",
2246+
"Sent before the stream dropped and after it came back.",
22422247
]);
22432248
}).pipe(Effect.scoped),
22442249
);

‎packages/provider-opencode/src/server/v2/adapter.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,10 +2565,18 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
25652565
for (const [index, part] of message.content.entries()) {
25662566
if (part.type === "text" || part.type === "reasoning") {
25672567
const block = { assistantMessageID: message.id, ordinal: ordinals[part.type]++ };
2568-
// The last block of a response still streaming keeps its text for the next delta.
2568+
// OpenCode saves a block's text only when the block ends, so the last block of a
2569+
// response still streaming stays open and keeps the text that already arrived.
25692570
const open =
25702571
message.time.streamed === undefined && index === message.content.length - 1;
2571-
yield* emitText(state, turn, block, part.type, () => part.text, !open);
2572+
yield* emitText(
2573+
state,
2574+
turn,
2575+
block,
2576+
part.type,
2577+
(text) => (open && !part.text.startsWith(text) ? text : part.text),
2578+
!open,
2579+
);
25722580
continue;
25732581
}
25742582
if (part.type !== "tool") continue;

0 commit comments

Comments
 (0)