Skip to content

state: pass state db handles through consumers#20561

Open
euroelessar wants to merge 6 commits intomainfrom
ruslan/state-db-handle-plumbing
Open

state: pass state db handles through consumers#20561
euroelessar wants to merge 6 commits intomainfrom
ruslan/state-db-handle-plumbing

Conversation

@euroelessar
Copy link
Copy Markdown
Collaborator

@euroelessar euroelessar commented May 1, 2026

Why

SQLite state was still being opened from consumer paths, including lazy OnceCell-backed thread-store call sites. That let one process construct multiple state DB connections for the same Codex home, which makes SQLite lock contention and database is locked failures much easier to hit.

State DB lifetime should be chosen by main-like entrypoints and tests, then passed through explicitly. Consumers should use the supplied Option<StateDbHandle> or StateDbHandle and keep their existing filesystem fallback or error behavior when no handle is available.

What Changed

  • Initialize the state DB in main-like entrypoints for CLI, TUI, app-server, exec, MCP server, and the thread-manager sample.
  • Pass Option<StateDbHandle> through ThreadManager, LocalThreadStore, app-server processors, TUI app wiring, rollout listing/recording, personality migration, shell snapshot cleanup, session-name lookup, and memory/device-key consumers.
  • Remove the lazy local state DB wrapper from the thread store so non-test consumers use only the supplied handle or their existing fallback path.
  • Collapse split rollout lookup/list APIs so callers use the normal methods with an optional state handle instead of _with_state_db variants.
  • Restore getConversationSummary(ThreadId) to delegate through ThreadStore::read_thread instead of a LocalThreadStore-specific rollout path special case.
  • Keep debug prompt-input filesystem-only so a one-off debug command does not initialize or backfill SQLite state just to print prompt input.
  • Keep goal-session test Codex homes alive only in the goal-specific helper, rather than leaking tempdirs from the shared session test helper.
  • Update tests and call sites to pass explicit state handles where DB behavior is expected and explicit None where filesystem-only behavior is intended.

Validation

  • CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo check -p codex-rollout -p codex-thread-store -p codex-app-server -p codex-core -p codex-tui -p codex-exec -p codex-cli --tests
  • CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-rollout session_index
  • CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-rollout find_thread_path
  • CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-rollout list_threads
  • CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-thread-store
  • CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-core shell_snapshot
  • CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-core --test all personality_migration
  • CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-core --test all rollout_list_find
  • CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-core interrupt_accounts_active_goal_before_pausing
  • CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-app-server get_auth_status -- --test-threads=1
  • CARGO_TARGET_DIR=/tmp/codex-target-state-db just fix -p codex-rollout -p codex-thread-store -p codex-core -p codex-app-server -p codex-tui -p codex-exec -p codex-cli
  • just argument-comment-lint -p codex-core

cargo test -p codex-app-server thread_list_respects_search_term_filter -- --test-threads=1 --nocapture was attempted locally but timed out waiting for the app-server test harness initialize response before reaching the changed thread-list code path.

@euroelessar euroelessar force-pushed the ruslan/state-db-handle-plumbing branch from e4a3f2d to e541ebe Compare May 1, 2026 05:39
@euroelessar euroelessar marked this pull request as ready for review May 1, 2026 08:19
@euroelessar euroelessar requested a review from a team as a code owner May 1, 2026 08:19
Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 830b771d06

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/app-server/src/codex_message_processor.rs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant