mirror of
https://github.com/openai/codex.git
synced 2026-04-24 14:45:27 +00:00
## 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: https://github.com/openai/codex/issues/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` --------- Co-authored-by: Skylar Graika <sgraika127@gmail.com> Co-authored-by: jif-oai <jif@openai.com> Co-authored-by: Eric Traut <etraut@openai.com>
16 lines
845 B
Rust
16 lines
845 B
Rust
/// Helpers for identifying model-visible "session prefix" messages.
|
|
///
|
|
/// A session prefix is a user-role message that carries configuration or state needed by
|
|
/// follow-up turns (e.g. `<environment_context>`, `<turn_aborted>`). These items are persisted in
|
|
/// history so the model can see them, but they are not user intent and must not create user-turn
|
|
/// boundaries.
|
|
pub(crate) const ENVIRONMENT_CONTEXT_OPEN_TAG: &str = "<environment_context>";
|
|
pub(crate) const TURN_ABORTED_OPEN_TAG: &str = "<turn_aborted>";
|
|
|
|
/// Returns true if `text` starts with a session prefix marker (case-insensitive).
|
|
pub(crate) fn is_session_prefix(text: &str) -> bool {
|
|
let trimmed = text.trim_start();
|
|
let lowered = trimmed.to_ascii_lowercase();
|
|
lowered.starts_with(ENVIRONMENT_CONTEXT_OPEN_TAG) || lowered.starts_with(TURN_ABORTED_OPEN_TAG)
|
|
}
|