fix: prevent repeating interrupted turns#9043
Conversation
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.
|
I have read the CLA Document and I hereby sign the CLA |
|
All contributors have signed the CLA ✍️ ✅ |
|
@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 Appreciate any review — thank you! |
|
I have read the CLA Document and I hereby sign the CLA |
|
I have read the CLA Document and I hereby sign the CLA |
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
codex-rs/core/tests/suite/interrupt_does_not_repeat_aborted_turn.rs
Outdated
Show resolved
Hide resolved
codex-rs/core/tests/suite/interrupt_does_not_repeat_aborted_turn.rs
Outdated
Show resolved
Hide resolved
|
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: 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! |
|
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 |
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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, 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! |
|
Thanks! I fixed the non-Bazel CI failures (missing Pushed a small follow-up commit; locally Happy to rerun CI (non-Bazel) once approved. |
|
@codex review |
There was a problem hiding this comment.
💡 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".
|
Quick update: merged latest
All green locally. Also addressed the compaction concern from the Codex bot: local compaction now preserves |
|
@etraut-openai This is ready to go! |
|
@etraut-openai Do you need me to keep updating the branch or should I let you all take it from here? |
|
@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. |
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
TurnAbortedbut 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 fmtjust fix -p codex-corecargo test -p codex-core -- --test-threads=1cargo test --all-features -- --test-threads=1