Skip to content

Conversation

@leeroybrun
Copy link

What

This PR adds persistent resume/recovery to the MCP codex-reply tool-call.

Previously, codex-reply only succeeded if the conversation was still present in the server’s in-memory ConversationManager. After restarting codex mcp-server, that map is empty and codex-reply immediately fails with “Session not found…”.

With this change, when a conversation is not in memory, codex-reply will rehydrate it from the persisted rollout JSONL on disk (under CODEX_HOME/sessions/...) using the provided conversation_id, then continue the conversation normally.

Why

This closes the gap described in:

  • #6168: MCP codex-reply cannot resume after restarting the MCP server even though the rollout exists and codex resume <sessionId> works.
  • #5066: MCP tool cannot resume conversations from persistence.

Resume parity with CLI: This effectively adds “resume” functionality to the MCP server in the same spirit as codex resume <sessionId>. External integrations can continue a session after a process restart by providing the conversation/session id, and Codex will load the persisted history from disk.

How

  • In the codex-reply handler:
    • Attempt conversation_manager.get_conversation(conversation_id)
    • If missing:
      • Locate rollout path via codex_core::find_conversation_path_by_id_str(&config.codex_home, <conversation_id>)
      • Resume via conversation_manager.resume_conversation_from_rollout(config.clone(), rollout_path, auth_manager.clone())
      • Emit a session_configured notification (so clients can observe the resume handshake)
      • Submit the new user prompt to the resumed conversation

Tests

Adds an integration test that:

  • Writes a minimal rollout file for a new conversation_id
  • Calls codex-reply directly (no prior in-memory conversation)
  • Asserts the server emits session_configured for that id and the tool call completes successfully

Run locally:

  • cargo test -p codex-mcp-server --tests

@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@leeroybrun
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Jan 2, 2026
Copy link
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: 38389bca5e

ℹ️ 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 on lines 552 to 556
let config = self.config.as_ref().clone();
let auth_manager = self.auth_manager.clone();
match self
.conversation_manager
.resume_conversation_from_rollout(config, rollout_path, auth_manager)
Copy link
Contributor

Choose a reason for hiding this comment

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

P2 Badge Preserve per-session config when resuming from rollout

Resuming a codex-reply session always clones the server’s global config (self.config) before calling resume_conversation_from_rollout, which silently drops any per-session overrides that were used when the conversation was created (e.g., custom cwd, model, approval/sandbox policy supplied via the initial codex tool call). After an MCP server restart, the resumed session can therefore run in the wrong directory or with different policies/models than the original, which changes tool behavior and can lead to commands acting on the wrong workspace. Consider deriving the config for resume from the rollout’s session metadata (or persisting the original config alongside the rollout) so resumed sessions keep their original settings.

Useful? React with 👍 / 👎.

Copy link
Author

Choose a reason for hiding this comment

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

Added a new commit to restore session settings from rollout TurnContext

Adds logic to restore session cwd, model, approval policy, and sandbox policy from the most recent TurnContextItem in rollout history when resuming a session. Updates tests to verify that these settings are correctly restored from the rollout file.
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.

Add MCP codex-reply Support for Resuming Conversations from Rollout Files : MCP tool enable to resume conversations from persistence

1 participant