fix(workspace-feeds): surface real sqlite errors and skip no-op boot writes - #15
Open
dshipper wants to merge 1 commit into
Open
fix(workspace-feeds): surface real sqlite errors and skip no-op boot writes#15dshipper wants to merge 1 commit into
dshipper wants to merge 1 commit into
Conversation
…writes Tend boots logged `SQLiteError: cannot rollback - no transaction is active` from SqliteWorkspaceFeedRepository.setFeedIds (4x in one tend-live restart) and the api only came up on a later attempt. Two problems stacked: 1. setFeedIds rolled back by hand inside a catch. When a statement inside the transaction fails with an error SQLite auto-rolls-back on (BUSY, FULL, IOERR), the explicit ROLLBACK then throws and masks the real error. Use db.transaction(...).immediate() like the rest of sqlite.ts; it only issues ROLLBACK while a transaction is still open. 2. MirroredWorkspaceFeedRepository.init unconditionally rewrote workspace_feeds in sqlite and the json mirror on every boot, and every CLI command boots the same store, so a read-only `state` call took a write lock and a busy database made boot fatal. Only write when the two copies actually disagree. Tests cover the masked-error path (injected post-rollback failure), a BEGIN IMMEDIATE lock conflict, a no-op consistent boot (created_at and mirror untouched), and a real merge when the copies disagree. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SqliteWorkspaceFeedRepository.setFeedIdsused a hand-rolledBEGIN IMMEDIATE/COMMIT/ROLLBACK. When a statement inside the transaction fails with an error SQLite auto-rolls-back on (SQLITE_BUSY,SQLITE_FULL,SQLITE_IOERR), the explicitROLLBACKin thecatchthrowscannot rollback - no transaction is activeand masks the real error. That is the line logged 4× during the 2026-08-29tend-live restart. Switched todb.transaction(...).immediate(), matching the other two transaction sites inserver/sqlite.ts; Bun's wrapper only issuesROLLBACKwhiledb.inTransactionis true.MirroredWorkspaceFeedRepository.initrewroteworkspace_feeds(sqlite) andworkspace.json(mirror) on every boot, and every CLI command boots the same store — so even a read-onlystatecall took a write lock, and a busy database made boot fatal instead of harmless. It now only writes when the two copies actually disagree.SqliteWorkspaceFeedRepositoryis exported so the test can drive it on a connection with the defaultbusy_timeoutof 0 (the store's own connection waits 5 s).Diagnosis correction
The initial hypothesis was that
BEGIN IMMEDIATEitself failing got masked. It does not:BEGINsits outside thetry, and the red-check confirmed a BEGIN lock conflict already surfacedSQLITE_BUSYon the old code. The masking happens when a statement inside the transaction fails after SQLite has already rolled back — the live stack isbun:sqlite run←sqlite.ts:987(theROLLBACKin the catch) ←setFeedIds←workspaceFeeds.ts:67. Because the inner error was swallowed, the specific trigger (most likely a lock conflict with the previous api'sPRAGMA wal_checkpoint(TRUNCATE)on close, or a concurrentbun run cli.ts) is inferred rather than observed; the log has zeroSQLITE_BUSY/lockedlines. Either way, fix 2 removes the write entirely on a steady-state boot, so this path no longer runs in the common case, and fix 1 means that if it does fail we will see the real error next time.Tests —
test/workspace-feeds.test.ts(temp dirs only, never touches the workbench)SQLITE_BUSYwith its own message, leaves the connection out of a transaction, and leaves the rows intactBEGIN IMMEDIATElock conflict surfacesSQLITE_BUSYand the repository recovers once the lock clearscreated_atsentinel unchanged; mirror untouched)The first and third fail on
mainand pass here (verified by stashingserver/and re-running).Verification
bun test— 132 pass / 1 skip (Supabase e2e, env-gated) / 0 failbunx tsc --noEmit— cleanbunx oxlint .— cleantend-live, pid 26373) was not restarted; it is still runningmain. Restart when you want this live.Branch lives in the
.worktrees/fix-workspace-feeds-boot-writeworktree; the main checkout stayed onfeat/ffo-editions.🤖 Generated with Claude Code