From f3d34174c89199ca0e1823209b420f6267dda73e Mon Sep 17 00:00:00 2001 From: Prom3theu5 Date: Mon, 1 Jun 2026 22:26:18 +0100 Subject: [PATCH] fix(graph): roll back on COMMIT failure in batched link_edges MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The batched edge writer rolled back on a mid-batch execution error but not when COMMIT itself failed — it just returned the error, leaving the transaction open and risking a dangling transaction/lock on the connection. Make the COMMIT path symmetric with the mid-batch path: on commit failure, best-effort ROLLBACK then return the error with context. Bumps version to 0.1.5. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/graph/ladybug_store.rs | 14 ++++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e553509..d1866ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -809,7 +809,7 @@ dependencies = [ [[package]] name = "synapse" -version = "0.1.4" +version = "0.1.5" dependencies = [ "anyhow", "blake3", diff --git a/Cargo.toml b/Cargo.toml index e013bbb..e029a70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "synapse" -version = "0.1.4" +version = "0.1.5" edition = "2024" [[bin]] diff --git a/src/graph/ladybug_store.rs b/src/graph/ladybug_store.rs index 0e5ee51..af28055 100644 --- a/src/graph/ladybug_store.rs +++ b/src/graph/ladybug_store.rs @@ -428,10 +428,16 @@ impl GraphStore for LadybugGraphStore { Ok(()) })(); match result { - Ok(()) => conn - .query("COMMIT") - .map(|_| ()) - .map_err(|e| anyhow!("commit transaction: {e}")), + Ok(()) => match conn.query("COMMIT") { + Ok(_) => Ok(()), + // A failed COMMIT leaves the transaction open; roll it back + // (best effort) before surfacing the error, mirroring the + // mid-batch error path so we never leave a dangling txn/lock. + Err(e) => { + let _ = conn.query("ROLLBACK"); + Err(anyhow!("commit transaction: {e}")) + } + }, Err(err) => { // Best-effort rollback; report the original error. let _ = conn.query("ROLLBACK");