Skip to content

Avoid SQLite startup races during parallel Bun qmd initialization#442

Open
sebkouba wants to merge 2 commits intotobi:mainfrom
sebkouba:feat/parallel-querying-pr
Open

Avoid SQLite startup races during parallel Bun qmd initialization#442
sebkouba wants to merge 2 commits intotobi:mainfrom
sebkouba:feat/parallel-querying-pr

Conversation

@sebkouba
Copy link
Copy Markdown
Contributor

@sebkouba sebkouba commented Mar 19, 2026

Problem

Parallel qmd processes can fail during startup with transient SQLite lock errors such as database is locked and SQLITE_BUSY_RECOVERY.

Root cause

  • busy_timeout was applied after early startup work
  • the sqlite-vec probe could run before contention handling was configured
  • multiple processes could race while flipping the shared database into WAL mode

Fix

  • configure connection pragmas before any sqlite-vec probe work
  • skip redundant PRAGMA journal_mode = WAL when the database is already in WAL mode
  • tolerate losing the WAL transition race instead of aborting startup
  • add focused regression coverage for concurrent Bun startup on both fresh and existing databases
  • run that regression through a tiny Bun startup harness so CI measures DB initialization directly instead of full CLI latency

Testing

  • bun test --timeout 60000 --preload ./src/test-preload.ts test/cli.test.ts
  • bunx vitest run --reporter=verbose test/store.helpers.unit.test.ts test/store.test.ts test/cli.test.ts
  • manual repro on a fresh DB: two concurrent bun src/cli/qmd.ts vsearch test runs exit 0 with no lock-related stderr
  • manual repro on an existing DB: same concurrent vsearch repro exits 0 with no lock-related stderr

zeattacker pushed a commit to zeattacker/qmd that referenced this pull request Mar 26, 2026
Merges dev-upstream-fixes (cherry-picked PRs tobi#462, tobi#463, tobi#455, tobi#418,
tobi#456, tobi#442, tobi#453) into dev. Resolved mcp/server.ts bind conflict —
keep 0.0.0.0 for Docker container accessibility.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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