Skip to content

codex-mcp: serialize connector runtime refreshes - #31472

Draft
mzeng-openai wants to merge 1 commit into
dev/mzeng/apps-runtime-state-managerfrom
dev/mzeng/apps-runtime-state-refresh
Draft

codex-mcp: serialize connector runtime refreshes#31472
mzeng-openai wants to merge 1 commit into
dev/mzeng/apps-runtime-state-managerfrom
dev/mzeng/apps-runtime-state-refresh

Conversation

@mzeng-openai

Copy link
Copy Markdown
Contributor

What

  • Add one async explicit-refresh lock per active connector runtime context.
  • Add McpConnectionManager::hard_refresh_codex_apps_runtime, which performs exactly one uncached Apps tools/list under that shared lock and returns the exact committed Arc<ConnectorRuntimeSnapshot>.
  • Start the host-owned Apps MCP client in initialize-only mode for the new strict path so startup cannot issue a second competing list request.
  • Keep legacy hard_refresh_codex_apps_tools / app/list behavior intact while routing its refresh through the same lock.
  • Retain the previously committed snapshot when fetch or publication fails.
  • Record the uncached list outcome/trigger and expose the committed snapshot to core for later consumers.

Why

This is stack PR 2 of 4, based on #31471. It creates the single refresh seam needed by request-stable runtime consumption and app/installed without changing app-server APIs yet.

Invariants

  • Concurrent explicit reloads serialize per account/workspace context.
  • A strict reload performs one network tools/list, then atomically publishes and returns that same committed state.
  • Generic tool filtering, exposure, approval, elicitation, and execution remain owned by McpConnectionManager.
  • The legacy app/list compatibility path remains available and retains its existing response behavior.

Checks

  • just test -p codex-mcp (114 passed)
  • just fmt

The broader codex-core suite was also compiled and exercised while developing this slice; its connector/MCP tests passed, with only the checkout's known sandbox/CLI-fixture failures in the full crate run.

@mzeng-openai
mzeng-openai force-pushed the dev/mzeng/apps-runtime-state-refresh branch from 9713df4 to adefe74 Compare July 8, 2026 22:20
@glook9001

Copy link
Copy Markdown

@codex review

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

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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: adefe7420c

ℹ️ 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".

Comment on lines +356 to +359
mcp_manager.connector_runtime_manager().current_snapshot(
config.codex_home.to_path_buf(),
connector_runtime_context_key(auth),
)

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.

P2 Badge Avoid activating runtimes during snapshot reads

When this read-only helper is called for a different auth/codex_home while another session's Codex Apps runtime is active, ConnectorRuntimeManager::current_snapshot calls context(...), which activates the requested identity and discards the entry held by the live McpConnectionManager. That makes connector_runtime_context_is_active() fail and drops that live session's Apps tools from later model requests, so this lookup should inspect the active identity without creating a new context.

AGENTS.md reference: AGENTS.md:L93-L96

Useful? React with 👍 / 👎.

Comment on lines +416 to +419
CodexAppsStartupMode::InitializeOnly,
)
.await;
let snapshot = connection_manager.hard_refresh_codex_apps_runtime().await;

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.

P2 Badge Cover strict Apps refresh with an integration test

This introduces a new core path that starts the host-owned Apps manager in InitializeOnly mode and then performs the explicit runtime refresh, but the commit only adds codex-mcp unit coverage for the lock; I checked refresh_connector_runtime_snapshot/hard_refresh_codex_apps_runtime in core/tests/suite and connectors_tests.rs and found no integration coverage. Because this path determines the agent-facing connector runtime snapshot, a regression could silently issue both startup and explicit tools/list or return a snapshot different from the committed one, so please add a test_codex Apps mock test that asserts one tools/list and the published snapshot.

AGENTS.md reference: AGENTS.md:L114-L118

Useful? React with 👍 / 👎.

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.

2 participants