mirror of
https://github.com/openai/codex.git
synced 2026-05-03 21:01:55 +03:00
Avoid compaction while tool outputs are still in flight
This commit is contained in:
@@ -3759,6 +3759,7 @@ pub(crate) async fn run_turn(
|
|||||||
&turn_context,
|
&turn_context,
|
||||||
auto_compact_limit,
|
auto_compact_limit,
|
||||||
needs_follow_up,
|
needs_follow_up,
|
||||||
|
true,
|
||||||
"run_turn",
|
"run_turn",
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
@@ -3836,6 +3837,7 @@ async fn log_post_sampling_token_usage_and_maybe_compact(
|
|||||||
turn_context: &Arc<TurnContext>,
|
turn_context: &Arc<TurnContext>,
|
||||||
auto_compact_limit: i64,
|
auto_compact_limit: i64,
|
||||||
needs_follow_up: bool,
|
needs_follow_up: bool,
|
||||||
|
allow_auto_compact: bool,
|
||||||
checkpoint: &'static str,
|
checkpoint: &'static str,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let total_usage_tokens = sess.get_total_token_usage().await;
|
let total_usage_tokens = sess.get_total_token_usage().await;
|
||||||
@@ -3850,11 +3852,12 @@ async fn log_post_sampling_token_usage_and_maybe_compact(
|
|||||||
auto_compact_limit,
|
auto_compact_limit,
|
||||||
token_limit_reached,
|
token_limit_reached,
|
||||||
needs_follow_up,
|
needs_follow_up,
|
||||||
|
allow_auto_compact,
|
||||||
checkpoint,
|
checkpoint,
|
||||||
"post sampling token usage"
|
"post sampling token usage"
|
||||||
);
|
);
|
||||||
|
|
||||||
if token_limit_reached && needs_follow_up {
|
if allow_auto_compact && token_limit_reached && needs_follow_up {
|
||||||
run_auto_compact(sess, turn_context).await;
|
run_auto_compact(sess, turn_context).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4500,6 +4503,7 @@ async fn drain_in_flight(
|
|||||||
&turn_context,
|
&turn_context,
|
||||||
auto_compact_limit,
|
auto_compact_limit,
|
||||||
true,
|
true,
|
||||||
|
in_flight.is_empty(),
|
||||||
"drain_in_flight",
|
"drain_in_flight",
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
@@ -4653,6 +4657,7 @@ async fn try_run_sampling_request(
|
|||||||
&turn_context,
|
&turn_context,
|
||||||
auto_compact_limit,
|
auto_compact_limit,
|
||||||
needs_follow_up,
|
needs_follow_up,
|
||||||
|
in_flight.is_empty(),
|
||||||
"stream_item_done_plan",
|
"stream_item_done_plan",
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
@@ -4682,6 +4687,7 @@ async fn try_run_sampling_request(
|
|||||||
&turn_context,
|
&turn_context,
|
||||||
auto_compact_limit,
|
auto_compact_limit,
|
||||||
needs_follow_up,
|
needs_follow_up,
|
||||||
|
in_flight.is_empty(),
|
||||||
"stream_item_done",
|
"stream_item_done",
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ async fn remote_compact_runs_automatically() -> Result<()> {
|
|||||||
|
|
||||||
#[cfg_attr(target_os = "windows", ignore)]
|
#[cfg_attr(target_os = "windows", ignore)]
|
||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn remote_auto_compact_runs_during_multi_tool_output_drain() -> Result<()> {
|
async fn remote_auto_compact_runs_after_multi_tool_output_drain() -> Result<()> {
|
||||||
skip_if_no_network!(Ok(()));
|
skip_if_no_network!(Ok(()));
|
||||||
|
|
||||||
let first_call_id = "first-large-call";
|
let first_call_id = "first-large-call";
|
||||||
@@ -257,7 +257,7 @@ async fn remote_auto_compact_runs_during_multi_tool_output_drain() -> Result<()>
|
|||||||
.await?;
|
.await?;
|
||||||
let codex = harness.test().codex.clone();
|
let codex = harness.test().codex.clone();
|
||||||
|
|
||||||
let responses_mock = responses::mount_sse_sequence(
|
responses::mount_sse_sequence(
|
||||||
harness.server(),
|
harness.server(),
|
||||||
vec![
|
vec![
|
||||||
sse(vec![
|
sse(vec![
|
||||||
@@ -297,16 +297,9 @@ async fn remote_auto_compact_runs_during_multi_tool_output_drain() -> Result<()>
|
|||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
compact_request
|
compact_request
|
||||||
.function_call_output_text(second_call_id)
|
|
||||||
.is_none(),
|
|
||||||
"expected compaction request before the second drained tool output"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(
|
|
||||||
responses_mock
|
|
||||||
.function_call_output_text(second_call_id)
|
.function_call_output_text(second_call_id)
|
||||||
.is_some(),
|
.is_some(),
|
||||||
"expected second tool output to be sent in follow-up sampling request"
|
"expected compaction request to include the second drained tool output"
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user