mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
## 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
58 lines
2.0 KiB
Rust
58 lines
2.0 KiB
Rust
//! Live compaction status. Its wall clock is separate from the turn's running time,
|
|
//! and only a matching live completion contributes a duration to the transcript.
|
|
|
|
use super::*;
|
|
|
|
pub(super) const COMPACTION_HEADER: &str = "Compacting context";
|
|
pub(super) const COMPACTION_DETAILS: &str = "Making room to continue.";
|
|
|
|
#[derive(Debug)]
|
|
pub(super) struct ActiveCompaction {
|
|
pub(super) id: String,
|
|
pub(super) started_at: Instant,
|
|
}
|
|
|
|
impl ChatWidget {
|
|
pub(super) fn on_context_compaction_started(&mut self, id: String, elapsed: Duration) {
|
|
if self
|
|
.status_state
|
|
.compaction
|
|
.as_ref()
|
|
.is_some_and(|active| active.id == id)
|
|
{
|
|
return;
|
|
}
|
|
self.flush_answer_stream_with_separator();
|
|
let now = Instant::now();
|
|
let started_at = now.checked_sub(elapsed).unwrap_or(now);
|
|
self.status_state.compaction = Some(ActiveCompaction { id, started_at });
|
|
self.bottom_pane.set_status_timer_origin(Some(started_at));
|
|
self.bottom_pane.ensure_status_indicator();
|
|
self.set_status_header(COMPACTION_HEADER.to_string());
|
|
}
|
|
|
|
pub(super) fn clear_context_compaction(&mut self) {
|
|
if self.status_state.compaction.take().is_some() {
|
|
self.bottom_pane
|
|
.set_status_timer_origin(/*started_at*/ None);
|
|
self.set_status_header("Working".to_string());
|
|
}
|
|
}
|
|
|
|
pub(super) fn on_context_compaction_completed(&mut self, id: &str, from_replay: bool) {
|
|
let mut message = "Context compacted".to_string();
|
|
if let Some(active) = self.status_state.compaction.as_ref()
|
|
&& active.id == id
|
|
{
|
|
if !from_replay {
|
|
let elapsed = crate::status_indicator_widget::fmt_elapsed_compact(
|
|
active.started_at.elapsed().as_secs(),
|
|
);
|
|
message = format!("Context compacted · {elapsed}");
|
|
}
|
|
self.clear_context_compaction();
|
|
}
|
|
self.add_info_message(message, /*hint*/ None);
|
|
}
|
|
}
|