Skip to content

[codex] Make active turn task singular#24105

Merged
pakrym-oai merged 3 commits into
mainfrom
pakrym/active-turn-single-task
May 26, 2026
Merged

[codex] Make active turn task singular#24105
pakrym-oai merged 3 commits into
mainfrom
pakrym/active-turn-single-task

Conversation

@pakrym-oai
Copy link
Copy Markdown
Collaborator

@pakrym-oai pakrym-oai commented May 22, 2026

Why

ActiveTurn already runs at most one task: starting a task requires that no task is present, and replacement aborts existing work first. Representing that state as an IndexMap leaves a multi-task shape for a single-task invariant and makes each lifecycle lookup operate like a collection lookup.

The slot remains optional because goal continuation uses an empty active turn as a reservation while deciding whether to start continuation work.

What changed

  • Replace ActiveTurn.tasks with task: Option<RunningTask>.
  • Update task abort/completion, session lookup and steering, input-queue matching, goal reservation, and network-approval lookup to operate on the singular slot.
  • Mutate the singular task slot directly instead of retaining collection-era add/remove/take helpers.
  • Record token usage on the completing active task span without a regular-task-only opt-in flag.

Validation

  • cargo test -p codex-core --lib session::tests::steer_input
  • cargo test -p codex-core --lib session::tests::abort_empty_active_turn_preserves_pending_input
  • cargo test -p codex-core --lib session::tests::queued_response_items_for_next_turn_move_into_next_active_turn
  • cargo test -p codex-core --lib session::tests::active_goal_continuation_runs_again_after_no_tool_turn
  • cargo test -p codex-core --lib session::tests::abort_regular_task_emits_turn_aborted_only
  • cargo test -p codex-core --lib session::input_queue::tests

@pakrym-oai pakrym-oai marked this pull request as ready for review May 22, 2026 18:03
@pakrym-oai pakrym-oai requested a review from a team as a code owner May 22, 2026 18:03
@pakrym-oai
Copy link
Copy Markdown
Collaborator Author

@codex review this

Copy link
Copy Markdown
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: 88e728326f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread codex-rs/core/src/tasks/mod.rs
_timer: timer,
};
turn.add_task(running_task);
turn.task = Some(running_task);
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.

Can we conditionally install only if the reserved turn state is still current, and otherwise bail/cleanup?

start_task has awaits between the empty active-turn reservation and installing the task, so if that reservation gets stolen by a user turn, this assignment can overwrite the new active task in release builds.
I don't think this can happen right now but it would be better to be loud/clean if this primitive changes in the future (because we know how stable primitives are...)

@pakrym-oai pakrym-oai merged commit b637fd2 into main May 26, 2026
46 of 47 checks passed
@pakrym-oai pakrym-oai deleted the pakrym/active-turn-single-task branch May 26, 2026 15:21
@github-actions github-actions Bot locked and limited conversation to collaborators May 26, 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