-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[codex] Harden overflow auto-compaction recovery #22141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a175208
1482455
c568bf1
a568d99
b20b795
6c445f6
c3a51fb
fb557f6
4d17876
4b691eb
2aa791e
c2bfd5e
77769ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ use crate::compact::InitialContextInjection; | |
| use crate::compact::collect_user_messages; | ||
| use crate::compact::run_inline_auto_compact_task; | ||
| use crate::compact::should_use_remote_compact_task; | ||
| use crate::compact::user_message_text; | ||
| use crate::compact_remote::run_inline_remote_auto_compact_task; | ||
| use crate::compact_remote_v2::run_inline_remote_auto_compact_task as run_inline_remote_auto_compact_task_v2; | ||
| use crate::connectors; | ||
|
|
@@ -310,7 +311,7 @@ pub(crate) async fn run_turn( | |
| Vec::new() | ||
| } else { | ||
| let initial_input_for_turn: ResponseInputItem = ResponseInputItem::from(input.clone()); | ||
| let response_item: ResponseItem = initial_input_for_turn.clone().into(); | ||
| let response_item: ResponseItem = initial_input_for_turn.into(); | ||
| let user_prompt_submit_outcome = run_user_prompt_submit_hooks( | ||
| &sess, | ||
| &turn_context, | ||
|
|
@@ -918,7 +919,11 @@ pub(super) fn filter_connectors_for_input( | |
| return Vec::new(); | ||
| } | ||
|
|
||
| let mentions = collect_tool_mentions_from_messages(&user_messages); | ||
| let user_message_texts = user_messages | ||
| .iter() | ||
| .map(|message| user_message_text(message)) | ||
| .collect::<Vec<_>>(); | ||
| let mentions = collect_tool_mentions_from_messages(&user_message_texts); | ||
| let mention_names_lower = mentions | ||
| .plain_names | ||
| .iter() | ||
|
|
@@ -1041,6 +1046,7 @@ async fn run_sampling_request( | |
| Arc::clone(&turn_diff_tracker), | ||
| ) | ||
| .await; | ||
| let max_retries = turn_context.provider.info().stream_max_retries(); | ||
| let mut retries = 0; | ||
| let mut initial_input = Some(input); | ||
| loop { | ||
|
|
@@ -1074,7 +1080,27 @@ async fn run_sampling_request( | |
| } | ||
| Err(CodexErr::ContextWindowExceeded) => { | ||
| sess.set_total_tokens_full(&turn_context).await; | ||
| return Err(CodexErr::ContextWindowExceeded); | ||
| if retries >= max_retries { | ||
| return Err(CodexErr::ContextWindowExceeded); | ||
| } | ||
| retries += 1; | ||
| let reset_client_session = match run_auto_compact( | ||
| &sess, | ||
| &turn_context, | ||
| client_session, | ||
| InitialContextInjection::BeforeLastUserMessage, | ||
| CompactionReason::ContextLimit, | ||
| CompactionPhase::MidTurn, | ||
| ) | ||
| .await | ||
| { | ||
| Ok(reset_client_session) => reset_client_session, | ||
| Err(_) => return Err(CodexErr::TurnAborted), | ||
| }; | ||
| if reset_client_session { | ||
| client_session.reset_websocket_session(); | ||
|
Comment on lines
19
to
+1101
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need to do this. |
||
| } | ||
| continue; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After this Useful? React with 👍 / 👎. |
||
| } | ||
| Err(CodexErr::UsageLimitReached(e)) => { | ||
| let rate_limits = e.rate_limits.clone(); | ||
|
|
@@ -1091,7 +1117,6 @@ async fn run_sampling_request( | |
| } | ||
|
|
||
| // Use the configured provider-specific stream retry budget. | ||
| let max_retries = turn_context.provider.info().stream_max_retries(); | ||
| if retries >= max_retries | ||
| && client_session.try_switch_fallback_transport( | ||
| &turn_context.session_telemetry, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The selection budget only counts text tokens, but the new structured path keeps every non-text item. Image-only messages have
tokens == 0, so the reverse scan can preserve an unbounded number of historical images without reducingremaining, and mixed messages keep all images even when text is truncated. Image-heavy threads can still overflow after “successful” compaction.Useful? React with 👍 / 👎.