Conversation
…, approvals, tokens, rate limits)
…ssion for approvals and input lifecycle
…external state locking
…story during streaming
…nal locking for history writes
…easoning; use them at call sites
pakrym-oai
reviewed
Sep 24, 2025
pakrym-oai
reviewed
Sep 24, 2025
pakrym-oai
reviewed
Sep 24, 2025
pakrym-oai
approved these changes
Sep 24, 2025
# Conflicts: # codex-rs/core/src/codex.rs # codex-rs/core/src/lib.rs
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.
Current State Observations
Sessioncurrently holds many unrelated responsibilities (history, approval queues, task handles, rollout recorder, shell discovery, token tracking, etc.), making it hard to reason about ownership and lifetimes.Statestruct insidecodex.rsmixes session-long data with turn-scoped queues and approval bookkeeping.run_task) relies on ad-hoc local variables that should conceptually belong to a per-turn state object.codex::compact, tests) frequently poke the rawSession.statemutex, which couples them to implementation details.Desired End State
Sessionobject that acts as the orchestrator and façade. It should expose a focused API (submit, approvals, interrupts, event emission) without storing unrelated fields directly.statemodule that encapsulates all mutable data structures:SessionState: session-persistent data (history, approved commands, token/rate-limit info, maybe user preferences).ActiveTurn: metadata for the currently running turn (sub-id, task kind, abort handle) and anArc<TurnState>.TurnState: all turn-scoped pieces (pending inputs, approval waiters, diff tracker, review history, auto-compact flags, last agent message, outstanding tool call bookkeeping).SessionServicesstruct soSessiondoes not accumulate "random" fields.TurnStateand that interrupts/finishes delegate cleanup to it.