Bug: Race condition in memory Phase 2 agent status subscription

Resolved 💬 0 comments Opened Apr 20, 2026 by hobostay Closed Apr 20, 2026

Description

In codex-rs/core/src/memories/phase2.rs line 384, there is a known but unfixed race condition:

tokio::spawn(async move {
    // TODO(jif) we might have a very small race here.
    let rx = match agent_control.subscribe_status(thread_id).await {

The TODO comment from the developer acknowledges this race condition. The issue is that between spawning the task and calling subscribe_status, the agent status could change, causing the subscription to miss the transition event.

Impact

If the agent completes very quickly, the spawned task might miss the final status transition, causing the Phase 2 memory processing to hang or fail silently.

Suggested fix

Consider subscribing to the status channel before spawning the task, or using a different synchronization mechanism that guarantees no events are missed.

Environment

  • File: codex-rs/core/src/memories/phase2.rs, line 384

View original on GitHub ↗