Show live context compaction status in the TUI (#42319)

## Why

Context compaction was only reported after it completed, so the TUI did not
show when compaction was actively making room to continue.

## What changed

- Show `Compacting context` as soon as manual or server-driven compaction
  starts, with an elapsed timer independent of the current turn timer.
- Preserve the compaction status across follow-up input and transient activity,
  while still allowing retry errors to take precedence.
- Restore in-progress compaction timing from thread snapshots and add the live
  duration to the completion message.
- Clear stale compaction state when the turn starts, completes, or terminates.

## Testing

Added TUI tests covering manual and server-driven compaction, narrow rendering,
follow-up input, replay and task switching, retry status, timer preservation,
and turn termination.

GitOrigin-RevId: 804e1bc553315da24ff1f99462e8e282818cada3
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-02 18:03:55 +00:00
1 parent a94a5db629
commit a526f54b00
17 files changed
+392 -8

No files matched your search

@@ -68,6 +68,7 @@ impl ChatWidget {
// Raw reasoning uses the same flow as summarized reasoning
pub(super) fn on_task_started(&mut self) {
self.clear_context_compaction();
self.input_queue.user_turn_pending_start = false;
self.reset_safety_buffering_for_turn_start();
self.turn_lifecycle.start(Instant::now());
@@ -176,6 +177,7 @@ impl ChatWidget {
self.refresh_thread_usage_after_turn();
}
// Mark task stopped and request redraw now that all content is in history.
self.clear_context_compaction();
self.status_state.pending_status_indicator_restore = false;
self.input_queue.user_turn_pending_start = false;
self.clear_active_hook_cell();
@@ -313,6 +315,7 @@ impl ChatWidget {
/// This does not clear MCP startup tracking, because MCP startup can overlap with turn cleanup
/// and should continue to drive the bottom-pane running indicator while it is in progress.
pub(super) fn finalize_turn(&mut self) {
self.clear_context_compaction();
self.clear_safety_buffering();
// Drop preview-only stream tail content on any termination path before
// failed-cell finalization, so transient tail cells are never persisted.