Skip to content

Fix critical sync, git undo, and Work draft lane bugs#342

Closed
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-detection-855d
Closed

Fix critical sync, git undo, and Work draft lane bugs#342
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-detection-855d

Conversation

@cursor
Copy link
Copy Markdown
Contributor

@cursor cursor Bot commented May 23, 2026

Summary

Cron critical-bug audit found three high-severity correctness issues in recent commits (#329 Memory Wipe, #332 History). This PR applies minimal fixes with tests.

Bugs fixed

1. Sync batch failure after Memory Wipe (data stall)

Impact: After desktop upgrades drop unified_memories, any CRDT batch from an older peer (e.g. iOS) that still includes memory changes caused applyChanges to throw on missing table schema, rolling back the entire batch — lanes/sessions/PRs in the same batch never applied.

Root cause: normalizeIncomingCrsqlChange requires a local table with a single PK; dropped tables have no table_info.

Fix: Skip incoming changes for dropped legacy memory tables and any table that no longer exists locally.

2. Git undo corrupts branch after checkout (History)

Impact: History Create branch hereUndo last head change runs git reset --hard on the new branch ref without restoring lanes.branch_ref from switchBranch, moving the wrong branch pointer.

Root cause: git_checkout_branch is recorded as a head-changing op but undo only reverses commit SHA, not branch metadata.

Fix: Exclude git_checkout_branch from undoable head changes (undo skips to the prior reset/cherry-pick/etc.).

3. Work draft sent on wrong lane

Impact: Composer draft text was keyed only by selectedSessionId (always null in draft mode), so switching lanes in the empty-state picker kept the previous lane's message; Send created a session on the wrong lane.

Fix: Store drafts under draft:${laneId} (same key as companion UI state) and restore on lane change.

Validation

  • npx vitest run src/main/services/git/gitOperationsService.test.ts -t "undo|redo|checkout" — pass
  • Added unit tests for checkout skip + legacy memory sync ignore (kvDb sync tests run when cr-sqlite is available in CI)

Not in scope

  • Per-lane git operation mutex (TOCTOU on concurrent undo + reset) — separate hardening
  • CTO/Files tab async race fixes — UX/stale display, lower immediate severity
Open in Web View Automation 

- Skip incoming CRDT changes for dropped unified_memories tables so
  mixed-version sync batches are not rejected after Memory Wipe (#329).
- Exclude git_checkout_branch from undo head changes; reset --hard alone
  corrupts branch refs after History "Create branch here".
- Key Work draft composer text by draft:\${laneId} so lane switches
  restore per-lane drafts instead of leaking text across lanes.

Co-authored-by: Arul Sharma <arul28@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 23, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
ade Ignored Ignored May 23, 2026 12:12am

@arul28
Copy link
Copy Markdown
Owner

arul28 commented May 25, 2026

Consolidated into #356.

@arul28 arul28 closed this May 25, 2026
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.

2 participants