Repository navigation
Conversation
This was referenced Aug 13, 2025
bolinfest
added a commit
that referenced
this pull request
Aug 13, 2025
…rsations (#2240) This PR does two things because after I got deep into the first one I started pulling on the thread to the second: - Makes `ConversationManager` the place where all in-memory conversations are created and stored. Previously, `MessageProcessor` in the `codex-mcp-server` crate was doing this via its `session_map`, but this is something that should be done in `codex-core`. - It unwinds the `ctrl_c: tokio::sync::Notify` that was threaded throughout our code. I think this made sense at one time, but now that we handle Ctrl-C within the TUI and have a proper `Op::Interrupt` event, I don't think this was quite right, so I removed it. For `codex exec` and `codex proto`, we now use `tokio::signal::ctrl_c()` directly, but we no longer make `Notify` a field of `Codex` or `CodexConversation`. Changes of note: - Adds the files `conversation_manager.rs` and `codex_conversation.rs` to `codex-core`. - `Codex` and `CodexSpawnOk` are no longer exported from `codex-core`: other crates must use `CodexConversation` instead (which is created via `ConversationManager`). - `core/src/codex_wrapper.rs` has been deleted in favor of `ConversationManager`. - `ConversationManager::new_conversation()` returns `NewConversation`, which is in line with the `new_conversation` tool we want to add to the MCP server. Note `NewConversation` includes `SessionConfiguredEvent`, so we eliminate checks in cases like `codex-rs/core/tests/client.rs` to verify `SessionConfiguredEvent` is the first event because that is now internal to `ConversationManager`. - Quite a bit of code was deleted from `codex-rs/mcp-server/src/message_processor.rs` since it no longer has to manage multiple conversations itself: it goes through `ConversationManager` instead. - `core/tests/live_agent.rs` has been deleted because I had to update a bunch of tests and all the tests in here were ignored, and I don't think anyone ever ran them, so this was just technical debt, at this point. - Removed `notify_on_sigint()` from `util.rs` (and in a follow-up, I hope to refactor the blandly-named `util.rs` into more descriptive files). - In general, I started replacing local variables named `codex` as `conversation`, where appropriate, though admittedly I didn't do it through all the integration tests because that would have added a lot of noise to this PR. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/openai/codex/pull/2240). * #2264 * #2263 * __->__ #2240
bolinfest
force-pushed
the
pr2264
branch
3 times, most recently
from
August 13, 2025 23:02
c50e892 to
1b07bd7
Compare
bolinfest
marked this pull request as ready for review
August 13, 2025 23:13
gpeal
approved these changes
Aug 14, 2025
| }; | ||
|
|
||
| let subscription_id = Uuid::new_v4(); | ||
| let (sender, mut receiver) = oneshot::channel(); |
Contributor
There was a problem hiding this comment.
Suggested change
| let (sender, mut receiver) = oneshot::channel(); | |
| let (cancel_tx, mut cancel_rx) = oneshot::channel(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This introduces a new set of request types that our
codex mcpsupports. Note that these do not conform to MCP tool calls so that instead of having to send something like this:{ "jsonrpc": "2.0", "method": "tools/call", "id": 42, "params": { "name": "newConversation", "arguments": { "model": "gpt-5", "approvalPolicy": "on-request" } } }we can send something like this:
{ "jsonrpc": "2.0", "method": "newConversation", "id": 42, "params": { "model": "gpt-5", "approvalPolicy": "on-request" } }Admittedly, this new format is not a valid MCP tool call, but we are OK with that right now. (That is, not everything we might want to request of
codex mcpis something that is appropriate for an autonomous agent to do.)To start, this introduces four request types:
newConversationsendUserMessageaddConversationListenerremoveConversationListenerThe new
mcp-server/tests/codex_message_processor_flow.rsshows how these can be used.The types are defined on the
CodexRequestenum, so we introduce a newCodexMessageProcessorthat is responsible for dealing with requests from this enum. The top-levelMessageProcessorhas been updated so that whenprocess_request()is called, it first checks whether the request conforms toCodexRequestand dispatches it toCodexMessageProcessorif so.Note that I also decided to use
camelCasefor the on-the-wire format, as that seems to be the convention for MCP.For the moment, the new protocol is defined in
wire_format.rswithin themcp-servercrate, but in a subsequent PR, I will probably move it to its own crate to ensure the protocol has minimal dependencies and that we can codegen a schema from it.Stack created with Sapling. Best reviewed with ReviewStack.