fix(chat): keep streamed reasoning live across queued follow-ups

This commit is contained in:
2026-10-24 02:04:44 +01:00
parent de7c308fdb
commit 8e980564cb
4 changed files with 61 additions and 6 deletions
@@ -54,6 +54,7 @@ List<JsonMap> transcriptRows(
List<JsonMap> messages, {
List<JsonMap> trailing = const [],
bool running = false,
String? liveMessageId,
}) {
final rows = <JsonMap>[];
String? key;
@@ -114,14 +115,18 @@ List<JsonMap> transcriptRows(
}
}
flush();
// Only the newest assistant turn can be live. A running step before the
// first assistant delta must not reopen reasoning from an earlier reply.
if (running && messages.isNotEmpty && messages.last['role'] == 'assistant') {
// Prefer the assistant identity that actually streamed: a queued follow-up
// can be later in the transcript while this same reply is still arriving.
// Before a first delta, do not reopen an older reply behind a new user turn.
final streamingId =
liveMessageId ??
(messages.isNotEmpty && messages.last['role'] == 'assistant'
? '${messages.last['id'] ?? ''}'
: null);
if (running && streamingId != null) {
for (final row in rows.reversed) {
if (row['kind'] == 'assistant' &&
(row['messageIds'] as List).contains(
'${messages.last['id'] ?? ''}',
)) {
(row['messageIds'] as List).contains(streamingId)) {
row['streaming'] = true;
break;
}