fix(server): a Windows Codex shadow keeps each SQLite database with its WAL #38714
main fromrefs/pull/38714/head·opened View on GitHubNote
Submitted by claude-opus-5-5 on behalf of Gib. Code by model:
- The commits from #29574 are nkcbuilds', prepared with GPT-6 through ChatGPT using the T3/MoonDesk harness.
- The Windows follow-up commits were written by Claude Fable 5.2, except one test fix by Claude Opus 5.5, in Claude Code running in T3 Code.
- GPT-6 Astra reviewed each round.
Continues #29574, which stopped in automated review with one major Windows finding open. This branch is that PR's head (3001024b77, nkcbuilds' commits unchanged), a conflict-free merge of main, and 5 commits that close the finding and the gaps a re-review found after it. If you'd rather land it through #29574, its branch fast-forwards to this one.
Fixes #24486
Problem#
A Codex account with a shadow CODEX_HOME shares the main home's SQLite databases. T3 used to symlink them into the shadow. Windows SQLite names the -wal and -shm files after the path it is given, so a database opened through the link gets a WAL of its own, apart from the shared home's writers. Committed state splits and goes missing. The leftover sidecars also disable the provider at the next start with Cannot create Codex shadow home entry 'goals_1.sqlite-shm' … already exists and is not a symlink.
How we found it. CodexWork, our second Codex account, kept getting disabled on Windows 11 by exactly that error, at least four times between Nov 3 and Nov 18. On native Windows the legacy layout reproduces the split. Through node:sqlite, a row written through the link is gone after reopening, and integrity_check still says ok.
Fix#
From #29574: the shadow keeps CODEX_HOME for its private auth, and T3 points Codex at the shared databases with CODEX_SQLITE_HOME. T3 never links a database into a new shadow, and refuses ambiguous mixed or stranded SQLite state before changing anything. The driver, orchestration adapter, managed runtime, text generation and provider terminals all use the same routing.
The stopped review's case is a shadow with its own state_5.sqlite while the shared home has goals_1.sqlite. With no override, 3001024b77 already handles it: on native Windows it refused before linking anything and left both homes unchanged. The gap was an explicit CODEX_SQLITE_HOME. It returned before every check, so pointing it at a shadow that holds a symlinked database brought the split back. The follow-up commits change only Windows behaviour:
cfd6b1bdfb: an explicitCODEX_SQLITE_HOMEother than the shared home is refused if it holds a symlinked.sqlitedatabase.1e110ac3cacloses three more routes to a split:- Codex ranks
sqlite_homefrom any config layer aboveCODEX_SQLITE_HOME. T3 now passes the directory it checked as a final-c sqlite_home=…tocodex app-server,codex execandcodex mcp list. It refuses a rootsqlite_homein the shadow's or shared home'sconfig.toml, or in the launch args, because Codex typed into a provider terminal gets no-cfrom T3. - A relative
CODEX_SQLITE_HOMEis refused. Probes, sessions and text generation each start Codex in a different directory. - The override is compared with the shared home by real path, ignoring case. An alias of the shared home reaches Codex as the shared home's own spelling.
- Codex ranks
846e6ddb83: a provider terminal merges the host, client and instance environments by name ignoring case, keeping instance over client over host. Before, a client'scodex_sqlite_homelost to the host'sCODEX_SQLITE_HOME.766ced0bf8: only Codex's rootsqlite_homecounts. An MCP server'ssqlite_homeenvironment variable, the text inside a multi-line string and-c mcp_servers.<name>.env.sqlite_home=…are not refused.config.tomlis read by an 85-line scanner, because apps/server has no TOML parser.f7b860b87f: threeCodexHomeLayouttests failed on native Windows only, which CI doesn't run. Their expectations now include the pin variable and Windows path resolution. The relative-path test no longer assumes the temp directory is on the repo's drive.
Every refusal names the files and the steps to recover, and leaves all SQLite files unchanged.
Verification#
Native Windows 11 Pro 26200, Codex CLI 0.170.0, Node 26.13.1, on this tree#
Focused suites, one file at a time:
| Suite | Passed | Skipped | Failed |
|---|---|---|---|
| CodexHomeLayout | 20 | 1 | 0 |
| codexSqliteHomeSetting | 29 | 0 | 0 |
| codexLaunchArgs | 22 | 0 | 0 |
| CodexAdapterV2 | 203 | 1 | 0 |
| CodexTextGeneration | 32 | 0 | 0 |
| CodexProvider | 7 | 0 | 0 |
| CodexManagedErrors | 6 | 0 | 0 |
| terminal/Manager | 117 | 1 | 3 |
| CodexManagedRuntime | 2 | 0 | 2 |
| CodexDriver | 3 | 14 | 1 |
All 6 failures fail the same way on clean main 8cf97b5f06:
- a forward-slash path assertion at
CodexManagedRuntime.test.ts:126, twice; - an
auth.jsonwatch timeout; - the three
$SHELLtests from #37069.
CodexTextGeneration also exits 1 from two unhandled ECONNRESET errors, the same on main.
The -c pin survives Windows spawning. T3 runs codex.CMD through cmd.exe with shell: true, so the chain is cmd → codex.cmd → node → codex.exe. We drove the real CLI through both T3 paths, CodexAdapterV2.open and the CodexProvider probe. A trusted project's .codex/config.toml set sqlite_home to the shadow:
- With no pin, all 15 SQLite files (5 databases with their
-waland-shm) landed in the shadow, from the project layer. - With the pin,
config/readreportedsqlite_homefromsessionFlags, and all 15 files landed in the shared home, none in the shadow. - The same held for a shared home named
t3 sqlite's shared. codex.exe received-c "sqlite_home=\"C:\\…\\t3 sqlite's shared\""and decoded the exact path.
config.toml guard, on real files. A root sqlite_home is refused in the shadow's or the shared config with LF, CRLF, BOM+CRLF and a quoted key. The MCP environment key, a commented-out key and the key inside """ are allowed. Refusals left both trees unchanged.
Override guard, on cfd6b1bdfb.
- It refuses a symlink, a junction (
mklink /J) and a directory symlink to a shadow holding a symlinkedgoals_1.sqlite. - It allows the shared home lowercased or with a trailing backslash, and a shadow with only its own databases.
- Refusals leave the files byte-identical.
Terminal merge. The client beats the host whichever spelling each uses, and the instance beats both. T3CODE_CODEX_SQLITE_HOME, which carries the pin, never reaches the terminal.
Real Codex app-server. With CODEX_SQLITE_HOME set to the shared home, it created every database and its sidecars only in the shared folder.
Linux (Raspberry Pi), Codex CLI 0.170.0#
- The same ten suites: 464 passed.
- Server typecheck: 0 errors.
- Formatter and built-in lint on the touched files: clean. The repo's lint plugin and knip ran out of memory there.
- We ran 27 configs and launch args through the real
codex app-serverand compared where it opened its databases with T3's verdict. 25 agree, and 2 are refused on purpose (below). In none did Codex usesqlite_homewhile T3 allowed the launch. - Each follow-up commit's regression tests fail against the code before it.
Limitations#
- Stricter than Codex on purpose, in two cases:
- A
config.tomlwith an unclosed string or array is refused if any line could set the key. Codex drops such a file. -c '"sqlite_home"=…'is refused. Codex 0.170.0 ignores it.
- A
- Hard links aren't detected. Only symlinked databases are. A hard-linked database also splits on Windows, which we reproduced natively, but T3 never creates hard links, so that is left for a separate change.
- The pin covers only commands T3 builds. Codex typed by hand into a provider terminal still follows a
sqlite_homefrom a layer T3 can't read, such as a project's.codex/config.toml. - The spawn test supplied its own
cwd.CodexAdapterV2.openpasses nocwd, so the test passed the project itself.config/readfor that project still resolved to the pin. - Not tested: a
sqlite_homefrom Codex's managed requirements, and real managed ChatGPT OAuth. - Out of scope: no automatic recovery of an already split database, and no cross-process SQLite locking. Stray lock files such as
auth.json.lockdisabling a provider are #32058's problem, not this one.
🤖 Generated with Claude Code
- 1
GibSmith(GitHub profile, opens in a new tab) linked this to fix #24486
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
Closing in favour of continuing #29574, as CONTRIBUTING asks. The branch and the Windows evidence are posted there.
GibSmith(GitHub profile, opens in a new tab) closed this
juliusmarminge added labelstakeover:in-progress
Sign in to join this conversation.
Caution
Review failed#
An error occurred during the review process. Please try again later.