diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-15 02:54:21 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-15 02:54:21 +0100 |
| commit | 7175543e00caa9ce35487fa7f8b1b479c1ba00a2 (patch) | |
| tree | 10f89f85ca35d6ac7515bbe88518255788d6dc22 /docs/adr | |
| download | agent686-7175543e00caa9ce35487fa7f8b1b479c1ba00a2.tar.gz agent686-7175543e00caa9ce35487fa7f8b1b479c1ba00a2.zip | |
M0: streaming provider, SSE decoder, mock provider, i686 build gate
Diffstat (limited to '')
| -rw-r--r-- | docs/adr/0001-dynamic-glibc-i686.md | 49 | ||||
| -rw-r--r-- | docs/adr/0002-append-only-sessions.md | 51 |
2 files changed, 100 insertions, 0 deletions
diff --git a/docs/adr/0001-dynamic-glibc-i686.md b/docs/adr/0001-dynamic-glibc-i686.md new file mode 100644 index 0000000..df791e0 --- /dev/null +++ b/docs/adr/0001-dynamic-glibc-i686.md | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | # 0001 — Ship a dynamically linked glibc i686 binary, not a static one | ||
| 2 | |||
| 3 | **Status:** accepted | ||
| 4 | |||
| 5 | ## Context | ||
| 6 | |||
| 7 | The target is a Debian 12 i386 machine: glibc 2.36, 2 cores, 4 GB RAM. The | ||
| 8 | development machine is x86-64 with `gcc-multilib` and the `i686-unknown-linux-gnu` | ||
| 9 | Rust target installed. | ||
| 10 | |||
| 11 | "Single static binary" was the original plan, on the assumption that it removes | ||
| 12 | all runtime dependencies. Two measurements on the development machine contradict | ||
| 13 | that: | ||
| 14 | |||
| 15 | 1. **Static glibc cannot use NSS modules, and crashes trying.** An i686 binary | ||
| 16 | built with `+crt-static` segfaults inside `libnss_resolve.so.2` at | ||
| 17 | `getaddrinfo()`, because the host's `nsswitch.conf` lists `resolve` before | ||
| 18 | `files`. Static glibc is documented as unable to load NSS modules; on any | ||
| 19 | systemd-resolved machine, DNS from a static glibc binary is a SIGSEGV. The | ||
| 20 | failure mode is invisible at build time and appears on the first network call. | ||
| 21 | 2. **Static musl requires a C-free dependency tree, which we do not have.** | ||
| 22 | `ring` (pulled in by `rustls`/`ureq`) compiles C and assembly; cc-rs invokes | ||
| 23 | `musl-gcc -m32` and fails because no 32-bit musl sysroot exists here. Making | ||
| 24 | musl work means adding an `i686-linux-musl` cross toolchain, or swapping the | ||
| 25 | TLS stack for a pre-1.0 pure-Rust provider. | ||
| 26 | |||
| 27 | The dynamic i686 build works unchanged: TLS handshake, DNS, JSON parse, exit 0. | ||
| 28 | Its highest required symbol version is `GLIBC_2.34`, and it runs correctly inside | ||
| 29 | `docker run --platform linux/386 debian:12` (glibc 2.36). | ||
| 30 | |||
| 31 | ## Decision | ||
| 32 | |||
| 33 | Build `i686-unknown-linux-gnu` **dynamically linked against glibc**, using the | ||
| 34 | host's 32-bit toolchain. Do not use `+crt-static`. Gate every release on a check | ||
| 35 | that the maximum required symbol version is `<= GLIBC_2.36`, and verify releases | ||
| 36 | by running them inside the `linux/386 debian:12` container before copying to the | ||
| 37 | target machine. | ||
| 38 | |||
| 39 | ## Consequences | ||
| 40 | |||
| 41 | - The binary is ~3 MB stripped and needs the target's glibc to be at least 2.34. | ||
| 42 | Debian 12 provides 2.36, so there is headroom, but a future dependency can pull | ||
| 43 | in newer symbol versions. The `readelf` ceiling check is mandatory, not | ||
| 44 | advisory — without it the failure appears only on the i686 machine. | ||
| 45 | - Distribution is a binary plus its glibc, not a single file to `scp` anywhere. | ||
| 46 | Accepted: the target is a known Debian 12 box, not an unknown fleet. | ||
| 47 | - `ring`/`rustls` stay available, so the dependency tree is unconstrained. | ||
| 48 | - If the target later turns out to be older than glibc 2.34, or a second target | ||
| 49 | appears with an older libc, this decision reopens and musl becomes the path. | ||
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 | |||
| 7 | Two forces meet in the session format. | ||
| 8 | |||
| 9 | The first is cost. The provider bills cached prompt reads at roughly 1/50th of | ||
| 10 | input price (DeepSeek V4.1 Flash: $0.003/M cached vs $0.15/M input). Cache hits | ||
| 11 | depend on the request prefix being byte-identical to the previous request. The | ||
| 12 | prefix is the system prompt, the tool schemas, and the message history — so any | ||
| 13 | edit to an earlier message invalidates the cache for everything after it and | ||
| 14 | re-bills the whole context. | ||
| 15 | |||
| 16 | The second is fidelity. The model's next step depends on what it actually said | ||
| 17 | and what the tools actually returned, so the stored history has to reproduce the | ||
| 18 | wire messages exactly: `reasoning_content` from a reasoning model must not be | ||
| 19 | sent back (wasted tokens at best, a 400 at worst on DeepSeek-style backends), | ||
| 20 | and tool-call arguments must round-trip as the original JSON string rather than | ||
| 21 | being parsed and re-serialised, which can reorder keys and change whitespace. | ||
| 22 | |||
| 23 | Summarising old turns, truncating old tool output, and dropping old messages all | ||
| 24 | solve context exhaustion, and all of them rewrite the prefix. They are | ||
| 25 | incompatible with cache stability. | ||
| 26 | |||
| 27 | ## Decision | ||
| 28 | |||
| 29 | Store each session as **append-only JSONL of wire-level messages**, replayed | ||
| 30 | verbatim. 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. | ||
