fix: retain first turn messages and restore last user message to composer on revert#2457
fix: retain first turn messages and restore last user message to composer on revert#2457shoaib050326 wants to merge 1 commit intopingdotgg:mainfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
ApprovabilityVerdict: 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.
462c5e6 to
2b75e80
Compare

Summary
Fixes two issues when clicking "Revert to this point" on a single-turn conversation:
Blank screen: The revert turn count was computed as
checkpointTurnCount - 1 = 0, but the checkpoint filter (checkpointTurnCount <= 0) matched no checkpoints (first checkpoint is atcheckpointTurnCount = 1), causing all messages to be removed.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— UseMath.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 forturnCount: 0revert.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.revertedprojection/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 forturnCount=0.Overview
Fixes single-turn thread revert behavior. When handling
thread.reverted, both the server projector and web store now clamp the effectiveturnCountto at least1, ensuring the first checkpoint/turn diff and its related messages/plans/activities aren’t wiped when the UI computesturnCount=0.Improves UX after revert. After a successful revert,
ChatViewreloads 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 withturnCount: 0preserves 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
turnCountto a minimum of 1 when handlingthread.revertedevents in both store.ts and projector.ts, preventing aturnCount <= 0from clearing the first turn's messages, plans, activities, and diff summaries.Macroscope summarized 2b75e80.