eca icon indicating copy to clipboard operation
eca copied to clipboard

Using Gemini as a backend now results in a HTTP 400 Error when using tools

Open stsquad opened this issue 11 months ago • 7 comments

To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.

Describe the bug

When attempting to use tools we get a 400 response from Gemini:

LLM response status: 400 body: [{                                                                                                                            
  "error": {                                                                                                                                                 
    "code": 400,                                                                                                                                             
    "message": "Please ensure that function call turn comes immediately after a user turn or after a function response turn.",                               
    "status": "INVALID_ARGUMENT"                                                                                                                             
  }                                                                                                                                                          
}                                                                                                                                                            
] 

To Reproduce Steps to reproduce the behavior:

  1. Start `eca' in a project
  2. C-c RET - select google/gemini-3-flash-preview
  3. Run query which triggers tool use, e.g. /init
  4. Witness 400 error

Doctor Running /doctor did confuse the model but it did spit out the following after some thought.

LLM response status: 400 body: [{                                                                                                                            
  "error": {                                                                                                                                                 
    "code": 400,                                                                                                                                             
    "message": "Function call is missing a thought_signature in functionCall parts. This is required for tools to work correctly, and missing                
thought_signature may lead to degraded model performance. Additional data, function call default_api:eca__read_file , position 6. Please refer to            
https://ai.google.dev/gemini-api/docs/thought-signatures for more details.",                                                                                 
    "status": "INVALID_ARGUMENT"                                                                                                                             
  }                                                                                                                                                          
}                                                                                                                                                            
]                                                                                                                                                            

stsquad avatar Dec 28 '25 17:12 stsquad

@zikajk do you think that could be related with your recent changes?

ericdallo avatar Dec 28 '25 20:12 ericdallo

@ericdallo I am not sure, but I will try to fix it soon. It looks like it is related to parallel tool calls.

zikajk avatar Jan 04 '26 10:01 zikajk

I can confirm the gemini-2.5-pro works but the gemini-3-pro-preview fails with the same warning. Obviously given the inference costs involved I would rather stick to the gemini-3-flash-preview as that seems to give the most bang for buck.

stsquad avatar Jan 04 '26 11:01 stsquad

Spoke too soon - gemini-2.5-pro got through the /init step but failed later on. Maybe the slower response meant its less likely to race?

Running 'emacs -batch -l ert -l ed...' ❌ 0.10 s

Tool: shell_command
Server: eca
Arguments: 
  command: "emacs -batch -l ert -l edit-server-test.el -f ert-run-tests-batch-and-exit"

Output: Exit code 255
Stderr:
Loading /etc/emacs/site-start.d/00debian.el (source)...
Loading /etc/emacs/site-start.d/50asymptote.el (source)...
Loading /etc/emacs/site-start.d/50autoconf.el (source)...
Loading /etc/emacs/site-start.d/50devhelp.el (source)...
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...
Loading /etc/emacs/site-start.d/50global.el (source)...
Loading /etc/emacs/site-start.d/50latex-cjk-common.el (source)...
Error while loading 50latex-cjk-common: Symbol’s value as variable is void: flavor
Loading /etc/emacs/site-start.d/50latex-cjk-thai.el (source)...
Error while loading 50latex-cjk-thai: Symbol’s value as variable is void: flavor
Loading /etc/emacs/site-start.d/50latexmk.el (source)...
Loading /etc/emacs/site-start.d/50texlive-lang-english.el (source)...
Cannot open load file: No such file or directory, edit-server
Stdout:
Error: file-missing ("Cannot open load file" "No such file or directory" "edit-server")
  require(edit-server)
  load-with-code-conversion("/home/alex/mysrc/edit-with-emacs.git/edit-server-test.el" "/home/alex/mysrc/edit-with-emacs.git/edit-server-test.el" nil t)
  command-line-1(("-l" "ert" "-l" "edit-server-test.el" "-f" "ert-run-tests-batch-and-exit"))
  command-line()
  normal-top-level()

Thought 0.00 s
The user wants me to fix the test command.
The previous command failed because `edit-server.el` was not in Emacs' `load-path`.
I need to add the current directory to the `load-path` so that Emacs can find `edit-server.el`.
The command should be `emacs -batch -L . -l ert -l edit-server-test.el -f ert-run-tests-batch-and-exit`.
The `-L .` part adds the current directory to the `load-path`.The test failed because `edit-server.el` isn't in Emacs' `load-path`. I'll add the current directory to the `load-path` and rerun the test.

Running 'emacs -batch -L . -l ert ...' ❌ 0.09 s

Tool: shell_command
Server: eca
Arguments: 
  command: "emacs -batch -L . -l ert -l edit-server-test.el -f ert-run-tests-batch-and-exit"

Output: Exit code 255
Stderr:
Loading /etc/emacs/site-start.d/00debian.el (source)...
Loading /etc/emacs/site-start.d/50asymptote.el (source)...
Loading /etc/emacs/site-start.d/50autoconf.el (source)...
Loading /etc/emacs/site-start.d/50devhelp.el (source)...
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...
Loading /etc/emacs/site-start.d/50global.el (source)...
Loading /etc/emacs/site-start.d/50latex-cjk-common.el (source)...
Error while loading 50latex-cjk-common: Symbol’s value as variable is void: flavor
Loading /etc/emacs/site-start.d/50latex-cjk-thai.el (source)...
Error while loading 50latex-cjk-thai: Symbol’s value as variable is void: flavor
Loading /etc/emacs/site-start.d/50latexmk.el (source)...
Loading /etc/emacs/site-start.d/50texlive-lang-english.el (source)...
Cannot open load file: No such file or directory, edit-server
Stdout:
Error: file-missing ("Cannot open load file" "No such file or directory" "edit-server")
  require(edit-server)
  load-with-code-conversion("/home/alex/mysrc/edit-with-emacs.git/edit-server-test.el" "/home/alex/mysrc/edit-with-emacs.git/edit-server-test.el" nil t)
  command-line-1(("-L" "." "-l" "ert" "-l" "edit-server-test.el" "-f" "ert-run-tests-batch-and-exit"))
  command-line()
  normal-top-level()


LLM response status: 400 body: [{
  "error": {
    "code": 400,
    "message": "Please ensure that function call turn comes immediately after a user turn or after a function response turn.",
    "status": "INVALID_ARGUMENT"
  }
}
]

stsquad avatar Jan 04 '26 11:01 stsquad

Fixed by https://github.com/editor-code-assistant/eca/pull/262/, @stsquad can you try latest release please?

ericdallo avatar Jan 12 '26 13:01 ericdallo

@stsquad It should be fixed now. From time to time, Gemini breaks the tags and starts behaving in a weird way. I am still trying to figure out if it is something we can improve on our side and if it can be related to returning reasoning in assistant messages back to model. Maybe their openai compatible API isn't perfect, let's see if you experience the problem.

zikajk avatar Jan 15 '26 06:01 zikajk

@zikajk looks good now - I have run through and /init and done some long chain prompts and it seems stable. Thanks!

stsquad avatar Jan 18 '26 18:01 stsquad