Skip to content

fix: match Codex sessions by session_meta timestamp not file birthtime#111

Merged
codeaholicguy merged 1 commit into
codeaholicguy:mainfrom
mvanhorn:fix/105-codex-session-meta-timestamp
Jun 17, 2026
Merged

fix: match Codex sessions by session_meta timestamp not file birthtime#111
codeaholicguy merged 1 commit into
codeaholicguy:mainfrom
mvanhorn:fix/105-codex-session-meta-timestamp

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

CodexAdapter now matches a running Codex process to its session by the logical session start time recorded in session_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 min in matchProcessesToSessions), the file is created late, its birthtimeMs drifts past the process start time, and the session never pairs with its PID. Transcript polling, conversation detail, and wait mode all break because sessionFilePath is never resolved.

The fix prefers the session_meta payload timestamp as the birthtimeMs used for matching in both code paths that build a SessionFile:

  • discoverSessions (bulk enumeration), where the first session_meta line was already parsed to set resolvedCwd.
  • findSessionFileById (the codex 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.ts is untouched: it still compares process.startTime against session.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

  • Added CodexAdapter cases 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.ts in packages/agent-manager: 59 passed.
  • tsc --noEmit and eslint clean on the touched files.

Fixes #105

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
@codeaholicguy

Copy link
Copy Markdown
Owner

LGTM! Thanks for the contribution.

@codeaholicguy codeaholicguy merged commit e734194 into codeaholicguy:main Jun 17, 2026
7 checks passed
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks @codeaholicguy for the merge. Matching Codex sessions by session_meta timestamp is more robust than the old approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot match session if Codex session file created more than 3 mins after the Codex process started

2 participants