fix(session): finalize interrupted assistant messages (#27254)

This commit is contained in:
Aiden Cline
2026-05-14 01:19:11 -05:00
committed by GitHub
parent c2723b5ea0
commit e76cf967e6
2 changed files with 139 additions and 12 deletions

View File

@@ -1755,12 +1755,25 @@ NOTE: At any point in time through this workflow you should feel free to ask the
sessionID,
}
yield* sessions.updateMessage(msg)
const handle = yield* processor.create({
assistantMessage: msg,
sessionID,
model,
const finalizeInterruptedAssistant = Effect.gen(function* () {
if (msg.time.completed) return
msg.error ??= MessageV2.fromError(new DOMException("Aborted", "AbortError"), {
providerID: msg.providerID,
aborted: true,
})
msg.time.completed = Date.now()
yield* sessions.updateMessage(msg)
})
const handle = yield* processor
.create({
assistantMessage: msg,
sessionID,
model,
})
.pipe(Effect.onInterrupt(() => finalizeInterruptedAssistant))
const outcome: "break" | "continue" = yield* Effect.gen(function* () {
const lastUserMsg = msgs.findLast((m) => m.info.role === "user")
const bypassAgentCheck = lastUserMsg?.parts.some((p) => p.type === "agent") ?? false
@@ -1859,7 +1872,10 @@ NOTE: At any point in time through this workflow you should feel free to ask the
})
}
return "continue" as const
}).pipe(Effect.ensuring(instruction.clear(handle.message.id)))
}).pipe(
Effect.ensuring(instruction.clear(handle.message.id)),
Effect.onInterrupt(() => finalizeInterruptedAssistant),
)
if (outcome === "break") break
continue
}