Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion codex-rs/core/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self>) {
Comment thread
etraut-openai marked this conversation as resolved.
let session = Arc::clone(self);
tokio::spawn(async move {
session.maybe_start_turn_for_pending_work().await;
Comment thread
etraut-openai marked this conversation as resolved.
Comment on lines +451 to +452

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Avoid detaching post-turn work past shutdown

When a turn finishes with trigger_turn mailbox work pending and the client immediately sends Shutdown or drops the submission channel, this untracked tokio::spawn can run after shutdown_session_runtime has already called abort_all_tasks and torn down runtime services; maybe_start_turn_for_pending_work() can then create a new regular task that shutdown no longer observes, potentially emitting work after thread stop or using shut-down services. Keeping this work tied to the task/session lifecycle (or guarding it against shutdown) avoids that race.

Useful? React with 👍 / 👎.

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.
///
Expand Down Expand Up @@ -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<ActiveTurn> {
Expand Down
Loading