Skip to content

feat(file-processors): add async/fallback support to docling-serve#6014

Merged
mattf merged 20 commits into
ogx-ai:mainfrom
sahana-sreeram:feat/docling-serve-asynch
Jun 29, 2026
Merged

feat(file-processors): add async/fallback support to docling-serve#6014
mattf merged 20 commits into
ogx-ai:mainfrom
sahana-sreeram:feat/docling-serve-asynch

Conversation

@sahana-sreeram

@sahana-sreeram sahana-sreeram commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Integrates AsyncDoclingServiceClient from docling-slim to enable async endpoints for both IBM Docling SaaS and local docling-serve. This enables IBM Docling SaaS and improves performance for local deployments.

Problem: Before this PR, docling-serve provider had critical limitations:

  • IBM Docling SaaS was completely incompatible (it only provides async endpoints, OGX docling-serve only used sync)
  • Local deployments experienced timeouts on large PDFs under concurrent load
  • No async capabilities or WebSocket-based status updates

Solution:

  • Use Docling's new AsyncDoclingServiceClient for async conversion with automatic fallback to sync
  • Handle dual response formats: presigned S3 URLs (IBM SaaS) and direct documents (local Docling-Serve)
  • Error handling approach for IBM SaaS' chunking limitation: catch HTTP 404/405 errors and throw clear InvalidParameterError

This solution is lightweight and requires no infrastructure changes. Users can:

  • Continue using local docling-serve with async mode (now the default)
  • Switch to IBM Docling SaaS by updating base_url and api_key in their config

Test Plan

Validated async functionality using both unit tests and integration testing against a local Docling Serve instance.

Unit Tests

23 passed in 1.49s

  Unit Tests
  New tests added:
  tests/unit/providers/file_processor/test_docling_serve.py::TestIBMSaaSCompatibility::test_ibm_saas_blocks_chunking_with_clear_error PASSED [ 91%]
  tests/unit/providers/file_processor/test_docling_serve.py::TestIBMSaaSCompatibility::test_ibm_saas_allows_conversion_without_chunking PASSED [ 95%]
  tests/unit/providers/file_processor/test_docling_serve.py::TestIBMSaaSCompatibility::test_local_docker_allows_chunking PASSED [100%]
  
  ======================== 23 passed, 1 warning in 1.49s =========================
  

Integration Testing

Tested against local docling-serve Docker (v1.24.0) and IBM's Docling SaaS (both in async mode) with real 37KB PDF (ogx_and_models.pdf):

Test 1: IBM Docling SaaS (Async Conversion)
  {
    "endpoint": "IBM SaaS",
    "base_url": "https://api.aws-c1.dcls.saas.ibm.com/...",
    "chunks_count": 1,
    "conversion_method": "async",
    "processing_time_ms": 934,
    "total_chars": 1486,
    "chunk_sizes": [1486]
  } 
  
  Test 2: Local docling-serve (Async Conversion + Chunking)
  {
    "endpoint": "Local Docker",
    "base_url": "http://localhost:5001",
    "chunks_count": 3,
    "conversion_method": "async",
    "processing_time_ms": 5072,
    "total_chars": 1457,
    "chunk_sizes": [792, 541, 120]
  }

Conversion works as expected for IBM SaaS; Local Docling-Serve can run both convert and chunk methods. Confirms API endpoints are hit correctly.

Test Setup

  • Docling Serve: Local instance via Docker (quay.io/docling-project/docling-serve)
  • IBM SaaS Docling API key and base url configured
  • Test file: ogx_and_models.pdf (86 pages, 63MB, from integration test fixtures)

@sahana-sreeram
sahana-sreeram force-pushed the feat/docling-serve-asynch branch from e4c4cdd to c39f590 Compare June 16, 2026 19:53
  Docling team confirmed async endpoints work on both local and SaaS.
  Default to async mode with automatic fallback to sync on failure.
  This eliminates timeout issues under load and enables compatibility
  with IBM Docling SaaS async-only endpoints.

  - Added async submit/poll/result workflow methods
  - Implemented automatic fallback from async to sync
  - Added unit tests for async mode and fallback behavior

  Will need rebase after ogx-ai#5627 merges.

Signed-off-by: Sahana Sreeram <[email protected]>
…g-serve using docling-slim's new asyncio capabilities.

  Adds support for async endpoints using AsyncDoclingServiceClient with automatic
  fallback to sync. Updates base_url to remove /v1 suffix (SDK adds it internally).
  Adds unit tests for async mode.

Signed-off-by: Sahana Sreeram <[email protected]>
@sahana-sreeram
sahana-sreeram force-pushed the feat/docling-serve-asynch branch from cafe291 to 2c26574 Compare June 16, 2026 19:58
Fix api_key type (str not Optional), remove unsupported chunking_max_tokens,
fix ChunkedDocumentResultItem handling (object not dict).

Signed-off-by: Sahana Sreeram <[email protected]>
@mergify

mergify Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@mergify mergify Bot added the needs-rebase label Jun 17, 2026
…g-serve

Integrate AsyncDoclingServiceClient to support async endpoints for both
IBM Docling SaaS and local docling-serve.

- Use AsyncDoclingServiceClient for async conversion
- Handle dual response formats (presigned URLs for SaaS, direct documents for local)
- Block chunking for IBM SaaS with clear error (not supported)
- Require docling-slim[service-client]>=2.103.0

This enables IBM Docling SaaS, which only provides async endpoints.

Signed-off-by: Sahana Sreeram <[email protected]>
@mergify mergify Bot removed the needs-rebase label Jun 17, 2026
sahana-sreeram and others added 3 commits June 17, 2026 16:19
…M SaaS chunking

Fixed URL matching by catching HTTP 404/405 responses instead of checking for 'ibm.com' in URL.
This resolves the CodeQL security warning and makes the code self-correcting if IBM adds chunking support later.

Signed-off-by: Sahana Sreeram <[email protected]>
Comment on lines +31 to +37
mode: str = Field(
default="async",
description=(
"API mode: 'async' (use asynchronous submit/poll endpoints, recommended for both local and SaaS), "
"'sync' (use synchronous endpoints, fallback option), or 'auto' (detect server capabilities)"
),
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Literal["async", "sync", "auto"] to get Pydantic validation at config load time

sdk_module="docling.service_client",
)
conversion_method = "async"
except Exception as e:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This catches all exceptions including InvalidParameterError, which _convert_and_chunk_async raises when IBM SaaS returns 404/405 for unsupported chunking. That user-facing error gets silently swallowed, a redundant sync request hits the same 404/405, and only then does the error reach the caller.

Also, mode='async' and mode='auto' behave identically here — both fall back to sync on any failure. If a user sets mode='async', they probably don't expect a silent sync fallback.

Consider narrowing the catch and only falling back in auto mode:

  except (httpx.ConnectError, httpx.TimeoutException) as e:
      if self.config.mode == "auto":
          log.warning("Async failed, falling back to sync", error=str(e))
          chunks = None
      else:
          raise

@sahana-sreeram sahana-sreeram Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0d54af1, now using your exact code suggestion which:

  • Catches network errors (httpx.ConnectError, httpx.TimeoutException)
  • In auto mode: falls back to sync on network errors. In async mode: raises immediately
  • InvalidParameterError raised up immediately (without sync retry)

Comment thread src/ogx/providers/remote/file_processor/docling_serve/docling_serve.py Outdated
sahana-sreeram and others added 3 commits June 24, 2026 16:49
Add Literal type validation, narrow exception handling to network errors only, and only fallback in auto mode.

Signed-off-by: Sahana Sreeram <[email protected]>
Signed-off-by: Sahana Sreeram <[email protected]>
@sahana-sreeram
sahana-sreeram requested a review from alinaryan June 24, 2026 21:15
@mattf

mattf commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

@alinaryan pls ping me when you've approved this

@alinaryan alinaryan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I have one nit, but non-blocking

)

@pytest.fixture
def config_async(self) -> DoclingServeFileProcessorConfig:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_fallback_from_async_to_sync takes config_async in its signature but creates its own config_auto inside the body. The fixture is instantiated but never used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed (2c222f6) - the parameter was left over from earlier testing. Also renamed the test to test_auto_mode_falls_back_to_sync to be more representative of its behavior after review code fixes

Comment thread src/ogx/providers/remote/file_processor/docling_serve/docling_serve.py Outdated
Comment thread src/ogx/providers/remote/file_processor/docling_serve/config.py
@sahana-sreeram
sahana-sreeram requested a review from mattf June 29, 2026 15:01
@mattf
mattf added this pull request to the merge queue Jun 29, 2026
@mattf
mattf removed this pull request from the merge queue due to a manual request Jun 29, 2026
@mattf
mattf enabled auto-merge June 29, 2026 17:36
@mattf
mattf added this pull request to the merge queue Jun 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Jun 29, 2026
@mattf
mattf added this pull request to the merge queue Jun 29, 2026
Merged via the queue into ogx-ai:main with commit 5a21c2a Jun 29, 2026
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants