[Linux][app-server] Document safe SQLite planner-statistics maintenance for concurrent desktop and managed daemon
Summary
On Linux with Codex App Server 0.170.0, two Codex App Server processes (a desktop GUI server and a managed daemon) can hold read/write connections to the same ~/.codex/state_5.sqlite WAL database. There does not appear to be a documented, application-owned way to refresh SQLite query-planner statistics while preserving active threads, pending writes and crash-recovery guarantees.
This is a request for a supported maintenance procedure/API, not a request to blindly run VACUUM or alter live SQLite files.
Read-only observations
- Ubuntu Linux, Codex App Server 0.170.0, approximately 8.5k thread metadata rows.
state_5.sqlitehas WAL journal mode and existing indexes forthreads.updated_at_msandthreads.recency_at_ms, but nosqlite_stat1.- Three diagnostic SQL proxies for "recent unarchived", "recent guardian", and "recent subagent" thread queries picked plans with
USE TEMP B-TREE FOR ORDER BY. Forcing an already-existing matching index in a read-only transaction returned equivalent rows and reduced individual query p50 from roughly 0.5/11.2/9.9 ms to 0.04/0.04/0.11 ms respectively. These proxy SQL strings are not confirmed to be the actual app-server thread/list queries. - The supported native WebSocket
thread/listwithuseStateDbOnly=trueis functional, and p50 was approximately 5 ms for 10 results, 13 ms for 20, 24 ms for 50, 37 ms for 100 on this machine. These are healthy sub-second times, not evidence of a corresponding GUI regression. - An isolated synthetic SQLite 3.45.1 fixture with a similar row count showed that
PRAGMA optimizecould generatesqlite_stat1and remove the unnecessary sort in the synthetic example. The Python library version is not assumed to equal the SQLite build embedded in Codex.
Concurrency / safety concern
Two live App Servers can have the DB, WAL and SHM open simultaneously. An external script that rewrites operational tables, copies WAL/SHM, or restarts arbitrary processes is not a safe, documented remedy. We have therefore not executed PRAGMA optimize, ANALYZE, VACUUM, or DB replacement against the live store.
In the inspected codex-rs/state/src/sqlite.rs open-state path, SQLite pools/migrations are managed by Codex; upstream comments explicitly avoid a full VACUUM at startup due to contention. We could not identify an exposed stats-maintenance request in the current App Server protocol.
Request
- Is absence of
sqlite_stat1expected for an established native state store? - Does 0.170.0 already perform application-owned
PRAGMA optimize/ANALYZEelsewhere, and if so under which conditions? - Could Codex provide or document a bounded, idempotent stats maintenance operation coordinated with all active App Servers, with lock-timeout semantics and a consistent backup/rollback procedure?
- Are the recent-thread list query plans already tuned independently of SQLite statistics, such that no maintenance is recommended here?
Please advise the supported procedure, if any. No session IDs, titles, tokens, log payloads or private file paths are included.
Related but separate performance reports: #45246 (unarchived thread count / remote listing), #18693 (giant desktop histories), #22411 (eager rollout loading).
Follow-up: narrowed diagnosis — default visible-thread listing already uses indexes
I ran an additional read-only, same-snapshot check, using a closer approximation to the actual thread/list SQL shape documented in current upstream codex-rs/state/src/runtime/threads.rs (upstream main at d52a39b307b77e81cd272d08189341d944542b82, NOT asserted to equal the installed 0.170.0 build). Unlike the simplified SQL proxies in the original report, the closer query includes archived=0, preview <> '', attached_thread_parent_id IS NULL, and ORDER BY <timestamp> DESC, id DESC LIMIT 21.
On the actual 8,463-thread SQLite store without sqlite_stat1, SQLite already selected:
idx_threads_visible_updated_at_msfor updated-at: diagnostic p50 0.018 ms;idx_threads_visible_recency_at_msfor recency: p50 0.010 ms;idx_threads_visible_created_at_msfor created-at: p50 0.017 ms.
These timings only retrieve 21 IDs and omit the real projection/serialization; some plans included USE TEMP B-TREE FOR RIGHT PART OF ORDER BY because of the ID tie-breaker. They do not prove the app's full list request is that fast. They do show that the earlier unrepresentative SQL proxies (9–11 ms) significantly overstate the case for planner-statistics maintenance as the fix to the actual listing path. I would not recommend modifying the live SQLite state based solely on absent sqlite_stat1.
Independent real thread/list(useStateDbOnly=true) native WebSocket calls to the managed daemon (0.170.0) still show ~5.35 ms / 25 KB for 10 results, 12.52 ms / 50 KB for 20, and 23.27 ms / 97 KB for 50 (four samples per variant, median). This suggests serialization/result size or client-side history/UI work deserves investigation as well; not evidence of a defect in any one layer.
Updated request to maintainers: please clarify whether the Codex runtime already handles planner statistics as intended, whether a safe supported operation exists at all, and which conditions warrant it. The immediate need is a supported read-path profiling and maintenance procedure for simultaneous GUI+managed daemon connections, not permission to run ad-hoc ANALYZE or VACUUM. I have not written to the live store or interrupted active threads.
Isolated follow-up (synthetic only): I built a disposable 8,463-row SQLite 3.45.1 fixture using the exact six idx_threads_visible_{updated,recency,created}_at_ms and ordinary timestamp-index definitions read from the live schema (index SQL only; no private data). For the near-real filter/order/21-row query, PRAGMA optimize on that disposable fixture only generated sqlite_stat1, but p50 timings were already in microseconds and barely changed: updated 0.023→0.016 ms, recency 0.016→0.016 ms, created 0.023→0.017 ms. Query results stayed equivalent in all three cases; 4/4 isolated contract tests PASS. These are not native App 0.170 measurements and are not evidence supporting live maintenance. Recommendation: prioritize documenting whether maintenance is actually needed and supported, rather than asking users to modify WAL state manually.