1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# 0002 — Sessions are append-only wire transcripts; history is never rewritten
**Status:** accepted
## Context
Two forces meet in the session format.
The first is cost. The provider bills cached prompt reads at roughly 1/50th of
input price (DeepSeek V4.1 Flash: $0.003/M cached vs $0.15/M input). Cache hits
depend on the request prefix being byte-identical to the previous request. The
prefix is the system prompt, the tool schemas, and the message history — so any
edit to an earlier message invalidates the cache for everything after it and
re-bills the whole context.
The second is fidelity. The model's next step depends on what it actually said
and what the tools actually returned, so the stored history has to reproduce the
wire messages exactly: `reasoning_content` from a reasoning model must not be
sent back (wasted tokens at best, a 400 at worst on DeepSeek-style backends),
and tool-call arguments must round-trip as the original JSON string rather than
being parsed and re-serialised, which can reorder keys and change whitespace.
Summarising old turns, truncating old tool output, and dropping old messages all
solve context exhaustion, and all of them rewrite the prefix. They are
incompatible with cache stability.
## Decision
Store each session as **append-only JSONL of wire-level messages**, replayed
verbatim. No compaction, no truncation, no summarisation, no sliding window.
- `reasoning_content` is stored (for the human to read) and stripped on replay.
- Tool-call arguments are stored and replayed as the original JSON string.
- The system prompt, environment block, and tool schemas are frozen at session
start and built from fixed-order structs — never a `HashMap`, never containing
session-varying values.
- When the conversation exceeds the model's context window, the provider returns
an error, the turn ends, and the user is told to start a new session.
## Consequences
- Prompt caching stays warm for the life of a session, which is the dominant cost
factor on a $10/month plan.
- Resuming a session is exact: replay the file and continue. No reconstruction
logic, no "the summary forgot the decision from ten turns ago".
- Long sessions have a hard ceiling and cannot be extended. The only remedy is a
new session, which loses the conversation. Accepted: with 128k-class windows
this is a rare event, and the failure is loud rather than silent.
- Session files grow without bound and are never garbage-collected. Accepted.
- Any future feature that wants to show a compacted view of history must render
it separately from what is sent to the provider. The transcript is the truth.
|