Skip to content

Retry goals after model capacity errors - #31176

Closed
etraut-openai wants to merge 24 commits into
mainfrom
etraut/goal-capacity-retry
Closed

Retry goals after model capacity errors#31176
etraut-openai wants to merge 24 commits into
mainfrom
etraut/goal-capacity-retry

Conversation

@etraut-openai

@etraut-openai etraut-openai commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Why

Active goals currently stop when any turn ends in an error. Model-capacity failures are different because retrying them does not consume user tokens, so blocking the goal forces unnecessary user intervention. Immediate retries would instead create a synchronized hot loop while the model remains overloaded.

What changed

  • Keep the current goal and turn active after a ServerOverloaded error, then retry failed sampling and compaction operations without appending another goal-continuation prompt.
  • Include already-queued agent updates in an automatic turn's first request, and let deliverable input interrupt retry backoffs while preserving deferred-mailbox and user-turn ordering.
  • Choose a fresh retry delay uniformly from four to six minutes, preserving a five-minute average while preventing clients from retrying in lockstep.
  • Surface retryable capacity failures as non-terminal status updates so a later successful completion is not reported as failed.
  • Retry only while the goal runtime remains enabled and available; preserve existing blocked and usage-limited behavior for other terminal errors.

@etraut-openai
etraut-openai marked this pull request as ready for review July 5, 2026 16:26
@etraut-openai etraut-openai changed the title [codex] retry goals after model capacity errors Retry goals after model capacity errors Jul 5, 2026

@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: 752aad34c6

ℹ️ 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/ext/goal/src/extension.rs Outdated
Comment thread codex-rs/ext/goal/tests/goal_extension_backend.rs Outdated

@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: 0129ff5001

ℹ️ 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/ext/goal/src/extension.rs Outdated
Comment thread codex-rs/ext/goal/src/runtime.rs Outdated
Comment thread codex-rs/ext/goal/Cargo.toml Outdated
Comment thread codex-rs/ext/goal/src/runtime.rs Outdated

@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: e80644f2f2

ℹ️ 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/ext/goal/src/api.rs Outdated
Comment thread codex-rs/ext/goal/src/extension.rs Outdated

@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: f44e5776ea

ℹ️ 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/ext/goal/src/extension.rs Outdated

@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: b3b25f039f

ℹ️ 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/ext/goal/src/extension.rs Outdated
Comment thread codex-rs/ext/goal/src/runtime.rs
Comment thread codex-rs/ext/goal/src/runtime.rs Outdated
Comment thread codex-rs/ext/goal/src/extension.rs Outdated
Comment thread codex-rs/ext/goal/src/extension.rs Outdated
.accounting_state()
.turn_is_current_active_goal(input.turn_id) =>
{
runtime.defer_retry();

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.

Doesn’t pre-turn compaction bypass this delay? The continuation stays pending, so RegularTask immediately retries and hot-loops instead of waiting five minutes. Can we cover that path too?

@etraut-openai
etraut-openai requested a review from a team as a code owner July 8, 2026 15:44

@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: 52929f1e34

ℹ️ 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/ext/goal/src/runtime.rs
@etraut-openai
etraut-openai requested a review from jif-oai July 8, 2026 18:12
Comment thread codex-rs/core/src/session/inject.rs Outdated
// Keep automatic input task-owned so a pre-turn failure drops this
// attempt instead of immediately replaying it from the pending queue.
let input = input.into_iter().map(TurnInput::ResponseItem).collect();
self.start_task(turn_context, input, RegularTask::new())

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.

(found by Codex)
This makes already-queued mailbox work miss the first request. start_task() moves mail into pending_input, but the non-empty task input makes run_turn() defer it until after one sample, so the goal can execute tools before seeing a child/trigger update that arrived before task installation

Comment thread codex-rs/ext/goal/src/runtime.rs Outdated
};
inner.retry_pending.store(false, Ordering::Relaxed);
let runtime = GoalRuntimeHandle { inner };
if let Err(err) = runtime.continue_if_idle().await {

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.

On a normal sampling overload, the continuation item has already been recorded in history. Calling continue_if_idle() here creates and records the full goal prompt again

Comment thread codex-rs/ext/goal/src/runtime.rs Outdated

// Capacity failures do not consume user tokens, but retrying immediately can
// create a tight loop of failed turns. Keep the retry cadence deliberately low.
const DEFERRED_GOAL_RETRY_DELAY: Duration = Duration::from_secs(5 * 60);

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.

Can we jitter this delay? and ideally back it off? I'm a bit scared by the retry wave it can create in case of an incident

@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: b5156738f6

ℹ️ 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/turn.rs Outdated
Comment thread codex-rs/core/src/session/turn.rs Outdated
Comment thread codex-rs/ext/goal/src/extension.rs Outdated

@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: 61be8adc57

ℹ️ 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/turn.rs Outdated
Comment thread codex-rs/core/src/session/turn.rs
Comment thread codex-rs/core/src/session/turn.rs Outdated

@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: 135c262a7a

ℹ️ 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/turn.rs Outdated
Comment thread codex-rs/core/src/session/turn.rs Outdated
Comment thread codex-rs/core/src/session/turn.rs Outdated

@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: ab636f44d1

ℹ️ 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/turn.rs Outdated
Comment thread codex-rs/core/src/session/turn.rs Outdated
Comment thread codex-rs/core/src/session/turn.rs Outdated

@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: 340d9226d3

ℹ️ 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/turn.rs Outdated
Comment thread codex-rs/core/src/session/turn.rs Outdated
Comment thread codex-rs/core/src/session/turn.rs Outdated

@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: cfb8ddb9ff

ℹ️ 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/turn.rs Outdated

@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: 6a66264bb5

ℹ️ 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/turn.rs Outdated
Comment thread codex-rs/core/src/session/turn.rs Outdated

@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: cf5851b5a6

ℹ️ 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".


#[tokio::test]
async fn turn_error_blocks_goal() -> anyhow::Result<()> {
async fn capacity_error_retries_sampling_but_not_compaction() -> anyhow::Result<()> {

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.

P2 Badge Cover goal capacity retries end to end

This test drives GoalExtensionHarness directly and only asserts the persisted goal status after a synthetic error; it never runs a real test_codex session through ServerOverloaded, the delayed idle restart, and the follow-up model request. Because this change alters agent/session retry behavior, regressions in lifecycle events, empty-input retry turns, or request contents would pass this crate-level test; add a core/suite integration test for the new user-facing retry flow.

AGENTS.md reference: AGENTS.md:L114-L118

Useful? React with 👍 / 👎.

@github-actions

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 14 days. If you plan to continue working on it, feel free to reopen or open a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants