Skip to content

Inject state DB, agent graph store#20689

Merged
rasmusrygaard merged 15 commits into
mainfrom
dev/rasmus/agent_store_interface_plumbing
May 5, 2026
Merged

Inject state DB, agent graph store#20689
rasmusrygaard merged 15 commits into
mainfrom
dev/rasmus/agent_store_interface_plumbing

Conversation

@rasmusrygaard
Copy link
Copy Markdown
Contributor

Why

We want the agent graph store to be passed down the stack as a real dependency, the same way we already treat the thread store.

This will let us inject the agent graph store as a real dependency and support implementations other than the local SQLite-backed one. Right now most code instantiates a state DB and an agent graph store just-in-time. Ideally, we would not depend on the state DB directly but only read through the higher-level interfaces.

This change makes the dependency boundaries explicit and moves state DB initialization to process bootstrap instead of hiding it inside local store implementations.

What changed

  • ThreadManager now requires a StateDbHandle and an AgentGraphStore at construction time instead of treating them as optional internals.
  • The local store constructors no longer lazily initialize SQLite. Callers now initialize the state DB once per process and use that shared handle to build:
    • LocalThreadStore
    • LocalAgentGraphStore
  • App bootstraps (app-server, mcp-server, prompt_debug, and the thread-manager sample) now initialize the state DB up front and inject the resulting handle down the stack.
  • app-server now consistently uses its process-scoped state DB handle instead of reopening SQLite or trying to recover it from loaded threads.
  • Device-key storage now reuses the shared state DB handle instead of maintaining its own lazy opener.
  • The thread archive / descendant traversal paths now use the injected AgentGraphStore instead of reaching through local thread-store-specific state.

Verification

  • cargo check -p codex-core -p codex-thread-store -p codex-app-server -p codex-mcp-server -p codex-thread-manager-sample --tests
  • cargo test -p codex-thread-store
  • cargo test -p codex-core thread_manager_accepts_separate_agent_graph_store_and_thread_store -- --nocapture
  • cargo test -p codex-app-server thread_archive_archives_spawned_descendants -- --nocapture

@rasmusrygaard rasmusrygaard requested a review from a team as a code owner May 1, 2026 21:45
@rasmusrygaard rasmusrygaard changed the title Dev/rasmus/agent store interface plumbing Inject stat DB, agent graph store May 1, 2026
@rasmusrygaard rasmusrygaard marked this pull request as draft May 1, 2026 21:45
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: 5f2fcd2754

ℹ️ 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/in_process.rs Outdated
@rasmusrygaard rasmusrygaard changed the title Inject stat DB, agent graph store Inject state DB, agent graph store May 1, 2026
rasmusrygaard added a commit that referenced this pull request May 1, 2026
rasmusrygaard added a commit that referenced this pull request May 1, 2026
Comment thread codex-rs/app-server/src/device_key_api.rs Outdated
rasmusrygaard added a commit that referenced this pull request May 1, 2026
Comment thread codex-rs/app-server/src/in_process.rs Outdated
Comment thread codex-rs/app-server/src/message_processor.rs
Comment thread codex-rs/app-server/src/message_processor.rs Outdated
Comment thread codex-rs/app-server/src/lib.rs Outdated
@vmy7zg24hc-maker
Copy link
Copy Markdown

dev/rasmus/agent_store_interface_plumbing

Comment thread codex-rs/thread-store/src/local/mod.rs
Comment thread codex-rs/mcp-server/src/message_processor.rs Outdated
Comment thread codex-rs/core/src/thread_manager.rs Outdated
Comment thread codex-rs/core/src/thread_manager.rs Outdated
Arc::new(LocalAgentGraphStore::new(state_db))
}

pub fn agent_graph_store_from_config(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same q about deciding store based on experimental_thread_store

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we should have a separate flag here. Can we take in a follow-up to make the scope of this PR more manageable?

Comment thread codex-rs/core/src/thread_manager.rs
Comment thread codex-rs/core/src/thread_manager.rs
Comment thread codex-rs/core/src/stream_events_utils.rs Outdated
Comment thread codex-rs/core/src/prompt_debug.rs Outdated
Comment thread codex-rs/core/src/session/tests.rs Outdated
Comment thread codex-rs/core/src/session/session.rs Outdated
Copy link
Copy Markdown
Collaborator

@pakrym-oai pakrym-oai left a comment

Choose a reason for hiding this comment

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

Minor comments.

rasmusrygaard added a commit that referenced this pull request May 5, 2026
rasmusrygaard added a commit that referenced this pull request May 5, 2026
@rasmusrygaard rasmusrygaard force-pushed the dev/rasmus/agent_store_interface_plumbing branch from 3216b5f to 73f6fcb Compare May 5, 2026 19:44
rasmusrygaard added a commit that referenced this pull request May 5, 2026
@rasmusrygaard rasmusrygaard force-pushed the dev/rasmus/agent_store_interface_plumbing branch from 7a4638f to 0fe0569 Compare May 5, 2026 20:47
@rasmusrygaard rasmusrygaard force-pushed the dev/rasmus/agent_store_interface_plumbing branch from 0fe0569 to 134a4df Compare May 5, 2026 21:03
@rasmusrygaard rasmusrygaard marked this pull request as ready for review May 5, 2026 21:04
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: 134a4df6f3

ℹ️ 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/core/Cargo.toml
chrono = { workspace = true, features = ["serde"] }
clap = { workspace = true, features = ["derive"] }
codex-analytics = { workspace = true }
codex-agent-graph-store = { workspace = true }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Regenerate the Bazel module lockfile

Adding codex-agent-graph-store to codex-core changes the Rust dependency graph, but MODULE.bazel.lock was not updated. just bazel-lock-check reports the lockfile is out of date, so Bazel CI will fail until just bazel-lock-update is run and committed.

Useful? React with 👍 / 👎.

@rasmusrygaard rasmusrygaard enabled auto-merge (squash) May 5, 2026 21:40
@rasmusrygaard rasmusrygaard merged commit 7e310bc into main May 5, 2026
47 of 50 checks passed
@rasmusrygaard rasmusrygaard deleted the dev/rasmus/agent_store_interface_plumbing branch May 5, 2026 21:45
@github-actions github-actions Bot locked and limited conversation to collaborators May 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants