fix: match Codex sessions by session_meta timestamp not file birthtime#111
Merged
codeaholicguy merged 1 commit intoJun 17, 2026
Conversation
Codex registers its session JSONL file lazily, so when the agent sits idle at the prompt for more than the matching tolerance the file's filesystem birthtime drifts past the running process start time and the session never pairs with its PID. Prefer the session_meta payload timestamp (the true session start) as the matching birthtime in both the bulk discovery and resume lookup paths, falling back to the filesystem birthtime when the metadata timestamp is missing or invalid. Fixes codeaholicguy#105
Owner
|
LGTM! Thanks for the contribution. |
Contributor
Author
|
Thanks @codeaholicguy for the merge. Matching Codex sessions by session_meta timestamp is more robust than the old approach. |
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
CodexAdapternow matches a running Codex process to its session by the logical session start time recorded insession_meta.payload.timestamp, rather than the session file's filesystem birth time.Codex registers a session before it writes the session JSONL file. If the agent sits idle at the prompt longer than the matching tolerance (
abs(process.startTime - session.birthtimeMs) <= 3 mininmatchProcessesToSessions), the file is created late, itsbirthtimeMsdrifts past the process start time, and the session never pairs with its PID. Transcript polling, conversation detail, and wait mode all break becausesessionFilePathis never resolved.The fix prefers the
session_metapayload timestamp as thebirthtimeMsused for matching in both code paths that build aSessionFile:discoverSessions(bulk enumeration), where the firstsession_metaline was already parsed to setresolvedCwd.findSessionFileById(thecodex resume <uuid>path).When the metadata timestamp is missing or unparseable, both paths fall back to the filesystem
stat.birthtimeMs, so existing behavior is unchanged.matching.tsis untouched: it still comparesprocess.startTimeagainstsession.birthtimeMs, which now carries the true session start when available.Why this matters
Closes the gap described in #105: a Codex agent left idle for more than three minutes before its first message would silently fail to surface its transcript, conversation, and wait status, because the late-written file's birth time fell outside the matching window even though the process and session were the same.
Testing
CodexAdaptercases covering the aligned timestamp/birthtime happy path, the late-created-file recovery via metadata timestamp, fallback to filesystem birthtime when the timestamp is missing or invalid, and malformed/unreadable inputs.vitest run src/__tests__/adapters/CodexAdapter.test.tsinpackages/agent-manager: 59 passed.tsc --noEmitandeslintclean on the touched files.Fixes #105