mirror of
https://github.com/open-webui/oikb.git
synced 2026-11-05 01:27:25 +00:00
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
open-webui/oikb#103
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/oikb/pull/81
Author: @calvinlow18
Created: 7/14/2026
Status: ❌ Closed
Base:
main← Head:fix/sqlite-thread-affinity📝 Commits (1)
5dde025fix(history): give each thread its own SQLite connection📊 Changes
1 file changed (+27 additions, -9 deletions)
View changed files
📝
src/oikb/history.py(+27 -9)📄 Description
Fixes #39.
The bug
SyncHistorycaches a singlesqlite3.Connectioninself._conn, created lazily by whichever thread calls_get_conn()first. The daemon runs every sync throughasyncio.to_thread(), so the next source lands on a different pool thread — andsqlite3(with its defaultcheck_same_thread=True) refuses it:The first source to finish wins the connection and succeeds; every other source raises. That matches #39's report exactly (4 of 5 sources failing), and it is connector-agnostic — #39 hit it with Google Drive, I hit it with
outline:on 4 sources.Why it's worse than it looks
SyncHistory.log()is called afterrun_sync()has already uploaded, and_run_entry_locked()catches the exception in its broadexcept Exception— which overwrites the just-set success state:So the documents do reach the knowledge base, while
/health, the dashboard and the history all reporterrorfor a sync that actually worked. Anything monitoring the daemon is permanently red, and the counts (files_added, etc.) are lost.The fix
Hold the connection in a
threading.local()so each thread gets its own. Also open with WAL and a busy timeout, so the now-genuinely-concurrent writers wait on the brief write lock instead of raisingdatabase is locked.One file, no API change.
Reproduction
Against
main, drivingSyncHistorythe way the daemon does:Before: 4 of 5 raise
ProgrammingError: SQLite objects created in a thread..., and the follow-upquery()raises too.After:
sources logged OK: 5/5,rows in history: 5.Also re-checked the single-threaded CLI path —
log,query(plain /errors_only/kb_id),last_sync,clear, and a doubleclose()— all unchanged.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.