Padded function-call name is answered under the trimmed name, so the next request fails with 400 INVALID_ARGUMENT
Maintainers usually reply within 1 day
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
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
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-cli0.66.0 from npm, Node 24, run headless (--prompt), so no/aboutoutput.- Seen on Linux in CI; reproduced on macOS with the stand-in server above.
handlePendingFunctionCallonmainis unchanged as of 2026-11-12.
Login information
API key (GEMINI_API_KEY).
Anything else we need to know?
- Workaround.
general.topicUpdateNarration: falsewithdrawsupdate_topic, which was the only tool we saw padded. - The error report misleads. For this failure, the
Turn.run-sendMessageStreamclient error report shows the function-response turn twice. The report is built from the chat history plus the failed request, andGeminiChat.sendMessageStreamkeeps 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
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from google-gemini/gemini-cli
-
status/need-triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
google-gemini/gemini-cli#30328 · 1 comment ·
Maintainers usually reply within 1 day
-
status/need-triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
google-gemini/gemini-cli#30242 · 1 comment ·
Maintainers usually reply within 1 day
-
Auto-update runs npm install -g when a Gemini CLI source checkout is run from outside the clonePossibly taken @tanveerhkit claimed this 4 days ago. Openarea/core effort/small status/bot-triaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
google-gemini/gemini-cli#30209 · 6 comments ·
Maintainers usually reply within 1 day
-
status/need-triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
google-gemini/gemini-cli#30127 ·
Maintainers usually reply within 1 day
-
web_fetch keeps a trailing comma on URLs in a comma-separated listMay be free again @tneemo claimed this 25 days ago, and no pull request is open. Openarea/agent status/need-triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
google-gemini/gemini-cli#29896 · 2 comments ·
Maintainers usually reply within 1 day
All issues in google-gemini/gemini-cli
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
vercel-labs/ui#809 ·
Maintainers usually reply within 1 day
-
bot:ai-assisted component:platform-js status:untriaged
Difficulty 1/5 Under an hour Newbie friendliness 74/100
midnightntwrk/platform-js#38 ·
-
[bug] Second false positive on high-cost plugin alert: detection only compares patch entry id, community plugin dsh-auto | [bug] 高成本插件告警第二次误报:检测只比对 patch 条目 id,社区插件 dsh-auto-review 被认成 @deepseek-ai/dsh-experimental-auto-reviewPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ranxianglei/billion-context#7068 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
mybigday/whisper.rn#348 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
six-group/six-webcomponents#600 ·