Skip to content

fix(builder): prevent undo from reverting multiple edits at once - #40

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-4548
Draft

cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-4548

Conversation

@cursor

@cursor cursor Bot commented Jul 28, 2026

Copy link
Copy Markdown

Bug and impact

When users made two or more graph edits in quick succession (before SWR revalidated), both mutations saved the same stale workflow snapshot to the undo stack. A single undo then PATCHed the server back two or more steps, causing unexpected data loss.

Root cause

Graph mutation handlers captured previous = workflow from SWR at callback start. While the server applied each edit sequentially, SWR often still held the pre-edit graph when the second mutation completed, pushing duplicate snapshots onto HistoryManager.

lastPersistedRef existed for undo transitions but was not used when recording history.

Fix

  • saveToHistory() now records lastPersistedRef (last known persisted graph) instead of caller-supplied stale SWR data.
  • mutateWorkflow() awaits SWR revalidation and refreshes lastPersistedRef from the server after each successful mutation.
  • HistoryManager.saveState skips duplicate consecutive snapshots as a safety net.

Validation

  • npm run test:run — 236 tests passing
  • Added regression test for duplicate snapshot deduplication in history-manager.test.ts
  • Updated builder canvas test for async mutateWorkflow behavior
Open in Web View Automation 

Fast successive graph mutations saved the same pre-change workflow into
the undo stack because handlers captured stale SWR data. One undo then
reverted multiple server-side edits at once.

Use lastPersistedRef for history snapshots, refresh it after each
mutation via SWR mutate, and skip duplicate consecutive snapshots.

Co-authored-by: esadrianno <esadrianno@gmail.com>
@vercel

vercel Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
v0-agent-kit Ready Ready Preview, Comment, Open in v0 Jul 28, 2026 11:08am

This branch was successfully deployed

1 active deployment
Preview — 8fa3929e Deployed Jul 28, 2026 by vercel[bot]
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