codex - 💡(How to fix) Fix rollout file not written until first API turn completes, no way to get thread_id at spawn time for embedding tools

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Code Example

# thread.started appears immediately in stdout — thread_id is here
codex exec --json "hello" &

# but the rollout file does NOT appear until ~16s later (after API responds)
ls ~/.codex/sessions/$(date +%Y/%m/%d)/
RAW_BUFFERClick to expand / collapse

Problem

External tools that spawn Codex sessions (e.g., task runners, mission managers) need to correlate their own session identifiers with Codex thread IDs at spawn time.

Currently the rollout file under ~/.codex/sessions/ is not written until the first API turn completes (~15–30s after startup). There is no earlier signal available to the host process.

Reproduction (exec mode)

# thread.started appears immediately in stdout — thread_id is here
codex exec --json "hello" &

# but the rollout file does NOT appear until ~16s later (after API responds)
ls ~/.codex/sessions/$(date +%Y/%m/%d)/

What we tried

  • Kill before first turn → no rollout file, session not resumable
  • /status slash command → local only, does not trigger file write
  • Watch ~/.codex/sessions/ → file appears only after first API response

Requested

Either of:

  1. Write session_meta to rollout file at session init (before first API call)
  2. Or: support --session-id <UUID> flag so embedders can assign the ID themselves (related: #15767)

Related

  • #15767 custom session ID via ThreadStartParams
  • #8923 expose session ID as env var
  • #15870 rollout not persisted on early transport failure

extent analysis

TL;DR

Implementing a solution to write session_meta to the rollout file at session initialization or adding support for a --session-id flag could resolve the issue of correlating external tool session identifiers with Codex thread IDs.

Guidance

  • To address the problem, consider modifying the Codex session initialization process to write the session_meta to the rollout file immediately, rather than waiting for the first API turn to complete.
  • Alternatively, explore adding a --session-id flag that allows external tools to assign a session ID, which could then be used to correlate with the Codex thread ID.
  • Investigate the feasibility of using environment variables or other signals to expose the session ID to the host process earlier in the session lifecycle.
  • Review related issues (#15767, #8923, #15870) for potential insights or existing solutions that could be adapted to this problem.

Example

No specific code example is provided due to the lack of detailed implementation context, but the solution might involve modifying the Codex initialization code to write to the rollout file sooner or adding a new command-line flag for custom session ID assignment.

Notes

The exact implementation details will depend on the internal workings of Codex and its session management mechanisms, which are not fully described in the issue. Therefore, any solution will need to be tailored to the specific requirements and constraints of the Codex system.

Recommendation

Apply a workaround by modifying the Codex session initialization to write the session_meta to the rollout file at the start, as this directly addresses the root cause of the delay in correlating session identifiers.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING