Skip to content

fix(sql-editor): stop splitting routine bodies on bare END - #251

Merged
huyplb merged 2 commits into
mainfrom
cursor/critical-bug-management-0270
Aug 14, 2026
Merged

fix(sql-editor): stop splitting routine bodies on bare END#251
huyplb merged 2 commits into
mainfrom
cursor/critical-bug-management-0270

Conversation

@cursor

@cursor cursor Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Audit of recent SQL editor commits (#245 safe-mode SELECT joins, #246 routine DDL one-cell, #247 grid copy) found one high-confidence critical correctness bug in #246.

Routine DDL nesting treated every unqualified END as a block closer. Bodies that used end as an alias/column/variable (AS end, SELECT end, DECLARE end INT) closed BEGIN early, so later DELETE/UPDATE lines became separate top-level cells and could run against the live DB on Run All.

Fix

  • Track BEGIN / CASE / BEGIN TRY / BEGIN CATCH on a stack
  • Pop BEGIN only for statement-leading END (not mid-expression identifiers)
  • Close SQL Server TRY/CATCH frames on END TRY / END CATCH so following statements are not swallowed

Test plan

  • npx vitest run packages/sql/src/modules/sql-splitter.test.ts (96 passed)
  • New regressions: AS end / DECLARE end / END AS CASE expr / BEGIN TRY…CATCH

Audit notes (no other criticals)

Open in Web View Automation 

Note

High Risk
Routine splitter bugs could split destructive DML out of procedure bodies and execute it as top-level SQL on Run All; hydrate mis-picks could emit wrong DDL on weave revert paths.

Overview
Fixes critical SQL editor splitting where routine DDL nesting treated every unqualified END as closing BEGIN. Aliases and columns named end (AS end, SELECT end, DECLARE end INT) could end the routine cell early so later DELETE/UPDATE became separate top-level cells and could run on Run All.

The splitter now tracks BEGIN / CASE / BEGIN TRY / BEGIN CATCH on a stack and only closes BEGIN on statement-leading END, not mid-expression identifiers. SQL Server END TRY / END CATCH close the matching frames. New tests cover those cases plus BEGIN TRY…CATCH batches.

Separately, pickOwnerContainer picks the owner-level container from a same-owner object group using the same ordered type:OWNER keys as blueprint assembly. hydrateTableSchemas uses it instead of the first container-typed object, so a table-owned trigger that appears before table:CUSTOMER is not mistaken for the table (wrong DDL like ALTER TABLE trg_audit vs customer). pickOwnerContainer and isLokeeContainerType are re-exported from the package entry.

Reviewed by Cursor Bugbot for commit 671477e. Bugbot is set up for automated code reviews on this repo. Configure here.

cursoragent and others added 2 commits August 13, 2026 11:13
Routine DDL nesting treated every END as a block closer, so aliases like
AS end or SELECT end closed BEGIN early and turned later DELETE/UPDATE
lines into top-level cells. Track BEGIN/CASE/TRY/CATCH on a stack and
only close BEGIN at statement-leading END.

Co-authored-by: huy.phan9 <huyplb@users.noreply.github.com>
objectsAtVersion loads by hash order, so a table-owned trigger can appear
before table:OWNER in the same owner group. Both are container types;
hydrate used find(isLokeeContainerType) and could emit ALTER TABLE for the
trigger name during revert. Pick the same ordered type:OWNER key as the
blueprint assembler.

Co-authored-by: huy.phan9 <huyplb@users.noreply.github.com>
@huyplb
huyplb marked this pull request as ready for review August 14, 2026 00:22
@huyplb
huyplb merged commit 0a841ff into main Aug 14, 2026
10 checks passed
@huyplb
huyplb deleted the cursor/critical-bug-management-0270 branch August 14, 2026 00:22
@cursor

cursor Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_104530e7-9c23-4666-9deb-ddd6a34e6fa9)

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