← Back to Pull requests

fix(messages): convert document blocks in user content #1679

Open
unknown opened this pull request with 392 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 26, 2026 12:44 UTC
Author

Description


A document block in a user message was forwarded as-is to the completion bridge, while the same block inside a tool result was already converted by _convert_document_block_to_openai. OpenAI-compatible backends got an Anthropic-shaped part they don't accept, and Gemini skipped it, so the model never saw the document.

_convert_user_blocks_to_openai now converts document blocks with _convert_document_block_to_openai, like the tool-result path: base64 and url sources become a file part, and text/content sources become a text part. An empty source raises InvalidRequestError, as it does in a tool result. Other unknown block types are still kept as-is.

The Responses path builds its input from the same converted messages, so a user document now goes as input_file. I updated the one assertion in test_messages_params_to_responses_params_maps_request_fields that expected the raw document block.

Wire output after the change, same request as in the issue:

[openai] {"type": "file", "file": {"file_data": "data:application/pdf;base64,JVBERi0xLjQKJcfsj6IK"}}
[gemini] {"inlineData": {"data": "JVBERi0xLjQKJcfsj6IK", "mime_type": "application/pdf"}}

PR Type

  • 🐛 Bug Fix
  • Relevant issues


    Fixes #1678

    Checklist


  • I understand the code I am submitting.

  • I have added unit tests that prove my fix/feature works

  • I have run this code locally and verified it fixes the issue.

  • New and existing tests pass locally

  • Documentation was updated where necessary

  • I have read and followed the contribution guidelines

  • AI Usage:

  • - [ ] No AI was used.
    - [ ] AI was used for drafting/refactoring.
    - [x] This is fully AI-generated.

    AI Usage Information

  • AI Model used:

  • AI Developer Tool used:

  • Any other info you'd like to share:
  • I am an AI Agent filling out this form (check box if true)
  • Testing details: new tests in tests/unit/test_messages_compat.py (base64, url and text sources in user content, and an empty source) fail on main and pass with the change. test_messages_compat.py, test_openai_base_provider.py and test_gemini_provider.py: 746 passed, 5 skipped. Across tests/unit with the extras I have installed, the change fixes exactly these 5 failures and adds none (the rest fail on main too, for provider SDKs that aren't installed). ruff check/ruff format --check (0.17.3), mypy and codespell pass on the changed files. I did not run integration tests (no provider keys).

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    New Features
    User messages can now include documents provided as text, encoded files, or URLs. These are converted into compatible text or file content when sent to supported services.
    Bug Fixes
    Requests with document attachments that lack required file data now return a clear error instead of being processed as valid attachments.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 392 lines (+294 / -98) across 4 files Reviewer: shlokbam Review duration: 6153m
    All Vouch review confidence checks passed
    Residual risk 0.26 = Change Risk (0.48) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 392 lines diff across 4 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.357
    Shallow Review Depth shallow_review_depth
    0.344
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #1679"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 48.1% (MEDIUM) · Higher = larger blast radius
    48.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.7% · Safe to merge
    25.7%