Skip to content

[codex] abort turns when rollout budgets expire (token budget 3/3)#28707

Merged
rka-oai merged 8 commits into
mainfrom
codex/rollout-budget-interruption
Jun 19, 2026
Merged

[codex] abort turns when rollout budgets expire (token budget 3/3)#28707
rka-oai merged 8 commits into
mainfrom
codex/rollout-budget-interruption

Conversation

@rka-oai

@rka-oai rka-oai commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Stack

Depends on #28494.

Description

This PR propagates shared rollout-budget exhaustion through the existing CodexErr::TurnAborted task result.

Each thread records its model usage against the same ledger. Once the ledger is exhausted, that usage update and all later usage updates return TurnAborted. The task wrapper emits the normal aborted-turn event and lifecycle instead of completing the turn.

This is intentionally a soft boundary: there is no cross-thread Op::Interrupt fanout. An in-flight thread can finish its current response before it observes the exhausted ledger, but every thread aborts at its next usage-accounting boundary.

Tests

The integration coverage verifies that:

  • the response that exhausts the budget aborts its turn;
  • a later response also aborts because the shared ledger remains exhausted; and
  • sub-agent usage draws from the same shared ledger; and
  • local and remote-v2 compaction abort without retrying or emitting a generic error.

Local checks:

  • just test -p codex-core exhausted_budget_aborts_current_and_later_turns
  • just test -p codex-core subagent_usage_draws_from_the_shared_budget
  • just test -p codex-core abort_regular_task_emits_marker_before_turn_aborted
  • just test -p codex-core compaction_budget_exhaustion_aborts_without_error_or_retry
  • just fix -p codex-core
  • just fmt
  • git diff --check

The full workspace test suite was not run locally.

@rka-oai rka-oai force-pushed the codex/minimal-session-token-budget branch from b984e14 to 0cf2c87 Compare June 17, 2026 16:10
@rka-oai rka-oai force-pushed the codex/rollout-budget-interruption branch from 5877cdf to 33db2e4 Compare June 17, 2026 16:10
@rka-oai rka-oai force-pushed the codex/minimal-session-token-budget branch from 0cf2c87 to 845074e Compare June 17, 2026 20:28
@rka-oai rka-oai force-pushed the codex/rollout-budget-interruption branch 2 times, most recently from 445c194 to 77ae42c Compare June 17, 2026 20:54
@rka-oai rka-oai force-pushed the codex/minimal-session-token-budget branch from 4473161 to cbb2072 Compare June 17, 2026 21:16
@rka-oai rka-oai force-pushed the codex/rollout-budget-interruption branch from 77ae42c to 45a551b Compare June 17, 2026 21:16
@rka-oai rka-oai changed the title [codex] interrupt sessions when rollout budgets expire [codex] interrupt sessions when rollout budgets expire (varlength 3/3) Jun 17, 2026
@rka-oai rka-oai force-pushed the codex/minimal-session-token-budget branch from cbb2072 to 7df6e0e Compare June 17, 2026 21:46
@rka-oai rka-oai force-pushed the codex/rollout-budget-interruption branch from 45a551b to 5fd96c8 Compare June 17, 2026 21:46
@rka-oai rka-oai marked this pull request as ready for review June 17, 2026 21:47
@rka-oai rka-oai requested a review from a team as a code owner June 17, 2026 21:47

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

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: 5fd96c8985

