fix: resolve SQLite transaction bugs, FTS5 sync, and atomic operations#94
Open
murilloimparavel wants to merge 1 commit intotirth8205:mainfrom
Open
fix: resolve SQLite transaction bugs, FTS5 sync, and atomic operations#94murilloimparavel wants to merge 1 commit intotirth8205:mainfrom
murilloimparavel wants to merge 1 commit intotirth8205:mainfrom
Conversation
…perations
Fixes multiple SQLite transaction management issues:
1. **BEGIN IMMEDIATE conflict** (graph.py): Add `in_transaction` guard
before `BEGIN IMMEDIATE` to prevent "cannot start a transaction within
a transaction" errors when implicit transactions are left open.
2. **FTS5 content sync** (search.py): Recreate FTS5 table with
`content='nodes'` and use `INSERT INTO nodes_fts(nodes_fts)
VALUES('rebuild')` for proper content-sync population.
3. **Atomic batch operations** (flows.py, communities.py): Wrap
DELETE + INSERT loops in `BEGIN IMMEDIATE` / `try` / `COMMIT` /
`except ROLLBACK` to prevent partial writes on crash.
4. **Missing rollback on error** (tools/build.py): Add `store.rollback()`
in post-processing except blocks to prevent lingering transactions.
5. **Public rollback API** (graph.py): Expose `GraphStore.rollback()`
method instead of accessing `_conn` directly.
6. **Diagnostic logging**: Add `logger.warning()` before silent rollbacks
in transaction guards for debuggability.
Tested on monorepo with 8,352 nodes, 50,259 edges — zero transaction
errors after fix.
Co-Authored-By: Claude Opus 4.6 (1M context) <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.
Summary
Fixes multiple SQLite transaction management issues that cause
cannot start a transaction within a transactionerrors and potential data corruption:graph.py): Addin_transactionguard beforeBEGIN IMMEDIATEto prevent errors when implicit transactions are left open by prior DML operationssearch.py): Recreate FTS5 table withcontent='nodes'and useINSERT INTO nodes_fts(nodes_fts) VALUES('rebuild')for proper content-sync population (was creating standalone table disconnected from nodes)flows.py,communities.py): Wrap DELETE + INSERT loops inBEGIN IMMEDIATE/try/COMMIT/except ROLLBACKto prevent partial writes on crashtools/build.py): Addstore.rollback()in post-processing except blocks to prevent lingering transactions that corrupt the DB on next rungraph.py): ExposeGraphStore.rollback()method instead of accessing_conndirectlylogger.warning()before silent rollbacks in transaction guards for debuggabilityReproduction
The
cannot start a transaction within a transactionerror occurs when:store_file_nodes_edges()callsBEGIN IMMEDIATEwhile a prior operation (e.g.,set_metadata,upsert_node) left an implicit Python sqlite3 transaction openTest plan
🤖 Generated with Claude Code