Skip to content

Preserve session MCP config on refresh#21055

Merged
aaronl-openai merged 7 commits intomainfrom
dev/aaronl/preserve-overlay-on-mcp-refresh
May 6, 2026
Merged

Preserve session MCP config on refresh#21055
aaronl-openai merged 7 commits intomainfrom
dev/aaronl/preserve-overlay-on-mcp-refresh

Conversation

@aaronl-openai
Copy link
Copy Markdown
Collaborator

@aaronl-openai aaronl-openai commented May 4, 2026

Overview

MCP refreshes were rebuilding active threads from fresh disk-backed config only, which dropped thread-start session overlays such as app-injected MCP servers. This keeps refreshes current with disk config while preserving the thread-local config that only the active thread knows about.

Changes

  • Rebuild refreshed config per active thread using that thread's current cwd, rather than fanning out one app-server config to every thread.
  • Preserve each thread's SessionFlags layer while replacing reloadable config layers with freshly loaded config, then derive the MCP refresh payload from the rebuilt result.
  • Move MCP refresh orchestration into app-server so manual refreshes fail loudly while background refreshes remain best-effort, and route plugin-triggered refreshes through the same per-thread reload path.
  • Add regression coverage for session overlays, fresh project config, plugin-derived MCP config, current requirements, and strict vs best-effort refresh behavior.

Verification

  • Passed focused Rust coverage for the thread-config rebuild behavior and deferred MCP refresh flow, plus cargo test -p codex-app-server --lib.
  • Verified end to end in the Codex dev app against the locally built CLI: registered an MCP via thread config, verified that it could be used successfully before refresh, manually triggered MCP refresh, and verified that it continued to be available afterward.

@aaronl-openai aaronl-openai requested a review from a team as a code owner May 4, 2026 18:24
@aaronl-openai aaronl-openai changed the title [codex] preserve session MCP config on refresh Preserve session MCP config on refresh May 4, 2026
Copy link
Copy Markdown
Collaborator

@dylan-hurd-oai dylan-hurd-oai left a comment

Choose a reason for hiding this comment

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

I am onboard with the general principle here unless @xl-openai has issues, but I think i'd propose restructuring this a bit:

  1. I'm not convinced we should add the purpose-specific refresh logic to codex-core config, it seems like this might be better served using a generic refresh interface (ideally an existing one) with app_server::config_manager?
  2. It seems like our current approach seems just thread more state through spawn_effective_plugins_changed_task - can we do this in a simpler way?

Comment thread codex-rs/core/src/config/mod.rs Outdated
}
}

pub async fn rebuild_for_mcp_refresh_planning(
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.

I'm curious why we need a purpose-specific rebuild function here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I renamed to rebuild_preserving_session_layers to make this more clearly generic. it does feel a bit weird that combining thread-level config on top of the refreshed config is so manual, but I think it's necessary.

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.

ack, yeah i think we should rethink this generally

@aaronl-openai
Copy link
Copy Markdown
Collaborator Author

aaronl-openai commented May 6, 2026

I'm not convinced we should add the purpose-specific refresh logic to codex-core config, it seems like this might be better served using a generic refresh interface (ideally an existing one) with app_server::config_manager?

Yeah, this one I'm not too sure about. The main reason rebuild_preserving_session_layers is in core is because it uses load_config_with_layer_stack, which is internal to core. I'm not familiar enough with the architecture to know if core being aware that long lived threads may need to refresh their config is pushing too much app-server knowledge into it. lmk what you think!

It seems like our current approach seems just thread more state through spawn_effective_plugins_changed_task - can we do this in a simpler way?

we're passing in the config manager instead of a config object here because refresh needs to take each thread's config into account, rather than applying the same global config to all threads. I'm not sure this is avoidable since we really do need more state to know how each thread is configured.

…verlay-on-mcp-refresh

# Conflicts:
#	codex-rs/app-server/src/request_processors/mcp_processor.rs
@aaronl-openai aaronl-openai merged commit 9f06d17 into main May 6, 2026
47 of 50 checks passed
@aaronl-openai aaronl-openai deleted the dev/aaronl/preserve-overlay-on-mcp-refresh branch May 6, 2026 04:09
@github-actions github-actions Bot locked and limited conversation to collaborators May 6, 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.

2 participants