Repository navigation
Conversation
gpeal
approved these changes
Aug 14, 2025
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.
Historically,
Codex::spawn()would create the instance ofCodexand enforce, by construction, thatOp::ConfigureSessionwas the firstOpsubmitted viasubmit(). Then over insubmission_loop(), it would handle the case for taking the parameters ofOp::ConfigureSessionand turning it into aSession.This approach has two challenges from a state management perspective:
codex/codex-rs/core/src/codex.rs
Line 718 in f968a13
sessvariable insubmission_loop()has to bemutandOption<Arc<Session>>because it is not invariant that aSessionis present for the lifetime of the loop, so there is a lot of logic to deal with the case wheresessisNone(e.g., thesend_no_session_eventfunction and all of its callsites).submission_loop()is written in such a way thatOp::ConfigureSessioncould be observed multiple times, but in practice, it is only observed exactly once at the start of the loop.In this PR, we try to simplify the state management by removing the
Op::ConfigureSessionenum variant and constructing theSessionas part ofCodex::spawn()so that it can be passed tosubmission_loop()asArc<Session>. The original logic from theOp::ConfigureSessionhas largely been moved to the newSession::new()constructor.Incidentally, I also noticed that the handling of
Op::ConfigureSessioncan result in events being dispatched in addition toEventMsg::SessionConfigured, as anEventMsg::Erroris created for every MCP initialization error, so it is important to preserve that behavior:codex/codex-rs/core/src/codex.rs
Lines 901 to 916 in f968a13
Though admittedly, I believe this does not play nice with #2264, as these error messages will likely be dispatched before the client has a chance to call
addConversationListener, so we likely need to make it sonewConversationautomatically creates the subscription, but we must also guarantee that the "ack" fromnewConversationis returned before any other conversation-related notifications are sent so the client knows whatconversation_idto match on.