Padded function-call name is answered under the trimmed name, so the next request fails with 400 INVALID_ARGUMENT

Open Beginner friendly
#30,256 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@arifrhm is already working on this.

Since Nov 13, 2026.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript
Domain
api, cli

Research direction

Start in packages/core/src/core/turn.ts at Turn.handlePendingFunctionCall and trace how the function-call name and response are added to history. Add regression coverage for a padded function-call name, then verify the next request sends the call and response with matching names. Done means the request no longer pairs the original padded name with the trimmed response name.

Written by the indexing model from the issue text.

Description

area/agent status/need-triage
What happened?

In headless runs (gemini --model gemini-4-argon --approval-mode yolo --output-format text --prompt …), about one run in six fails right after the model's first round of tool calls with:

Error when talking to Gemini API … {"error":{"code":400,"message":"Request contains an invalid argument.","status":"INVALID_ARGUMENT"}}

Every failure we captured has the same trigger: the model's first function call came back with a leading space in its name, " update_topic".

Turn.handlePendingFunctionCall (packages/core/src/core/turn.ts) trims the name to dispatch the call and to build its response:

const name = fnCall.name?.trim() || 'generic_tool';
...
// Mutate the function call object ID so that history consolidation inherits it
fnCall.id = callId;

It writes the new id back onto the history object but not the trimmed name. The next request therefore pairs the call and its response under different names, with the same id:

model: functionCall      name=" update_topic"  id="update_topic_…"
user:  functionResponse  name="update_topic"   id="update_topic_…"

The API rejects that request with 400 INVALID_ARGUMENT.

Reproduction, no API key needed. Point the CLI at a stand-in server with GOOGLE_GEMINI_BASE_URL (and security.auth.selectedType: "gemini-api-key"). The server answers the first streamGenerateContent with a parallel call whose first name is padded, then logs the second request:

// node mock.mjs <port>
import http from 'node:http';
let n = 0;
http.createServer((req, res) => {
  let body = '';
  req.on('data', (c) => (body += c));
  req.on('end', () => {
    if (!req.url.includes(':streamGenerateContent')) {
      res.writeHead(200, { 'Content-Type': 'application/json' });
      return res.end(JSON.stringify({ totalTokens: 1, candidates: [{ content: { role: 'model', parts: [{ text: '{}' }] } }] }));
    }
    n += 1;
    if (n === 2) {
      for (const c of JSON.parse(body).contents)
        for (const p of c.parts ?? [])
          if (p.functionCall || p.functionResponse) console.log(c.role, JSON.stringify(p.functionCall ?? p.functionResponse).slice(0, 80));
    }
    const parts = n === 1
      ? [{ functionCall: { name: ' update_topic', args: {} }, thoughtSignature: 'c2ln' },
         { functionCall: { name: 'read_file', args: { file_path: 'README.md' } } }]
      : [{ text: 'done' }];
    res.writeHead(200, { 'Content-Type': 'text/event-stream' });
    res.end(`data: ${JSON.stringify({ candidates: [{ content: { role: 'model', parts }, finishReason: 'STOP' }] })}\n\n`);
  });
}).listen(Number(process.argv[2]), '127.0.0.1');

With 0.66.0 the second request carries name: " update_topic" on the call and name: "update_topic" on the response. A padded " read_file" behaves the same, so this is not specific to one tool.

What did you expect to happen?

The call and its response should carry the same name in the request that goes back to the API. The smallest fix is to write the trimmed name back next to the id:

fnCall.id = callId;
fnCall.name = name;

Alternatively, answer the call under its original, untrimmed name.

Client information
  • @google/gemini-cli 0.66.0 from npm, Node 24, run headless (--prompt), so no /about output.
  • Seen on Linux in CI; reproduced on macOS with the stand-in server above.
  • handlePendingFunctionCall on main is unchanged as of 2026-11-12.
Login information

API key (GEMINI_API_KEY).

Anything else we need to know?
  • Workaround. general.topicUpdateNarration: false withdraws update_topic, which was the only tool we saw padded.
  • The error report misleads. For this failure, the Turn.run-sendMessageStream client error report shows the function-response turn twice. The report is built from the chat history plus the failed request, and GeminiChat.sendMessageStream keeps a failed function-response send in the history (it rolls back other kinds). The duplicate is therefore only in the report, but it looks like a duplicated turn and hides the real cause.
Dominant language
TypeScript
Stars
109k
Forks
14.9k
Avg merge
1d 2h
Merged PRs (30d)
111

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from google-gemini/gemini-cli

All issues in google-gemini/gemini-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.