fix(server): wait for concurrent SQLite writers instead of failing with SQLITE_BUSY #5134
main fromrefs/pull/5134/head·merged by juliusmarminge View on GitHubShowing 2 changed files with 68 additions and 0 deletions.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
What is the current stability status of node:sqlite in the latest Node.js LTS release, and does Bun fully support node:sqlite as of its latest stable release?
💡 Result:
As of July 31, 2026, the node:sqlite module in Node.js is classified with a stability index of 1.2, which designates it as a release candidate [1][2]. While the module has been unflagged—meaning it no longer requires the --experimental-sqlite flag—it has not yet been declared fully stable [3][4]. The release candidate status indicates that while no further breaking changes are anticipated, they may still occur in response to user feedback or specification developments [4]. Regarding Bun, it does not support the node:sqlite module [5][6]. Bun natively provides its own high-performance SQLite driver through the bun:sqlite module, which is the recommended alternative for use within the Bun runtime [5][7]. Users requiring cross-runtime compatibility between Node.js and Bun typically must use conditional imports or implement a wrapper to handle the differences between the node:sqlite and bun:sqlite APIs [6].
Citations:
- 1: https://nodejs.org/api/sqlite.html
- 2: http://nodejs.org/dist/latest/docs/api/sqlite.html
- 3: https://github.com/nodejs/node/issues/57445
- 4: https://github.com/nodejs/node/pull/61262
- 5: https://bun.sh/reference/node/sqlite
- 6: https://github.com/oven-sh/bun/issues/31402
- 7: https://bun.com/docs/runtime/sqlite
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== repo files relevant to runtime/package config =="
git ls-files | rg '(^|/)(package\.json|pnpm-lock\.yaml|bun\.lockb|bun\.lock|README\.md|\.env|\.github/workflows/.+\.ya?ml|vitest\.config\..+|vite\.config\..+|bunfig\.toml|bun\.doc|package\.lock\.json|yarn\.lock)$' || true
echo
echo "== package.json files =="
for f in $(git ls-files 'package.json'); do
echo "--- $f"
cat "$f"
done
echo
echo "== references to bun/script engines/tests =="
rg -n '"bun"|"typecheck:bun"|bun (test|run)|pnpm test|vitest|node:sqlite|Vite_HTTP_URL|VITE_HTTP_URL|VITE_WS_URL' -S . || true
echo
echo "== target test file excerpt =="
sed -n '1,90p' apps/server/src/persistence/Layers/Sqlite.test.ts
Repository: pingdotgg/t3code
Length of output: 50372
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== target test file excerpt =="
sed -n '1,90p' apps/server/src/persistence/Layers/Sqlite.test.ts
echo
echo "== GitHub workflow commands mentioning bun node pnpm test =="
for f in .github/workflows/*.yml .github/workflows/*.yaml; do
[ -f "$f" ] || true
done | xargs -r -n1 sh -c '
echo "--- $0"
rg -n "bun|node|pnpm test|test:" "$0" || true
' sh
echo
echo "== package/runtime config focused =="
rg -n '"node"|engines|packageManager|bun run|bun (test|run)|pnpm test|node:sqlite' package.json Apps/server/package.json apps/server/package.json package-lock.json pnpm-lock.yaml .github/workflows/ci.yml || true
Repository: pingdotgg/t3code
Length of output: 50372
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== target test file excerpt =="
sed -n '1,90p' apps/server/src/persistence/Layers/Sqlite.test.ts
echo
echo "== GitHub workflow commands mentioning bun node pnpm test =="
for f in .github/workflows/*.yml .github/workflows/*.yaml; do
[ -f "$f" ] || continue
echo "--- $f"
rg -n "bun|node|pnpm test|test:" "$f" || true
done
echo
echo "== engine/runtime config focused =="
rg -n '"node"|engines|packageManager|bun run|bun test|pnpm test|node:sqlite' package.json apps/server/package.json pnpm-lock.yaml .github/workflows/ci.yml || true
Repository: pingdotgg/t3code
Length of output: 50372
Keep the lock-helper on a runtime-specific path.
lockHolderSource spawns process.execPath and requires node:sqlite. Bun does not provide node:sqlite, so this helper breaks under Bun despite the PR mentioning Node and Bun writable connections. Use a Bun/Native bun:sqlite helper here, or structure the test to run this Node-specific lock simulation only on Node.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/server/src/persistence/Layers/Sqlite.test.ts` around lines 15 - 24,
Update the lock-holder setup around lockHolderSource so it does not require
node:sqlite when tests run under Bun. Use a Bun-compatible bun:sqlite helper for
Bun, or conditionally run the existing process.execPath/node:sqlite lock
simulation only on Node while preserving the lock behavior.
The suite only runs under Node, so the helper can't hit the missing-node:sqlite path: CI's Test job sets up Node (node-version-file: package.json) and runs vp run test — vitest with environment: node; there is no Bun test path in the repo. The existing suite already carries this constraint: NodeSqliteClient.test.ts imports NodeSqliteClient.ts, which imports node:sqlite at module scope. The node/bun mention in the description is about the production clients — both get the pragma through the shared setup layer, which the second test pins; the lock-holder child is test scaffolding only. Happy to add a skipIf(process.versions.bun) guard if you'd rather make the Node-only assumption explicit.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '== Relevant file locations =='
fd -a -t f '^(package\.json|.*vitest.*|.*Sqlite.*\.(test\.)?ts|.*NodeSqliteClient.*\.ts)$' . \
| sort
echo
echo '== Test scripts and runtime declarations =='
for file in package.json apps/server/package.json; do
if [ -f "$file" ]; then
echo "--- $file"
rg -n -C 3 '"(test|test:.*|packageManager|engines)"\s*:' "$file" || true
fi
done
echo
echo '== CI test commands and Node setup =='
if [ -d .github/workflows ]; then
rg -n -i -C 4 '(node-version-file|setup-node|vp run test|bun|vitest|test:)' .github/workflows || true
fi
echo
echo '== Vitest environment configuration =='
vitest_files="$(fd -a -t f -i 'vitest.config.*' . || true)"
if [ -n "$vitest_files" ]; then
while IFS= read -r file; do
echo "--- $file"
rg -n -C 3 '(environment|test)' "$file" || true
done <<< "$vitest_files"
fi
echo
echo '== Existing node:sqlite imports in server tests and implementation =='
rg -n -C 3 'from "node:sqlite"|require\("node:sqlite"\)' apps/server || true
echo
echo '== Reviewed test excerpt =='
sed -n '1,75p' apps/server/src/persistence/Layers/Sqlite.test.ts
Length of output: 37985
@ostapondo, verified. The test suite has a Node-only execution contract.
CI configures Node from package.json and runs vp run test. The repository also already imports node:sqlite at module scope in apps/server/src/persistence/NodeSqliteClient.ts. This test directly uses Node built-ins and @effect/platform-node/NodeServices.
The Node/Bun production support does not require the lock-holder test scaffold to support Bun. The shared setup test covers the shared busy_timeout configuration.
No skipIf(process.versions.bun) guard is needed for the current test contract. I am withdrawing this finding.
✏️ Learnings added
Learnt from: ostapondo
Repo: pingdotgg/t3code PR: 5134
File: apps/server/src/persistence/Layers/Sqlite.test.ts:15-24
Timestamp: 2026-07-31T17:30:20.576Z
Learning: The repository test suite is Node-only: `.github/workflows/ci.yml` configures Node from the root `package.json` and runs `vp run test`. Node-specific test scaffolding is valid in `apps/server/src/persistence/Layers/Sqlite.test.ts`; this includes the `lockHolderSource` child process that uses `node:sqlite`. The production SQLite layer still supports Node and Bun through shared setup, but tests do not run under Bun.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.