Skip to content
2 changes: 2 additions & 0 deletions codex-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 14 additions & 9 deletions codex-rs/core/src/codex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2476,6 +2476,7 @@ async fn try_run_turn(
let mut needs_follow_up = false;
let mut last_agent_message: Option<String> = None;
let mut active_item: Option<TurnItem> = None;
let mut should_emit_turn_diff = false;
let receiving_span = info_span!("receiving_stream");
let outcome: CodexResult<TurnRunResult> = loop {
let handle_responses = info_span!(
Expand Down Expand Up @@ -2551,14 +2552,7 @@ async fn try_run_turn(
} => {
sess.update_token_usage_info(&turn_context, token_usage.as_ref())
.await;
let unified_diff = {
let mut tracker = turn_diff_tracker.lock().await;
tracker.get_unified_diff()
};
if let Ok(Some(unified_diff)) = unified_diff {
let msg = EventMsg::TurnDiff(TurnDiffEvent { unified_diff });
sess.send_event(&turn_context, msg).await;
}
should_emit_turn_diff = true;

break Ok(TurnRunResult {
needs_follow_up,
Expand Down Expand Up @@ -2632,7 +2626,18 @@ async fn try_run_turn(
}
};

drain_in_flight(&mut in_flight, sess, turn_context).await?;
drain_in_flight(&mut in_flight, sess.clone(), turn_context.clone()).await?;

if should_emit_turn_diff {
let unified_diff = {
let mut tracker = turn_diff_tracker.lock().await;
tracker.get_unified_diff()
};
if let Ok(Some(unified_diff)) = unified_diff {
let msg = EventMsg::TurnDiff(TurnDiffEvent { unified_diff });
sess.clone().send_event(&turn_context, msg).await;
}
}

outcome
}
Expand Down
13 changes: 3 additions & 10 deletions codex-rs/core/src/stream_events_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use codex_protocol::models::FunctionCallOutputPayload;
use codex_protocol::models::ResponseInputItem;
use codex_protocol::models::ResponseItem;
use futures::Future;
use tracing::Instrument;
use tracing::debug;
use tracing::instrument;

Expand Down Expand Up @@ -59,16 +58,10 @@ pub(crate) async fn handle_output_item_done(
.await;

let cancellation_token = ctx.cancellation_token.child_token();
let tool_runtime = ctx.tool_runtime.clone();

let tool_future: InFlightFuture<'static> = Box::pin(
async move {
let response_input = tool_runtime
.handle_tool_call(call, cancellation_token)
.await?;
Ok(response_input)
}
.in_current_span(),
ctx.tool_runtime
.clone()
.handle_tool_call(call, cancellation_token),
);

output.needs_follow_up = true;
Expand Down
2 changes: 1 addition & 1 deletion codex-rs/core/src/tools/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl ToolCallRuntime {

#[instrument(skip_all, fields(call = ?call))]
pub(crate) fn handle_tool_call(
&self,
self,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did this change?

Copy link
Collaborator Author

@aibrahim-oai aibrahim-oai Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we don't have to the tool runtime in a short lived function

call: ToolCall,
cancellation_token: CancellationToken,
) -> impl std::future::Future<Output = Result<ResponseInputItem, CodexErr>> {
Expand Down
4 changes: 4 additions & 0 deletions codex-rs/core/tests/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ tokio = { workspace = true, features = ["time"] }
walkdir = { workspace = true }
wiremock = { workspace = true }
shlex = { workspace = true }

[dev-dependencies]
pretty_assertions = { workspace = true }
reqwest = { workspace = true }
1 change: 1 addition & 0 deletions codex-rs/core/tests/common/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::path::PathBuf;
use assert_cmd::cargo::cargo_bin;

pub mod responses;
pub mod streaming_sse;
pub mod test_codex;
pub mod test_codex_exec;

Expand Down
Loading
Loading