# fix\(server\): reverting past Claude compaction preserves earlier rollback · PR \#21599 · pingdotgg/t3code

[View on GitCafe](https://git.cafe/pingdotgg/t3code/pull/21599)

Repository: [pingdotgg/t3code](https://git.cafe/pingdotgg/t3code)

Visibility: public

State: open

Source repository: pingdotgg/t3code

Source branch: claude-10/rollback-adapter

Target branch: claude-10/rollback-schema

Head commit: b2996ac0064c99c4a14453417b69991eec8fdf65

[Discussion and reviews](https://git.cafe/pingdotgg/t3code/pull/21599)

[Commits](https://git.cafe/pingdotgg/t3code/pull/21599/commits?format=markdown)

[Files changed](https://git.cafe/pingdotgg/t3code/pull/21599/diffs?format=markdown)

## Description

---

Reverting to a Claude message hidden by compaction used to save an unusable resume cursor. Forking can recover that message, but Claude rewrites the fork's UUIDs, so replacing the native session alone also loses earlier rollback targets.

Read the instance's resumable history through the existing isolated history worker. If a nonempty chain omits the target, fork the original session at that message and validate the recovered head. Preserve the provider-thread identity and persist retained turns' source sessions using the preceding schema layer. Earlier rollback and native forks continue to address the original UUID in its original session, including after restart and a second compaction. An empty recovered fork or a missing saved source fails before publishing the rollback. Initial active-session empty/error lookups retain their existing fallback.

Stack companion: [#21598](https://github.com/pingdotgg/t3code/pull/21598).

Rebuilt from @elmarbeckmann's [#17430](https://github.com/pingdotgg/t3code/pull/17430), which identified the SDK fork fallback. The replacement keeps earlier-turn rollback instead of discarding it. It adds no client-specific behavior or database migration.

Verification at this head:

- `vp test run` for `ClaudeAdapterV2.test.ts` and `CheckpointRollbackService.test.ts`: **308 pass / 2 fail before the implementation → 310 pass**. Later missing-source and relative-home assertions each failed before their respective fixes and pass with them. Main had 305 cases; the original PoC's four new cases were rebuilt as five shared-fixture behavioral cases. No extra case was added for the review fix.
- The real SDK and production worker read/fork synthetic transcripts. Tests assert exact resumed content, codec roundtrips, runtime recreation, earlier rollback, new turns, a second compaction, native fork and custom-home isolation. The query process is faked. The 19 unchanged rollback-service tests pass; no SQL projection integration was added.
- Server typecheck, changed-file lint/format and `git diff --check` pass. Existing lint warnings remain. One unrelated background-wake timeout in an initial run did not recur on an unchanged full rerun; the reviewer also reran all 310 successfully.
- `vp pack` succeeds. Source, npm worker and npm hidden-command dispatch each recover the exact four-message prefix, fork an earlier source target, isolate an empty instance home and leave the source/parent environment unchanged.
- **Real Claude CLI, loopback mock only:** the original hidden cursor fails before any model request. The recovered fork and new cursor send exactly four retained history messages plus the follow-up to a local mock and complete its synthetic response. The same proof passes with absolute and relative Claude homes. No real account or external model request was used.
- Four full independent review rounds (claude-opus-5-5 and gpt-6-sol). Fixed the missing saved-source failure, made the Electron worker flag explicit, and bounded history worker waits to 30 seconds through the existing error path, and matched the worker cwd to the session so relative Claude homes resolve correctly. Deferred the pre-existing ordinary native-fork home issue, optional map compression and cleanup of unselected SDK forks.

Nonvisual server behavior; screenshots do not apply. Not verified: the full web/server rollback UI, real subscription/model turns, native single-executable artifact, macOS, Windows, iOS, Android or Electron desktop. Historical source transcripts must still exist to revisit their checkpoints; confirmed-missing sources now fail explicitly. A thrown initial lookup retains the compatibility fallback. Unmerged; maintainer review and native/account verification remain.

Implemented with gpt-6.1-sol through Codex in T3 Code; tests by gpt-6-astra, reviews by claude-opus-5-5 and gpt-6-sol.

Current review gate: Macroscope correctness passes, but its approvability check requires **human approval** for persisted session lineage and child-process history operations. CodeRabbit confirmed the worker timeout fixed; Macroscope’s relative-home finding is fixed; current-head correctness and CodeRabbit checks pass, with no unresolved threads. The schema base also has an unresolved web CI failure. This stack is **not ready** until those gates clear.

Final published head: [b2996ac](https://github.com/pingdotgg/t3code/commit/b2996ac0064c99c4a14453417b69991eec8fdf65). All current adapter CI jobs that ran passed; the earlier cancelled fingerprint job is superseded by its successful replacement. Macroscope correctness and CodeRabbit pass, with no unresolved threads. Human approvability and the schema base’s web CI gate still block stack readiness. The optional request to reject *thrown* initial saved-source lookups was declined: a worker error does not prove the source is absent, and the explicit compatibility fallback is retained; confirmed empty saved sources already fail.

