From ba687813c166a110a612909586278c5e910a885a Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Wed, 10 Jun 2026 00:10:52 +0200 Subject: [PATCH] fix(elasticsearch): commit failed status immediately --- .../app/tasks/connector_indexers/elasticsearch_indexer.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/surfsense_backend/app/tasks/connector_indexers/elasticsearch_indexer.py b/surfsense_backend/app/tasks/connector_indexers/elasticsearch_indexer.py index 3283b41eb..ba0aa3445 100644 --- a/surfsense_backend/app/tasks/connector_indexers/elasticsearch_indexer.py +++ b/surfsense_backend/app/tasks/connector_indexers/elasticsearch_indexer.py @@ -6,6 +6,7 @@ Implements 2-phase document status updates for real-time UI feedback: - Phase 2: Process each document: pending → processing → ready/failed """ +import contextlib import json import logging import time @@ -406,10 +407,15 @@ async def index_elasticsearch_documents( try: document.status = DocumentStatus.failed(str(e)) document.updated_at = get_current_timestamp() + # Commit now so the failed status survives a later rollback or + # crash; otherwise the doc stays stuck in pending/processing. + await session.commit() except Exception as status_error: logger.error( f"Failed to update document status to failed: {status_error}" ) + with contextlib.suppress(Exception): + await session.rollback() documents_failed += 1 continue