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