Render dynamic tool activity and preserve TUI history ordering (#46731)

## Why

The TUI ignored dynamic tool items, and replayed tool activity could differ from live output. Concurrent tool completion also needs to preserve transcript order when writing to terminal scrollback.

## What changed

- Retain dynamic tool rows, update them when calls finish out of order, and mark unfinished calls interrupted when a turn ends.
- Queue terminal output behind unfinished dynamic tools and drain settled rows in bounded batches. Preserve queued output through stream consolidation, resize, and rollback without emitting it twice.
- Align replayed file changes, MCP results, and exploration groups with live rendering. Keep hidden reasoning and terminal interaction details within compatible activity groups, and preserve finalized plan fragments.
- Ignore stale history-page responses, bound turn metadata requests to missing turns, and insert older history after session headers. Keep hidden review prompts as activity-group boundaries.

## Testing

Add regression tests and snapshots for out-of-order tool completion, interruption, ordered scrollback emission, rollback, deferred usage updates, replay consistency, overlapping history, and repeated hidden prompts.

GitOrigin-RevId: a3636cfcf4c9c43a0a5bc52a842b80a7834f1409
This commit is contained in:
Eric Traut
2026-09-20 00:03:43 +00:00
committed by copyberry
parent 392f56a611
commit 6ba6b73657
43 changed files with 1384 additions and 259 deletions
@@ -11,8 +11,9 @@ impl ChatWidget {
return;
};
let cell = history_cell::new_unified_exec_interaction(wait.command_display, String::new());
self.app_event_tx
.send(AppEvent::InsertHistoryCell(Box::new(cell)));
if let Err(cell) = self.absorb_activity_detail(Box::new(cell)) {
self.app_event_tx.send(AppEvent::InsertHistoryCell(cell));
}
self.restore_reasoning_status_header();
}
@@ -368,6 +369,25 @@ impl ChatWidget {
let is_unified_exec_interaction =
matches!(source, ExecCommandSource::UnifiedExecInteraction);
let is_user_shell = source == ExecCommandSource::UserShell;
// Completion-only replay has no begin event to join adjacent exploration. Extend only
// a finished, compatible group; an unrelated running group must retain orphan routing.
if let Some(cell) = self
.transcript
.active_cell
.as_mut()
.and_then(|cell| cell.as_any_mut().downcast_mut::<ExecCell>())
&& !cell.is_active()
&& !cell.should_flush()
&& !cell.iter_calls().any(|call| call.call_id == id)
{
cell.add_call(
id.clone(),
command.clone(),
parsed.clone(),
source,
/*interaction_input*/ None,
);
}
let end_target = match self.transcript.active_cell.as_ref() {
Some(cell) => match cell.as_any().downcast_ref::<ExecCell>() {
Some(exec_cell) if exec_cell.iter_calls().any(|call| call.call_id == id) => {
@@ -389,8 +409,6 @@ impl ChatWidget {
None => ExecEndTarget::NewCell,
};
// Unified exec interaction rows intentionally hide command output text in the exec cell and
// instead render the interaction-specific content elsewhere in the UI.
let output = if is_unified_exec_interaction {
CommandOutput::new(exit_code, String::new())
} else {