Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): reject checkpoint reverts before mutating the workspace #9069

Closeddlowzzxx(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/9069/headopened View on GitHub

Fixes #8958.

Problem

CheckpointReactor.handleRevertRequested restored the filesystem checkpoint before calling providerService.rollbackConversation. When the provider rejects the conversation rollback — Codex refuses thread/rollback for paginated threads with paginated threads do not support thread/rollback — the operation stopped after the file change. The workspace moved back to the target point while the Codex conversation stayed ahead of it, and the user gets no signal that the two have diverged.

Change

The revert handler now fails before mutating anything:

  1. Pre-validate the checkpoint store with the non-mutating hasCheckpointRef for turns > 0 (turn 0 keeps its fallbackToHead semantics and is excluded), so a read-model ref that outlived the checkpoint store fails gracefully before anything changes.
  2. Roll the provider conversation back first. A provider rejection (e.g. the paginated-thread refusal above) now surfaces as the existing checkpoint.revert.failed activity while both the workspace and the conversation are untouched.
  3. Restore the filesystem checkpoint last, followed by the unchanged workspace-index refresh.

Tests

  • New: does not restore the workspace when the provider rejects the conversation rollback — with a rejecting rollbackConversation, the revert records checkpoint.revert.failed, the provider rollback is attempted exactly once, and the workspace file is byte-identical to its pre-revert content.
  • Existing revert tests continue to cover the success path and the claude/codex variants.

Verification: focused suite apps/server/src/orchestration/Layers/CheckpointReactor.test.ts — my new test passes; the pre-existing executes provider revert... test asserts v2 byte equality and fails identically on pristine main on a Windows checkout with core.autocrlf=true (v2 ), so that one failure is a local line-ending artifact, not a behavior change. oxfmt --check clean on both files.


Note

Medium Risk Changes the checkpoint revert failure path and workspace restore semantics; mistakes could leave workspace and conversation diverged or lose uncommitted edits around revert attempts.

Overview Fixes checkpoint reverts that could leave the workspace reverted while the provider conversation still advanced when rollbackConversation fails (e.g. Codex paginated threads rejecting thread/rollback).

CheckpointReactor now captures a per-thread revert-base git ref (checkpointRefForRevertBase) immediately before applying a revert. If provider rollback fails after the target checkpoint was restored, it restores that snapshot, refreshes the workspace index, records checkpoint.revert.failed with the provider error, and exits without completing the revert. On success, the temporary revert-base ref is deleted along with stale turn checkpoints.

Adds a reactor test that mocks a rejecting rollbackConversation and asserts the workspace content matches the pre-revert state (with CRLF-normalized comparison).

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ef92e38778727d37207604f6d83be5af611a5974. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Capture pre-revert checkpoint before attempting CheckpointReactor conversation rollback

  • On thread.checkpoint.revert, the reactor now snapshots the working tree via a new checkpointRefForRevertBase ref before calling rollbackConversation.
  • If the provider rollback fails with ProviderServiceError, the reactor restores that snapshot (no fallback to HEAD), refreshes workspace entries, appends a checkpoint.revert.failed activity, and returns early.
  • On successful revert the temporary revert-base ref is included in stale checkpoint cleanup.
  • Behavioral Change: revert no longer leaves a partially mutated workspace when rollbackConversation fails; callers see a checkpoint.revert.failed activity and the pre-revert file contents.
Macroscope summarized ef92e38.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 7f7434a1d0816a2489c7f1011ced7bb96b7e3066. Configure [here](https://www.cursor.com/dashboard/bugbot).
    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Would Approve

      Macroscope's review found this PR approvable — This is a focused checkpoint-revert bug fix with localized production changes and targeted regression coverage; normal successful reverts retain their existing outcome. An unresolved medium-severity finding remains about preserving pre-existing staged edits during compensation and should be considered separately.

      Not approved because:

      • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. @@ -776,7 +787,17 @@
      776787
      777788 const rolledBackTurns = Math.max(0, currentTurnCount - event.payload.turnCount);
      778789 if (rolledBackTurns > 0) {
      779- yield* providerService.rollbackConversation({
      780- threadId: sessionRuntime.value.threadId,
      781- numTurns: rolledBackTurns,
      782- });
      790+ const rollbackFailure = yield* providerService
      791+ .rollbackConversation({
      792+ threadId: sessionRuntime.value.threadId,
      793+ numTurns: rolledBackTurns,
      794+ })
      795+ .pipe(
      796+ Effect.map(() => Option.none<ProviderServiceError>()),
      797+ Effect.catch((error) => Effect.succeed(Option.some(error))),
      798+ );
      799+ if (Option.isSome(rollbackFailure)) {
      800+ // Compensate: the workspace moved but the conversation did not.
      801+ // Restore the pre-revert snapshot so both sides stay in their
      802+ // original state and retrying the revert starts from a clean slate.
      803+ yield* checkpointStore
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium Layers/CheckpointReactor.ts:803

      When provider rollback fails, the compensation restores file contents but leaves any pre-existing staged edits unstaged, so it does not restore the claimed exact pre-revert state. captureCheckpoint stores only a tree commit, while restoreCheckpoint resets the index to HEAD after restoring with --staged --worktree; preserve the original index state as part of the revert-base snapshot and restore it here.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/server/src/orchestration/Layers/CheckpointReactor.ts around line 803:
      
      When provider rollback fails, the compensation restores file contents but leaves any pre-existing staged edits unstaged, so it does not restore the claimed exact pre-revert state. `captureCheckpoint` stores only a tree commit, while `restoreCheckpoint` resets the index to `HEAD` after restoring with `--staged --worktree`; preserve the original index state as part of the revert-base snapshot and restore it here.
    5. Pushed ef92e3877 addressing both findings:

      • Compensating recovery (Macroscope high, Cursor medium): the handler now captures the pre-revert worktree as a per-thread revert-base checkpoint before touching anything. If rollbackConversation fails after the file restore, the revert-base snapshot is restored and the workspace index refreshed, so both the workspace and the conversation end in their original state and a retry starts from a clean slate. The revert-base ref is deleted on success and overwritten (git update-ref) on each attempt, so no refs accumulate. If the restore itself fails, nothing else has run yet — no divergence.
      • Test error type (Macroscope): the regression test now fails with the real ProviderAdapterRequestError and the harness mock is typed on the ProviderServiceError channel — no cast.
      • The hasCheckpointRef pre-check from the previous commit is gone; the revert-base capture supersedes it.

      Focused suite: 16/17 pass; the one failure (executes provider revert...) is the pre-existing core.autocrlf byte-equality artifact that also fails on pristine main on Windows checkouts.

    6. On the staged-edits finding: that is a property of the underlying store rather than of this compensation — captureCheckpoint records a tree commit, so restoreCheckpoint never reconstructs the staged/unstaged split, and the ordinary successful revert has had the same behavior all along. The compensation is therefore no worse than the feature's normal outcome. If index fidelity matters, that is a store-level enhancement to captureCheckpoint/restoreCheckpoint, which I kept out of this fix to stay scoped — happy to take it up separately if wanted.

    7. Note: GPT-6 on behalf of shivam (@shivamhwp).

      The compensating restore can fail while leaving the workspace at the selected checkpoint. For example, if .git/index.lock appears during the provider request and Codex rejects rollback, recovery throws, but Effect.catch(() => Effect.void) discards that error. The activity then reports only the Codex rejection, without telling the user that their files are still reverted. A false restore result is also ignored.

      Please check the recovery result and report an explicit workspace-recovery failure alongside the provider error. Preserve the recovery snapshot until that failure is resolved; a retry currently overwrites the same revert-base ref with the already-reverted workspace. The new regression should include distinct uncommitted and untracked files plus a failed recovery, and wait on the reactor drain or receipt instead of polling.

    8. Superseded by #11338, which makes Codex paginated rewind succeed via thread/revert instead of failing closed before workspace mutation. Closing this pre-validate/reject path for #8958 as wash leftover hygiene — reopen if the fail-before-mutate guard is still wanted independently.

    9. juliusmarminge closed this

Sign in to join this conversation.