fix(server): reject checkpoint reverts before mutating the workspace #9069
Closeddlowzzxx(GitHub profile, opens in a new tab)wants to merge 2 commits into
main fromrefs/pull/9069/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/server/src/orchestration/Layers/CheckpointReactor.test.ts lines 1137 to 1143OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1085,0 +1123,21 @@1123+ harness.engine.dispatch({1124+ type: "thread.turn.diff.complete",1125+ commandId: CommandId.make("cmd-diff-rejected-2"),1126+ threadId: ThreadId.make("thread-1"),1127+ turnId: asTurnId("turn-rejected-2"),1128+ completedAt: createdAt,1129+ checkpointRef: checkpointRefForThreadTurn(ThreadId.make("thread-1"), 2),1130+ status: "ready",1131+ files: [],1132+ checkpointTurnCount: 2,1133+ createdAt,1134+ }),1135+ );1136+1137+ harness.provider.rollbackConversation.mockImplementation(1138+ () =>1139+ Effect.fail(1140+ new Error(1141+ "Provider adapter request failed (codex) for thread/rollback: paginated threads do not support thread/rollback",1142+ ),1143+ ) as unknown as Effect.Effect<void>,
- apps/server/src/orchestration/Layers/CheckpointReactor.ts line 769Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -758 +769,21 @@769+ threadId: event.payload.threadId,770+ turnCount: event.payload.turnCount,771+ detail: `Filesystem checkpoint is unavailable for turn ${event.payload.turnCount}.`,772+ createdAt: now,773+ }).pipe(Effect.catch(() => Effect.void));774+ return;775+ }776+777+ // Roll the provider conversation back before restoring files: a provider778+ // that rejects the rollback (Codex refuses thread/rollback for paginated779+ // threads) must leave both the conversation and the workspace untouched780+ // instead of restoring files the conversation never rewound.781+ const rolledBackTurns = Math.max(0, currentTurnCount - event.payload.turnCount);782+ if (rolledBackTurns > 0) {783+ yield* providerService.rollbackConversation({784+ threadId: sessionRuntime.value.threadId,785+ numTurns: rolledBackTurns,786+ });787+ }788+758789 const restored = yield* checkpointStore.restoreCheckpoint({
- apps/server/src/orchestration/Layers/CheckpointReactor.ts line 768Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -757,0 +768,21 @@768+ yield* appendRevertFailureActivity({769+ threadId: event.payload.threadId,770+ turnCount: event.payload.turnCount,771+ detail: `Filesystem checkpoint is unavailable for turn ${event.payload.turnCount}.`,772+ createdAt: now,773+ }).pipe(Effect.catch(() => Effect.void));774+ return;775+ }776+777+ // Roll the provider conversation back before restoring files: a provider778+ // that rejects the rollback (Codex refuses thread/rollback for paginated779+ // threads) must leave both the conversation and the workspace untouched780+ // instead of restoring files the conversation never rewound.781+ const rolledBackTurns = Math.max(0, currentTurnCount - event.payload.turnCount);782+ if (rolledBackTurns > 0) {783+ yield* providerService.rollbackConversation({784+ threadId: sessionRuntime.value.threadId,785+ numTurns: rolledBackTurns,786+ });787+ }788+
- @@ -776,7 +787,17 @@776787777788 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* providerService791+ .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 their802+ // original state and retrying the revert starts from a clean slate.803+ yield* checkpointStore
juliusmarminge closed this
Sign in to join this conversation.


macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed