Preserve streamed answers and plans when turns terminate (#45549)

## Why

Interrupted or failed turns can discard buffered answer or plan source, leaving incomplete math content missing from the transcript or unable to reflow correctly.

## What changed

Flush and consolidate both answer and plan streams before `finalize_turn` clears streaming state. Reuse the same helper for normal completion, preserving received source for terminal resizing and raw output mode changes.

## Testing

Add regression coverage for interrupted answers and plans, failed plans, and policy errors with unfinished math blocks, with and without a trailing newline. Verify source preservation and stable content across width and raw output mode changes, with narrow transcript snapshots. Update the usage activity test to verify that history insertion waits for stream consolidation.

GitOrigin-RevId: 1ae0c192e2fee00dc0b5ee2ac07f3d5f2313ad1b
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-14 23:52:39 +00:00
1 parent c18db9ba69
commit 529bcb2fdf
8 files changed
+178 -16

No files matched your search

+2
View File
@@ -2,6 +2,8 @@
#[path = "tests/daybreak_tests.rs"]
mod daybreak_tests;
#[path = "tests/math_interruption_tests.rs"]
mod math_interruption_tests;
#[path = "tests/advanced_reasoning_tests.rs"]
mod advanced_reasoning_tests;