Skip to content

fix: prevent repeating interrupted turns#9043

Merged
etraut-openai merged 32 commits intoopenai:mainfrom
swordfish444:fix/interrupt-aborted-turn-marker
Jan 20, 2026
Merged

fix: prevent repeating interrupted turns#9043
etraut-openai merged 32 commits intoopenai:mainfrom
swordfish444:fix/interrupt-aborted-turn-marker

Conversation

@swordfish444
Copy link
Contributor

What

Record a model-visible <turn_aborted> marker in history when a turn is interrupted, and treat it as a session prefix.

Why

When a turn is interrupted, Codex emits TurnAborted but previously did not persist anything model-visible in the conversation history. On the next user turn, the model can’t tell the previous work was aborted and may resume/repeat earlier actions (including duplicated side effects like re-opening PRs).

Fixes: #9042

How

On TurnAbortReason::Interrupted, append a hidden user message containing a <turn_aborted>…</turn_aborted> marker and flush.
Treat <turn_aborted> like <environment_context> for session-prefix filtering.
Add a regression test to ensure follow-up turns don’t repeat side effects from an aborted turn.

Testing

just fmt
just fix -p codex-core
cargo test -p codex-core -- --test-threads=1
cargo test --all-features -- --test-threads=1

Record a model-visible <turn_aborted> marker in history when a turn is interrupted, and treat it as a session prefix so it doesn't change user-turn boundaries.

Add a regression test to ensure follow-up turns don't repeat side effects from the aborted turn.
@swordfish444
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@github-actions
Copy link
Contributor

github-actions bot commented Jan 10, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@swordfish444
Copy link
Contributor Author

@jif-oai would you mind taking a look when you have a chance?

This PR fixes the "interrupt mid-turn → later turns repeat aborted work" issue by recording a model-visible <turn_aborted> marker in history (and includes a regression test).

Appreciate any review — thank you!

@swordfish444
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Jan 11, 2026
@sgraika
Copy link
Contributor

sgraika commented Jan 11, 2026

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Jan 11, 2026
@etraut-openai
Copy link
Collaborator

@codex review

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. Keep them coming!

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

@cgraika127
Copy link

I want to explicitly call out that this fix was implemented by @swordfish444 (my brother), and I’ve reviewed the full diff + tests closely because this bug had a real, material impact on my day-to-day use of Codex.

In v0.80.0, interrupted turns not being persisted as model-visible state caused follow-up turns to resume or repeat aborted work, often re-triggering side effects. It was disruptive enough that I had to downgrade to v0.78.0 to stay productive.

What I really appreciate about this PR is that it addresses the problem at the correct abstraction layer:
• A durable, model-visible <turn_aborted> marker is recorded into history at interrupt time
• The marker is treated consistently as a session prefix (alongside environment_context)
• The marker is flushed before emitting TurnAborted, ensuring deterministic visibility
• Event ordering edge cases are handled explicitly rather than assumed
• Comprehensive regression tests assert that follow-up requests carry the marker and do not repeat aborted side effects

This isn’t a workaround or a heuristic — it’s a clean, well-scoped fix that aligns the event stream, session history, and model context in a way that’s robust under interruption, retries, and concurrency.

From a user perspective, this dramatically improves reliability for longer or interruption-prone Codex workflows. From a code perspective, the solution feels intentional, well-tested, and future-proof.

Strongly hope this lands soon — it’s a big quality-of-life improvement for anyone using Codex seriously.

Thank you OpenAi/Codex team for your wonderful product!

@jif-oai
Copy link
Collaborator

jif-oai commented Jan 13, 2026

This contains a behavioural change of the model so we are discussing internally on the best approach to take here and will come back to you shortly

@jif-oai
Copy link
Collaborator

jif-oai commented Jan 16, 2026

@codex review

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. Delightful!

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

@etraut-openai
Copy link
Collaborator

@swordfish444, looks like this PR is close. There are a few CI failures that still need to be addressed. You can ignore the Bazel ones, but the other linter issues need to be fixed. Once that's done, I think this will be good to merge!

@etraut-openai etraut-openai added the needs-response Additional information is requested label Jan 16, 2026
@swordfish444
Copy link
Contributor Author

Thanks! I fixed the non-Bazel CI failures (missing text_elements in a couple UserInput::Text initializers in codex-rs/core/tests/suite/abort_tasks.rs).

Pushed a small follow-up commit; locally just fmt, just fix -p codex-core, and cargo test -p codex-core --all-features -- --test-threads=1 are all green.

Happy to rerun CI (non-Bazel) once approved.

@etraut-openai
Copy link
Collaborator

@codex review

Copy link
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: e8fb3f2760

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

@swordfish444
Copy link
Contributor Author

Quick update: merged latest main to resolve conflicts and re-ran local checks.

  • cd codex-rs && just fmt
  • cd codex-rs && just fix -p codex-core
  • cd codex-rs && cargo test --all-features -- --test-threads=1

All green locally.

Also addressed the compaction concern from the Codex bot: local compaction now preserves <turn_aborted> markers (with a regression test in codex-rs/core/src/compact.rs).

@swordfish444
Copy link
Contributor Author

@etraut-openai This is ready to go!

@etraut-openai etraut-openai removed the needs-response Additional information is requested label Jan 20, 2026
@swordfish444
Copy link
Contributor Author

@etraut-openai Do you need me to keep updating the branch or should I let you all take it from here?

@etraut-openai
Copy link
Collaborator

@swordfish444, thanks again for the contribution. Apologies for taking a while to approve it. This change touches some areas that have high regression risk, so we wanted to be extra cautious before merging this one.

@etraut-openai etraut-openai merged commit b236f1c into openai:main Jan 20, 2026
26 of 32 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 20, 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.

Interrupted turns aren’t recorded in history, causing follow-up turns to repeat aborted work

6 participants