Skip to content

fix(github-copilot): place image prompt in user content for Gemini compatibility - #80442

Closed
afunnyhy wants to merge 3 commits into
openclaw:mainfrom
afunnyhy:fix/copilot-gemini-prompt-format
Closed

afunnyhy wants to merge 3 commits into
openclaw:mainfrom
afunnyhy:fix/copilot-gemini-prompt-format

Conversation

@afunnyhy

@afunnyhy afunnyhy commented May 10, 2026 •

Copy link
Copy Markdown

When shouldPlaceImagePromptInUserContent returns false, the image prompt is placed in a system message while the user message contains only image data. Copilot-hosted Gemini models reject this format with "Request must contain at least one non-empty message" (400).

Return true for github-copilot provider so the prompt text travels in the user message alongside the image, matching the format Copilot Gemini expects.

Refs: #79946, Follow-up to #80393

Summary

  • Problem: The image tool traditionally places the text prompt in a system message and isolated image data in a user message. When routed through GitHub Copilot to Gemini backends (like gemini-3.1-pro-preview), this payload format is strictly rejected with a 400 error because it expects non-empty text inside the user message.
  • Why it matters: Even after fixing the Copilot authentication bypass (PR fix(github-copilot): exchange API token for image tool requests and update IDE headers #80393), users still cannot use Gemini multi-modal models due to this structural incompatibility.
  • What changed: Added a provider check (model.provider === "github-copilot") to shouldPlaceImagePromptInUserContent to return true, ensuring the text prompt and image data are bundled together in the user message's content array.
  • What did NOT change (scope boundary): Logic for openrouter and other default providers remains completely untouched.

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • Skills / tool execution
  • Integrations
  • API / contracts

Linked Issue/PR

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: 400 Payload-format error when using github-copilot/gemini-3.1-pro-preview in the image tool.
  • Real environment tested: Ubuntu 22.04 on WSL2, Node.js v22.22.2
  • Exact steps or command run after this patch:
    1. Configured default image model to github-copilot/gemini-3.1-pro-preview.
    2. Executed a prompt with an image: Describe this image, focusing on expressions.
  • Evidence after fix:
    Terminal output - successful image description
  • Observed result after fix: The image tool successfully built the payload format accepted by Gemini. The 400 empty message error is completely resolved, and the agent returns a valid image description.
  • What was not tested: Claude-series models via Copilot (they do not support image input on Copilot's API — returns model_not_supported). Legacy models without vision capabilities (not routed to image tool). Live multi-image payloads and edge cases with very long prompts.
  • Before evidence:
    Terminal output - 400 error before fix

Root Cause (if applicable)

  • Root cause: Provider format strictness. The Copilot API gateway (specifically when routing to Gemini backends) enforces a strict structural requirement that user messages contain text content. It rejects multi-modal arrays that exclusively contain image_url types when the text prompt is separated into a system role.
  • Missing detection / guardrail: Provider format divergence was not tested against live Copilot Gemini endpoints.
  • Contributing context: This was exposed only after the auth routing for Copilot image requests was fixed in fix(github-copilot): exchange API token for image tool requests and update IDE headers #80393, unblocking traffic to the Gemini models.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:

    • Unit test
  • Target test or file: src/media-understanding/image.test.ts

  • Scenario the test should lock in: Two unit tests in describeImageWithModel:

    1. places image prompt in user content for github-copilot provider — verifies that when provider === "github-copilot", the context passed to complete() has NO systemPrompt and the user message contains both text and image content types.
    2. does not place image prompt in user content for non-copilot providers — verifies that non-Copilot models (tested with openai) retain the original behavior: systemPrompt is set and the user message contains only image blocks.
  • Why this is the smallest reliable guardrail: These tests lock in the payload shape at the complete() call boundary without requiring live endpoint calls, covering both codepaths (copilot and non-copilot).

User-visible / Behavior Changes

Users can finally use github-copilot/gemini-3.1-pro-preview for multi-modal image tasks seamlessly.

Diagram (if applicable)

Before (400 Error):
[Message 1] role: "system", content: "Describe this image"
[Message 2] role: "user", content: [{ type: "image_url", url: "..." }]

After (200 OK):
[Message 1] role: "user", content: [
  { type: "text", text: "Describe this image" },
  { type: "image_url", url: "..." }
]

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No
  • If any Yes, explain risk + mitigation: N/A. Pure payload formatting change.

Repro + Verification

Environment

  • OS: WSL2 (Ubuntu 22.04.5 LTS)
  • Runtime/container: Node.js
  • Model/provider: github-copilot/gemini-3.1-pro-preview
  • Relevant config (redacted): imageModel: { primary: "github-copilot/gemini-3.1-pro-preview" }

Steps

  1. Make sure the PR fix(github-copilot): exchange API token for image tool requests and update IDE headers #80393 auth fix is applied.
  2. Set the image model to github-copilot/gemini-3.1-pro-preview in openclaw.json.
  3. Send an image with a text prompt to the agent.

Expected

The API returns a 200 OK and successfully describes the image.

Actual

(Before patch) 400 Bad Request: Request must contain at least one non-empty message.

Evidence

Attach at least one:

  • Screenshot/recording

Screenshots embedded in the Real behavior proof section above.

Human Verification (required)

  • Verified scenarios: Live Copilot subscription with gemini-3.1-pro-preview — successfully received an image description without any payload rejection.
  • Edge cases checked: Live-tested across all Copilot models that support image input:
    • github-copilot/gemini-3.1-pro-preview ✅
    • github-copilot/gpt-4.1 ✅
    • github-copilot/gpt-5.2 ✅
    • github-copilot/gpt-4o ✅
      The { role: "user", content: [{text}, {image_url}] } format is the canonical OpenAI multimodal schema and is natively supported by all tested models behind Copilot.
  • What you did not verify: Legacy models without vision capabilities (as they shouldn't be routed to the image tool anyway).

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Risks and Mitigations

  • Risk: Altering the payload structure for all github-copilot image models might inadvertently affect how other models (e.g., GPT-4o or Claude) process the system instructions.
  • Mitigation: The updated structure (bundling text + image array inside the user message) is the standard OpenAI schema and is natively supported by GPT-4o, Claude 3.5, and Gemini. It is fundamentally safe and arguably more standard for multi-modal requests than splitting it.

Copilot AI review requested due to automatic review settings May 10, 2026 22:39
@openclaw-barnacle openclaw-barnacle Bot added size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 10, 2026

Copilot AI 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.

Pull request overview

Fixes GitHub Copilot–hosted Gemini multimodal requests by ensuring the text prompt is included in the user message content (alongside image blocks), avoiding Copilot Gemini’s 400 "Request must contain at least one non-empty message" rejection.

Changes:

  • Force shouldPlaceImagePromptInUserContent() to return true for model.provider === "github-copilot".
  • Add unit coverage to lock in the Copilot vs non-Copilot request-shape behavior at the complete() call boundary.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/media-understanding/image.ts Routes Copilot image requests through the “prompt in user content” path to satisfy Gemini’s strict payload requirements.
src/media-understanding/image.test.ts Adds regression tests verifying Copilot gets {text + image} in the user message and non-Copilot retains {systemPrompt + image-only user}.

@clawsweeper

clawsweeper Bot commented May 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Summary
The PR makes GitHub Copilot image requests put prompt text in the user content array with image blocks and adds Copilot/non-Copilot payload-shape tests.

Reproducibility: yes. Current main has a source-backed path that sends Copilot image requests as systemPrompt plus image-only user content, and the supplied before screenshot shows Copilot Gemini rejecting that shape; I did not run a live credentialed Copilot repro locally.

Real behavior proof
Sufficient (screenshot): The PR body includes before/after screenshots showing the real Copilot Gemini image-tool failure and a successful image description after the patch.

Next step before merge
No repair job is needed; maintainers should review and land this with or after the linked Copilot image-auth PR once normal checks are acceptable.

Security
Cleared: The diff only changes provider payload formatting and focused tests; it adds no dependency, workflow, secret-handling, permission, or execution-surface change.

Review details

Best possible solution:

Land this payload-format fix with or after the Copilot image-auth fix, preserving non-Copilot behavior and the focused regression coverage.

Do we have a high-confidence way to reproduce the issue?

Yes. Current main has a source-backed path that sends Copilot image requests as systemPrompt plus image-only user content, and the supplied before screenshot shows Copilot Gemini rejecting that shape; I did not run a live credentialed Copilot repro locally.

Is this the best way to solve the issue?

Yes. Extending the existing prompt-in-user-content seam to github-copilot is the narrowest maintainable fix for the payload-format portion, with tests covering both the new Copilot path and retained non-Copilot behavior.

Acceptance criteria:

  • pnpm test src/media-understanding/image.test.ts
  • pnpm check:changed

What I checked:

  • Current main payload shape: Current main builds image context with prompt text as systemPrompt unless shouldPlaceImagePromptInUserContent returns true, and that predicate currently only returns true for OpenRouter-shaped endpoints, not github-copilot. (src/media-understanding/image.ts:176, fd79013b8f37)
  • PR diff shape: The PR adds a github-copilot branch before the existing capability check and adds tests for Copilot user-content prompt placement and non-Copilot systemPrompt behavior. (src/media-understanding/image.ts:202, f4f4e8b1f8c0)
  • Copilot model route: The GitHub Copilot plugin can synthesize unknown Copilot model ids as image-capable provider models and maps non-Claude ids, including Gemini ids, to openai-responses. (extensions/github-copilot/models.ts:23, fd79013b8f37)
  • Dependency payload contract: @earendil-works/pi-ai 0.74.0 exposes Context.systemPrompt plus user TextContent/ImageContent arrays; its Responses transformer maps text/image arrays to input_text/input_image, and its Chat Completions transformer maps them to text/image_url blocks.
  • Real behavior proof: The supplied before screenshot shows github-copilot/gemini-3.1-pro-preview failing with 400 'Request must contain at least one non-empty message'; the after screenshot shows a successful image description.
  • Related auth dependency: The related Copilot image-token PR is still open, so this payload-format fix is useful but should be reviewed with or after that auth path fix.

Likely related people:

  • steipete: Recent public path history shows multiple media-understanding image test and image-probe commits in the affected area, and current main's tip is also authored by Peter Steinberger. (role: recent media-understanding contributor; confidence: high; commits: 3c6e0b4a95f3, b433e643bb23, e07febd07530; files: src/media-understanding/image.ts, src/media-understanding/image.test.ts)
  • efpiva: Recent Copilot model-catalog work touched the provider model surface that makes new Copilot multimodal models available to this image path. (role: recent GitHub Copilot plugin contributor; confidence: medium; commits: 75405f64d0a7; files: extensions/github-copilot/openclaw.plugin.json, extensions/github-copilot/models.ts)
  • obviyus: Earlier GitHub Copilot catalog publication work is adjacent to the provider/model routing involved in this PR. (role: adjacent Copilot catalog contributor; confidence: medium; commits: 42b352c57eb8; files: extensions/github-copilot/openclaw.plugin.json)

Remaining risk / open question:

Codex review notes: model gpt-5.5, reasoning high; reviewed against fd79013b8f37.

Re-review progress:

afunnyhy added 2 commits May 11, 2026 06:47
…mpatibility

When shouldPlaceImagePromptInUserContent returns false, the image prompt
is placed in a system message while the user message contains only image
data. Copilot-hosted Gemini models reject this format with
"Request must contain at least one non-empty message" (400).

Return true for github-copilot provider so the prompt text travels in
the user message alongside the image, matching the format Copilot Gemini
expects.

Refs: openclaw#79946
Add two tests verifying the payload structure for image context:

1. github-copilot provider: prompt and image data are bundled together
   in the user message, with NO separate systemPrompt.
2. Non-copilot provider (openai): prompt goes to systemPrompt,
   images stay in user message without text.

Refs: openclaw#79946, openclaw#80393
@afunnyhy
afunnyhy force-pushed the fix/copilot-gemini-prompt-format branch from 1d66fe0 to 7eeeaee Compare May 10, 2026 22:47
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 10, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 10, 2026
@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 11, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 11, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
steipete added a commit that referenced this pull request May 13, 2026
Fixes Copilot image understanding by exchanging OAuth tokens for Copilot API tokens, routing Copilot Gemini image requests through Chat Completions, and sending the prompt in user content with Copilot vision headers.

Real behavior proof:
- Old Responses route with real Copilot key reproduced `400 model gemini-3.1-pro-preview does not support Responses API`.
- Fixed route with the same real Copilot key returned `Cat`.
- Final CLI live smoke returned `ok: true` and `text: Cat` for `github-copilot/gemini-3.1-pro-preview`.

Verification:
- pnpm test src/media-understanding/image.test.ts extensions/github-copilot/models.test.ts extensions/github-copilot/stream.test.ts src/agents/pi-hooks/compaction-safeguard.test.ts -- --reporter=verbose
- pnpm check:changed via Blacksmith Testbox tbx_01krgt56pqmft8txekt017wke6, Actions run https://github.com/openclaw/openclaw/actions/runs/25803926150, exit 0.

Refs #80393, #80442.

Co-authored-by: Yang Haoyu <[email protected]>
@steipete

Copy link
Copy Markdown
Contributor

Thanks @afunnyhy. I landed this as part of the combined maintainer follow-up in #81429 because the two Copilot image fixes needed to be rebased and cleaned up together.

Landed commit: 0b8ee46

What landed:

  • Copilot image understanding now exchanges the GitHub OAuth token for the Copilot API token and uses the returned Copilot base URL.
  • Copilot Gemini models now use the Chat Completions payload route instead of Responses.
  • Image prompts for Copilot are placed in the user content with the image, and Copilot vision/IDE headers are sent.

Proof:

  • Before fix, the real Copilot key on the old Responses route returned 400 model gemini-3.1-pro-preview does not support Responses API.
  • After fix, the real Copilot Gemini image route returned Cat.
  • Final CLI live smoke on the landed branch returned ok: true and text: Cat for github-copilot/gemini-3.1-pro-preview.
  • pnpm check:changed passed via Blacksmith Testbox tbx_01krgt56pqmft8txekt017wke6.

Closing this PR as superseded by the landed replacement. Your commits were preserved in the replacement branch, and the squash merge includes your co-author credit.

l3ocifer pushed a commit to l3ocifer/frack-openclaw that referenced this pull request May 13, 2026
Fixes Copilot image understanding by exchanging OAuth tokens for Copilot API tokens, routing Copilot Gemini image requests through Chat Completions, and sending the prompt in user content with Copilot vision headers.

Real behavior proof:
- Old Responses route with real Copilot key reproduced `400 model gemini-3.1-pro-preview does not support Responses API`.
- Fixed route with the same real Copilot key returned `Cat`.
- Final CLI live smoke returned `ok: true` and `text: Cat` for `github-copilot/gemini-3.1-pro-preview`.

Verification:
- pnpm test src/media-understanding/image.test.ts extensions/github-copilot/models.test.ts extensions/github-copilot/stream.test.ts src/agents/pi-hooks/compaction-safeguard.test.ts -- --reporter=verbose
- pnpm check:changed via Blacksmith Testbox tbx_01krgt56pqmft8txekt017wke6, Actions run https://github.com/openclaw/openclaw/actions/runs/25803926150, exit 0.

Refs openclaw#80393, openclaw#80442.

Co-authored-by: Yang Haoyu <[email protected]>
@afunnyhy
afunnyhy deleted the fix/copilot-gemini-prompt-format branch May 18, 2026 17:18
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
Fixes Copilot image understanding by exchanging OAuth tokens for Copilot API tokens, routing Copilot Gemini image requests through Chat Completions, and sending the prompt in user content with Copilot vision headers.

Real behavior proof:
- Old Responses route with real Copilot key reproduced `400 model gemini-3.1-pro-preview does not support Responses API`.
- Fixed route with the same real Copilot key returned `Cat`.
- Final CLI live smoke returned `ok: true` and `text: Cat` for `github-copilot/gemini-3.1-pro-preview`.

Verification:
- pnpm test src/media-understanding/image.test.ts extensions/github-copilot/models.test.ts extensions/github-copilot/stream.test.ts src/agents/pi-hooks/compaction-safeguard.test.ts -- --reporter=verbose
- pnpm check:changed via Blacksmith Testbox tbx_01krgt56pqmft8txekt017wke6, Actions run https://github.com/openclaw/openclaw/actions/runs/25803926150, exit 0.

Refs openclaw#80393, openclaw#80442.

Co-authored-by: Yang Haoyu <[email protected]>
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
Fixes Copilot image understanding by exchanging OAuth tokens for Copilot API tokens, routing Copilot Gemini image requests through Chat Completions, and sending the prompt in user content with Copilot vision headers.

Real behavior proof:
- Old Responses route with real Copilot key reproduced `400 model gemini-3.1-pro-preview does not support Responses API`.
- Fixed route with the same real Copilot key returned `Cat`.
- Final CLI live smoke returned `ok: true` and `text: Cat` for `github-copilot/gemini-3.1-pro-preview`.

Verification:
- pnpm test src/media-understanding/image.test.ts extensions/github-copilot/models.test.ts extensions/github-copilot/stream.test.ts src/agents/pi-hooks/compaction-safeguard.test.ts -- --reporter=verbose
- pnpm check:changed via Blacksmith Testbox tbx_01krgt56pqmft8txekt017wke6, Actions run https://github.com/openclaw/openclaw/actions/runs/25803926150, exit 0.

Refs openclaw#80393, openclaw#80442.

Co-authored-by: Yang Haoyu <[email protected]>
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
Fixes Copilot image understanding by exchanging OAuth tokens for Copilot API tokens, routing Copilot Gemini image requests through Chat Completions, and sending the prompt in user content with Copilot vision headers.

Real behavior proof:
- Old Responses route with real Copilot key reproduced `400 model gemini-3.1-pro-preview does not support Responses API`.
- Fixed route with the same real Copilot key returned `Cat`.
- Final CLI live smoke returned `ok: true` and `text: Cat` for `github-copilot/gemini-3.1-pro-preview`.

Verification:
- pnpm test src/media-understanding/image.test.ts extensions/github-copilot/models.test.ts extensions/github-copilot/stream.test.ts src/agents/pi-hooks/compaction-safeguard.test.ts -- --reporter=verbose
- pnpm check:changed via Blacksmith Testbox tbx_01krgt56pqmft8txekt017wke6, Actions run https://github.com/openclaw/openclaw/actions/runs/25803926150, exit 0.

Refs openclaw#80393, openclaw#80442.

Co-authored-by: Yang Haoyu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants