Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): a Windows Codex shadow keeps each SQLite database with its WAL #38714

ClosedGibSmith(GitHub profile, opens in a new tab)wants to merge 0 commits intomain fromrefs/pull/38714/headopened View on GitHub

Note

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:

  1. cfd6b1bdfb: an explicit CODEX_SQLITE_HOME other than the shared home is refused if it holds a symlinked .sqlite database.
  2. 1e110ac3ca closes three more routes to a split:
    • Codex ranks sqlite_home from any config layer above CODEX_SQLITE_HOME. T3 now passes the directory it checked as a final -c sqlite_home=… to codex app-server, codex exec and codex mcp list. It refuses a root sqlite_home in the shadow's or shared home's config.toml, or in the launch args, because Codex typed into a provider terminal gets no -c from T3.
    • A relative CODEX_SQLITE_HOME is 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.
  3. 846e6ddb83: a provider terminal merges the host, client and instance environments by name ignoring case, keeping instance over client over host. Before, a client's codex_sqlite_home lost to the host's CODEX_SQLITE_HOME.
  4. 766ced0bf8: only Codex's root sqlite_home counts. An MCP server's sqlite_home environment variable, the text inside a multi-line string and -c mcp_servers.<name>.env.sqlite_home=… are not refused. config.toml is read by an 85-line scanner, because apps/server has no TOML parser.
  5. f7b860b87f: three CodexHomeLayout tests 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:

SuitePassedSkippedFailed
CodexHomeLayout2010
codexSqliteHomeSetting2900
codexLaunchArgs2200
CodexAdapterV220310
CodexTextGeneration3200
CodexProvider700
CodexManagedErrors600
terminal/Manager11713
CodexManagedRuntime202
CodexDriver3141

All 6 failures fail the same way on clean main 8cf97b5f06:

  • a forward-slash path assertion at CodexManagedRuntime.test.ts:126, twice;
  • an auth.json watch timeout;
  • the three $SHELL tests 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 -wal and -shm) landed in the shadow, from the project layer.
  • With the pin, config/read reported sqlite_home from sessionFlags, 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 symlinked goals_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-server and compared where it opened its databases with T3's verdict. 25 agree, and 2 are refused on purpose (below). In none did Codex use sqlite_home while 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.toml with 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.
  • 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_home from a layer T3 can't read, such as a project's .codex/config.toml.
  • The spawn test supplied its own cwd. CodexAdapterV2.open passes no cwd, so the test passed the project itself. config/read for that project still resolved to the pin.
  • Not tested: a sqlite_home from 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.lock disabling a provider are #32058's problem, not this one.

🤖 Generated with Claude Code

    1. Caution

      Review failed

      An error occurred during the review process. Please try again later.

      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. Closing in favour of continuing #29574, as CONTRIBUTING asks. The branch and the Windows evidence are posted there.

    4. juliusmarminge added labelstakeover:in-progress

Sign in to join this conversation.