Skip to content

fix(agents): skip tool calls without valid name on model switch#43985

Open
guang384 wants to merge 9 commits intoopenclaw:mainfrom
guang384:fix/issue-43930
Open

fix(agents): skip tool calls without valid name on model switch#43985
guang384 wants to merge 9 commits intoopenclaw:mainfrom
guang384:fix/issue-43930

Conversation

@guang384
Copy link
Copy Markdown

Summary

Fixes #43930

Problem

When switching between models (e.g., Gemini → Grok → Gemini), the context may contain function_response entries that were valid for the previous model but cause errors for Gemini API with:

INVALID_ARGUMENT: Name cannot be empty
GenerateContentRequest.contents[N].parts[0].function_response.name: Name cannot be empty

Root Cause

When switching models mid-session, the conversation history contains tool calls from the previous model. These may have different format requirements. Gemini API requires function_response.name to be non-empty, but other models may allow empty names.

Solution

Skip tool calls without valid name during message conversion in convertMessagesToInputItems(). This prevents the INVALID_ARGUMENT error from Gemini API.

Related

Test

  1. Configure Gemini Latest Flash
  2. Switch to Grok mid-session
  3. Switch back to Gemini Latest Flash
  4. Send a message - should work without error

Fixes openclaw#43930

When switching between models (e.g., Gemini → Grok → Gemini), the context
may contain function_response entries that were valid for the previous
model but cause errors for Gemini API with 'Name cannot be empty'.

This fix skips tool calls without valid name during message conversion,
preventing the INVALID_ARGUMENT error from Gemini API.

Related to PR openclaw#41173 which added stripRuntimeModelState() for session reset,
but model switching is a different scenario that needs separate handling.
@openclaw-barnacle openclaw-barnacle bot added agents Agent runtime and tooling size: XS labels Mar 12, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 12, 2026

Greptile Summary

This PR correctly completes the fix for the INVALID_ARGUMENT: Name cannot be empty Gemini error during model switches by addressing all three gaps identified in previous review rounds: orphaned function_call_output entries, the unreachable !callId guard, and missing regression tests.

Key changes:

  • Introduces a skippedCallIds: Map<string, boolean> in convertMessagesToInputItems() that records whether a given callId had a valid function_call emitted (true) or was skipped due to an empty name (false)
  • When a toolResult is processed, any callId mapped to false causes the corresponding function_call_output to be suppressed, eliminating the previously-orphaned entry
  • The delete on skip plus true-overwrite on valid emission correctly handles the edge case where the same callId is reused (first skipped, then valid) without blocking the legitimate output
  • Two focused tests are added: one for the empty-name function_call drop, and one verifying the paired function_call_output is also suppressed

Confidence Score: 4/5

  • Safe to merge — correctly suppresses both the function_call and its paired function_call_output for empty-name tool calls, with regression tests covering the core scenario.
  • The logic is sound across all traced cases (skipped call, valid call, ID reuse). All three issues raised in previous review threads are addressed. The one minor observation is that skippedCallIds.set(callId, true) for valid calls stores entries that are never evaluated on the true branch (since the only guard is === false), making those entries functionally inert — but this causes no behavioral difference and adds negligible overhead. No regressions are introduced for existing paths.
  • No files require special attention.

Last reviewed commit: 5be87be

@katoue

This comment was marked as spam.

@guang384
Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@guang384
Copy link
Copy Markdown
Author

@greptileai review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c1aaed1cdc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@guang384
Copy link
Copy Markdown
Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1b9c24fd39

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@guang384
Copy link
Copy Markdown
Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 557d3e9d91

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@guang384
Copy link
Copy Markdown
Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 22c1c66023

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@guang384
Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@guang384
Copy link
Copy Markdown
Author

@greptileai review

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

Labels

agents Agent runtime and tooling size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: LLM Error switching default agent from Gemini

2 participants