mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
## Why A streamed Markdown table can briefly disappear as the inline TUI moves it from the live response into scrollback. A resize during that handoff can also leave queued history wrapped to the previous terminal width. ## What changed Keep the last frame visible while stream consolidation is pending, while still accepting keyboard input. Clear and replay terminal history in the same synchronized update. If the terminal resizes before a queued replay is painted, rebuild it at the new width without waiting for the resize debounce. ## Testing Add a regression test that keeps a streamed table visible while accepting typeahead, then widens the terminal and checks that the table moves into scrollback and the next message fits on one line. Extend the terminal lifecycle test to cover resuming with a replay pending. GitOrigin-RevId: 11eb2ca0eef90e9e014383546e807cb73cdacfd8
59 lines
2.4 KiB
Rust
59 lines
2.4 KiB
Rust
//! Defer reset hints until active transcript output and stream consolidation have settled.
|
|
|
|
use super::ChatWidget;
|
|
use crate::app_event::AppEvent;
|
|
|
|
impl ChatWidget {
|
|
/// Reports whether completed asynchronous usage output must wait before insertion.
|
|
///
|
|
/// Inserting while a stream, queued consolidation, or active transcript cell is
|
|
/// present can reorder output relative to visible work, so callers retry once
|
|
/// these barriers clear.
|
|
pub(crate) fn usage_history_insertion_blocked(&self) -> bool {
|
|
self.stream_controller.is_some()
|
|
|| self.plan_stream_controller.is_some()
|
|
|| self.has_pending_stream_consolidation()
|
|
|| self.transcript.active_cell.is_some()
|
|
|| self.active_hook_cell.is_some()
|
|
}
|
|
|
|
pub(crate) fn has_pending_stream_consolidation(&self) -> bool {
|
|
self.pending_stream_consolidations > 0
|
|
}
|
|
|
|
/// Records a stream consolidation barrier that delays reset hint insertion.
|
|
///
|
|
/// Each queued consolidation should eventually call
|
|
/// [`ChatWidget::note_stream_consolidation_completed`].
|
|
pub(crate) fn note_stream_consolidation_queued(&mut self) {
|
|
self.pending_stream_consolidations =
|
|
self.pending_stream_consolidations.saturating_add(/*rhs*/ 1);
|
|
}
|
|
|
|
/// Releases one queued stream consolidation barrier.
|
|
///
|
|
/// The counter saturates at zero so an unmatched completion does not underflow,
|
|
/// but paired queue/completion calls are still the intended contract.
|
|
pub(crate) fn note_stream_consolidation_completed(&mut self) {
|
|
self.pending_stream_consolidations =
|
|
self.pending_stream_consolidations.saturating_sub(/*rhs*/ 1);
|
|
}
|
|
|
|
/// Requests another insertion attempt when completed usage output is waiting.
|
|
///
|
|
/// This is used after stream or history lifecycle events that may have cleared
|
|
/// the insertion barriers without directly owning the completed output.
|
|
pub(crate) fn request_pending_usage_output_insertion(&self) {
|
|
if self.pending_rate_limit_reset_hint().is_some() {
|
|
self.app_event_tx.send(AppEvent::CommitPendingUsageOutput);
|
|
}
|
|
}
|
|
|
|
pub(crate) fn request_pending_usage_output_insertion_after_stream_shutdown(&self) {
|
|
if self.pending_rate_limit_reset_hint().is_some() {
|
|
self.app_event_tx
|
|
.send(AppEvent::CommitPendingUsageOutputAfterStreamShutdown);
|
|
}
|
|
}
|
|
}
|