From 4d1ffa4b88424d27cfe97603edd85443c13b73ec Mon Sep 17 00:00:00 2001 From: huqiantao Date: Sun, 7 Jun 2026 19:32:58 +0800 Subject: [PATCH] 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. --- crates/tui/src/client/chat.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/tui/src/client/chat.rs b/crates/tui/src/client/chat.rs index 751698a7..4488506b 100644 --- a/crates/tui/src/client/chat.rs +++ b/crates/tui/src/client/chat.rs @@ -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);