Skip to content

Commit da9956f

Browse files
committed
fix: take snapshot before stream starts to fix diff tracking for some providers
Some providers emit the start-step event after tool execution has already begun, causing step-start and step-finish to have identical snapshots. This results in empty diffs and missing Modified Files in the UI. By taking the initial snapshot before the stream starts, we ensure we always capture the true 'before' state regardless of provider timing.
1 parent 0eaec2a commit da9956f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/opencode/src/session/processor.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export namespace SessionProcessor {
4040
},
4141
async process(fn: () => StreamTextResult<Record<string, AITool>, never>) {
4242
log.info("process")
43+
// Take initial snapshot BEFORE stream starts to ensure we capture
44+
// the "before" state regardless of when start-step event fires
45+
// (some providers emit start-step after tool execution begins)
46+
const initialSnapshot = await Snapshot.track()
4347
while (true) {
4448
try {
4549
let currentText: MessageV2.TextPart | undefined
@@ -229,7 +233,9 @@ export namespace SessionProcessor {
229233
throw value.error
230234

231235
case "start-step":
232-
snapshot = await Snapshot.track()
236+
// Use initialSnapshot taken before stream started to ensure
237+
// we have the true "before" state (some providers emit start-step late)
238+
snapshot = initialSnapshot
233239
await Session.updatePart({
234240
id: Identifier.ascending("part"),
235241
messageID: input.assistantMessage.id,

0 commit comments

Comments
 (0)