Append-Only Context for LLMs: A Practical Guide to Stop Rewriting History
This guide explains why treating conversation history as editable can break reasoning reuse in modern LLM applications, and how an append-only context model avoids silent cost, latency, and quality regressions. It covers which common practices invalidate cached reasoning, the three-layer impact of prefix changes, a protected base-class implementation, alternative patterns for five frequent scenarios, and a deployment checklist.
1. Where the Problem Comes From: “Editable History” Is an Implicit Assumption
Over the past two years, teams building agent applications have adopted a common habit: treating context as something that can be trimmed at will. Conversation history is handled like an array that can be rolled back, compressed, or replaced at any time. This assumption held up on earlier models, because each request was modeled independently and the server kept no intermediate state tied to the reasoning process across requests.
The assumption breaks once a model starts producing structured intermediate reasoning states within a single response—commonly referred to as reasoning items or reasoning traces—and the server attempts to reuse them across turns. The mutability of history now conflicts directly with state reuse. One model service states the rule plainly in its migration notes: if any content before the point of change is modified, all reasoning states after that point are treated as invalid and discarded, and the model must derive them again.
This is not only a cache hit-rate issue. The documentation frames the behavior as part of a safeguard: intermediate reasoning states may contain intermediate conclusions that never appear in the final answer, and reusing them across requests creates risks of information overreach and cross-talk. Invalidating everything when a prefix mismatch is detected is the more conservative choice on the safety side.
2. Which Common Practices Count as “Prefix Modification”
Checking everyday engineering practices against this rule yields a high hit rate:
- Dynamically assembling the system prompt per scenario, rewriting the opening each turn based on retrieval results;
- Truncating an earlier tool call result after a few turns when tool logs grow too long;
- Summarizing and replacing the original text of early turns when the conversation gets long;
- Switching the structured output mode as the task phase changes;
- Dynamically adding or removing tools based on permissions;
- Changing the model, end user, or organization mid-session.
Any one of these, when it lands before the point of change, invalidates all subsequent reasoning states. For a moderately complex code-review agent, hitting three to five of them at once is normal—which means a carefully designed trimming strategy becomes an amplifier of repeated computation.
3. The Cost Is More Than Tokens: A Three-Layer Chain Reaction
The first layer is cost. Once reasoning states are invalidated, the model must re-derive from the point of change, increasing effective computation on the input side and thinking consumption on the output side.
The second layer is latency. Both time to first token and overall completion time increase. For interactive products this is especially sensitive: users perceive it as “I changed one small setting and the answer got twice as slow.”
The third layer is quality. The documentation states clearly that output quality degrades when reasoning cannot be recovered, showing up as inconsistent conclusions across long-chain tasks, drifting tool-call parameters, and weaker format adherence. This kind of degradation usually raises no errors and only surfaces slowly in production metrics, making it expensive to diagnose.
4. The Refactor: Treat Context as an Append-Only Event Stream
The core principle is one sentence: append to the end of the context in time order, and write configuration changes as new records without modifying any existing content. In practice, a protected base class can constrain all write paths:
class AppendOnlyContext:def __init__(self):self._events = []def append(self, event: dict):# Tail writes only; index-based overwrite is forbiddenself._events.append(event)return len(self._events) - 1def snapshot(self):# Return an immutable view to prevent downstream mutationreturn tuple(self._events)
Recommended engineering constraints to add to your code review checklist: no index-based assignment to historical messages; no in-place truncation of persisted tool results; summaries may only be appended as new events and must explicitly reference the summarized range.
5. Alternative Patterns for Five High-Frequency Scenarios
Adjusting reasoning effort. Do not modify request-level parameters. Append a configuration update event at the end declaring the new value effective for this turn, and leave request-level parameters unchanged.
Switching output mode. Again, append a configuration update event. History corresponding to the old mode is preserved as-is.
Adjusting available tools. Declare newly available tools for the turn by appending, or narrow the callable scope with an allow list. Permission changes therefore carry a natural audit trail.
Updating developer instructions. Instead of rewriting the opening, append a new developer message at the end, forming a layered structure of “initial constraints + incremental constraints.”
Handling oversized tool output. Truncate or structurally extract before the first write into context, then treat it as an immutable fact. If further trimming is truly needed, append a reference-style summary event.
Example:
[developer] Initial constraints (immutable)[user] Task description[tool] Result (truncated before first write)[config_update] effort=high, format=schema_v2[developer] Incremental constraint: external network access is forbidden from this turn[additional_tools] +lookup_order[allowed_tools] This turn: search,read only
6. An Easily Overlooked Billing Detail: Where Fixed Instructions Live
Many migration guides note that the top-level instruction field is placed after the input in semantic order. If you want a long, fixed instruction to hit the cache reliably, move it to become the first developer message in the input. Otherwise that content is billed as uncached input, and the difference can be substantial with long system prompts. This is consistent with the append-only principle: a prefix with a fixed position and unchanging content is the prefix that can be reused.
7. Deployment Checklist
- Audit all history write paths and confirm there is no index-based overwrite;
- Split the system prompt into a “stable prefix + incremental constraints,” with the stable part placed first and frozen;
- Clean tool results before they enter context; treat them as read-only afterward;
- Model summaries, mode switches, and permission changes uniformly as appended events;
- Build dashboards for time to first token, thinking consumption, and cache hit rate in your monitoring, alerting, and logging services, and compare before and after migration;
- If your agent runtime runs on a container platform, include context storage and the immutable snapshot strategy in the release process.
8. Conclusion
“Append-only, never rewrite” looks like an interface-level restriction, but it effectively moves context management from mutable state editing toward event sourcing. It requires developers to decide at design time which information is a stable fact and which is an incremental decision, and to carry the latter in an auditable event stream. After this refactor, cache reuse, cost control, and output stability all benefit at once, and the safety-side prefix consistency check stops being an obstacle to business logic.
