mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Delay automatic recaps and compact their TUI layout (#45089)
## What changed - Increase the automatic recap delay from 3 to 30 minutes. - Replace the recap heading and divider with an italic `↳ Recap:` layout, hanging indentation, and right padding. Preserve explicit line breaks and Unicode, splitting URLs only when they exceed the available text column. - Use Tokio's clock for automatic recap eligibility and create the timer before spawning its task. - Remove the `token_budget.use_history_notes_extension` override from temporary structured requests. ## Testing Add coverage for the 30-minute deadline, recap styling, narrow terminals, Unicode, and URL wrapping. Update recap generation and reconnect tests to advance Tokio's clock instead of relying on host uptime. GitOrigin-RevId: 79a9bca779020b59a409207163b02944b30c1a20
This commit is contained in:
1 parent
ee6814bfa4
commit
f16c2237a5
7 files changed
+193
-62
No files matched your search
@@ -2950,7 +2950,9 @@ impl App {
|
||||
AppEvent::CheckRecap { thread_id } => {
|
||||
if self.current_displayed_thread_id() == Some(thread_id)
|
||||
&& !self.chat_widget.is_user_turn_pending_or_running()
|
||||
&& self.recap.should_generate(std::time::Instant::now())
|
||||
&& self
|
||||
.recap
|
||||
.should_generate(tokio::time::Instant::now().into_std())
|
||||
{
|
||||
self.request_recap(app_server, thread_id, RecapTrigger::Automatic);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ use uuid::Uuid;
|
||||
|
||||
const MIN_COMPLETED_TURNS: usize = 3;
|
||||
const MIN_TURNS_BETWEEN_RECAPS: usize = 2;
|
||||
pub(super) const RECAP_DELAY: Duration = Duration::from_secs(/*secs*/ 3 * 60);
|
||||
pub(super) const RECAP_DELAY: Duration = Duration::from_secs(/*secs*/ 30 * 60);
|
||||
const RECAP_HISTORY_MAX_TURNS: usize = 8;
|
||||
const RECAP_MAX_CHARS: usize = 320;
|
||||
const RECAP_RETRY_DELAY: Duration = Duration::from_secs(/*secs*/ 30);
|
||||
@@ -196,10 +196,11 @@ impl App {
|
||||
return;
|
||||
};
|
||||
let delay = deadline.saturating_duration_since(now);
|
||||
let sleep = tokio::time::sleep(delay);
|
||||
let app_event_tx = self.app_event_tx.clone();
|
||||
|
||||
self.recap.scheduled_check = Some(tokio::spawn(async move {
|
||||
tokio::time::sleep(delay).await;
|
||||
sleep.await;
|
||||
app_event_tx.send(AppEvent::CheckRecap { thread_id });
|
||||
}));
|
||||
}
|
||||
@@ -357,7 +358,9 @@ impl App {
|
||||
};
|
||||
|
||||
let trigger_is_eligible = match trigger {
|
||||
RecapTrigger::Automatic => self.recap.should_generate(Instant::now()),
|
||||
RecapTrigger::Automatic => self
|
||||
.recap
|
||||
.should_generate(tokio::time::Instant::now().into_std()),
|
||||
RecapTrigger::Manual => true,
|
||||
};
|
||||
|
||||
|
||||
@@ -21,10 +21,13 @@ use crate::history_cell::PlainHistoryCell;
|
||||
use crate::history_cell::ThreadRecapHistoryCell;
|
||||
use crate::history_cell::ThreadRecapLoadingCell;
|
||||
use crate::history_cell::UserHistoryCell;
|
||||
use crate::line_truncation::line_width;
|
||||
use codex_app_server_protocol::Turn;
|
||||
use codex_app_server_protocol::TurnStatus;
|
||||
use codex_protocol::ThreadId;
|
||||
use pretty_assertions::assert_eq;
|
||||
use ratatui::style::Modifier;
|
||||
use ratatui::style::Stylize;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
@@ -316,7 +319,7 @@ fn regaining_focus_preserves_only_manual_in_flight_request() {
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread", start_paused = true)]
|
||||
async fn scheduled_check_fires_at_recap_deadline() {
|
||||
async fn scheduled_check_fires_after_thirty_minutes() {
|
||||
let thread_id = ThreadId::new();
|
||||
let now = Instant::now();
|
||||
let mut app = make_test_app().await;
|
||||
@@ -330,7 +333,7 @@ async fn scheduled_check_fires_at_recap_deadline() {
|
||||
app.schedule_recap_check(thread_id, now);
|
||||
tokio::task::yield_now().await;
|
||||
|
||||
tokio::time::advance(RECAP_DELAY - Duration::from_secs(/*secs*/ 1)).await;
|
||||
tokio::time::advance(Duration::from_secs(/*secs*/ 30 * 60 - 1)).await;
|
||||
tokio::task::yield_now().await;
|
||||
assert!(matches!(event_rx.try_recv(), Err(TryRecvError::Empty)));
|
||||
|
||||
@@ -518,20 +521,28 @@ fn restored_history_never_reduces_observed_completed_turns() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recap_history_cell_uses_labeled_checkpoint_layout() {
|
||||
fn recap_history_cell_uses_hanging_indent_and_right_padding() {
|
||||
let cell =
|
||||
ThreadRecapHistoryCell::new("Automatic recaps stay compact on wide terminals.".to_string());
|
||||
let rendered = cell
|
||||
.display_lines(/*width*/ 64)
|
||||
let lines = cell.display_lines(/*width*/ 56);
|
||||
assert!(
|
||||
lines
|
||||
.iter()
|
||||
.all(|line| line.style.add_modifier.contains(Modifier::ITALIC))
|
||||
);
|
||||
assert_eq!(
|
||||
&lines[0].spans[..3],
|
||||
&[" ".into(), "↳ ".dim(), "Recap: ".bold()],
|
||||
);
|
||||
let rendered = lines
|
||||
.iter()
|
||||
.map(ToString::to_string)
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
|
||||
insta::assert_snapshot!(rendered, @r"
|
||||
─ Conversation recap ───────────────────────────────────────────
|
||||
|
||||
Automatic recaps stay compact on wide terminals.
|
||||
↳ Recap: Automatic recaps stay compact on wide
|
||||
terminals.
|
||||
");
|
||||
}
|
||||
|
||||
@@ -548,13 +559,119 @@ fn recap_history_cell_wraps_in_narrow_terminals() {
|
||||
.join("\n");
|
||||
|
||||
insta::assert_snapshot!(rendered, @r"
|
||||
─ Conversation recap ───────────
|
||||
|
||||
Keep conversation recaps
|
||||
readable in narrow terminals.
|
||||
↳ Recap: Keep conversation
|
||||
recaps readable in
|
||||
narrow terminals.
|
||||
");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recap_history_cell_preserves_unicode_and_url_tokens() {
|
||||
let cell = ThreadRecapHistoryCell::new(
|
||||
"Résumé ready. See https://example.com/review/42 日本語 details.".to_string(),
|
||||
);
|
||||
let rendered = cell
|
||||
.display_lines(/*width*/ 48)
|
||||
.iter()
|
||||
.map(ToString::to_string)
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
|
||||
insta::assert_snapshot!(rendered, @r"
|
||||
↳ Recap: Résumé ready. See
|
||||
https://example.com/review/42
|
||||
日本語 details.
|
||||
");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recap_history_cell_wraps_long_urls_in_narrow_terminals() {
|
||||
let cell = ThreadRecapHistoryCell::new(
|
||||
"The café review is paused with the draft ready at https://example.com/review/42. 日本語"
|
||||
.to_string(),
|
||||
);
|
||||
let lines = cell.display_lines(/*width*/ 32);
|
||||
assert!(lines.iter().all(|line| line_width(line) <= 30));
|
||||
assert!(
|
||||
lines
|
||||
.iter()
|
||||
.skip(/*n*/ 1)
|
||||
.all(|line| line.to_string().starts_with(" "))
|
||||
);
|
||||
assert!(
|
||||
lines
|
||||
.iter()
|
||||
.all(|line| line.style.add_modifier.contains(Modifier::ITALIC))
|
||||
);
|
||||
let rendered = lines
|
||||
.iter()
|
||||
.map(ToString::to_string)
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
|
||||
insta::assert_snapshot!(rendered, @"
|
||||
↳ Recap: The café review is
|
||||
paused with the
|
||||
draft ready at
|
||||
https://example.com
|
||||
/review/42. 日本語
|
||||
");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recap_history_cell_splits_only_urls_wider_than_the_text_column() {
|
||||
for (url, expected) in [
|
||||
(
|
||||
"https://example.com",
|
||||
vec![" ↳ Recap: https://example.com"],
|
||||
),
|
||||
(
|
||||
"https://example.com/",
|
||||
vec![" ↳ Recap: https://example.com", " /"],
|
||||
),
|
||||
(
|
||||
"https://a.co/ガガガガガガ",
|
||||
vec![" ↳ Recap: https://a.co/ガガガ", " ガガガ"],
|
||||
),
|
||||
] {
|
||||
let cell = ThreadRecapHistoryCell::new(url.to_string());
|
||||
let lines = cell.display_lines(/*width*/ 32);
|
||||
assert!(lines.iter().all(|line| line_width(line) <= 30));
|
||||
assert_eq!(
|
||||
lines.iter().map(ToString::to_string).collect::<Vec<_>>(),
|
||||
expected
|
||||
);
|
||||
let displayed_url = lines
|
||||
.iter()
|
||||
.map(|line| line.to_string().chars().skip(/*n*/ 11).collect::<String>())
|
||||
.collect::<String>();
|
||||
assert_eq!(displayed_url, url);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recap_history_cell_uses_available_space_below_indent_width() {
|
||||
let cell = ThreadRecapHistoryCell::new(
|
||||
"Resume this task.\nhttps://example.com/review/42.".to_string(),
|
||||
);
|
||||
let rendered = cell
|
||||
.display_lines(/*width*/ 12)
|
||||
.iter()
|
||||
.map(ToString::to_string)
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
|
||||
insta::assert_snapshot!(rendered, @r"
|
||||
↳ Recap:
|
||||
Resume
|
||||
this task.
|
||||
https://ex
|
||||
ample.com/
|
||||
review/42.
|
||||
");
|
||||
assert_eq!(cell.display_lines(/*width*/ 0), Vec::new());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recap_history_cell_preserves_heading_in_raw_history() {
|
||||
let cell = ThreadRecapHistoryCell::new("Resume this task.".to_string());
|
||||
@@ -590,10 +707,8 @@ fn recap_history_cell_preserves_explicit_line_breaks() {
|
||||
.join("\n");
|
||||
|
||||
insta::assert_snapshot!(displayed, @r"
|
||||
─ Conversation recap ───────────────────────────
|
||||
|
||||
Finished the parser.
|
||||
Next: run the focused tests.
|
||||
↳ Recap: Finished the parser.
|
||||
Next: run the focused tests.
|
||||
");
|
||||
insta::assert_snapshot!(raw, @r"
|
||||
Conversation recap
|
||||
|
||||
@@ -231,7 +231,7 @@ async fn reconnect_restores_history_permissions_and_keeps_old_input_paused() ->
|
||||
&mut app.rate_limit_hard_stop_generation,
|
||||
)
|
||||
.unwrap();
|
||||
let before_disconnect = Instant::now() - Duration::from_secs(/*secs*/ 300);
|
||||
let before_disconnect = Instant::now();
|
||||
app.recap.note_focus_lost(before_disconnect);
|
||||
for _ in 0..3 {
|
||||
app.recap
|
||||
@@ -273,6 +273,10 @@ async fn reconnect_restores_history_permissions_and_keeps_old_input_paused() ->
|
||||
!app.agent_navigation
|
||||
.finish_picker_refresh(id, stale_picker_refresh)
|
||||
);
|
||||
// Let the rebound timer become due without depending on machine uptime.
|
||||
tokio::time::pause();
|
||||
tokio::time::advance(recap::RECAP_DELAY).await;
|
||||
tokio::time::resume();
|
||||
let mut deferred = Vec::new();
|
||||
tokio::time::timeout(Duration::from_secs(/*secs*/ 5), async {
|
||||
loop {
|
||||
|
||||
@@ -34,7 +34,7 @@ fn render_chat_widget(app: &App) -> String {
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
fn prepare_eligible_recap(app: &mut App, thread_id: ThreadId) {
|
||||
async fn prepare_eligible_recap(app: &mut App, thread_id: ThreadId) {
|
||||
app.active_thread_id = Some(thread_id);
|
||||
app.transcript_cells
|
||||
.push(Arc::new(crate::history_cell::UserHistoryCell {
|
||||
@@ -44,15 +44,19 @@ fn prepare_eligible_recap(app: &mut App, thread_id: ThreadId) {
|
||||
local_image_paths: Vec::new(),
|
||||
remote_image_urls: Vec::new(),
|
||||
}));
|
||||
let ready_at = Instant::now() - recap::RECAP_DELAY;
|
||||
let ready_at = Instant::now();
|
||||
app.recap.note_focus_lost(ready_at);
|
||||
for _ in 0..3 {
|
||||
app.recap
|
||||
.note_turn_finished(&TurnStatus::Completed, ready_at);
|
||||
}
|
||||
// Advance the scheduler's clock instead of subtracting from the host's uptime.
|
||||
tokio::time::pause();
|
||||
tokio::time::advance(recap::RECAP_DELAY).await;
|
||||
tokio::time::resume();
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
#[tokio::test]
|
||||
async fn recap_generation_uses_bounded_structured_request_and_inserts_result() -> Result<()> {
|
||||
let chunks = [
|
||||
ev_response_created("recap-response"),
|
||||
@@ -113,7 +117,7 @@ stream_max_retries = 0
|
||||
.await?;
|
||||
while app_event_rx.try_recv().is_ok() {}
|
||||
|
||||
prepare_eligible_recap(&mut app, thread_id);
|
||||
prepare_eligible_recap(&mut app, thread_id).await;
|
||||
|
||||
app.handle_event(
|
||||
&mut tui,
|
||||
@@ -305,7 +309,7 @@ async fn manual_recap_works_when_auto_recap_disabled() -> Result<()> {
|
||||
async fn auto_recap_opt_out_blocks_requests_and_cleans_up_pending_start() -> Result<()> {
|
||||
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
|
||||
let thread_id = ThreadId::new();
|
||||
prepare_eligible_recap(&mut app, thread_id);
|
||||
prepare_eligible_recap(&mut app, thread_id).await;
|
||||
let (mut app_server, requests, proxy) = start_recording_remote_app_server(&app.config).await?;
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
app.local_settings.tui.auto_recap = false;
|
||||
@@ -453,7 +457,7 @@ async fn temporary_recap_threads_disable_memories_and_remote_mcp_servers() -> Re
|
||||
async fn recap_check_rejects_a_non_displayed_thread() -> Result<()> {
|
||||
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
|
||||
let displayed_thread_id = ThreadId::new();
|
||||
prepare_eligible_recap(&mut app, displayed_thread_id);
|
||||
prepare_eligible_recap(&mut app, displayed_thread_id).await;
|
||||
while app_event_rx.try_recv().is_ok() {}
|
||||
let (mut app_server, requests, proxy) = start_recording_remote_app_server(&app.config).await?;
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
@@ -483,7 +487,7 @@ async fn recap_check_rejects_a_non_displayed_thread() -> Result<()> {
|
||||
async fn recap_check_rejects_a_running_turn() -> Result<()> {
|
||||
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
|
||||
let thread_id = ThreadId::new();
|
||||
prepare_eligible_recap(&mut app, thread_id);
|
||||
prepare_eligible_recap(&mut app, thread_id).await;
|
||||
app.chat_widget
|
||||
.handle_thread_session(test_thread_session(thread_id, app.config.cwd.to_path_buf()));
|
||||
app.chat_widget.handle_server_notification(
|
||||
|
||||
Reference in new issue
Block a user