fix: serialise RAG indexing writers (RC5 — close concurrent SQLITE_BUSY path)#15
Merged
Merged
Conversation
callIndexDocuments invoked Engine.IndexDocuments directly, bypassing the indexWithLock guard (re.indexing) that only the startup and file-watcher paths used. A manual index_documents and a background watcher index could therefore write to vectors.db concurrently. The 0.8.4 per-connection busy_timeout made them queue up to 5s, but a heavy index holding a write transaction longer than that could still return SQLITE_BUSY. Hold a dedicated Engine.indexMu for the whole IndexDocuments duration so every indexing run is serialised regardless of caller. The watcher's `indexing` flag is kept (it coalesces debounced ticks); foreground callers wait on the mutex and index for real instead of being skipped. Regression test asserts a second call blocks while the lock is held and completes once released.
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.
Follow-up к #14 (0.8.4). Закрывает последний путь конкурентной записи в
vectors.db.Проблема (RC5)
server.callIndexDocumentsзовётEngine.IndexDocumentsнапрямую, минуя guardindexWithLock(re.indexing), которым пользуются только startup и file_watcher. Значит ручнойindex_documentsи фоновый watcher-индекс могли писать вvectors.dbодновременно. Фикс 0.8.4 (per-connectionbusy_timeout) делает их вежливой очередью до 5с, но при тяжёлом индексе с write-txn >5сSQLITE_BUSYоставался возможен.Фикс
IndexDocumentsдержит выделенныйEngine.indexMu sync.Mutexна всё время записи → любые indexing-прогоны сериализованы независимо от вызывающего.re.indexingоставлен как есть — он коалесцирует дебаунс-тики watcher'а, чтобы они не стекались.indexMuи реально индексирует, а не «пропускается».re.muосвобождается до вызоваIndexDocuments,indexMuнезависим.Тест
TestIndexDocumentsSerialisesWriters— детерминированный: держимindexMu→ второйIndexDocumentsобязан блокироваться (150ms окно) → после release отрабатывает без ошибки. Проходит под-race.Проверено
go build ./...,go vet ./internal/rag/...,go test ./...(+./internal/rag/... -race) — всё зелёное.См.
06-planning/2026-05-05-sqlite-busy-incident.md§7 RC5 (помечен FIXED).