What Changed#
Exclude turns from already rolled-back runs when preparing a provider rollback. The audit history stays intact, and the existing rollback test now covers a previous rewind and both rollback targets.
Targets the orchestration V2 branch from #2829.
Fixes #12679.
Why#
In a Codex legacy-history thread with turns A, B, C, rewinding to B and then A makes Codex discard A too: T3 still shows one completed turn, but the provider has none. The second rollback incorrectly counts C again even though it was already removed.
Pi hits the same stale-history problem after rewinding to A, adding D, and rewinding to A again: it tries to fork at an already-removed entry. Filtering those turns makes both providers use the current conversation.
Validation#
- Regression fails without the fix; all 13 tests in
CheckpointRollbackService.test.ts pass with it.
- Server typecheck and changed-file lint/format checks pass.
- Retested in real workspaces with Codex CLI 0.155.1 and GPT-6 Astra (
gpt-6-astra). Legacy-history baseline: 3 → 2 → 0 native turns. Fixed: 3 → 2 → 1 → 2 → 1, with matching files and retained turn IDs. All three fixed rollback receipts succeed on the first attempt.
- Pi 0.86.0 independently reproduced the stale-entry failure and passed with the fix.
The isolated test launcher explicitly requests the supported thread/start.historyMode: "legacy"; all other requests pass unchanged to Codex 0.155.1. Default new sessions use paginated history and hit a separate V2 adapter rejection on the first rewind, before this repeated-rollback bug can be exercised.
Reproduction#
New recording: Codex CLI 0.155.1, GPT-6 Astra, legacy history, original rollback implementation. After the second rewind, T3 retains A while the native provider history is empty.

MP4 recording
Checklist#
Built and verified with GPT-6 Astra in Codex CLI 0.155.1.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes