Skip to content

feat(sqlite): transaction state per connection - #941

Merged
EVWorth merged 2 commits into
mainfrom
claude/hopeful-bardeen-1k4d1h
Oct 31, 2026
Merged

EVWorth merged 2 commits into
mainfrom
claude/hopeful-bardeen-1k4d1h

Conversation

@EVWorth

@EVWorth EVWorth commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Done by the implementer-frontend lane, with a small backend change.

Closes #935

Design

All tabs on a SQLite file share one connection, so a BEGIN in one tab is open in every tab on that file. For SQLite, the transaction state belongs to the connection. MySQL keeps one state per tab, as before.

Changes

  • Backend: a failed SQLite run now reports QueryError.transaction, read from !is_autocommit() after the failure. MySQL got the same in fix: timeout and failure lose run results/state #917. bindings.ts is unchanged because the field already existed.
  • Store:
    • transactionStore gains openConnections, setConnectionOpen and forgetConnection.
    • It also gains hasOpenTransactionForTab(tab), which is true when either the tab or its SQLite connection has a transaction open.
    • resultStore sets the connection flag from every SQLite run, including from the error after a failure.
  • UI:
    • The TX badge (new TransactionBadge.tsx) shows on every tab bound to the file. Its tooltip says the transaction is on the file's connection.
    • The toolbar's "Transaction open" bar, with Commit and Rollback, shows on those tabs too. The buttons run on the shared connection.
  • Prompts:
    • Closing or re-pointing a tab asks first only when no other tab stays bound to the file. This also covers Close Others and Close to the Right.
    • The wording names the file: "…is the last tab on app.db, and a transaction is open on the file's connection."
  • Rollback when the last tab goes: closing a tab doesn't close the SQLite connection. So once the last tab bound to the file is gone, a watcher (sqlite-transactions.ts, modelled on server-sessions.ts) runs ROLLBACK. That makes "Roll back and close" do what it says. If the rollback fails, the flag stays.
  • Disconnect: closing the file clears the flag without a prompt, as a MySQL disconnect does.
  • Mock:
    • The SQLite mock tracks BEGIN, COMMIT/END and ROLLBACK per connection; ROLLBACK TO keeps the transaction open.
    • Like real SQLite, it refuses a nested BEGIN, and refuses a commit or rollback when no transaction is open.

Tests

  • Rust: a_failure_says_whether_a_transaction_is_still_open (mas-sqlite) and a_failure_reports_whether_the_connection_is_in_a_transaction (sqlpilot). Both fail without the fix.
  • Frontend:
    • New test files: transactionStore.test.ts, transaction-prompt.test.ts, sqlite-transactions.test.ts, and EditorTabs.sqlite.test.tsx (runs against the real stores).
    • Extended: the editorStore, resultStore, sqliteStore, QueryToolbar, RollbackSwitchDialog, mock and tauri-api tests.
    • Cases covered:
      • BEGIN in one tab shows the badge on both tabs on the file, and COMMIT from the other clears both;
      • closing or re-pointing one of two tabs doesn't prompt, and doing it to the last tab does, with confirm running ROLLBACK;
      • closing the file clears the flag;
      • MySQL state stays per tab.
    • With the change reverse-applied, the 27 new tests fail.
  • Gates:
    • npm run test:unit: 3784 passed.
    • Browser tests for QueryToolbar, MainPanel and AppLayout pass.
    • Lint shows 0 errors and no new warnings; type-check and dprint are clean.
    • cargo fmt, clippy -D warnings, and cargo test -p mas-sqlite and -p sqlpilot are clean.

Generated by Claude Code

A failed SQLite run now says whether the file's connection is still
inside a transaction, read with is_autocommit() after the failure, as
#917 does for a MySQL session. A failing statement does not end a
transaction, so a script that ran BEGIN and then failed leaves one open.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
A SQLite file has one connection, shared by every tab on it, so a BEGIN
in one tab is open in all of them. The transaction store now keeps that
state per connection beside the per-tab MySQL state, and resultStore
records what each SQLite run reports, failures included.

Every tab bound to the file shows the TX badge, and the toolbar offers
Commit and Rollback on it. Closing or re-pointing a tab asks only when it
is the last tab on the file; confirming rolls the transaction back.
Closing the file forgets it. The mock now tracks BEGIN, COMMIT and
ROLLBACK per SQLite connection. MySQL tabs are unchanged.

Closes #935

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
@EVWorth
EVWorth merged commit f9fe2d5 into main Oct 31, 2026
12 checks passed
@EVWorth
EVWorth deleted the claude/hopeful-bardeen-1k4d1h branch October 31, 2026 12:20
EVWorth pushed a commit that referenced this pull request Oct 31, 2026
A failed run on an editor session reports whether the session is still
in a transaction (#917), and CommandError carries it since #941. The
failure path still inferred the state from the statements that ran,
which is wrong when the failing statement changed it itself (DDL's
implicit commit, a deadlock's rollback) or when a transaction was
opened where the SQL does not show it. Prefer the reported state and
keep the inference only as the fallback.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
@github-actions github-actions Bot mentioned this pull request Nov 8, 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.

feat: transaction state for SQLite tabs

2 participants