amogh.cloud

Menu

P108

Learned to

Keep the prompt append-only

A cached prompt only saves time if each request starts exactly where the last one did. Small things in Piaa kept changing the past, and the silences grew.

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 ssilence at the start of a voice turn late in a long session (about 16K tokens in), before the fix; 3.4 s at about 5,000 tokens.Method time before the first spoken word, read from session logs; it grew with the length of the conversation.My session logs, Oct 2026 · Measured by me10.4 ssilence at the start of a voice turn late in a long session (about 16K tokens in), before the fix; 3.4 s at about 5,000 tokens.Methodtime before the first spoken word, read from session logs; it grew with the length of the conversation.SourceMy session logs, Oct 2026ClassMeasured by me · Oct 2026 once a conversation got long. When I went through all my session logs, 27%share of quick-mode replies that reused none of the cached prompt, across all my logged sessions before the fix; 34 to 38% for the slower modes.Method count of completions whose prompt-cache reuse was 0%, from the server log lines of every logged session.My session logs, Oct 2026 · Measured by me27%share of quick-mode replies that reused none of the cached prompt, across all my logged sessions before the fix; 34 to 38% for the slower modes.Methodcount of completions whose prompt-cache reuse was 0%, from the server log lines of every logged session.SourceMy session logs, Oct 2026ClassMeasured by me · Oct 2026 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 tokensminimum gap between the points the server can roll its cache back to, for this kind of model.Method the inference server keeps restore points for hybrid models at least this far apart.My notes on the server, Oct 2026 · Specification8,192 tokensminimum gap between the points the server can roll its cache back to, for this kind of model.Methodthe inference server keeps restore points for hybrid models at least this far apart.SourceMy notes on the server, Oct 2026ClassSpecification · Oct 2026 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 msdead time before the first token on an 8k conversation once the system prompt stopped changing every turn; was 4,551 ms; prompt-cache reuse 0% → 99.6%.Method prompt-processing time on turn 2 of a realistic 8k-token conversation, per-turn timestamp vs a frozen prefix.Note The cause was a seconds-precision clock in the system prompt, so no two turns shared a prefix.My measurements, same session, Aug–Sep 2026 · Measured by me214 msdead time before the first token on an 8k conversation once the system prompt stopped changing every turn; was 4,551 ms; prompt-cache reuse 0% → 99.6%.Methodprompt-processing time on turn 2 of a realistic 8k-token conversation, per-turn timestamp vs a frozen prefix.NoteThe cause was a seconds-precision clock in the system prompt, so no two turns shared a prefix.SourceMy measurements, same session, Aug–Sep 2026ClassMeasured by me · Sept 2026. 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×how much slower a request is when its tools array is new to the server.Method 6,056.2 ms divided by 87.2 ms, the two readings of the same A/B.Note There is no partial credit. Chat templates render the tools at the very start of the prompt, so any change reprocesses everything after it.My measurements, same-session A/B, Aug 2026 · Derived69×how much slower a request is when its tools array is new to the server.Method6,056.2 ms divided by 87.2 ms, the two readings of the same A/B.NoteThere is no partial credit. Chat templates render the tools at the very start of the prompt, so any change reprocesses everything after it.SourceMy measurements, same-session A/B, Aug 2026ClassDerived · Aug 2026 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 turnsturns that reprocessed the whole prompt when history trimming moved its cut on every turn; became 9 of 39 once the cut moved in steps of ten messages.Method offline replay of the assistant's history bookkeeping over 40 turns (a tool call with a large result every other turn), counting requests that were not an exact extension of the previous one.My replay test, Oct 2026 · Measured by me39 of 39 turnsturns that reprocessed the whole prompt when history trimming moved its cut on every turn; became 9 of 39 once the cut moved in steps of ten messages.Methodoffline replay of the assistant's history bookkeeping over 40 turns (a tool call with a large result every other turn), counting requests that were not an exact extension of the previous one.SourceMy replay test, Oct 2026ClassMeasured by me · Oct 2026. The new way does it on 9 of 39 turnsturns that reprocessed the whole prompt once the trimming cut moved only in steps of ten messages; was 39 of 39.Method the same 40-turn offline replay, with the window start rounded to steps of ten messages.My replay test, Oct 2026 · Measured by me9 of 39 turnsturns that reprocessed the whole prompt once the trimming cut moved only in steps of ten messages; was 39 of 39.Methodthe same 40-turn offline replay, with the window start rounded to steps of ten messages.SourceMy replay test, Oct 2026ClassMeasured by me · Oct 2026, 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 mstime to read the prompt on the eighth turn of a voice session, after the fix; was 1,973 ms; cache reuse 56% → 99%.Method live session of 8 voice turns, each with a tool call, old and new bookkeeping; prompt-processing time from the server log.My measurements, live session, Oct 2026 · Measured by me183 mstime to read the prompt on the eighth turn of a voice session, after the fix; was 1,973 ms; cache reuse 56% → 99%.Methodlive session of 8 voice turns, each with a tool call, old and new bookkeeping; prompt-processing time from the server log.SourceMy measurements, live session, Oct 2026ClassMeasured by me · Oct 2026.

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.