gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

INVALID_ARGUMENT resuming a saved chat (400 BadRequest)

Open dvasya opened this issue 1 year ago • 71 comments

What happened?

After /chat save, /quit, gemini, /chat load the conversation history is showing up but the response to all prompts is:

✕ [API Error: [{
    "error": {
      "code": 400,
      "message": "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn.",
      "errors": [
        {
          "message": "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn.",
          "domain": "global",
          "reason": "badRequest"
        }
      ],
      "status": "INVALID_ARGUMENT"
    }
  }
  ]]


> What do we do with error messages like above?

✕ [API Error: [{
    "error": {
      "code": 400,
      "message": "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn.",
      "errors": [
        {
          "message": "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn.",
          "domain": "global",
          "reason": "badRequest"
        }
      ],
      "status": "INVALID_ARGUMENT"
    }
  }
  ]]

The settings.json file is pretty vanilla

{
  "theme": "Dracula",
  "selectedAuthType": "oauth-personal",
  "preferredEditor": "cursor"
}

What did you expect to happen?

Resume my chat with the entire history in the context as if I never interrupted it.

Client information

$ gemini -v
0.1.3

Login information

No response

Anything else we need to know?

No response

dvasya avatar Jun 26 '25 01:06 dvasya

same problem for me - looks like a bug

DarrenJCoxon avatar Jun 26 '25 20:06 DarrenJCoxon

Im stuck at this exact point

dudufcb1 avatar Jun 26 '25 22:06 dudufcb1

Same, it's very annoying. My workaround was to open a new chat in cursor with gemini 2.5 pro, then do this:

  1. Ask it to look through this link to find where conversations are stored: https://github.com/google-gemini/gemini-cli/tree/main
  2. Ask it to find the conversation that crashed and copy the it into a non-hidden folder
  3. Start a new conversation in gemini-cli and @ the file so it can read the last conversation.

kayazuko avatar Jun 27 '25 01:06 kayazuko

I can take a stab at this.

Initial Analysis

The Problem

When loading a saved chat that contained function calls and responses:

  1. The code was displaying function call/response items in the UI, even though they have no displayable text
  2. This created a mismatch in the chat history where the Gemini API expected function calls and responses to be properly paired

The Solution

Modified /packages/cli/src/ui/hooks/slashCommandProcessor.ts to:

  1. Continue adding all items to the chat history (to maintain API compatibility)
  2. Only display items that contain text content and aren't function calls/responses
  3. Add a check hasOnlyText to identify items that contain only text parts
  4. Skip displaying items with function calls or responses while keeping them in the history

heartyguy avatar Jun 27 '25 08:06 heartyguy

Same issue here. Guess I won't be experimenting with your software this weekend.

dhstrom avatar Jun 28 '25 15:06 dhstrom

same

somersby10ml avatar Jun 28 '25 18:06 somersby10ml

same problem here

SalmanKarkhano avatar Jun 28 '25 18:06 SalmanKarkhano

I am also getting same error

MFaiqKhan avatar Jun 28 '25 19:06 MFaiqKhan

for me this happens when it wants to take two actions, but if I want to interrupt and stop it from executing them. To do that I have to hit escape twice. And when I do that every subsequent follow up via question or slash command has this number of function response mismatch problem.

bubosanac avatar Jun 29 '25 02:06 bubosanac

I've gone back to Claude Code. Feels like it was released too early. Like Firebase Studio.

DarrenJCoxon avatar Jun 29 '25 17:06 DarrenJCoxon

One alternative that has worked for me is:

  1. Manually copy the entire current conversation from the terminal and save it to a text file, for example: history.txt.
  2. When starting a new Gemini session, you can say something like:

    “Please use the contents of the history.txt file as context to continue where we left off.”

This doesn't fix, but it allows you to continue your workflow.

KCHIPANACH avatar Jun 29 '25 20:06 KCHIPANACH

I'm hitting this same issue now after successfully using GCLI yesterday. I'll try the history.txt hack

jkaster avatar Jun 30 '25 22:06 jkaster

Same issue. For me, seems like it started happening after I setup the Supabase mcp. And I think it crashes during/ after mcp functions.

It completely disables the terminal, after some of these errors. And gets stuck. Keep getting the same error when you type anything & send, or try to continue.

coderd4 avatar Jul 01 '25 17:07 coderd4

Same issue here

raphasampaio avatar Jul 02 '25 18:07 raphasampaio

Hello friends, we're trying to actively track down the cause for this issue. Would you all mind hopping over to https://github.com/google-gemini/gemini-cli/issues/3131#issuecomment-3032567269 and answering some of those questions to help me get to the bottom of this?

NTaylorMullen avatar Jul 03 '25 16:07 NTaylorMullen

got this once.

orchidfire avatar Jul 03 '25 16:07 orchidfire

@NTaylorMullen is this fixed via #3333?

jackwotherspoon avatar Jul 06 '25 15:07 jackwotherspoon

same issue here - using 0.1.12

✕ [API Error: [{ "error": { "code": 400, "message": "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn.", "errors": [ { "message": "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn.", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT" } } ]]

Using 1 GEMINI.md file

michelsdev avatar Jul 19 '25 04:07 michelsdev

✕ [API Error: [{ "error": { "code": 400, "message": "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn.", "errors": [ { "message": "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn.", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT" } } ]]

I have seen this twice including today

bluefing avatar Jul 19 '25 21:07 bluefing

Hi mate! @NTaylorMullen Just wanted to ask you if there's any news of fixing this issue in the near future!

Thank you for building this amazing tool.

Best regards, Andrés

7andres avatar Jul 20 '25 00:07 7andres