Skip to content

Lightpanda: the headless browser designed for AI and automation

docs(agent): note why the streamed_text guard is turn-wide safe

Adrià Arrufat2e8e0d1a6fe9
diff --git a/src/agent/Agent.zig b/src/agent/Agent.zig
index 141253599..8c340f3c8 100644
--- a/src/agent/Agent.zig
+++ b/src/agent/Agent.zig
@@ -683,7 +683,10 @@ fn runTurn(self: *Agent, input: TurnInput) bool {
if (!input.suppress_answer) {
if (text) |t| {
// Streaming already emitted the text incrementally (plus a closing
- // newline); only the buffered path needs to print it here.
+ // newline); only the buffered path needs to print it here. Safe as a
+ // turn-wide flag: the stream accumulator reconstructs `t` from the
+ // same deltas it emitted, and the synthesis fallback also streams, so
+ // `streamed_text` implies `t` was already shown in full.
if (!self.streamed_text) self.terminal.printAssistant(t);
} else if (self.last_turn_refused)
self.terminal.printInfo("(model declined to respond — safety refusal)", .{})