Skip to content

feat: revert a thread to just after a message - #116

Merged
akiva-quickvett merged 7 commits into
akiva/feature-tipfrom
akiva/revert-to-message
Nov 26, 2026
Merged

akiva-quickvett merged 7 commits into
akiva/feature-tipfrom
akiva/revert-to-message

Conversation

@akiva-quickvett

@akiva-quickvett akiva-quickvett commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Adds Revert to here beneath a sent message. It keeps that message and its reply and drops every later turn from the chat and from the agent's context: an automation's wake, a prompt that sent the agent off course, or a compaction that came too early. Unlike Edit from here, the prompt stays put and nothing returns to the composer. The existing confirm dialog asks whether to revert files too.

Problem

The only way back was Edit from here, which rewinds to before a prompt and moves it into the composer. To drop a cron turn or a stray message after a good exchange, you had to resend the good prompt. Reverting a Claude thread to before a /compact also kept the compaction summary in context: Claude's resume re-applies a compaction written anywhere later in the transcript, even past resumeSessionAt.

Fix

  • Web: deriveRevertTurnCountByUserMessageId returns edit and keep targets. keep is the prompt's own run checkpoint, offered only when a later visible run exists and the provider can roll back to it. The row shows a history-icon button, and the dialog and rewindToMessage take a mode, so keep leaves the composer alone.
  • Server (ClaudeAdapterV2.rollbackThread): when the transcript has a compact_boundary after the target cursor, fork the session up to that cursor (SDK forkSession) and point the provider thread at the fork. The rollback returns the kept turns with their cursors moved to the fork's uuids, read from the forkedFrom the SDK writes on each copied message. CheckpointRollbackService now writes any turns an adapter returns as provider-turn.updated (every adapter returned [] before), so later rollbacks and forks resolve inside the fork with no new stored field.
  • Rewinding to a compaction run itself (Edit from here on the prompt after /compact) keeps that compaction: no fork, as before.
  • A fork missing a kept cursor fails the rollback, which leaves the thread as it was. An unreadable transcript is logged, and the rollback takes the old path.

Evidence

  • Haiku, live, on a dev server: APPLE, then BANANA, then /compact. Revert to here on BANANA forked the session, the run became rolled_back, and Haiku quoted both messages and said its context held no compaction summary (before the fix it said it was reading a summary). A second revert, to APPLE, made no new fork, resumed at the aliased cursor, and Haiku listed only APPLE.
  • An earlier run without compaction: APPLE, then BANANA, Revert to here on APPLE, and Haiku listed only APPLE.
  • Second live Haiku run after review fixes: APPLE, BANANA, /compact, CHERRY.
    • Edit from here on CHERRY: no fork, and Haiku said the summary was in its context and listed APPLE and BANANA.
    • Revert to here on BANANA: a fork, and both kept turns re-pointed into it.
    • Revert to here on APPLE: no new fork, and Haiku said no summary and listed APPLE.
  • A real forkSession cut after an existing compaction copied every earlier line with forkedFrom on each (checked during review).
  • ClaudeAdapterV2.test.ts: the compaction case fails on the old adapter, and the compaction-target case fails on the first version of this fix. CheckpointRollbackService.test.ts: the moved-turns case fails on main's service. The session-logic.test.ts keep targets cover wake runs, unavailable checkpoints and steers.
  • vp run check:changed passes.

Surfaces

  • Web and desktop. Mobile has no Edit from here today, so it has no Revert to here either.
  • Providers: the button appears wherever conversation rollback is supported. Only Claude needed the compaction fork.
  • Backend change, so it also goes to akiva/server-tip.

Upstream

A candidate. It is branched from main and has no tip dependencies.

Review

Tier 1 (5 points, R1). The general reviewer raised two highs and two meds. All are fixed:

  • High: a code revert could strand forked threads. The first version stored a cursor alias map. Kept turns are now rewritten in the rollback's own events, so nothing new is stored. That keeps it R1.
  • High: Edit from here after a /compact dropped the compaction. The fork is skipped when the target is the compaction run. A test covers it.
  • Med: a cursor missing from the fork failed silently. The rollback now fails instead. A real fork was checked for forkedFrom on every line.
  • Med: an unreadable transcript was swallowed. It is now logged.

Lows left as they are: every Claude rollback with a cursor reads its transcript file(s) to look for a compaction. The old session file stays on disk after a fork.

Fixed after the last review: everything above. No re-check was due (R1, under 8 points, and each fix has a test that fails without it).

Deferred decisions

  • Before/after images: the fork's assets branch that earlier PRs used is gone, so the screenshots (row with both buttons, the dialog, the reverted thread) are not embedded. Recreate the branch, or say where they should go.
  • The Claude fork runs only when a compaction follows the target. Forking on every rollback would be simpler, but it would change the proven path for ordinary reverts.

🤖 Generated with Claude Code

akiva-quickvett and others added 7 commits November 25, 2026 12:40
Edit from here rewinds to before a prompt and returns it to the composer.
Revert to here keeps the prompt and its reply and drops every later run
(an automation wake, an unwanted compaction, a stray prompt) from the
thread and the provider's history, using the same checkpoint rollback.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…summary

Claude's resume re-applies a compaction written later in the transcript,
even past resumeSessionAt, so a rollback to before /compact kept the
summary in context. When the transcript compacts after the target, fork
the session up to it and alias earlier turn cursors to the fork's uuids.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…liasing them

Review findings on the compaction fork:
- the rollback returns the kept turns with their cursors moved to the
  fork, and CheckpointRollbackService writes them, so no new stored field
  is needed and a code revert cannot strand a forked thread
- rewinding to a compaction run keeps that compaction (no fork)
- a fork missing a kept cursor fails the rollback instead of dangling
- an unreadable transcript is logged

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@akiva-quickvett
akiva-quickvett marked this pull request as ready for review November 26, 2026 00:47
@akiva-quickvett
akiva-quickvett merged commit 2a2367d into akiva/feature-tip Nov 26, 2026
akiva-quickvett added a commit that referenced this pull request Nov 26, 2026
…r-tip

Merged onto the upstream-synced tip. Upstream pingdotgg#41276 dropped
providerTurns from thread snapshots, so rollbackThread now returns
ProviderAdapterV2RollbackThreadResult, which carries the moved turns;
the compaction fork drops forkSession's dir (upstream pingdotgg#22836).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
akiva-quickvett added a commit that referenced this pull request Nov 26, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant