Skip to content

Commit e24253e

Browse files
Darth-Hidiousclaude
andcommitted
fix: emit clean content_text, not raw streaming deltas with leaked tool JSON
Streaming deltas captured partial tool_call JSON when SSE chunks split across the ``` boundary. Now emits the stripped content_text from the response instead — tool call blocks never leak into visible chat. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent da073e0 commit e24253e

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

crates/agent/src/agent_loop.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -431,17 +431,17 @@ pub async fn run_turn(
431431
transcript.record_cost("llm_turn", usage.prompt_tokens, usage.completion_tokens);
432432
}
433433

434-
// ── 2e. Emit streamed text deltas ─────────────────────────
435-
tracing::debug!(delta_count = streaming_deltas.len(), "emitting streamed text deltas");
436-
for delta in &streaming_deltas {
437-
emit(AgentEvent::TextDelta {
438-
text: delta.clone(),
439-
});
440-
}
441-
if !streaming_deltas.is_empty() {
442-
// Flush text so the TUI moves it from streaming buffer to chat history
443-
// before cost/turn-complete events arrive.
444-
emit(AgentEvent::TextFlush);
434+
// ── 2e. Emit text to TUI ─────────────────────────────────
435+
// Use the clean content from the response (tool call blocks already
436+
// stripped) instead of raw streaming deltas which can leak partial
437+
// tool call JSON when SSE chunks split across the ``` boundary.
438+
if let Some(content) = &response.message.content {
439+
if !content.is_empty() {
440+
emit(AgentEvent::TextDelta {
441+
text: content.clone(),
442+
});
443+
emit(AgentEvent::TextFlush);
444+
}
445445
}
446446

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

0 commit comments

Comments
 (0)