codex app-server can pollute subsequent TUI session metadata (wrong cwd/source/originator)
Summary
After starting codex app-server, subsequent Codex TUI sessions launched from a project directory were recorded with incorrect session metadata.
The sessions were started from a CLI/TUI workflow in:
/data00/home/<user>/Work/team-docs
But multiple session records were written as if they came from Desktop / VS Code, and in the wrong working directory:
cwd=/data00/home/<user>
originator=Codex Desktop
source=vscode
The expected metadata should have been:
cwd=/data00/home/<user>/Work/team-docs
originator=codex-tui
source=cli
Environment
- OS: Linux 5.4.0 x86_64
- Affected session metadata was created with
codex-cli 0.130.0 - Current local CLI after update:
codex-cli 0.131.0 - Storage inspected:
~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl~/.codex/state_5.sqlite
What happened
I normally launch Codex TUI from the repository directory. A previous normal session had metadata like:
{
"cwd": "/data00/home/<user>/Work/team-docs",
"originator": "codex-tui",
"source": "cli"
}
After starting codex app-server, new sessions created from the same repository were indexed incorrectly.
A backup taken before manual repair showed the canonical DB rows in ~/.codex/state_5.sqlite had the wrong cwd/source for 6 sessions from the same day:
cwd=/data00/home/<user>
source=vscode
thread_source=user
The rollout JSONL session_meta first line also showed wrong metadata for most of those sessions:
cwd=/data00/home/<user>
originator=Codex Desktop
source=vscode
cli_version=0.130.0
One JSONL had already been manually corrected by the time the broader backup was taken, but the SQLite threads table still showed the same wrong cwd/source pattern for all 6 affected session rows.
Expected behavior
Starting codex app-server should not affect metadata for later CLI/TUI sessions.
A TUI session launched from a terminal in a repository should consistently write:
cwd=<actual project cwd>
originator=codex-tui
source=cli
This should be true in both:
- the first
session_metaline of the rollout JSONL file - the corresponding row in
~/.codex/state_5.sqlite.threads
Actual behavior
After codex app-server had been started, later TUI sessions were attributed to Desktop / VS Code and indexed under the parent home directory instead of the active project directory.
This caused repository-based session lookup to fail or return incomplete results, because the affected sessions no longer appeared to belong to the project they were actually launched from.
Impact
Tools and workflows that rely on session metadata break or become misleading:
- listing sessions for the current repository misses affected sessions
- session recall/search by
cwdpoints to the wrong directory - TUI sessions appear to have been created by Desktop / VS Code
- the JSONL session file and SQLite thread index can disagree during/after partial repair
Manual repair performed
I manually repaired:
- the first-line
session_metapayload in affected~/.codex/sessions/.../rollout-*.jsonlfiles - the corresponding
cwdandsourcefields in~/.codex/state_5.sqlite.threads
After repair, all 6 affected sessions resolved correctly under:
/data00/home/<user>/Work/team-docs
with:
originator=codex-tui
source=cli
logs_2.sqlite still contains historical telemetry strings such as Codex_Desktop / source=vscode, but those appear to be log text rather than the canonical session metadata index.
Related issues
I found a few Desktop/session-history related issues, for example #20864 and #20741, but this report is specifically about codex app-server apparently leaking Desktop/VS Code attribution into later TUI session metadata and the SQLite thread index.
5 Comments
openai/codex #23437: App-Server Pollutes TUI Session Metadata
Issue
Summary
After starting
codex app-server, subsequent Codex TUI sessions launched from a project directory were recorded with incorrect session metadata. Sessions were started from a CLI/TUI workflow in/data00/home/<user>/Work/team-docsbut multiple session records were written as if they came from Desktop / VS Code, in the wrong working directory (cwd=/data00/home/<user>,originator=Codex Desktop,source=vscode).Expected:
cwd=/data00/home/<user>/Work/team-docs,originator=codex-tui,source=cli.Root Cause Analysis
1. Session Metadata Pollution
The
codex app-serverlikely maintains global/shared state for session metadata that is not properly isolated between:2. Likely Code Paths
Hypothesis A: Shared Session Store
The app-server and CLI/TUI share a session metadata store (likely in-memory or a file). When the app-server starts, it writes its own metadata (cwd, originator, source) to the shared store, and subsequent CLI sessions read from this store instead of computing their own.
Hypothesis B: Environment Variable Inheritance
The app-server may set environment variables (
CODEX_ORIGINATOR,CODEX_SOURCE,CODEX_CWD) that are inherited by child processes or persisted to a config file that CLI sessions read.Hypothesis C: State File Not Reset
A state file (e.g.,
~/.codex/session-state.jsonor similar) is written by the app-server with its metadata and not cleared/overwritten when CLI sessions start.3. Regression Nature
The issue is labeled as
regression, meaning this worked correctly in a previous version. The regression was likely introduced when:Proposed Fix
Fix 1: Session Metadata Isolation
Ensure each session computes its own metadata independently:
Fix 2: App-Server State Separation
Separate app-server state from CLI/TUI state:
Fix 3: Metadata Override Prevention
Prevent app-server from overwriting CLI session metadata:
Implementation Details
Files to Modify
Configuration
No new configuration needed — this is a bug fix that should be transparent to users.
Test Plan
Unit Tests
computeSessionMetadata()returns correct values for CLI sessionsdetectOriginator()correctly identifies launch contextIntegration Tests
Regression Tests
Impact Assessment
This is fixed in 0.133.0
@etraut-openai Not fixed for me in the Codex app.
My About dialog shows Desktop 26.527.31326 (3390), but I do not know what bundled CLI/app-server version that corresponds to. Is there a way in Codex Desktop to confirm that the embedded app-server is actually 0.133.0 or later? My Desktop sidebar/history issue is still reproducible on this Desktop build.
@bsabiston, this bug was specifically about metadata recorded when creating a new thread via the TUI. It sounds like you're using the app.
@etraut-openai I see - sorry. Is there any way to call attention to the problem with the app losing all but the most recent chats in all projects? https://github.com/openai/codex/issues/20741