diff --git a/ai-hub/app/core/orchestration/architect.py b/ai-hub/app/core/orchestration/architect.py index 25f7a76..4e3e596 100644 --- a/ai-hub/app/core/orchestration/architect.py +++ b/ai-hub/app/core/orchestration/architect.py @@ -148,6 +148,10 @@ async for event in self.stream.process_chunk(fallback_text, turn): if event["type"] == "content": accumulated_content += event["content"] yield event + # Ensure the fallback (and potential header) is flushed + async for event in self.stream.end_stream(turn): + if event["type"] == "content": accumulated_content += event["content"] + yield event # Branch: Tools or Exit? if not tool_calls_map: diff --git a/ai-hub/app/core/orchestration/stream.py b/ai-hub/app/core/orchestration/stream.py index 578fbd0..aae34da 100644 --- a/ai-hub/app/core/orchestration/stream.py +++ b/ai-hub/app/core/orchestration/stream.py @@ -60,11 +60,12 @@ self.tag_buffer = "" else: - # Inside thinking tag - reasoning should not be prefix-buffered - # But if we were buffering prefix, flush it now - if not self.header_sent and self.prefix_buffer: + # Inside thinking tag + if not self.header_sent: async for event in self._flush_prefix("", turn_header): yield event + + # reasoning should not be prefix-buffered lower_buf = self.tag_buffer.lower() end_tag_idx = lower_buf.find("") @@ -133,9 +134,10 @@ text = text[:md_header_match.start()] + text[md_header_match.end():] if not text.strip(): - # If after stripping the text is empty, don't send anything yet (unless it's the very first chunk) + # If after stripping the text is empty, but we must send the header, do it now if not self.header_sent: - return None + self.header_sent = True + return header return "" if not self.header_sent: diff --git a/ai-hub/test.db-shm b/ai-hub/test.db-shm index 16a8a19..a748772 100644 --- a/ai-hub/test.db-shm +++ b/ai-hub/test.db-shm Binary files differ diff --git a/ai-hub/test.db-wal b/ai-hub/test.db-wal index 56bd098..bd2b173 100644 --- a/ai-hub/test.db-wal +++ b/ai-hub/test.db-wal Binary files differ