mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
compact: preserve incoming items during pre-turn trim retries
This commit is contained in:
@@ -3406,10 +3406,10 @@ mod handlers {
|
||||
// Attempt to inject input into current task.
|
||||
if let Err(SteerInputError::NoActiveTurn(items)) = sess.steer_input(items, None).await {
|
||||
sess.seed_initial_context_if_needed(¤t_context).await;
|
||||
let resumed_model = sess.take_pending_resume_previous_model().await;
|
||||
let previous_model = sess.previous_model().await;
|
||||
let pre_turn_context_items = sess.build_settings_update_items(
|
||||
previous_context.as_ref(),
|
||||
resumed_model.as_deref(),
|
||||
previous_model.as_deref(),
|
||||
¤t_context,
|
||||
);
|
||||
let has_user_input = !items.is_empty();
|
||||
|
||||
@@ -167,6 +167,12 @@ async fn run_compact_task_inner(
|
||||
&[initial_input_for_turn.into()],
|
||||
turn_context.truncation_policy,
|
||||
);
|
||||
// Keep incoming turn items and the compaction prompt pinned at the tail while trimming.
|
||||
// Pre-turn compaction should fail with ContextWindowExceeded rather than dropping incoming
|
||||
// items to force compaction to succeed.
|
||||
let protected_tail_items = incoming_items
|
||||
.as_ref()
|
||||
.map_or(1_usize, |items| items.len().saturating_add(1));
|
||||
|
||||
let mut truncated_count = 0usize;
|
||||
|
||||
@@ -224,7 +230,7 @@ async fn run_compact_task_inner(
|
||||
return Err(CodexErr::Interrupted);
|
||||
}
|
||||
Err(e @ CodexErr::ContextWindowExceeded) => {
|
||||
if turn_input_len > 1 {
|
||||
if turn_input_len > 1 && history.raw_items().len() > protected_tail_items {
|
||||
// Trim from the beginning to preserve cache (prefix-based) and keep recent
|
||||
// messages intact.
|
||||
error!(
|
||||
|
||||
Reference in New Issue
Block a user