[faster-connectors] (1/4) Extract apps cache logic into ConnectorRuntimeManager - #31471
[faster-connectors] (1/4) Extract apps cache logic into ConnectorRuntimeManager#31471mzeng-openai wants to merge 9 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9f4775b492
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 95f76cd3e0
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4f6fb1bbf1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| use super::emit_duration; | ||
|
|
||
| const MCP_TOOLS_CACHE_WRITE_DURATION_METRIC: &str = "codex.mcp.tools.cache_write.duration_ms"; | ||
| pub(crate) const CODEX_APPS_TOOLS_CACHE_MAX_BYTES: u64 = 32 * 1024 * 1024; |
There was a problem hiding this comment.
Cap cached tool payloads below context limits
This 32 MiB cache limit is still accepted as a valid Codex Apps tool snapshot, and cached ToolInfo values flow through McpConnectionManager::list_all_tools() into model-visible tool declarations. A single cached tool description/schema under this byte limit can far exceed the 10K-token item cap, so oversized cache entries should be dropped or trimmed with a model-context-sized hard cap before exposure.
AGENTS.md reference: AGENTS.md:L97-L99
Useful? React with 👍 / 👎.
| /// Activating a different context discards the prior in-memory entry. Handles | ||
| /// to a discarded context can no longer read or publish its snapshot, which | ||
| /// prevents account A state from bleeding into account B. | ||
| pub struct ConnectorRuntimeManager<T: ConnectorRuntimePayload> { |
There was a problem hiding this comment.
Split the runtime extraction into smaller stages
This commit changes 16 files with 1,612 insertions and 509 deletions while introducing new ConnectorRuntimeManager semantics, active-context discard/cancellation, bounded/atomic persistence, call-site rewrites, and extensive test changes, so it is not a mechanical move and exceeds the 800-line / 500-line complex-logic size guidance. A smaller coherent first stage would be to move the existing codex_apps_cache implementation/tests into codex-connectors behind compatibility aliases with unchanged behavior, then layer the runtime-context and persistence hardening changes separately.
AGENTS.md reference: AGENTS.md:L125-L131
Useful? React with 👍 / 👎.
| if self.routing_cancellation_token.is_cancelled() { | ||
| return Err(StartupOutcomeError::Cancelled); | ||
| } |
There was a problem hiding this comment.
Add integration coverage for Apps context discard
This new routing-cancellation branch changes agent-visible behavior because client() now makes stale Codex Apps managers fail before tool listing/calls reach core, but the commit adds only crate-level unit tests and no core/tests/suite TestCodex coverage for an account/workspace context switch. Add an integration test that proves stale Apps tools are not sent in the model request and stale Apps tool calls are rejected after the runtime context changes.
AGENTS.md reference: AGENTS.md:L114-L118
Useful? React with 👍 / 👎.
| mod persistence; | ||
|
|
||
| #[cfg(test)] | ||
| mod tests; |
There was a problem hiding this comment.
Put new connector-runtime tests in a named test file
This introduces a new unit-test module through the implicit connector_runtime/tests.rs path, while the repo guidance asks new test modules to use an explicit #[path = "..._tests.rs"] with a descriptive filename. Rename the file and declare it with an explicit path so the connector-runtime tests follow the expected layout.
AGENTS.md reference: AGENTS.md:L169-L178
Useful? React with 👍 / 👎.
| #[cfg(test)] | ||
| pub(crate) fn write_cached_codex_apps_tools_for_test<T>( |
There was a problem hiding this comment.
Move test-only cache helpers out of the implementation
These #[cfg(test)] helper APIs are only consumed by connector_runtime/tests.rs, so the production persistence module now carries test-only setup surface instead of keeping that fixture code beside the tests or exercising the production persistence entry points directly. Move these helpers into test code/test support to keep the implementation free of test-only functions.
AGENTS.md reference: AGENTS.md:L120-L121
Useful? React with 👍 / 👎.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4f6fb1bbf1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if self.routing_cancellation_token.is_cancelled() { | ||
| return None; | ||
| } |
There was a problem hiding this comment.
Revalidate Apps tools before returning the aggregate
When a Codex Apps client passes this guard, McpConnectionManager::list_all_tools() can still keep those tools in its local tools vector while awaiting later MCP servers; if another account/workspace activates the shared runtime during that later await, the discarded Apps tools are still normalized and returned for the next model-visible tool list. Please recheck the routing context at the aggregate boundary, or carry a guarded Apps snapshot through aggregation, so tools from a discarded context cannot be advertised.
AGENTS.md reference: AGENTS.md:L91-L93
Useful? React with 👍 / 👎.
|
|
||
| [dependencies] | ||
| anyhow = { workspace = true } | ||
| arc-swap = { workspace = true } |
There was a problem hiding this comment.
This commit adds normal dependencies to codex-connectors and updates Cargo.lock, but the diff does not include MODULE.bazel.lock. The repo requires running just bazel-lock-update for Rust dependency changes and notes that CI verifies lockfile drift, so Bazel-based checks will fail until the corresponding lockfile update is committed.
AGENTS.md reference: AGENTS.md:L37-L39
Useful? React with 👍 / 👎.
What
ConnectorRuntimeManager,ConnectorRuntimeContext, and an immutable tools-plus-refresh-time snapshot.app/listcallers and startup behavior do not change in this slice.Why
This is stack PR 1 of 4 for the connector runtime state refactor. It establishes one owner for committed connector runtime state before later PRs add explicit refresh serialization, request-stable consumption, and the v2
app/installedAPI.The snapshot intentionally contains runtime facts only: the raw
/ps/mcp tools/listToolInfoset andrefreshed_at. Connector directory metadata remains owned byapp/read/ConnectorMetadataStore.Compatibility and impact
app/listbehavior change._meta.installedAppsdependency.{ "schema_version": 4, "tools": [...] }, so existing caches remain readable.Checks
just test -p codex-mcp(112 passed)just fmt