Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Jan 13, 2026

Summary

Fixes Gemini API validation error where empty tool result content causes "Unable to submit request because it must include at least one parts field" error.

Problem

Users were encountering an ApiProviderError when using Gemini models via OpenRouter because tool result messages with empty content fail Gemini's validation requirements.

Root Cause

While most tool execution paths add fallback content, empty content can still reach the API from:

  • Legacy/persisted conversations stored before fallbacks were added
  • Resumed tasks from history with empty tool results
  • Context condensation where tool results may lose content
  • MCP tools with empty responses (processToolContent returns "" for empty results)

Solution

Applied a defensive fix at the transformation layer in src/api/transform/openai-format.ts:

content: content || "(empty)",

This is the correct location because:

  • It's the last transformation before the API call
  • It catches ALL edge cases regardless of origin
  • It doesn't require changes across multiple tool execution paths

Testing

  • Added 3 test cases covering empty string, undefined, and empty array content
  • All 27 tests in openai-format.spec.ts pass

PostHog Reference

https://us.posthog.com/error_tracking/019bb191-73dd-7471-8079-4723c6b2efa0

Closes ROO-517


Important

Fixes Gemini API validation by using "(empty)" placeholder for empty tool result content in convertToOpenAiMessages() in openai-format.ts.

  • Behavior:
    • Fixes Gemini API validation error by using "(empty)" placeholder for empty tool result content in convertToOpenAiMessages() in openai-format.ts.
    • Handles cases with empty string, undefined, and empty array content.
  • Testing:
    • Adds test cases for empty content scenarios in openai-format.spec.ts.
    • Ensures all 27 tests in openai-format.spec.ts pass.
  • Misc:
    • Closes issue ROO-517.

This description was created by Ellipsis for 5ef90c7. You can customize this summary. It will automatically update as commits are pushed.

…validation

Gemini (via OpenRouter) requires function responses to have non-empty content
in the 'parts' field. Empty content causes validation failure with error:
'Unable to submit request because it must include at least one parts field'

Added defensive fix in openai-format.ts transformation layer to use '(empty)'
placeholder when tool result content is empty (string, undefined, or empty array).

Added 3 test cases covering the empty content scenarios.

Closes ROO-517
@daniel-lxs daniel-lxs requested review from cte, jr and mrubens as code owners January 13, 2026 00:14
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Jan 13, 2026
@roomote
Copy link
Contributor

roomote bot commented Jan 13, 2026

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

This is a well-targeted fix that correctly handles empty tool result content for Gemini API compatibility. The change is minimal, properly placed at the transformation layer, and has good test coverage.

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap Jan 13, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 13, 2026
@mrubens mrubens merged commit 78821a3 into main Jan 13, 2026
20 checks passed
@mrubens mrubens deleted the feature/roo-517-fix-gemini-api-error-empty-tool-result-content-causes-parts branch January 13, 2026 06:39
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jan 13, 2026
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants