From cd33777d759f68c2736fc11a1cfd13fefb16f304 Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Sat, 25 Apr 2026 22:15:21 +0200 Subject: [PATCH] fix: Pass 0b INSERT ON CONFLICT DO UPDATE + per-result commit/rollback Prevents UniqueViolation from blocking entire batch. Each result is committed individually, errors are rolled back without affecting subsequent results. Co-Authored-By: Claude Opus 4.6 (1M context) --- control-pipeline/services/decomposition_pass.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/control-pipeline/services/decomposition_pass.py b/control-pipeline/services/decomposition_pass.py index 998c52b..9aa58a7 100644 --- a/control-pipeline/services/decomposition_pass.py +++ b/control-pipeline/services/decomposition_pass.py @@ -3314,6 +3314,11 @@ class DecompositionPass: CAST(:framework_id AS uuid), 'pass0b', 2 ) + ON CONFLICT (framework_id, control_id) DO UPDATE + SET title = EXCLUDED.title, + objective = EXCLUDED.objective, + requirements = EXCLUDED.requirements, + updated_at = NOW() RETURNING id::text """), { @@ -3686,11 +3691,19 @@ class DecompositionPass: self._handle_batch_result_0a(custom_id, text_content, stats) else: await self._handle_batch_result_0b(custom_id, text_content, stats) + self.db.commit() except Exception as e: logger.error("Processing batch result %s: %s", custom_id, e) stats["errors"] += 1 + try: + self.db.rollback() + except Exception: + pass - self.db.commit() + try: + self.db.commit() + except Exception: + pass stats["status"] = "completed" return stats