Repository navigation
Serialise SQLite bootstrap across processes (patch #180) - #141
Merged
Merged
Conversation
Two uvicorn workers of one Gateway share pythia's SQLite file. At the 2026-11-28 promote both upgraded 0058 to 0064 at once and one died on "table coord_task_grants already exists". Hold an flock on <db>.bootstrap.lock beside the database for the whole bootstrap, after the in-process lock; poll so the event loop stays free. In-memory databases and platforms without fcntl keep the in-process lock alone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Patch bytedance#180. Pythia and pyrrhus keep their app database in SQLite and run two uvicorn workers. At the 2026-11-28 promote both of pythia's workers read revision 0058 and upgraded to 0064 at once. One died on
table coord_task_grants already exists; uvicorn respawned it and it found head. Upstream's SQLite bootstrap lock is in-process only, so every migration that adds a table repeats this on those two stacks.Change (
deerflow/persistence/bootstrap.py):asyncio.Lock,_sqlite_lockholds an exclusiveflockon<db>.bootstrap.lockbeside the database. It covers the whole reflect-and-act sequence, including the alembic worker thread, so a second process reads the revision only after the first has written head._sqlite_lock's docstring gives for not usingBEGIN IMMEDIATE.LOCK_NBevery 0.2 s withasyncio.sleepand waits as long as the holder takes, like the Postgres advisory lock. A cancelled waiter holds nothing, and the kernel releases the lock if its holder dies.file:URIs and platforms withoutfcntlkeep the in-process lock alone, as before.Tests:
tests/test_persistence_bootstrap_sqlite_file_lock.py, 6 cases.0001_baselineand both exit 0 at head. With the lock disabled this case failed 3 runs of 3: one worker died with alembicCommandError("expected to match one row when updating '0001_baseline' to '0002_runs_token_usage'; 0 found").The bootstrap, concurrency, sqlite-lock and forward-revision suites give 79 passed and 7 skipped (Postgres). Ruff is clean, and
check_patches_ledger.pyis consistent.Ledger: PATCHES.md gains bytedance#180 (TOC row and section, Delete-when: the two stacks move to Postgres or one worker, or upstream serialises SQLite bootstrap).
Roll-out: rides the next acropolis pin bump. It matters at the next migration on pythia or pyrrhus.
🤖 Generated with Claude Code