Skip to content

Commit f5efac8

Browse files
Darth-Hidiousclaude
andcommitted
fix: add TextFlush event so LLM response text renders before cost line
Agent loop collected streaming deltas but never flushed them before emitting Cost/TurnComplete. TUI showed cost but no response text. Added AgentEvent::TextFlush emitted after all deltas, before turn end. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f4f3d28 commit f5efac8

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

crates/agent/src/agent_loop.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,15 @@ pub async fn run_turn(
432432
}
433433

434434
// ── 2e. Emit streamed text deltas ─────────────────────────
435-
for delta in &streaming_deltas {
436-
emit(AgentEvent::TextDelta {
437-
text: delta.clone(),
438-
});
435+
if !streaming_deltas.is_empty() {
436+
for delta in &streaming_deltas {
437+
emit(AgentEvent::TextDelta {
438+
text: delta.clone(),
439+
});
440+
}
441+
// Flush text so the TUI moves it from streaming buffer to chat history
442+
// before cost/turn-complete events arrive.
443+
emit(AgentEvent::TextFlush);
439444
}
440445

441446
// ── 2f. Push assistant message ────────────────────────────

crates/agent/src/protocol.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3774,6 +3774,9 @@ fn emit_agent_event(event: AgentEvent) {
37743774
AgentEvent::TextDelta { text } => {
37753775
emit_notification("ui.text.delta", serde_json::json!({ "text": text }));
37763776
}
3777+
AgentEvent::TextFlush => {
3778+
emit_notification("ui.text.flush", serde_json::json!({ "text": "" }));
3779+
}
37773780
AgentEvent::ToolCallStart {
37783781
tool_name,
37793782
call_id,

crates/agent/src/types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ pub enum AgentEvent {
8181
TextDelta {
8282
text: String,
8383
},
84+
/// Signal the frontend to flush accumulated streaming text into chat history.
85+
TextFlush,
8486
ToolCallStart {
8587
tool_name: String,
8688
call_id: String,

0 commit comments

Comments
 (0)