mirror of
https://github.com/openai/codex.git
synced 2026-12-05 01:00:54 +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
62 lines
1.8 KiB
Rust
62 lines
1.8 KiB
Rust
//! Pause-aware status time owned independently of the optional status row.
|
|
//! A phase can override the displayed clock without changing turn accounting.
|
|
|
|
use std::time::Duration;
|
|
use std::time::Instant;
|
|
|
|
#[derive(Debug)]
|
|
pub(crate) struct StatusTimer {
|
|
/// Optional wall-clock origin for the displayed phase, without resetting turn accounting.
|
|
pub(crate) display_started_at: Option<Instant>,
|
|
pub(super) elapsed_running: Duration,
|
|
pub(super) last_resume_at: Instant,
|
|
pub(super) is_paused: bool,
|
|
}
|
|
|
|
impl Default for StatusTimer {
|
|
fn default() -> Self {
|
|
Self {
|
|
display_started_at: None,
|
|
elapsed_running: Duration::ZERO,
|
|
last_resume_at: Instant::now(),
|
|
is_paused: false,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl StatusTimer {
|
|
pub(crate) fn reset(&mut self, elapsed: Duration) {
|
|
self.elapsed_running = elapsed;
|
|
self.last_resume_at = Instant::now();
|
|
// A turn can start while an MCP elicitation or approval is still open.
|
|
// Reset elapsed time without changing that modal's pause state.
|
|
}
|
|
|
|
pub(crate) fn pause_at(&mut self, now: Instant) {
|
|
if !self.is_paused {
|
|
self.elapsed_running += now.saturating_duration_since(self.last_resume_at);
|
|
self.is_paused = true;
|
|
}
|
|
}
|
|
|
|
pub(crate) fn resume_at(&mut self, now: Instant) {
|
|
if self.is_paused {
|
|
self.last_resume_at = now;
|
|
self.is_paused = false;
|
|
}
|
|
}
|
|
|
|
pub(crate) fn elapsed_at(&self, now: Instant) -> Duration {
|
|
self.elapsed_running
|
|
+ if self.is_paused {
|
|
Duration::ZERO
|
|
} else {
|
|
now.saturating_duration_since(self.last_resume_at)
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "timer_tests.rs"]
|
|
mod tests;
|