Skip to content

fix(vlm): read the streamed API answer from reasoning_content/tool calls and report stream errors - #5033

Open
pcbeingused333 wants to merge 1 commit into
docling-project:mainfrom
pcbeingused333:fix/vlm-api-streaming-fallback
Open

pcbeingused333 wants to merge 1 commit into
docling-project:mainfrom
pcbeingused333:fix/vlm-api-streaming-fallback

Conversation

@pcbeingused333

Copy link
Copy Markdown

Continues #4561.

api_image_request_streaming read the answer from delta.content only, and a server error inside the stream ended the call as if it had succeeded.

  • Fallback. The non-streaming path (_extract_generated_text) falls back to reasoning_content and then to the text in the tool-call arguments when content is empty, because some OpenAI-compatible servers route the whole answer there. The streaming path now does the same: it collects delta.reasoning_content and the delta.tool_calls[].function.arguments fragments (joined per call index), and uses them when no content was streamed. content still wins, and the stoppers still look at content only.
  • Error chunks. An SSE chunk of the form data: {"error": {...}} with no choices was skipped like any unexpected shape and the stream ended as END_OF_SEQUENCE with whatever text had arrived. It now ends the call the way an HTTP error does: an empty result with error set and INFERENCE_ERROR, so the page is reported as failed instead of as a truncated success.

Checklist:

  • Documentation has been updated, if necessary. (not needed: no user-facing option changes)
  • Examples have been added, if necessary. (not needed)
  • Tests have been added, if necessary.

Review evidence: four tests in tests/test_api_image_request.py (TestApiImageRequestStreamingFallbacks): reasoning-only stream, tool-call-argument stream split over two chunks, content taking precedence over reasoning_content, and an error chunk after partial text. On main three of them fail (the precedence one already passed); with the change tests/test_api_image_request.py and tests/test_api_usage_propagation.py pass (28 tests) and ruff check is clean. mypy, the full suite and requests against a real server were not run.

This change was prepared with AI assistance (Claude Code).

🤖 Generated with Claude Code

…lls and report stream errors

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @pcbeingused333, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working error-handling vlm-pipeline labels Oct 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit b4c090f3e4. The analysis read the diff only. It did not run code from this pull request.

The streaming API request path now uses reasoning_content or tool-call arguments as the answer when no content arrives. An error chunk in the stream (data: {"error": ...}) now returns a failed result with INFERENCE_ERROR.

Topic labels added: bug, vlm-pipeline, error-handling.

CI safety: no concern found. A maintainer must still approve CI.

1 related pull request(s) in the same code
PR State Signal Assessment
#4561 merged referenced as #4561 related: The merged PR added _failed_streaming_request and error handling for HTTP and connection failures. This PR builds on that helper and adds the reasoning_content/tool-call fallback and in-stream error chunks. These are different changes.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@github-actions github-actions Bot 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.

AI first review (advisory): no blocker found

This review covers the full diff at b4c090f3e4. It read the code and did not run it.

I checked that streaming fallbacks for reasoning content and tool-call arguments align with the non-streaming path, and that SSE error chunks are correctly caught to report failures instead of truncations. All added test cases are complete and valid.

A maintainer makes the merge decision. This review never approves the pull request.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Oct 27, 2026
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.95652% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/utils/api_image_request.py 86.95% 0 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@PeterStaar-IBM

Copy link
Copy Markdown
Member

@cau-git I think we need to think about this one ...

)
text = "".join(full_text)
if not text:
text = "".join(reasoning_text).strip()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not sure we want the reasoning or tool-call in the text. It would be cleaner to have dedicated fields for those in the return object and assign them.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@cau-git ^^ what is your opinion

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) bug Something isn't working error-handling vlm-pipeline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants