Repository navigation
Codex sessions: new ~/.codex/sessions files are not picked up and active process mapping falls back to latest session #209
Description
Codex sessions: new ~/.codex/sessions files are not picked up and active process mapping falls back to latest session
Summary
I am running codbash on a Linux VPS and viewing it from Windows through an SSH tunnel. Codex session files are being written under ~/.codex/sessions, but fresh Codex sessions do not reliably appear in /api/sessions, and the Running/Active view maps multiple live Codex processes to the same session via fallback-latest.
This looks like two related issues in the Codex integration:
- The sessions cache invalidation appears to watch Claude paths, but not Codex paths.
- Active Codex process detection depends on
ps + lsof + cwd-match; on my host thelsofcall returns an unrelated cwd entry unless-ais used, so process-to-session mapping fails and falls back to the latest Codex session.
Environment
codbashversion:7.4.0- OS: Linux VPS
- Node:
v22.12.0 - Codex CLI:
0.129.0 codbashcommand:codbash run --port=3847 --no-browser- Browser access: Windows -> SSH local forward -> VPS
127.0.0.1:3847
What I observed
A fresh Codex session file exists on disk, for example:
~/.codex/sessions/2026/05/11/rollout-2026-05-11T11-29-03-<session-id>.jsonl
The file starts with session_meta and includes a valid payload.cwd:
{"type":"session_meta","payload":{"id":"<session-id>","cwd":"/home/devuser/project","originator":"codex_cli_rs","cli_version":"0.129.0"}}However, /api/sessions did not show this fresh session while the long-running codbash server was up. Restarting/rescanning appears to be required.
At the same time /api/active did detect live Codex processes, but all of them were mapped to the same session with _sessionSource: "fallback-latest", for example:
{
"kind": "codex",
"entrypoint": "codex",
"status": "waiting",
"sessionId": "<same-old-session-id>",
"cwd": "/proc/1/cwd (readlink: Permission denied)",
"_sessionSource": "fallback-latest"
}Likely cause 1: cache invalidation does not watch Codex files
In src/data.js, loadSessions() uses a hot cache and _sessionsNeedRescan() checks HISTORY_FILE / PROJECTS_DIR, which are Claude paths:
~/.claude/history.jsonl~/.claude/projects
But Codex sessions are loaded from:
~/.codex/history.jsonl~/.codex/session_index.jsonl~/.codex/sessions/**/*.jsonl
So a new Codex JSONL file can be written without invalidating the cached session list.
Likely cause 2: lsof needs -a for cwd lookup
In getActiveSessions(), cwd lookup is currently done with a command equivalent to:
lsof -d cwd -p <pid> -FnOn my host this returns cwd entries outside the requested PID, so the first parsed n... line may be unrelated, e.g. /proc/1/cwd (readlink: Permission denied).
This breaks the later cwd + tool session match and causes fallback to the latest Codex session.
The command works correctly for the specific PID when using -a:
lsof -a -p <pid> -d cwd -FnAlternatively, on Linux the implementation could use:
readlink /proc/<pid>/cwdExpected behavior
- New Codex session files under
~/.codex/sessions/**/*.jsonlshould appear in/api/sessionswithout restartingcodbash. /api/activeshould map each live Codex process to the correct Codex session when possible.- If exact mapping is not possible, it should avoid confidently assigning the wrong latest session to every process.
Suggested fixes
-
Extend cache invalidation to include Codex paths:
~/.codex/history.jsonlmtime/size~/.codex/session_index.jsonlmtime/size~/.codex/sessionsrecursive or shallow date-dir mtimes
-
Fix cwd lookup for active processes:
- use
lsof -a -p <pid> -d cwd -Fn, or - prefer
/proc/<pid>/cwdon Linux and fall back tolsof.
- use
-
Improve Codex active mapping:
- prefer sessions whose
projectequals the real process cwd; - if multiple sessions match the same cwd, choose the most recently modified Codex JSONL file;
- if no confident match exists, return
sessionId: ""or_sessionSource: "unmatched"instead offallback-latest, so the UI does not show a misleading active session.
- prefer sessions whose
Thanks for the project. The dashboard is very useful; this issue mainly affects long-running codbash servers and multiple concurrent Codex sessions.
Activity
NovakPAai commentedon May 14, 2026
PR #215 addresses all three points raised here:
_sessionsNeedRescan()now watches~/.codex/history.jsonl,~/.codex/session_index.jsonl, and per-day mtimes of~/.codex/sessions/YYYY/MM/DD, so new session files are picked up without restarting the server.readlink /proc/<pid>/cwdon Linux; the lsof fallback now strips the" (readlink: Permission denied)"annotation and rejects/proc/*pseudo-paths, so they no longer leak into the cwd→session match.fallback-latest— when cwd is known but no session matches, the response now returnssessionId: ""with_sessionSource: "unmatched"(per your suggestion) instead of confidently misattributing to the latest session. Among multiple same-cwd sessions, the most recently active one wins. Frontend keeps unmatched processes visible on the Agent Board under a syntheticpid:<pid>key.Thanks for the detailed report and the suggested fixes — they mapped cleanly to the code. Would appreciate a manual verification on your VPS once the PR lands, since the smoke locally is macOS and can't exercise the
/proc/<pid>/cwdpath.fix(codex): pick up new sessions and stop misattributing active proce…