ℹ️ 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 thread codex-rs/core/src/session/rollout_budget.rs Outdated
Comment thread codex-rs/core/src/agent/control.rs Outdated
Comment thread codex-rs/core/src/rollout_budget.rs Outdated
@rka-oai rka-oai force-pushed the codex/rollout-budget-interruption branch from 5fd96c8 to bf0d519 Compare June 17, 2026 22:10
Comment thread codex-rs/core/src/rollout_budget.rs Outdated
Comment thread codex-rs/core/src/agent/control.rs Outdated
@rka-oai rka-oai force-pushed the codex/rollout-budget-interruption branch from bf0d519 to adfc267 Compare June 17, 2026 22:33
@rka-oai rka-oai force-pushed the codex/minimal-session-token-budget branch from 74d1a92 to 0c95ffd Compare June 18, 2026 11:35
@rka-oai rka-oai force-pushed the codex/rollout-budget-interruption branch 3 times, most recently from 350cc23 to aaca015 Compare June 18, 2026 12:11
@rka-oai rka-oai force-pushed the codex/minimal-session-token-budget branch from 0e01b88 to 9d97673 Compare June 18, 2026 12:39
@rka-oai rka-oai force-pushed the codex/rollout-budget-interruption branch from aaca015 to 529597a Compare June 18, 2026 12:39
@rka-oai rka-oai force-pushed the codex/minimal-session-token-budget branch from 9d97673 to 1807f7f Compare June 18, 2026 16:13
@rka-oai rka-oai force-pushed the codex/rollout-budget-interruption branch from 529597a to 4db5c2e Compare June 18, 2026 16:14
@rka-oai rka-oai force-pushed the codex/minimal-session-token-budget branch from 1807f7f to 4333d42 Compare June 18, 2026 17:19
@rka-oai rka-oai force-pushed the codex/rollout-budget-interruption branch from 4db5c2e to eb51c76 Compare June 18, 2026 17:19
@rka-oai rka-oai requested a review from pakrym-oai June 18, 2026 18:05
@rka-oai rka-oai force-pushed the codex/minimal-session-token-budget branch from 4333d42 to bc62a74 Compare June 18, 2026 18:07
@rka-oai rka-oai force-pushed the codex/rollout-budget-interruption branch from eb51c76 to 4f520fc Compare June 18, 2026 18:07
Base automatically changed from codex/minimal-session-token-budget to main June 18, 2026 18:52
@rka-oai rka-oai force-pushed the codex/rollout-budget-interruption branch from 4f520fc to 93aba6e Compare June 18, 2026 19:06
@rka-oai rka-oai changed the title [codex] interrupt sessions when rollout budgets expire (varlength 3/3) [codex] interrupt sessions when rollout budgets expire (token budget 3/3) Jun 18, 2026
Comment thread codex-rs/core/src/agent/control.rs Outdated
@rka-oai rka-oai changed the title [codex] interrupt sessions when rollout budgets expire (token budget 3/3) [codex] abort turns when rollout budgets expire (token budget 3/3) Jun 18, 2026
} = compaction_output_result?;
if let Some(token_usage) = token_usage {
sess.record_rollout_budget_usage(&token_usage);
sess.record_rollout_budget_usage(&token_usage)?;

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.

will this get turned into Error running remote compact task ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, I thought it was okay bc the point is to just kill the rollout right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hmm actually, i can see how this is bad - fixing now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread codex-rs/core/src/tasks/mod.rs Outdated
true
}

async fn on_task_aborted(self: &Arc<Self>) {

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.

is there more to share with normal abort path?

Comment thread codex-rs/core/src/tasks/mod.rs Outdated
}
Err(err) => {
warn!(%err, "session task returned an unexpected error");
sess.on_task_finished(

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.

Not confident: Should we try to handle error case through onTaskFinished too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

handling everything through on_task_finished now

@pakrym-oai pakrym-oai left a comment

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 get rid of net new code for task aborted? There is so much code in task lifecycle already

])
};
let responses = mount_sse_sequence(&server, vec![compact_response]).await;
let mut model_provider = built_in_model_providers(/*openai_base_url*/ None)["openai"].clone();

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.

this is some very special test setup code

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.

non blocking

attempt
.track(sess.as_ref(), status, codex_error, analytics_details)
.await;
if matches!(&result, Err(CodexErr::TurnAborted)) {

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.

nit: probably better as a switch.

@rka-oai rka-oai merged commit dac588f into main Jun 19, 2026
45 of 47 checks passed
@rka-oai rka-oai deleted the codex/rollout-budget-interruption branch June 19, 2026 09:00
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 19, 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