Skip to content

Fix database locked error during concurrent access#16

Merged
alecgard merged 1 commit intomainfrom
fix/db-locked-concurrent-access
Mar 18, 2026
Merged

Fix database locked error during concurrent access#16
alecgard merged 1 commit intomainfrom
fix/db-locked-concurrent-access

Conversation

@alecgard
Copy link
Copy Markdown
Owner

Summary

Closes #12.

kb sources list (and other read-only commands) failed with database is locked when run during ingestion, because initSchema unconditionally ran write statements even when the schema was already set up.

Added a schemaReady() read-only check — a single SELECT on the metadata table. If the schema is already initialized with the correct embedding dimension, all writes are skipped entirely.

Changes

  • internal/store/sqlite.go — Added schemaReady() fast path in initSchema
  • internal/store/sqlite_test.go — Added TestConcurrentOpenDuringWrite

Test plan

  • make test passes
  • New test reproduces the concurrent access scenario
  • Manual: run kb ingest on a large repo, simultaneously run kb sources list

🤖 Generated with Claude Code

@alecgard alecgard force-pushed the fix/db-locked-concurrent-access branch from 7b53549 to 10b081a Compare March 17, 2026 17:07
Added schemaReady() read-only check to initSchema so read-only
operations (sources list, query, export) skip all writes when the
schema is already initialized. This prevents SQLITE_BUSY errors
when these commands run during ingestion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alecgard alecgard force-pushed the fix/db-locked-concurrent-access branch from 10b081a to 17a2945 Compare March 18, 2026 20:12
@alecgard alecgard merged commit 86c002d into main Mar 18, 2026
1 check passed
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.

kb sources list fails with 'database is locked' during concurrent ingestion

1 participant