From 71b9acfda60467ddf9ac4a461cc29bd55abddd18 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 8 Mar 2026 07:01:35 +0000 Subject: [PATCH 1/2] Initial plan From 59daf4ccb3d95defa32b354606529749818ee5ec Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 8 Mar 2026 07:04:09 +0000 Subject: [PATCH 2/2] Fix blockchain cache race condition: update cache only after successful DB commit Co-authored-by: RohanExploit <178623867+RohanExploit@users.noreply.github.com> --- backend/routers/issues.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/routers/issues.py b/backend/routers/issues.py index de27e1a9..28a4d844 100644 --- a/backend/routers/issues.py +++ b/backend/routers/issues.py @@ -186,9 +186,6 @@ async def create_issue( hash_content = f"{description}|{category}|{prev_hash}" integrity_hash = hashlib.sha256(hash_content.encode()).hexdigest() - # Update cache for next report - blockchain_last_hash_cache.set(data=integrity_hash, key="last_hash") - # RAG Retrieval (New) relevant_rule = rag_service.retrieve(description) initial_action_plan = None @@ -212,10 +209,16 @@ async def create_issue( # Offload blocking DB operations to threadpool await run_in_threadpool(save_issue_db, db, new_issue) + + # Update cache only after a successful DB commit + blockchain_last_hash_cache.set(data=integrity_hash, key="last_hash") else: # Don't create new issue, just return deduplication info new_issue = None except Exception as e: + # Invalidate cache so next request re-fetches the true last hash from DB + blockchain_last_hash_cache.invalidate("last_hash") + # Clean up uploaded file if DB save failed if image_path and os.path.exists(image_path): try: