Skip to content

feat: concurrency hardening — fine-grained ingest transactions + fast-path DB init + write retry #124 - #125

Merged
four-bytes-robby merged 1 commit into
mainfrom
feat/124-concurrency-hardening
Jun 10, 2026
Merged

four-bytes-robby merged 1 commit into
mainfrom
feat/124-concurrency-hardening

Conversation

@four-bytes-robby

@four-bytes-robby four-bytes-robby commented Jun 10, 2026

Copy link
Copy Markdown
Member

Closes #124

Changes

  1. Fine-grained per-file transactions in ingestPath() — replaced giant SAVEPOINT (write lock held for minutes) with per-file SAVEPOINTs (write lock held for milliseconds). Other write operations (memory, knowledge) no longer blocked during ingest.
  2. Fast-path DB initialization — added getSchemaVersion() + version check in initBrainDatabase(). When DB is already at current schema version, skips createSchema() and runMigrations() entirely.
  3. Write retry wrappers — brain_kb_add, brain_kb_record, brain_kb_review, and brain_reindex now use withDbRetry() for SQLITE_BUSY handling.
  4. Removed migration helpers from createSchema() — destructive migrateKnowledgeFts() (DROP+CREATE entries_fts) no longer runs on every init. Migration helpers only run in runMigrations() during schema upgrades.

Verification

  • ✅ bun run build — success
  • ✅ bun test — 247 pass, 0 fail
  • ✅ Version bumped to 1.7.3

Summary by cubic

Improves database concurrency and startup time. Ingest now uses per-file transactions, DB init short-circuits when the schema is current, and write paths auto-retry to avoid SQLITE_BUSY.

  • Refactors
    • Per-file SAVEPOINTs in ingest to avoid long write locks; other writes continue during ingest.
    • Fast-path init: check schema_version via getSchemaVersion(); skip createSchema() and migrations when up to date.
    • Write retries: wrap knowledge writes and reindex in withDbRetry() to handle SQLITE_BUSY.
    • Remove migration helpers from createSchema(); destructive FTS rebuild runs only during migrations.

Written for commit cfb08a6. Summary will update on new commits.

Review in cubic

@four-bytes-robby
four-bytes-robby merged commit 82d8026 into main Jun 10, 2026
4 checks passed
@four-bytes-robby
four-bytes-robby deleted the feat/124-concurrency-hardening branch June 10, 2026 22:26
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] Concurrency hardening: fine-grained ingest transactions + fast-path DB init + write retry

1 participant