← Back to Pull requests

fix(model/openaimodel): refuse media in system and developer Responses messages #1887

Open
unknown opened this pull request with 575 lines diff across 7 files
View on GitHub
unknown unknown commented on Oct 17, 2026 01:24 UTC
Author

Please ensure you have read the contribution guide before creating a pull request.

Linked issue

1. Link the issue this change is for. Required for everything except small
documentation and typo fixes. If no issue exists yet, please open one first.

  • Closes: #1881

  • Related: #1543
  • 2. Describe the change:

    _If applicable, please follow the issue templates to provide as much detail as
    possible._

    Problem:
    On the Responses endpoint, newMessage converted media parts in system and developer turns into input_image / input_file. The OpenAI API rejects those roles with a 400 (Invalid value: 'input_image'. Supported values are: 'input_text'.). Chat Completions already refuses the same content locally with openai: media in a %s message is not supported: %s. Callers on Responses only saw a server error.

    Solution:
    Refuse media in those roles inside newMessage before building content, using the same error string as Completions so the caller gets a local error that names the role. User-role media is unchanged. Assistant media was already refused in newOutputMessage.

    Python Labs Responses still attaches media for system/developer and only skips it for assistant (src/google/adk/models/lite_llm/_openai_responses_llm.py). This Go change matches Go Chat Completions instead of that path, because the Responses API does not accept input_image on those roles.

    Behavior change

    What behaves differently for someone already on the current release?

    A Responses request whose contents include media on a system or developer message now fails in buildParams with openai: media in a {role} message is not supported: {mime} instead of being sent and rejected by the API with HTTP 400. User and assistant turns are unchanged. A request that never put media in those roles is unaffected.

    Testing Plan

    _Please describe the tests that you ran to verify your changes. This is required
    for all PRs that are not small documentation or typo fixes._

    Unit Tests:

  • All unit tests pass locally.
  • With your source change reverted and your tests kept, which test fails?

    TestBuildParams_Media/image_in_a_system_message_is_refused and TestBuildParams_Media/image_in_a_developer_message_is_refused. Both fail with buildParams() err = nil, want an error when request.go is reverted to unmodified upstream/main.

    Commands:

    go test -race -count=1 ./model/openaimodel/internal/responses/ -run 'TestBuildParams_Media$'
    go test -race -count=1 ./model/openaimodel/...
    golangci-lint run
    

    Before (tests added, newMessage unmodified):

    --- FAIL: TestBuildParams_Media (0.00s)
        --- FAIL: TestBuildParams_Media/image_in_a_system_message_is_refused (0.00s)
            request_test.go:1001: buildParams() err = nil, want an error
        --- FAIL: TestBuildParams_Media/image_in_a_developer_message_is_refused (0.00s)
            request_test.go:1001: buildParams() err = nil, want an error
    FAIL
    FAIL	google.golang.org/adk/v2/model/openaimodel/internal/responses	0.024s
    FAIL
    

    After the newMessage guard:

    ok  	google.golang.org/adk/v2/model/openaimodel	4.859s
    ok  	google.golang.org/adk/v2/model/openaimodel/internal/completions	2.262s
    ok  	google.golang.org/adk/v2/model/openaimodel/internal/responses	1.472s
    ok  	google.golang.org/adk/v2/model/openaimodel/internal/shared	1.023s
    

    golangci-lint v2.3.1 (repo config):

    0 issues.
    

    Manual End-to-End (E2E) Tests:

    Not run against a live OpenAI Responses API (no credentials in this environment; LLM traffic in this package is replayed). The unit cases exercise buildParams with {Role: "system"|"developer", Parts: [{InlineData: {MIMEType: "image/png", Data: ...}}]} — the same shape as the issue reproduction. A live check would be: API: APIResponses with that content and assert the local error rather than HTTP 400.

    Checklist

  • I have read the CONTRIBUTING.md document.

  • I have performed a self-review of my own code.

  • I have commented my code, particularly in hard-to-understand areas.

  • I have added tests that prove my fix is effective or that my feature works.

  • New and existing unit tests pass locally with my changes.

  • I have manually tested my changes end-to-end.

  • Any dependent changes have been merged and published in downstream modules.
  • Additional context

    This change was prepared with AI assistance. I remain responsible for the contribution and have reviewed it.

    Diff: 575 lines (+431 / -144) across 7 files Reviewer: ktsoator Review duration: 8089m
    All Vouch review confidence checks passed
    Residual risk 0.31 = Change Risk (0.55) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.55 · 575 lines diff across 7 files
    0.55
    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%
    42%
    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.380
    Shallow Review Depth shallow_review_depth
    0.344
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #1887"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% 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: 54.8% (MEDIUM) · Higher = larger blast radius
    54.8%
    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: 43.0% · Lower = rushed or shallow review
    43.0%
    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: 31.3% · Safe to merge
    31.3%
    Repository