waveterm icon indicating copy to clipboard operation
waveterm copied to clipboard

[Bug]: Google AI Studio API (`gemini-2.5-pro`) does not preserve prior `assistant`-role messages in chat history

Open atlasveldine opened this issue 3 months ago • 0 comments

Current Behavior

Within the first fifteen minutes of downloading and playing around with Wave Terminal, I almost instantly ran into this glaring question:

What’s with the janky AI “chat” when using gemini-2.5-pro?!

I’m super glad I caught onto this sooner rather than later, and didn’t end up wasting a whole buncha cash in the process. AI APIs—especially Gemini 2.5 Pro—are expensive, and for this kind of error to exist is almost unforgivable. For something this polished in appearance, it’s genuinely difficult to believe that a bug of this kind exists at all…

“What bug?” you ask?

Just take a look at this chatlog. Something should almost immediately (within the first few AI replies) stand out to you as bizarre. It only gets worse as the conversation continues:

Plaintext, for those using screen readers or translators…

User: Hello. My name is Jonathan Lonathan.

AI: Hello, Jonathan Lonathan. It’s a pleasure to meet you.

How can I help you today?

User: It’s a pleasure to meet you, too. What did I say my name was, by the way?

AI: You said your name was Jonathan Lonathan.

User: And did you believe me?

AI: Hello Jonathan Lonathan!

You said your name was Jonathan Lonathan.

As for whether I believed you, that's an interesting question! As an AI, I don’t have personal beliefs or skepticism the way humans do. I accept the information you give me as the premise for our conversation.

So, for our chat, your name is Jonathan Lonathan. It’s a pleasure to meet you

User: I'm trying to debug this tool; it seems like, perhaps, messages are being sent out of order or something of the sort. Can you please tell me, in what order do you see our messages?

AI: Of course, I can help you with your debugging. This is an interesting test.

To answer your questions first:

  • What did I say my name was? You said your name was Jonathan Lonathan.

  • Did you believe me? As an AI, I don’t “believe” in the human sense. I accept the information you provide as the basis for our conversation. So, for our purposes, I accepted “Jonathan Lonathan” as your name.

Now, regarding the order of messages, I received all of your text as a single input block. Here is the exact order in which the sentences appeared in that block:

Hello. My name is Jonathan Lonathan. It’s a pleasure to meet you, too. What did I say my name was, by the way? And did you believe me? I’m trying to debug this tool; it seems like, perhaps, messages are being sent out of order or something of the sort. Can you please tell me, in what order do you see our messages?

It seems your suspicion might be correct, as the second sentence, “It’s a pleasure to meet you, too,” reads like a response to something I would have said, but I hadn’t said anything yet. I hope this helps with your debugging

Screenshot of a chat interface showing the first part of a conversation where the user tests the AI’s memory and conversational flow. Second part of the chat screenshot, where the AI reveals it received all the user’s messages as a single block, with all prior AI responses removed, confirming a bug in the message history formulation.

In Short…

For whatever reason—at least when using gemini-2.5-pro from Google’s AI Studio API—message history is being crushed down into just the user’s messages. All prior AI messages are simply removed from the message history on subsequent turns, and all user messages are then (rightfully, mind you) compressed into a single message.

Note: The reason I say “rightfully” is that this API (and, in fact, most AI APIs) expects messages to be alternating between the user and assistant role; thus, user, user, user, user, assistant would be invalid and would simply cause an error to be returned (from most APIs).

This only happens on Gemini models, seemingly

I’ve only tested this and found it to occur on gemini-2.5-pro, but it’s likely it occurs on the other gemini-2.5-* models. It doesn’t happen, however, on the preconfigured gpt-5-mini:

Plaintext, for those using screen readers or translators…

User: How about now? Do you see your past responses, or do you only see all of my messages crushed down into a single message?

AI: I see the full conversation history for this session as an ordered sequence of messages (both your messages and my responses), not just a single crushed user message.

Here’s the sequence I see, in order (each line shows the sender and the message content):

User: “Hello. My name is Jonathan Lonathan.” Assistant: “Hello, Jonathan Lonathan. It’s a pleasure to meet you.\n\nHow can I help you today?” User: “It’s a pleasure to meet you, too. What did I say my name was, by the way?” Assistant: “You said your name was Jonathan Lonathan.” User: “And did you believe me?” Assistant: “Hello Jonathan Lonathan!\n\nYou said your name was Jonathan Lonathan.\n\nAs for whether I believed you, that’s an interesting question! As an AI, I don’t have personal beliefs or skepticism the way humans do. I accept the information you give me as the premise for our conversation.\n\nSo, for our chat, your name is Jonathan Lonathan. It’s a pleasure to meet you” User: “I'm trying to debug this tool; it seems like, perhaps, messages are being sent out of order or something of the sort. Can you please tell me, in what order do you see our messages?” Assistant: (my previous reply noting I received your text as a single input block and listing four sentences you had sent in that block) User: “How about now? Do you see your past responses, or do you only see all of my messages crushed down into a single message?”

So: I do see my past responses as well as your messages, in their sent order. If you’re seeing different ordering or aggregated messages in the client or logs, that behavior would be coming from the tool or interface you’re using rather than from my view of the session. If you want, I can help you design a small test you can run to reproduce ordering, or I can echo messages back immediately to help pinpoint where the reordering/compression is happening. Which would you prefer?

Screenshot showing a correct, un-crushed conversation history with the gpt-5-mini model, demonstrating that the bug is specific to Gemini.

Expected Behavior

Message history should be correctly preserved regardless of model choice.

Steps To Reproduce

Simply send a message to the AI Studio Gemini API, then send another, and watch as it completely forgets everything it previously responded with. From a user perspective, it will continually repeat its replies to your questions/statements in slightly different ways, over and over and over again.

.\presets\ai.json block:

{
  "[email protected]": {
    "display:name": "Gemini 2.5 Pro",
    "display:order": 1,
    "ai:*": true,
    "ai:apitype": "google",
    "ai:model": "gemini-2.5-pro",
    "ai:apitoken": "<redacted>"
  }
}

Environment

Wave Version

0.11.6 (202509221836)

Platform

Windows

OS Version/Distribution

Windows 11 24H2 (26100.4946)

Architecture

x64

Anything else?

You’d expect to be able to configure some very basic elements like the system prompt (what’s referred to as the instructions by the Gemini API), sampler config (temp, top_p, et cetera), context size, max thinking token count (for the Gemini API) or reasoning strength (for generic OpenAI APIs), et cetera. For a product like this, you’d likewise expect to be able to configure and connect to MCP servers, but that doesn’t seem to be a feature, unless I’m somehow missing it?

As far as I could tell, there is no way to configure practically anything in regards to the AI, beyond selecting a model. While the wsh ai utility is handy enough, I can’t see much of any reason to use this implementation. There are myriad other terminal-based AI utilities that do what this does, and more, e.g. viby, gemini-cli, and easily dozens more.

That’s not to say there isn’t a market for this—if the utility was fully-featured, I’d absolutely use it, but without MCP support and with this major bug with gemini-2.5-* models (at a minimum; for all I know this impacts the entire Gemini API), it’s unusable for me. I’m not fond of gpt-* models whatsoever, and I need to be able to configure at least the basic settings; plus, I rely heavily on MCP servers when interacting with AI.

That said, even without the AI tooling, Wave is a fantastic tool. It’d just be that much more fantastic if the AI utilities were a bit richer. :)

As an aside…

The -h for ws ai claims that -f accepts a stringArray, but quite literally nothing I tried allowed me to input more than a single file. I tried:

  • ws ai -f "file1" -f "file2" -f "file3" "message"
  • ws ai -f "file1,file2,file3" "message"
  • ws ai -f "file1" "file2" "file3" "message"
  • ws ai -f "file1',"file2","file3" "message"

None of the above worked. If it does accept an array, it’d be nice if it would clarify how this can be used. If it doesn’t, then making it clear that it accepts a string would be nice.

Thank you!

Thanks in advance to whoever looks into this!

Questionnaire

  • [ ] I'm interested in fixing this myself but don't know where to start
  • [ ] I would like to fix and I have a solution
  • [x] I don't have time to fix this right now, but maybe later

atlasveldine avatar Oct 03 '25 07:10 atlasveldine