OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.
Python
fix: pass jwt to docling polling calls (#1797)
Lucas Oliveirae1bbd5240cc4
diff --git a/src/services/docling_polling_service.py b/src/services/docling_polling_service.pyindex 9067db47c..ab018986d 100644--- a/src/services/docling_polling_service.py+++ b/src/services/docling_polling_service.py@@ -53,6 +53,8 @@ class DoclingPollingService:backoff_factor: float = 1.5,transient_retry_budget: int = 5,result_fetch_retry_budget: int = 3,+ user_id: str | None = None,+ auth_header: str | None = None,) -> DoclingPollResult:"""Loop on Docling status until terminal or until max_seconds elapses.@@ -82,7 +84,9 @@ class DoclingPollingService:while True:logger.debug("Docling polling", task_id=task_id)- snapshot = await self.docling_service.check_task_status(task_id)+ snapshot = await self.docling_service.check_task_status(+ task_id, user_id=user_id, auth_header=auth_header+ )last_snapshot = snapshotlogger.debug("Snapshot received", task_id=task_id, snapshot=last_snapshot)elapsed = time.monotonic() - start@@ -112,7 +116,9 @@ class DoclingPollingService:elapsed_seconds=elapsed,)try:- await self.docling_service.fetch_task_result(task_id)+ await self.docling_service.fetch_task_result(+ task_id, user_id=user_id, auth_header=auth_header+ )breakexcept DoclingTransientError as e:result_fetch_errors += 1diff --git a/src/services/docling_service.py b/src/services/docling_service.pyindex e72fc2938..b7d569cbf 100644--- a/src/services/docling_service.py+++ b/src/services/docling_service.py@@ -214,7 +214,12 @@ class DoclingService:logger.error("Docling result retrieval failed", task_id=task_id, error=str(e))raise- async def check_task_status(self, task_id: str) -> DoclingStatusSnapshot:+ async def check_task_status(+ self,+ task_id: str,+ user_id: str | None = None,+ auth_header: str | None = None,+ ) -> DoclingStatusSnapshot:"""Single (non-blocking) status check against Docling Serve.@@ -224,8 +229,9 @@ class DoclingService:"""client = self._get_client()url = f"{self.docling_url}/v1/status/poll/{task_id}"+ headers = self._get_auth_headers(user_id, auth_header)try:- response = await client.get(url)+ response = await client.get(url, headers=headers)except httpx.RequestError as e:# Transient network error — surface as PROCESSING so caller can# retry without prematurely failing the file.@@ -261,7 +267,7 @@ class DoclingService:status = payload.get("task_status")if status == "success":return DoclingStatusSnapshot(state=DoclingTaskState.SUCCESS, raw=payload)- if status == "failure" or payload.get("errors"):+ if status == "failure" or payload.get("errors") or payload.get("error"):errors = payload.get("errors", [])err_msg_list = []for err in errors:@@ -269,6 +275,11 @@ class DoclingService:err_msg_list.append(err["error_message"])elif isinstance(err, str):err_msg_list.append(err)++ single_err = payload.get("error")+ if isinstance(single_err, str):+ err_msg_list.append(single_err)+err_details = ("; ".join(err_msg_list) if err_msg_list else "Unknown Docling processing error")@@ -281,7 +292,12 @@ class DoclingService:return DoclingStatusSnapshot(state=DoclingTaskState.PROCESSING, raw=payload)return DoclingStatusSnapshot(state=DoclingTaskState.PENDING, raw=payload)- async def fetch_task_result(self, task_id: str) -> dict[str, Any]:+ async def fetch_task_result(+ self,+ task_id: str,+ user_id: str | None = None,+ auth_header: str | None = None,+ ) -> dict[str, Any]:"""Fetch the converted document for a Docling task that is already SUCCESS.@@ -292,8 +308,9 @@ class DoclingService:"""client = self._get_client()url = f"{self.docling_url}/v1/result/{task_id}"+ headers = self._get_auth_headers(user_id, auth_header)try:- response = await client.get(url)+ response = await client.get(url, headers=headers)except httpx.RequestError as e:raise DoclingTransientError(f"Network error fetching docling result: {str(e)}") from ediff --git a/src/services/langflow_file_service.py b/src/services/langflow_file_service.pyindex f73a519c9..da3a90a7b 100644--- a/src/services/langflow_file_service.py+++ b/src/services/langflow_file_service.py@@ -920,6 +920,8 @@ class LangflowFileService:max_interval=DOCLING_POLL_MAX_INTERVAL_SECONDS,backoff_factor=DOCLING_POLL_BACKOFF_FACTOR,transient_retry_budget=DOCLING_POLL_TRANSIENT_RETRIES,+ user_id=owner,+ auth_header=jwt_token,)if poll_result.outcome != PollOutcome.SUCCESS:diff --git a/src/tui/managers/docling_manager.py b/src/tui/managers/docling_manager.pyindex 903a480a1..73c61d85b 100644--- a/src/tui/managers/docling_manager.py+++ b/src/tui/managers/docling_manager.py@@ -302,10 +302,12 @@ class DoclingManager:"--with","easyocr","--with",- f"docling[{docling_extras}]",+ f"docling[{docling_extras}]==2.95.0","--with","docling-core==2.77.1","--with",+ "docling-jobkit==1.20.0",+ "--with","transformers>=5.8.1,<5.9.0",]if override_path:diff --git a/tests/unit/test_docling_polling_service.py b/tests/unit/test_docling_polling_service.pyindex 300a9a3b4..d9109f2d9 100644--- a/tests/unit/test_docling_polling_service.py+++ b/tests/unit/test_docling_polling_service.py@@ -56,7 +56,9 @@ async def test_returns_success_immediately_when_already_done(polling_service, moassert result.outcome == PollOutcome.SUCCESSassert mock_docling_service.check_task_status.call_count == 1- mock_docling_service.fetch_task_result.assert_awaited_once_with("t1")+ mock_docling_service.fetch_task_result.assert_awaited_once_with(+ "t1", user_id=None, auth_header=None+ )@pytest.mark.asyncio@@ -79,7 +81,9 @@ async def test_loops_through_processing_then_success(assert result.outcome == PollOutcome.SUCCESSassert mock_docling_service.check_task_status.call_count == 4assert no_sleep.call_count == 3- mock_docling_service.fetch_task_result.assert_awaited_once_with("t1")+ mock_docling_service.fetch_task_result.assert_awaited_once_with(+ "t1", user_id=None, auth_header=None+ )@pytest.mark.asyncio@@ -95,7 +99,9 @@ async def test_success_status_requires_fetchable_result(polling_service, mock_doassert result.outcome == PollOutcome.FAILEDassert "missing document.json_content" in (result.detail or "")- mock_docling_service.fetch_task_result.assert_awaited_once_with("t1")+ mock_docling_service.fetch_task_result.assert_awaited_once_with(+ "t1", user_id=None, auth_header=None+ )@pytest.mark.asyncio@@ -133,7 +139,9 @@ async def test_tolerates_brief_not_found_then_succeeds()assert result.outcome == PollOutcome.SUCCESS- mock_docling_service.fetch_task_result.assert_awaited_once_with("t1")+ mock_docling_service.fetch_task_result.assert_awaited_once_with(+ "t1", user_id=None, auth_header=None+ )@pytest.mark.asyncio@@ -214,7 +222,9 @@ async def test_backoff_grows_interval_up_to_cap(polling_service, mock_docling_se# see the raw progression.sleeps = [call.args[0] for call in no_sleep.call_args_list]assert sleeps == [1.0, 2.0, 4.0, 4.0]- mock_docling_service.fetch_task_result.assert_awaited_once_with("t1")+ mock_docling_service.fetch_task_result.assert_awaited_once_with(+ "t1", user_id=None, auth_header=None+ )@pytest.mark.asyncio@@ -277,4 +287,6 @@ async def test_permanent_result_fetch_error_fails_immediately(assert result.outcome == PollOutcome.FAILEDassert "task expired" in (result.detail or "")- mock_docling_service.fetch_task_result.assert_awaited_once_with("t1")+ mock_docling_service.fetch_task_result.assert_awaited_once_with(+ "t1", user_id=None, auth_header=None+ )