Skip to content

fix(builder): fetch server graph before version restore undo baseline - #43

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

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

Conversation

@cursor

@cursor cursor Bot commented Aug 1, 2026

Copy link
Copy Markdown

Bug and impact

Restoring an older workflow version could permanently lose edits that had already persisted to the server. If the user restored before SWR revalidated, the undo baseline was taken from the stale client snapshot instead of the latest server graph.

Root cause

handleRestoreVersion called saveState(previous) with previous = workflow from SWR. The builder disables revalidateOnFocus / revalidateOnReconnect, so after a successful mutation the client snapshot can lag behind the server until mutate completes.

Fix

  • Add resolveLatestPersistedWorkflow() to GET /api/workflows/:id before restore.
  • Use the fresh server graph as the undo baseline and update lastPersistedRef.
  • Fall back to lastPersistedRef / SWR snapshot if the GET fails.

Validation

  • Added regression test: stale SWR + fresh GET → restore → undo PATCH includes server-only node (n2).
  • npm run test:run -- tests/components/builder-canvas.test.tsx — 13/13 passed.
Open in Web View Automation 

Version restore used the stale SWR workflow snapshot for saveState, so a
restore before revalidation could overwrite newer persisted edits and make
undo unable to recover them. Fetch the latest workflow from the API first.

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

vercel Bot commented Aug 1, 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, v0 Aug 1, 2026 11:07am

This branch was successfully deployed

1 active deployment
Preview — e0d211dc Deployed Aug 1, 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