Engineering note / 07 Nov 2026

Codex failed to start because of a 75 MB log file on a hard drive

Written by the founder. First published on technomancer.work.

Codex on my Linux workstation kept failing to start with this:

failed to connect to ~/.codex/app-server-control/app-server-control.sock:
No such file or directory (os error 2)

It got more frequent over a few weeks, and each failure took longer to clear. My usual fix was to move the SQLite files out of ~/.codex and let Codex rebuild them. That always worked for a while. This time I wanted to see what the daemon was doing before I deleted anything.

The obvious suspect

~/.codex/thread_history_1.sqlite had grown to 5 GB. It was the natural thing to blame, and trimming it costs something real: old threads stop being recoverable.

The error is narrower than it looks. Codex 0.167 runs a background app-server daemon, and the CLI talks to it through a Unix socket. "No such file or directory" means the socket didn't exist yet. The daemon was running but hadn't finished starting, and the client gave up first.

So the question became: what happens between the daemon starting and the socket appearing?

Tracing a cold start

I stopped the daemon, evicted the Codex databases from the page cache, and started it again under strace:

strace -f -tt -T -o daemon.strace \
  -e trace=openat,pread64,bind,listen \
  codex app-server daemon start

The daemon is a static musl binary, and it opens files with open rather than openat, so the trace showed reads on bare file descriptors. Reading /proc/<pid>/fd on the running daemon mapped them back to files.

Two phases came before bind(). First, about 13,000 reads covered every page of state_5.sqlite, mostly in order, on one thread. Then about 1,400 reads hit logs_2.sqlite, almost none of them adjacent, at roughly 10 ms each. Only after that did the daemon bind and listen on its control socket. It never read the 5 GB thread history before that point.

Ten milliseconds per read is a disk head seeking. This machine keeps its root filesystem on a 7200 rpm hard drive.

What reads a whole database at startup?

An integrity check reads every page of a database, read-only, in one thread. The Codex binary contains PRAGMA quick_check(1), and the open-source code runs it as it opens each runtime database (validation.rs).

I ran the same check myself on a cold cache:

Warm, the check is invisible. Cold, it's most of the startup.

That explains the pattern too. The check runs once per daemon process, the daemon restarts whenever Codex updates itself, and new releases arrive often. Whether the files are still in memory at that moment depends on what else the machine has been doing.

My first numbers were worse than these. A disk usage scan I had started earlier was competing for the same drive, and the first two starts I timed took 43 and 27 seconds. I stopped the scan and measured again before trusting anything.

The budget that didn't hold

Upstream tries to keep this cheap. The check runs under a SQLite progress handler with a 100 ms deadline. On my machine it ran to the end anyway: the trace shows every page of state_5 read before the socket opened.

My guess is that the deadline only gets looked at between units of SQLite work. A 4 KB read that blocks on a seeking disk can't be interrupted, so on cold storage the wall clock escapes the budget. I haven't confirmed that in the SQLite source. It's the part I'd most like someone who knows the progress handler to check.

The fix

The logs database costs the most, and I care about it the least. It holds diagnostics, churns constantly and fragments quickly: the file held less than a day of rows but had grown to 75 MB, a third of it free pages. Codex 0.167 lets log_dir move it:

# ~/.codex/config.toml, top level
log_dir = "/tmp/codex-logs"

/tmp is tmpfs here, so the check reads from memory. Those logs now disappear at reboot, which I'm fine with. Codex won't migrate the old file, so I stopped the daemon and moved it into a backup folder myself.

After that change, a cold start took 3.7 seconds from process launch to socket bound. The clean check timings before it added up to about 18 seconds. Thread history is untouched.

I also tried VACUUM on state_5. A freshly written copy checked in 2.1 seconds, which looked promising, but compacting the real file in place made no measurable difference: 4.8 and 5.9 seconds in later runs. Where the file sits on the disk seems to matter more than SQLite's free pages.

What's left

The remaining few seconds are state_5 on the hard drive. Codex has sqlite_home (or the CODEX_SQLITE_HOME environment variable) to move every database, and an SSD should finish the job. Use a Linux filesystem for it. WAL mode depends on shared memory and file locking, and I wouldn't trust it on an NTFS mount.

If you hit the same socket error, measure before you delete anything:

for db in ~/.codex/*.sqlite; do
  case "$db" in *thread_history*) continue ;; esac
  /usr/bin/time -f "%es  $db" sqlite3 -readonly "$db" 'pragma quick_check(1);' >/dev/null
done

Run it after a reboot or a burst of heavy disk activity to see cold numbers. Several seconds on a small file points at the same problem.

The Codex repository doesn't take outside pull requests, so an issue with these numbers is the next step. If you're on an SSD and still see this error, I'd like to hear about it, because that would mean the check is only part of the story.

← All notes