mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #4552] [Engine] session-save-append: park-borrow / slot-mount / checkpoint-mount watermarks dirty from token 0, so a resumed session cannot earn its next append #2058
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2058
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sakuumomo on GitHub (Oct 28, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4552
Problem: a session saved to a v3 append file earns its next append only if no request runs in between. Any new request — even one that only adds 7 tokens above the file's committed boundary, with the whole prior conversation prefix-matched — makes the next save full-rewrite with
save gate: full rewrite - pool rows at or below the file's saved boundary may differ from what it committed. (Observed on the draft append PR's branch, #4551.)Environment:
--session-save-reclaim --session-save-append, 0.2.7.1 train (branch lineage @ dd4790a7+), NixOS x86_64, AMD gfx1030 / ROCm 7.2.3, model Qwen3.8-Flash-Next IQ3_XXS GGUF,--kv fp16 --max-context 262144 --kv-resident 32768 --layer-split 19.Reproduce (against a live serve instance): save a ~29k-token session to a fresh file (full, as expected); send one new short chat message (a handful of tokens) to the same session id; save again. Expected: append of the new group. Actual: full rewrite of the whole file. The no-request re-save variant appends correctly, which isolates the cause to the resume path.
Expected: the gate's own docs say a save should append when nothing below the committed boundary changed. Actual: the refusal fires on every post-request save.
Mechanism (static reading, consistent with the observed refusals):
--session-save-reclaimreleases the saved conversation's checkpoints/rows (session_save_reclaim(...),freed.parked). The session's next request therefore resumes through a physical re-copy — park-borrow (watermark M4,generate.cpp:14703), slot replacement (M5,:12818), or checkpoint mount (M3,:13989) — each of which callsmark_kv_dirty(0). The refusal is correct under current accounting: re-copied rows can land in different physical pool cells than the file recorded, and appending over them is the wrong-file restore the gate exists to make impossible. But the consequence is that append eligibility survives only while nothing touches the conversation — i.e. never in the ladder's steady state (save → turn → save). The feature's benefit today is limited to re-save chains.Evidence — proof B from #4551 (short-increment shape, same host): saves 2–4 after +7..17-token asks full-rewrote (1.053 → 1.0535 → 1.0540 → 1.0544 GB); save 5, a re-save with no request in between, appended 237,210,624 bytes in 2.11 s vs 31.5 s full.
Reproduction status: reproduced locally (live serve host, both increment shapes, several sessions).
Design question: provenance-aware, offset-aware dirty accounting for engine-internal mounts/borrows. An engine-internal checkpoint captured from this session's own pool, never evicted, re-filled into the same physical cells byte-for-byte, could dirty from the mount offset instead of 0; anything whose provenance can't be established keeps dirty-from-0. Is there an existing invariant — or a cheap one to add, e.g. the checkpoint recording the pool generation it was captured from — that makes that identity provable?
Refusal lines as observed (click to expand)
The last line shows the eligible shape (no request in between) working end to end: the append reports its delta as
bytes, consumed by the serve-side save ledger fields from #4551.@sakuumomo commented on GitHub (Oct 29, 2026):
A steady-state shape that sharpens this problem (live host, append branch,
--session-save-reclaim --session-save-append): the save the serve unload button runs is exactly this mechanism, hit at the worst moment.Sequence as it happened, with the engine's own lines:
[appended]saves in the 174k→188k-token range).conversation cache: parked … evictions=5, then the next turn mounts the conversation back:conversation cache: restored 195063 tokens (live)— the M3 mount,mark_kv_dirty(0).engine.unload()drops the park (the save is required — park dies with the engine). The save is a few tokens above the committed boundary but the mount dirtied from 0:save gate: full rewrite - pool rows at or below the file's saved boundary may differ from what it committed→ a 5.79 GB tmp+rename rewrite of a session whose conversation changed by ~2k tokens.So in the ladder's normal loop, the mount bump doesn't just limit "re-save chains" — the one save that must happen (before the engine goes away) is guaranteed to ride a dirty-from-0 watermark.
Two related observations from the same host, same flags:
no verified checkpoint chain for this file (v2 file, torn tail, or foreign identity)fires identically for: file absent, chain digest failure, and a plan refused because the runtime's own read limits (which follow the boot-time split search — carve sizes vary between boots on a dual-GPU box) say this runtime could not restore the file. A post-restart first save is the common case; operators currently can't tell which guard fired. Splitting the reason intoabsent/refused by this runtime's limits/chain invalidis a small change to the same gate that makes all of this diagnosable.@nazerim commented on GitHub (Nov 5, 2026):
Confirmed at code level on the current PR head (
pr/4551=f1dbcea0). The defect is exactly as described, and it is complete: the watermark only ever rises after a successful save (generate.cpp:13958–13960:ss.kv_first_dirty = std::max(ss.kv_first_dirty, strata::core::session_whole_cells((int64_t) live.size(), save_page))), while every resume path slams it to 0:mark_kv_dirty(0)on every carvesrc/program/generate.cpp:14063–14064src/program/generate.cpp:14778src/program/generate.cpp:14805–14807src/program/generate.cpp:12857–12860src/program/generate.cpp:14884–14886, 14911–14912conversation_kv_restoresrc/core/conversation_snapshot.cpp:458–461conversation_kv_restore_prefixsrc/core/conversation_snapshot.cpp:485Since
whole_cells(0) = 0 < whole_cells(saved_tokens)for any non-empty file,kv_append_ok(session.hpp:113–115) fails andsession_save_gatedeclines with its own words (conversation_file.cpp:2664):"pool rows at or below the file's saved boundary may differ from what it committed"→ the first save after any restore/borrow/mount is a forced full rewrite. In a conversation-switching workload — which is the whole reason the format exists and whatserve/session_ladder.pydrives — a restore precedes essentially every save, so the append path only fires on the same-conversation second consecutive turn — the only site that does not force 0 is M1, which marks at the request's ownread_from(:14974–14979): the resume point on a continuing conversation, which sits at or above the saved prefix. A genuine full re-read (reread_to > 0) makesread_from0, and that refusal is exactly correct — the pools are about to be rewritten from token 0.One imprecision in the issue text worth fixing while it's open: checkpoint-mount (M8) is not dirty-from-0 —
conversation_state.cpp:437–443, 471–475mark atrow * idx_block, andsession_watermark_test.cpp:85–95explicitly pins that a same-tokens mount stays append-eligible. The blunt sites are M2/M3/M4/M5/M9.Two adjacent defects in the same mechanism
session_save_gate(..., ss.kv_first_dirty, ...)(generate.cpp:13935–13937) while the file commits every stage's K/V; and the post-save raise at:13958lifts onlyss— thefor (auto& st : stages)loop present at every bump site is absent there. A stage-only rewrite via the M8/M9 backstops (they fire onst.owner, which can be a later stage alone) is invisible to the gate, and stage watermarks never rise after a save. Every bulk path also bumpsss, so it's latent rather than live — but the invariant is undocumented and unenforced.session_watermark_test.cppstructurally cannot see this class of bug — by its own header: "The bump sites (M1–M9) live in the engine and core restore paths; this file pins the WATERMARK ITSELF" (:2). All 22 checks exerciseSessionStatearithmetic in isolation; there is no test of "restore → save appends" and no test that amark_kv_dirty(0)site costs a full rewrite.deb3f3c2shows the author already hit this family empirically on the host ("every save on the host full-rewrote … even a re-save with no request between saves") and fixed the unaligned-boundary variant; the resume variant is the same symptom from the other cause.Proposed shape (matching the issue's direction)
Resume paths should mark at the restored prefix —
whole_cells(saved_tokens)— not at 0. That is sound for the copy-in resumes because the bytes below the restored prefix are what the file committed: RESTORE validates and loads them; park-borrow and slot-mount re-install pool content that came from the same linear conversation that saved the file. If any of those three is judged too subtle, the conservative alternative is a second watermark ("trusted-from-file") separate from the dirty mark — same outcome, less reasoning at the call sites. The zeroing M2 sites keep marking 0 (nothing was restored). Plus the per-stage gate fix, and one integration-style test per resume site asserting append eligibility after the resume.Why it matters from here
Our workload is the motivating case: an agent main session (~190K tokens) alternating with regenerating subagent conversations (~210K) on a 2-GPU split with
--kv-resident. We just measured the file sizes on our mixed-arch v2 validation (k8v4, kv-resident): 3.42 GB per 256,667-token conversation, 1.09 GB per 69K — and our harness is exactly the restore-before-save shape (save → switch → restore → next save). On the append branch every such save full-rewrites: ~68 GB written per 20 turns of one 256K agent, ~22 GB for the 69K one, where the delta the user actually produced is kilobytes to megabytes. SSD endurance, not just latency. #4552 is the blocker for taking #4310→#4551 seriously on switching hosts.@sakuumomo commented on GitHub (Nov 7, 2026):
Fix landed on the append branch (#4551) in the shape this thread converged on — recorded here so the issue can close once the live re-measure runs. Branch tip
c3e4cdc4(the 0.2.12 train @ upstream123bad4a, engine 0.1.58; earlier lineage tips fetchable aspin-*tags onsakuumomo/Strata).conversation_kv_restore/conversation_kv_restore_prefixmark a COMPLETED restore atupto(whole cells); a mid-transfer failure marks 0 — partial bytes did land; a refusal that wrote no pools marks nothing, so a rejected attempt cannot erase the eligibility a previous save earned.row * idx_blockat spare-row granularity, untouched, with the same-tokens-mount-stays-eligible pin now covering that reading directly.session_gate_watermark, the most-dirty fold over every carve (not just stage 0), so a stage-only rewrite via the M8/M9 backstops below the committed boundary refuses the append — the file-corrupting direction of the same defect; and the post-save raise lifts every carve's watermark, so a split save stops refusing its own next append.session_watermark_testgrew 21 → 31 checks (completed/mid-failure/refusal marking, park + borrow prefix pins, split-resume eligibility, the fold, the raise); CPU session family 7/7 (append 1969, file 263, reclaim 167); ThreadSanitizer 1969 + 260 checks, 0 warnings.One honest boundary from the thread stays stated in the body: a resume that genuinely rewrites pool rows below the boundary (the grow/trim churn from the original repro) still refuses, correctly — this fix closes the proven-bytes half, which is what makes the normal save-after-request cycle append-eligible again.
The live re-measure — this issue's own reproduce (fresh file, one short ask, re-save) against a running 0.2.12 engine — follows the owner's re-pin; the 0.1.54 → 0.1.58 identity change (engine version is in the file's config fingerprint) makes the first save of each existing session file a full rewrite, so the steady-state numbers will be posted as an update to #4551's proof tables once the deployed hosts run.