Piaa, my voice assistant, had a problem that got worse the longer I talked to it. Each turn started with a silence before it spoke, and the silence grew through a session: 10.4 s once a conversation got long. When I went through all my session logs, 27% of its quick replies had reused none of the work the server had already done.
The cause was the same every time. Something near the front of the prompt changed between turns.
How prompt caching works
Every time Piaa replies, the server first reads the whole conversation so far. That reading is the slow part of a long conversation. To save it, the server keeps the work it did on the beginning of the prompt. If the next request starts with exactly the same text, the server reuses that work and only reads what's new at the end.
The catch is the word "exactly". If anything changes near the front, the server has to read everything after that point again.
The model Piaa runs makes this stricter. Most of its layers don't keep a record of every word; they carry a fixed-size running summary. So the server can't step back to any point it likes. It can only go back to saved restore points, kept at least 8,192 tokens apart. Change anything behind the newest restore point and it falls back to an older one, or to the very beginning.
What kept changing the past
None of these looked like bugs. Each one was a reasonable idea on its own.
- A clock in the system prompt. The very first lines said when the conversation started, down to the second, and they were redrawn every turn. No two turns could ever share a beginning. Stamping the start time once per session, to the minute, took the wait before the first word on a long conversation down to 214 ms. If the model needs the exact time, it has a tool for that.
- A changed list of tools. A list of tools the server hasn't seen before costs a full reread, which was 69× slower than with a list it already knew. So the list now stays fixed for the whole session, and a test checks it.
- Extras added to my message but not saved. Piaa sent each of my messages along with some recalled memories and a short note about where the message came from, but it saved only my plain words. On the next turn, that message was sent again without the extras, which changed the past.
- A history window that slid every turn. To stay within its limits, Piaa drops the oldest messages once a conversation passes 30 of them. The cut moved forward by a message or two each turn, so every request started from a slightly different point. Old tool results were also shortened after the fact, which rewrote them too.
The fix: history only grows at the end
The rule now is that history only ever grows at the end, except in deliberate jumps.
Each of my messages keeps two versions: the clean words for the screen, and the exact text that was sent. The exact text is what gets sent again. The history window now moves in steps of ten messages, so a long session pays for one full reread per step instead of one per turn. Old tool results are shortened only on a turn where the window steps anyway.
I wrote a test that replays Piaa's bookkeeping over 40 turns and counts how often a request is not an exact extension of the one before. The old way rewrote the past on 39 of 39 turns. The new way does it on 9 of 39 turns, and only when the window steps.
In a live session of eight voice turns, each with a tool call, the eighth turn read its prompt in 183 ms.
What still breaks it
Two things are not fixed. The server drops a reply's earlier reasoning by default, so when Piaa thinks before answering, the next turn still rewrites that reply. Keeping the reasoning would cost space in the conversation, and I haven't decided yet. And other jobs that share the same server slot can push the main conversation out of the cache between turns.
What I check now
- Anything that changes goes at the end of the prompt, never at the front.
- Save exactly what was sent, not a tidier version of it.
- Trim history in steps, not a little every turn.
- Test it with a replay that counts rewrites, because a broken cache doesn't throw an error. It just makes everything slower.
Seen it differently, or hit the same wall? Email me.
Written by me.