fix: use content_index directly for ContentBlockStop cleanup

The content_index is only incremented AFTER a block is closed, not
when opened. Using saturating_sub(1) would close the wrong block.
The reviewer correctly identified this logic error.
This commit is contained in:
huqiantao
2026-06-07 19:32:58 +08:00
parent 3468b25cf3
commit 4d1ffa4b88
+4 -6
View File
@@ -434,13 +434,11 @@ impl DeepSeekClient {
}
}
// Close any open blocks — use the current content_index
// (which points to the next unused slot, so -1 gives the
// last-opened block) but guard against underflow when no
// content block was ever opened.
// Close any open blocks — content_index points to the
// currently active open block (it is only incremented
// *after* a block is closed, not when opened).
if thinking_started || text_started {
let idx = content_index.saturating_sub(1);
yield Ok(StreamEvent::ContentBlockStop { index: idx });
yield Ok(StreamEvent::ContentBlockStop { index: content_index });
}
release_stream_buffer(byte_buf);