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 the lsof call returns an unrelated cwd entry unless -a is used, so process-to-session mapping fails and falls back to the latest Codex session.
Environment
codbash version: 7.4.0
- OS: Linux VPS
- Node:
v22.12.0
- Codex CLI:
0.129.0
codbash command: 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:
On 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 -Fn
Alternatively, on Linux the implementation could use:
Expected behavior
- New Codex session files under
~/.codex/sessions/**/*.jsonl should appear in /api/sessions without restarting codbash.
/api/active should 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.jsonl mtime/size
~/.codex/session_index.jsonl mtime/size
~/.codex/sessions recursive or shallow date-dir mtimes
-
Fix cwd lookup for active processes:
- use
lsof -a -p <pid> -d cwd -Fn, or
- prefer
/proc/<pid>/cwd on Linux and fall back to lsof.
-
Improve Codex active mapping:
- prefer sessions whose
project equals 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 of fallback-latest, so the UI does not show a misleading active session.
Thanks for the project. The dashboard is very useful; this issue mainly affects long-running codbash servers and multiple concurrent Codex sessions.
Codex sessions: new ~/.codex/sessions files are not picked up and active process mapping falls back to latest session
Summary
I am running
codbashon 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 viafallback-latest.This looks like two related issues in the Codex integration:
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.0v22.12.00.129.0codbashcommand:codbash run --port=3847 --no-browser127.0.0.1:3847What I observed
A fresh Codex session file exists on disk, for example:
The file starts with
session_metaand includes a validpayload.cwd:{"type":"session_meta","payload":{"id":"<session-id>","cwd":"/home/devuser/project","originator":"codex_cli_rs","cli_version":"0.129.0"}}However,
/api/sessionsdid not show this fresh session while the long-runningcodbashserver was up. Restarting/rescanning appears to be required.At the same time
/api/activedid 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()checksHISTORY_FILE/PROJECTS_DIR, which are Claude paths:~/.claude/history.jsonl~/.claude/projectsBut Codex sessions are loaded from:
~/.codex/history.jsonl~/.codex/session_index.jsonl~/.codex/sessions/**/*.jsonlSo a new Codex JSONL file can be written without invalidating the cached session list.
Likely cause 2:
lsofneeds-afor cwd lookupIn
getActiveSessions(), cwd lookup is currently done with a command equivalent to:On 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 + toolsession match and causes fallback to the latest Codex session.The command works correctly for the specific PID when using
-a:Alternatively, on Linux the implementation could use:
Expected behavior
~/.codex/sessions/**/*.jsonlshould appear in/api/sessionswithout restartingcodbash./api/activeshould map each live Codex process to the correct Codex session when possible.Suggested fixes
Extend cache invalidation to include Codex paths:
~/.codex/history.jsonlmtime/size~/.codex/session_index.jsonlmtime/size~/.codex/sessionsrecursive or shallow date-dir mtimesFix cwd lookup for active processes:
lsof -a -p <pid> -d cwd -Fn, or/proc/<pid>/cwdon Linux and fall back tolsof.Improve Codex active mapping:
projectequals the real process cwd;sessionId: ""or_sessionSource: "unmatched"instead offallback-latest, so the UI does not show a misleading active session.Thanks for the project. The dashboard is very useful; this issue mainly affects long-running
codbashservers and multiple concurrent Codex sessions.