Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: A retried Edit from here on a Codex thread removes turns before the chosen message #41822

Closedjuliusmarminge opened this issue 1 comment
juliusmarmingecommented

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server (Codex provider, Edit from here)

What happens

Edit from here on a Codex thread shortens the Codex conversation first, then restores files, and only afterwards records which runs were rolled back. When a later step fails, or the server stops in between, the rollback is retried automatically (up to five attempts, and again after a restart). Each retry works out "remove the newest N turns" from T3's own records, which still show the old history, and applies it to the Codex conversation that is already N turns shorter. So every retry removes N more turns, including turns before the message the user picked.

Steps to reproduce

  1. Create a thread that runs in a worktree, with Codex as the provider. Send at least four prompts that each change a file, and let each finish.
  2. In a terminal in that worktree, hold the Git index lock: touch "$(git rev-parse --git-dir)/index.lock".
  3. Under the last sent message, choose Edit from here, then Revert files too.
  4. Wait until the rollback reports that it failed (it retries for several seconds first).
  5. Remove the lock file, then send a new prompt asking Codex to list the earlier prompts in this conversation.

I have not run this, and I am not certain the index lock is the right way to make the file restore fail on every setup. Any failure after the Codex conversation was shortened has the same effect: a failed file restore, a failed write of the rollback events, or the server stopping at that point.

Expected behavior

The timeline and Codex agree. A retried rollback notices that the Codex conversation already ends at the chosen point and only finishes the remaining steps (files, records).

Actual behavior

T3's timeline still shows every turn, but Codex has lost the last turn and up to four more before it, so it no longer knows about work the user chose to keep. A later successful Edit from here removes even more.

Impact

Data loss (conversation history in the provider)

Version or commit

main @ 6ac68172675d79a7e1d68252c0359a216e128698

Environment

Web and desktop, Codex threads.

Where

  • CheckpointRollbackService.ts: execute calls session.rollbackThread before checkpoints.restore; the rolled_back run events are written further down.
  • CodexAdapterV2.ts: resolveCodexRollbackTurnCount counts turns from T3's stored provider turns.
  • CodexThreadRevert.ts: revertCodexThread counts that many turns back from whatever the Codex conversation holds now, with no check against the intended turn. When the history has fewer turns than the count, it reverts from the oldest turn it found.
  • EffectWorker.ts retries failed effects, and EffectOutbox.ts lists provider-thread.rollback as safe to replay after the process is lost.

Likely fix: record the turn the Codex conversation should end at before the first revert, and skip the revert on a retry when it already ends there.

  1. tanstack-source added labelsbug

  2. I tried to reproduce this on the current build and could not.

    Commit: origin/main 700a4644a4. (1) Real Codex CLI (codex-cli 0.171.0, codex app-server over stdio, paginated history): started a thread, sent 4 prompts (all 4 turns completed), then ran the exact calls T3's Codex rollback makes for Edit from here under the last message (thread/turns/list desc limit 1, thread/revert beforeTurnId=), then ran them again as a retry does, with T3's records unchanged so N is still 1. Codex history: 4 turns before, 3 after attempt 1, 2 after the retry. The retry removed a turn the user chose to keep. Driver: https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/bf7094c9c43ba4f1/codex_double_revert.py. (2) Added a CodexAdapterV2 replay test: T3's providerThreadTurns are [first, second], the target is first, and Codex's newest turn is already native-turn-first. On main the adapter sends thread/revert {beforeTurnId: native-turn-first}, which removes the kept turn, and the test fails. I did not drive the full UI flow (forcing a failure after the provider revert, then asking Codex for earlier prompts). The reporter's index.lock step likely does not make the restore fail, because the restore path builds its index under GIT_INDEX_FILE. So the end-to-end app flow is reasoned from the code order in CheckpointRollbackService.execute (session.rollbackThread, then checkpoints.restore, then the rolled_back events) and the EffectWorker/EffectOutbox retry and replay of provider-thread.rollback.

    Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.

  3. juliusmarminge closed this

Sign in to join this conversation.