Codex local history index becomes stale and recent sessions cannot be resumed
Bug Report: Codex local history index becomes stale and recent sessions cannot be resumed
Summary
Codex VSCode/local history sometimes fails to show or resume recent sessions even though the actual session data still exists on disk.
This appears to be an index synchronization bug in Codex's local history management.
Environment
- Product: Codex VSCode integration / local Codex
- CLI version observed in session metadata:
0.125.0-alpha.3 - Platform: Linux
- Source in local thread DB:
vscode - Model configured:
gpt-5.5
Impact
Recent Codex conversations can disappear from the visible history/resume list. This causes repeated context loss and additional token usage because the agent cannot reliably load the immediately prior work.
This is especially costly for long-running coding and research sessions where continuity is expected.
Evidence
Recent sessions existed in the local Codex data store:
~/.codex/state_5.sqlite~/.codex/sessions/YYYY/MM/DD/rollout-...jsonl
However:
~/.codex/session_index.jsonlwas stale and only listed sessions up to the previous day.- The current-day session was missing from the visible/resume history index.
state_5.sqliteintegrity check returnedok.logs_2.sqliteintegrity check returnedok.
Additionally, an internal approval-review/guardian thread was inserted into the normal threads table:
source:{"subagent":{"other":"guardian"}}model:codex-auto-reviewtitle: began withThe following is the Codex agent history whose request action you are assessing...
This internal review thread appeared alongside user-facing threads and polluted the history table.
Observed State Before Repair
The local threads table contained the recent user-facing thread:
archived:0source:vscoderollout_path: pointed to an existing~/.codex/sessions/.../rollout-...jsonl
But session_index.jsonl did not include it until manually rebuilt.
Manual Repair Performed
The following local repair was performed:
- Backed up:
config.tomlsession_index.jsonlstate_5.sqlitelogs_2.sqlite
- Rebuilt
session_index.jsonlfromstate_5.sqlite. - Marked internal guardian /
codex-auto-reviewthreads as archived so they do not appear as normal user history. - Ran SQLite WAL checkpoints.
After repair, the missing recent session appeared in session_index.jsonl.
Expected Behavior
- Recent user-facing sessions should always appear in the history/resume list if the session exists in
state_5.sqliteand the rollout JSONL exists. session_index.jsonlshould stay synchronized withstate_5.sqlite.- Internal approval-review / guardian /
codex-auto-reviewthreads should not be inserted into, or at least not surfaced through, normal user-facing history. - If
session_index.jsonlis stale or corrupt, Codex should rebuild it automatically fromstate_5.sqliteand/orsessions/**/*.jsonl.
Actual Behavior
- Recent sessions existed on disk but were missing from the history index.
- The visible history could not reliably load the latest work.
- Internal review-agent threads appeared in the same local thread store as normal user sessions.
Requested Fix
Please fix Codex local history handling so that:
session_index.jsonlis transactionally updated or automatically regenerated when stale.- Recent sessions are discovered from
state_5.sqlite/ rollout JSONL even if the index is stale. - Internal guardian / approval-review threads are excluded from user-facing history.
- WAL/checkpoint behavior cannot leave the UI with a stale history list after a normal session.
Severity
High for paid users relying on Codex continuity. The issue causes context loss, duplicate work, and avoidable token spend.
2 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
I would make one architectural rule explicit here:
session_index.jsonlshould be a rebuildable projection, never an authority for session existence.If the durable sources are something like:
then history listing can reconcile the index against those sources rather than failing closed on an incomplete index.
A useful contract could be:
with reconciliation roughly:
The important failure rule is:
not the other way around.
I would also persist enough provenance on an index entry to detect silent staleness without waiting for a user-visible failure: source path, source mtime/hash or DB revision, and last indexed time. Then startup/listing can cheaply answer whether a row is still backed by the version it was derived from.
For crash consistency, rebuilding into a temp file and atomic rename is safer than mutating
session_index.jsonlin place. If WAL/checkpoint state means SQLite is newer than the index, reconciliation simply regenerates the projection.A regression fixture could deliberately create the reported split:
plus the inverse stale-entry case:
I maintain a small local-first project that uses the same evidence/projection boundary—durable source-backed records in SQLite with source path/line/content-hash provenance, while query/context views are derived: https://github.com/leadingproblemsolver/living-context-engine
The relevant principle here is simply that a convenience index can be thrown away and rebuilt from authoritative evidence; losing or staling the projection should never make the underlying work disappear.