Problem
In code_review_graph/flows.py:412-415, incremental_trace_flows performs
multiple DELETE operations (flow_memberships and flows) in a loop without
wrapping them in a BEGIN IMMEDIATE transaction:
for fid in affected_ids:
conn.execute("DELETE FROM flow_memberships WHERE flow_id = ?", (fid,))
conn.execute("DELETE FROM flows WHERE id = ?", (fid,))
conn.commit()
If an error occurs mid-loop (e.g., disk full, locked DB), some flows will be
deleted while others remain, leaving the database in an inconsistent state.
Expected Behavior
The deletion loop should be wrapped in a transaction with rollback on failure,
matching the pattern already used by store_flows and store_communities in the
same file:
conn.execute("BEGIN IMMEDIATE")
try:
for fid in affected_ids:
conn.execute("DELETE FROM flow_memberships WHERE flow_id = ?", (fid,))
conn.execute("DELETE FROM flows WHERE id = ?", (fid,))
conn.commit()
except Exception:
conn.rollback()
raise
Impact
Partial deletions could corrupt flow data during incremental updates,
especially on slower storage or under concurrent access.
so let me know if I can raise a PR !
Problem
In
code_review_graph/flows.py:412-415,incremental_trace_flowsperformsmultiple DELETE operations (flow_memberships and flows) in a loop without
wrapping them in a
BEGIN IMMEDIATEtransaction: