From 68bcf5cefafe5eed3e8fe7900aa48b9f328054bc Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Thu, 4 Jun 2026 23:23:16 -0700 Subject: [PATCH] Pump trigger-turn work before idle lifecycle --- codex-rs/core/src/tasks/mod.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/codex-rs/core/src/tasks/mod.rs b/codex-rs/core/src/tasks/mod.rs index 3bfcc1fbfc..e83d436c2a 100644 --- a/codex-rs/core/src/tasks/mod.rs +++ b/codex-rs/core/src/tasks/mod.rs @@ -445,6 +445,15 @@ impl Session { .await; } + // Keep this detached work in a synchronous helper so the task runner future remains Send. + fn spawn_post_task_idle_work(self: &Arc) { + let session = Arc::clone(self); + tokio::spawn(async move { + session.maybe_start_turn_for_pending_work().await; + session.emit_thread_idle_lifecycle_if_idle().await; + }); + } + /// Starts a regular turn with the provided sub-id when pending work should wake an idle /// session. /// @@ -755,7 +764,7 @@ impl Session { if !cleared_active_turn { return; } - self.emit_thread_idle_lifecycle_if_idle().await; + self.spawn_post_task_idle_work(); } async fn take_active_turn(&self) -> Option {