Skip to content

Fix CRR alter leak and restore binding on failed remote switch#363

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

Fix CRR alter leak and restore binding on failed remote switch#363
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-detection-1798

Conversation

@cursor
Copy link
Copy Markdown
Contributor

@cursor cursor Bot commented May 26, 2026

Bug and impact

CRR alter session leak (AdeDb.run)
When a runtime ALTER TABLE on a CRR table fails (e.g. two processes race safeAlter and the loser hits “duplicate column”), AdeDb.run() rethrew without calling crsql_commit_alter, leaving the table stuck mid-alter. Subsequent writes to that table (e.g. automation_runs) could fail until manual DB repair.

Failed remote project switch (appStore)
switchRemoteProject cleared projectBinding before open and did not restore it on failure. The UI could show a remote project with a null binding, diverging from preload/main and risking wrong-target behavior after the transition ended.

Root cause

  • Migrate-time alters already commit on failure (makeMigrateDb); the post-open AdeDb.run wrapper did not.
  • Remote switch error handling only cleared transition state, not the previous binding.

Fix

  • Mirror migrate behavior: crsql_commit_alter in the catch path of AdeDb.run() before rethrowing.
  • Stash and restore previousBinding when switchRemoteProject fails for the active generation.

Validation

  • npx vitest run src/renderer/state/appStore.test.ts -t "restores projectBinding when switchRemoteProject fails"
  • CRR alter regression test added in kvDb.test.ts (runs when crsqlite is available on macOS CI)
Open in Web View Automation 

- Commit crsql alter sessions in AdeDb.run() when ALTER fails, matching
  migrate-time behavior so duplicate-column races cannot leave CRR tables
  stuck mid-alter and block automation_runs writes.
- Restore previous projectBinding in appStore when switchRemoteProject
  fails so renderer state stays aligned with the active remote project.

Regression tests in kvDb.test.ts (CRR) and appStore.test.ts.

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

vercel Bot commented May 26, 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 26, 2026 4:14am

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