Grounding with google search is full of bugs

When I ask gemini 3.1 pro preview in google ai studio to generate code, and “Grounding with google search” is turned on, it’s a perfect recipe for bugs.

Earlier today I asked the model to fix an issue, thinking level “High”, temperature 1.0
It started thinking, then it wrote in the chat this:

def build_files():
pass

And then it started thinking again endlessly, and I had to manually stop it at 4 minutes. It’s definately not normal, it wasn’t that hard of a task to justify thinking for 4 minutes, and it wasn’t the usual thinking that shows what the model is thinking about, because that part was already completed, it’s a thinking that started after
def build_files():
pass

Some other times Grounding with google search on causes the model to truncate files and stop answering abruptly, in particular when [] is present in the code.
I believe that giving the model access to the internet is a powerful and necessary tool, and while i’ll just keep it turned off for the time being, it would be great if this could be fixed properly.