Repository navigation
Description
Summary
After an unclean shutdown, reconcileJournal() restores ~/.codex/config.toml from a
snapshot that may be arbitrarily old, silently reverting the user's Codex settings. On a
machine that never records a clean shutdown, this repeats at every start, so the same
stale snapshot is replayed indefinitely.
writeJournal already guards against this on the write side. src/codex/journal.ts
says so directly:
without it the first snapshot a machine ever takes is the only one it ever has, so an
unclean shutdown days later replays a day-one config over the user's plugins, model
choice, and trusted projects.
The restore side has no equivalent guard: no snapshot age limit, no expiry, and no check
that the snapshot is still a plausible description of the user's intent.
Observed on a real machine
A kernel bugcheck (0xC2) forced a reboot. On the next logon-triggered service start:
[2026-08-29 19:42:47.55] opencodex service wrapper start
⚠️ Previous session (PID 70816) did not shut down cleanly. Codex state restored from journal.
[model-rename-migration] renamed "google-antigravity/gemini-3.6-flash" to "gemini-3.7-flash" ...
[model-rename-migration] renamed "google-antigravity/gemini-3.6-flash-low" to "gemini-3.7-flash" ...
... (the full rename set replays)
The restored config was a snapshot taken at 05:58 that same day; edits made after it were
lost, and the migration set re-ran against the reverted file.
The more serious part is the frequency. Every one of the last 12 service starts on this
host logged the same "did not shut down cleanly" line — there is no clean-shutdown record
at all. The service wrapper (opencodex-service.cmd) runs the CLI in a :loop, and no
exit path through logoff, crash, or wrapper restart clears the journal. So the restore is
not a rare crash-recovery event; it is the steady state.
Why the write-side guard does not cover this
writeJournal refuses to overwrite an existing snapshot unless the caller proves the
current state is native (currentStateIsNative === true). That is correct for preventing
opencodex's own routing from becoming the "original". But it also means that while
injection stays in place, the snapshot is not refreshed — so it ages while the user
keeps editing config.toml. The older it gets, the more a restore destroys.
restoreJournalState then applies it whenever injectedConfigHash still matches, which
is exactly the routed-and-unmodified case that occurs after a crash.
Liveness check is weaker than it looks
try {
process.kill(journal.pid, 0);
return false;
} catch (e) { ... }A bare PID is not a stable identity across a reboot. After a restart the recorded PID
almost always refers to nothing — correct here — but it can equally refer to an unrelated
reused PID, in which case a genuinely needed restore is skipped. There is no start-time or
image-name component to make the identity composite.
Suggested direction
I have not opened a PR, since the right policy is a maintainer call. Options, roughly in
increasing order of behaviour change:
- Record a boot/session identity alongside the PID so "is the journaling process
still alive" is answered by a composite identity rather than a reusable number. - Bound snapshot age. Past some threshold, decline to restore automatically and
report the snapshot instead of applying it. A stale snapshot is far more likely to be
wrong than right. - Refresh the snapshot's non-owned content while routed, so an eventual restore
reinstates the user's current settings rather than day-one ones. - Make an unclean shutdown less than certain. Given the wrapper loop, a clean-exit
path that clears the journal would remove most restores entirely.
Options 1 and 2 are the smallest changes that stop the observed damage; 4 addresses why
the path is reached so often.
Environment
- Windows 11 (26100), OpenCodex 2.35.0, Bun 1.4.0
- Scheduled-task service install, logon trigger
OPENCODEX_HOMEunset (resolves underUSERPROFILE)
Activity
coderabbitai commentedon Aug 29, 2026
📝 Issue Planner
Check the box below or use the
@coderabbitai plancommand to generate an implementation plan and prompts that you can use with your favorite coding assistant.🧪 Issue enrichment is currently in open beta.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml:💬 Have feedback or questions? Drop into our discord!
github-actions commentedon Aug 29, 2026
Issue closed: use an issue template
Thanks for taking the time to submit this issue. It was closed automatically because it was not opened with a recognized issue template (Bug report, Feature request, Documentation, or Provider compatibility). Freeform and API-opened issues cannot skip this check.
Please edit the issue to add:
See the Contributing guide for details.
Once the report passes the automated checks, it will be reopened automatically unless a maintainer has changed its state.