remote-control should recover from a corrupt logs_2.sqlite instead of failing readiness
What happened
codex remote-control failed to become ready because one local state database, logs_2.sqlite, was corrupt. The systemd service still appeared active, but the remote-control app-server never became available to the mobile client.
The CLI error was:
Starting app-server with remote control enabled...
Error: foreground app-server exited before remote control became ready
Caused by:
failed to initialize sqlite state runtime under ~/.codex: failed to initialize state runtime at ~/.codex: error returned from database: (code: 26) file is not a database
The main thread/session database was healthy:
sqlite3 ~/.codex/state_5.sqlite 'PRAGMA integrity_check;'
# ok
But the log database was not a valid SQLite database:
file ~/.codex/logs_2.sqlite
# data
sqlite3 ~/.codex/logs_2.sqlite 'PRAGMA integrity_check;'
# Error: in prepare, file is not a database (26)
Renaming the corrupt log DB and restarting remote-control fixed the problem:
mv ~/.codex/logs_2.sqlite ~/.codex/logs_2.sqlite.corrupt-$(date +%Y%m%d-%H%M%S)
systemctl --user restart codex-remote-control.service
After restart, Codex recreated logs_2.sqlite, integrity check returned ok, and remote-control became available again:
This machine is available for remote control as <host>.
Press Ctrl-C to stop.
Expected behavior
If logs_2.sqlite is app-owned/rebuildable log state, codex remote-control / app-server startup should not fail permanently when only that database is corrupt. It could quarantine the corrupt file, recreate the log database, emit a warning, and continue startup.
For example:
warning: ~/.codex/logs_2.sqlite is corrupt; moved to ~/.codex/logs_2.sqlite.corrupt-<timestamp> and recreated it
Why this matters
Remote-control is commonly used as a headless/background process, sometimes on remote Linux/HPC/SSH machines with network-mounted home directories. A corrupt rebuildable log database currently makes the service look alive while remote access is unavailable, and the mobile client cannot recover it because remote-control never becomes ready.
Environment
- Codex CLI:
0.133.0 - Command:
codex remote-control - OS: Linux remote/HPC host
~/.codexwas on a network-backed home directory
Suggested fix
During state runtime initialization, distinguish required state databases from rebuildable log/event databases. If logs_2.sqlite fails with SQLite code 26 (SQLITE_NOTADB) or equivalent corruption/open errors, move it aside with a timestamped .corrupt-* suffix and recreate it. The startup path should still fail for non-rebuildable databases such as the main thread/session state unless there is a safe recovery path.
2 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
---
title: "codex #24001 — Remote Control Corrupt DB Recovery Fix"
issue: https://github.com/openai/codex/issues/24001
date: 2026-05-22
type: bug-fix
quote: $1,500-$2,500
labels: [bug, CLI, app-server, remote]
competition: zero
---
Solution: codex #24001 — Remote Control Corrupt DB Recovery Fix
Executive Summary
Issue:
codex remote-controlfails to become ready because a local state database (logs_2.sqlite) is corrupt. The systemd service still appears active, but the remote-control app-server never becomes ready. This is a reliability issue — a single corrupt database file should not permanently disable the service.Severity: High (service permanently unavailable until manual intervention)
Zero Competition: 0 comments from others, 0 PRs
Quote: $1,500-$2,500
Root Cause Analysis
Primary Root Cause: No Corrupt Database Recovery Path
The remote-control service initializes by loading
logs_2.sqlitewithout any corruption detection or recovery mechanism. When the database is corrupt (due to disk errors, interrupted writes, or filesystem issues), the initialization fails silently or with an unhandled error, leaving the service in a "zombie" state — process running but not functional.Failure Chain:
Secondary Issues:
Step-by-Step Reproduction
codex remote-controlservicelogs_2.sqlite(e.g., truncate file, inject garbage bytes)Proposed Fix
Fix 1: Database Integrity Check on Startup
Add a database integrity check before using the database.
Fix 2: Automatic Recovery from Backup
Implement automatic recovery from the last known good backup.
Fix 3: Health Check Endpoint
Add a health check endpoint that verifies database connectivity.
Fix 4: Systemd Watchdog Integration
Add systemd watchdog support so the service is automatically restarted if it fails to become ready.
Testing Plan
| Test | Description | Expected |
|------|-------------|----------|
| Unit: Integrity check | Open corrupt database | Error::DatabaseCorrupt |
| Unit: Recovery from backup | Corrupt DB + valid backup | Service starts from backup |
| Unit: Fresh database creation | No backup available | Fresh database created |
| Integration: Health check | Service with corrupt DB | Returns 503 |
| Integration: Systemd restart | Service fails to become ready | Auto-restart after 30s |
Impact Assessment
| Metric | Value |
|--------|-------|
| Severity | High (permanent service outage) |
| Affected Users | Anyone using remote-control with unreliable storage |
| Risk of Fix | Low (additive safety checks) |
| Rollback Plan | Revert database initialization code |
User Workaround
Until fixed, users can:
logs_2.sqliteand let the service recreate itSummary
| Item | Detail |
|------|--------|
| Issue | codex #24001 |
| Type | Bug fix (corrupt DB recovery) |
| Root Cause | No corruption detection or recovery path |
| Fix Complexity | Medium (4 code changes) |
| Quote | $1,500-$2,500 |
| Competition | Zero |