Skip to content

fix: retain first turn messages and restore last user message to composer on revert#2457

Open
shoaib050326 wants to merge 1 commit intopingdotgg:mainfrom
shoaib050326:fix/revert-loses-input-text-2268
Open

fix: retain first turn messages and restore last user message to composer on revert#2457
shoaib050326 wants to merge 1 commit intopingdotgg:mainfrom
shoaib050326:fix/revert-loses-input-text-2268

Conversation

@shoaib050326
Copy link
Copy Markdown

@shoaib050326 shoaib050326 commented May 2, 2026

Summary

Fixes two issues when clicking "Revert to this point" on a single-turn conversation:

  1. Blank screen: The revert turn count was computed as checkpointTurnCount - 1 = 0, but the checkpoint filter (checkpointTurnCount <= 0) matched no checkpoints (first checkpoint is at checkpointTurnCount = 1), causing all messages to be removed.

  2. Lost input text: After revert completed, the composer input was not populated with the last retained user message text.

Changes

  • apps/web/src/store.ts — Use Math.max(1, turnCount) as the effective filter threshold in the "thread.reverted" reducer so the first checkpoint is always retained.
  • apps/server/src/orchestration/projector.ts — Same fix in the server-side projector for consistency.
  • apps/web/src/components/ChatView.tsx — After revert completes, restore the last retained user message text into the composer input.
  • apps/web/src/store.test.ts — Regression test for turnCount: 0 revert.

Verification

  • apps/web: typecheck ✓, 90 test files / 926 tests pass ✓
  • apps/server: 3 test files / 41 orchestration tests pass ✓

Closes #2268


Note

Medium Risk
Touches both server and client thread.reverted projection/reducer logic, which can affect message retention during revert (potentially user-visible data loss if incorrect). Scope is small and covered by a new regression test for turnCount=0.

Overview
Fixes single-turn thread revert behavior. When handling thread.reverted, both the server projector and web store now clamp the effective turnCount to at least 1, ensuring the first checkpoint/turn diff and its related messages/plans/activities aren’t wiped when the UI computes turnCount=0.

Improves UX after revert. After a successful revert, ChatView reloads the updated thread from the store and, if the composer is empty, restores the last retained user message text into the composer draft. A regression test was added to verify that reverting with turnCount: 0 preserves first-turn state.

Reviewed by Cursor Bugbot for commit 2b75e80. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fix thread revert to retain first-turn messages and restore last user message to composer

  • Clamps turnCount to a minimum of 1 when handling thread.reverted events in both store.ts and projector.ts, preventing a turnCount <= 0 from clearing the first turn's messages, plans, activities, and diff summaries.
  • After reverting to a checkpoint in ChatView.tsx, if the composer prompt is empty, it is auto-filled with the text of the last user message from the updated thread.

Macroscope summarized 2b75e80.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 2, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9e9e4e7a-489c-4aaa-adc5-88b9285a5598

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels May 2, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 462c5e65d2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/web/src/store.ts
Comment thread apps/web/src/components/ChatView.tsx
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes 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.

Reviewed by Cursor Bugbot for commit 462c5e6. Configure here.

Comment thread apps/web/src/components/ChatView.tsx
Comment thread apps/server/src/orchestration/projector.ts
Comment thread apps/web/src/components/ChatView.tsx
Comment thread apps/web/src/components/ChatView.tsx
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented May 2, 2026

Approvability

Verdict: Needs human review

1 blocking correctness issue found. Unresolved review comments identify potential bugs: a race condition where the composer reads stale state after revert, and a semantic change to turnCount=0 handling that may cause client/server divergence. These substantive issues warrant human review.

You can customize Macroscope's approvability policy. Learn more.

…oser on revert

When clicking 'Revert to this point' on a single-turn conversation,
the revert turn count was computed as checkpointTurnCount - 1 = 0,
causing the checkpoint filter (checkpointTurnCount <= 0) to match
nothing. This resulted in all messages being removed (blank screen)
and the user's input text being lost.

Fix checkpoint filtering to use Math.max(1, turnCount) so the first
checkpoint is always retained, and restore the last retained user
message text into the composer input after revert completes.
@shoaib050326 shoaib050326 force-pushed the fix/revert-loses-input-text-2268 branch from 462c5e6 to 2b75e80 Compare May 2, 2026 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Revert to this point completely loses the text in the input

1 participant