fix(codex): detect resumed Windows Codex sessions stored under a previous date (#153)#154
Open
aznikline wants to merge 1 commit into
Open
Conversation
…te (graykode#153) Closes graykode#153. The CodexCollector::map_pid_to_jsonl Windows fallback scanned only today's ~/.codex/sessions/YYYY/MM/DD/ directory for rollout-*.jsonl candidates, so a Codex CLI session resumed on a later date — whose rollout file stays under the ORIGINAL date dir — was invisible and its PID left unmapped. Replace the today-only read_dir with a recursive scan of ~/.codex/sessions/ via a new #[cfg(windows)] collect_all_rollouts_with_mtime (walks all YYYY/MM/DD/ subdirectories). The existing strategy is preserved unchanged: candidates sorted by mtime descending, most-recent assigned to the first discovered Codex PID. Linux (/proc/{pid}/fd) and macOS (lsof) arms are untouched — the change is fully #[cfg(target_os="windows")]-gated. Same root cause + fix direction the reporter (@Astiyac) identified and locally validated with a built Windows abtop.exe. Verified: cargo clippy --target x86_64-pc-windows-gnu -- -D warnings clean (also clean on -msvc and aarch64-apple-darwin); cargo test --target x86_64-pc-windows-gnu --no-run links the new #[cfg(windows)] regression test cleanly. CI is ubuntu-only so the windows branch isn't exercised there (the reporter's built-exe validation is the exec confirmation).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #153. On Windows,
abtopcould miss an active Codex CLI session that was resumed on a later date than the one it was created on, because the Codex collector's Windows fallback scanned only today's~/.codex/sessions/YYYY/MM/DD/directory.A resumed Codex session keeps writing the rollout file created on the original date — e.g. a session started 2026/07/07 and resumed on 2026/07/08 still appends to
~/.codex/sessions/2026/07/07/rollout-*.jsonl. The Windows fallback scanned~/.codex/sessions/2026/07/08/and never saw it.Root cause
CodexCollector::map_pid_to_jsonlinsrc/collector/codex.rshas a#[cfg(target_os = "windows")]arm (Windows has nolsof//proc/{pid}/fd). It usedSelf::today_session_dir(sessions_dir)to enumerate candidaterollout-*.jsonlfiles — i.e. only~/.codex/sessions/<today>/*.jsonl. A resumed session's rollout file lives under a previous date directory, so it was invisible to the fallback and the PID was left unmapped.This is the same root cause and fix direction the issue reporter (@Astiyac) identified and locally validated; this PR implements it.
Fix
Scan
~/.codex/sessions/recursively forrollout-*.jsonlacross all datedYYYY/MM/DD/subdirectories, instead of only today's. The existing strategy is preserved unchanged:#[cfg(target_os = "linux")](/proc/{pid}/fd) and macOS (lsof) arms are untouchedImplementation: a new
#[cfg(target_os = "windows")] fn collect_all_rollouts_with_mtimerecurses the sessions tree collecting(PathBuf, SystemTime)pairs; the Windows arm ofmap_pid_to_jsonlnow calls it instead oftoday_session_dir+read_dir.Why this is safe
#[cfg(target_os = "windows")]-gated. The non-Windows arms compile to the same code as before.collect_recent_desktop_rollouts), so this mirrors an established approach.Validation
cargo clippy --target x86_64-pc-windows-gnu -- -D warnings— clean.cargo clippy --target x86_64-pc-windows-msvc -- -D warnings— clean.cargo test --target x86_64-pc-windows-gnu --no-run— the test binary compiles and links cleanly (this type-checks the new#[cfg(windows)]function and the#[cfg(windows)]regression test fully; a reference error or signature mismatch would fail to link).windows_map_pid_to_jsonl_finds_resumed_session_under_previous_date_dir(#[cfg(target_os = "windows")]) builds two dated dirs (today + a previous date), writes a rollout in each with the previous-date one more recently modified, and asserts the Windows fallback maps the resumed (previous-date) rollout to the first PID — i.e. the Windows: resumed Codex CLI sessions from previous dates may not be detected #153 scenario now resolves.