Repository navigation
Description
Upstream issue draft: Partial session restore, fork support, and a hash-chain index
Pain (the problem)
Long agent conversations that alternate between sessions pay repeated prefill costs when the conversation is no longer in the RAM cache. Existing session files write and read whole snapshots, which amplifies I/O when only a small part changes or only a prefix is needed.
Two common situations where this bites:
- Engine restart: the conversation cache is in RAM; a restart drops it. Upstream's
--conversation-spill-persistonly keeps what was actually evicted to the SSD tier, so a wide RAM pool means nothing survives (we measured 0 adopted at 24 GiB). - History rewrite / fork (a sub-agent branches off, or a client edits mid-history): the on-disk checkpoint can only be mounted at an exact checkpoint length, so a prompt that diverges finds no checkpoint and recomputes the whole prompt.
Both are common in multi-agent workloads where several long conversations rotate.
The workloads we actually run
- Same-family agent requests: many agents share one card, and their requests alternate;
- Skill-heavy agents: an agent with many skills carries a at least 10–60K-token system prompt that every one of its turns reuses;
- Forking matters: sub-agents branch off a parent's context — a rewrite of mid-history must not force a full recompute of the parent's 277K-token conversation.
What we did (engine side only, no gateway)
- Partial restore: a session file can be mounted at an arbitrary depth (the longest common prefix), reading only the K/V prefix it needs;
- Fork support: a rewritten history mounts the nearest checkpoint at or below the divergence and recomputes only the tail;
- Hash-chain index: block-level chained hashes (
H(k) = hash(H(k-1) + block_k)) so a match is a hash compare, not a token-by-token scan; - Observability: every restore reports its depth, the common prefix, and the tail recomputed.
Measured results (three-session rotation, 8 GiB pool, 277K-token conversations, AMD W7900)
| Metric | Full prefill (no cache) | Before (native) | After (ours) |
|---|---|---|---|
| Restart recovery — X (277K) | ~100 s | 100 s (cold) | 6.0 s (restored) |
| Restart recovery — Y (29K) | ~10 s | 10 s (cold) | 1.6 s (restored) |
| Restart recovery — Z (277K) | ~100 s | 100 s (cold) | 5.8 s (restored) |
| Fork after a rewrite | ~100 s (full recompute) | ~100 s | partial restore (27–38 s first, 4–5 s once the fork has its own archive) |
| Matching cost (20 candidates of 277K) | 27.3 ms (token-by-token scan) | 0.1 ms (hash chain) — 358× | |
| Re-save write volume | whole archive (4.06 GB) | 427 MB (incremental, 1/9.5) | |
| Write time | — | spill 7.1 s (background) / full save 21.2 s | incremental 427 MB ≈ 2 s (re-save) |
| Reuse rate | ≈99.99% | 99.98–99.998% (no regression) | |
| Steady-state rotation | 0.35 / 0.24 / 0.22 s | 0.26–0.80 s (no regression) |
The 358× matching gain shows up only when there are many candidates and long archives; it does not change the dominant inference cost.
Also: a real upstream bug we hit and fixed
The restore path crashes (ERR restoring a conversation checkpoint failed → engine exit) when a mount lands at a checkpoint depth: resume uses the prompt's LCP instead of the depth actually mounted. This happens on the native path too (not only our additions). We fixed it by resuming at the mounted depth and treating a partial mount as a live state.
Why small PRs (the #5500 lesson)
We previously sent a large PR (#5500) that bundled a new session format, incremental saves, and a disk tier. The maintainer's feedback was that it was too large and overlapped the disk tier that had just shipped. We closed it in favor of smaller mechanism PRs. This issue is that split, done properly: each PR is small, independently reviewable, and gated behind a switch (default off = upstream behavior).
Proposed split
- Crash fix (resume at the mounted depth) — smallest, a real bug;
- Observability (restore depth / lcp / tail fields);
- Partial restore (arbitrary-depth mount + prefix-only read);
- Fork support (rewind to the divergence, recompute the tail);
- Incremental writes (base + delta chain);
- Checkpoint density knob;
- Save-before-stop (a stop script that saves first);
- Hash-chain index (block-level hashes for checkpoint lookup).
Each is gated behind a switch (default off = upstream behavior), with negative controls and the three-session rotation as acceptance.
Notes
- We are aware of the open session-persistence PR chain ([Engine] session files: format v2 with per-stage save/restore under --layer-split #4310 / [Engine] session-file v3: incremental append saves under --session-save-append #4551 / [Other] serve: session ladder — conversations survive an engine unload #4306 / ...). Our partial-restore work is complementary: those PRs add format v2/v3 and incremental saves; ours adds arbitrary-depth mount and fork support on top of the existing formats.
- All measurements are on an AMD RDNA host (W7900), Qwen3.8-Flash IQ4_XS, 277K-token conversations.
The four PRs (in order)
- [Engine] Fix a crash on restore: resume at the mounted depth, not the prompt's prefix (#7648, PR 1) #7650 — crash fix (resume at the mounted depth);
- [Engine] Restore log: name the depth, the prefix matched, and the tail read (#7648, PR 2) #7651 — observability (restore depth / prefix / tail fields);
- [Engine] A knob for checkpoint density: STRATA_SESSION_CKPT_EVERY (#7648, PR 3) #7652 — checkpoint density knob (
STRATA_SESSION_CKPT_EVERY); - [Engine] Save before stop: a stop script that saves every conversation first (#7648, PR 4) #7653 — save before stop (a stop script that saves first).
Each is based on upstream main, a clean branch, no dependence on our switches, and gated behind a switch (default off = upstream behavior).
The second batch (stacked)
- [Engine] Partial restore: mount a session file at an arbitrary depth (#7648, PR 5) #7656 — partial restore (mount at an arbitrary depth);
- [Engine] Fork support: mount at the divergence, recompute only the tail (#7648, PR 6) #7657 — fork support (mount at the divergence, recompute only the tail).
Both are based on upstream main, clean branches, no dependence on our switches.
Activity
[-][Engine] Partial session restore, fork support, and a hash-chain index (small, gated PRs)[/-][+][Engine] Save ~95% prefill time on returning conversations — partial restore, fork support, and a hash-chain index[/+]engine: STRATA_SESSION_CKPT_EVERY - the session file can keep more th…
engine: STRATA_SESSION_CKPT_EVERY - the session file can keep more th…