[GH-ISSUE #606] DS4: a checkpoint at every turn, so going back or editing an earlier message does not re-read the conversation #251

Open
opened 2026-10-29 21:23:18 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @mgabor3141 on GitHub (Oct 28, 2026).
Original GitHub issue: https://github.com/mw00/project-maya/issues/606

Setup: v1.1.34 (no change to this code in v1.1.35), DeepSeek-V4.1-Flash Maya-S on 4x RTX 3090, MAYA_DS4_SLOT_KEEP=1. Client: pi coding agent; one user, long agent sessions (100-220K tokens).

What happens. A conversation, in the model or in a slot, can be resumed only at its three checkpoints: the end of the last prompt, the position before it, and the anchor (from #394). When a client goes back to an earlier turn, or the user edits their last message, the prompt leaves the conversation before the last prompt's end. Maya then falls back to the anchor or to token 0 and re-reads everything after it.

Example from today's slots (the token arrays in the .meta files):

tokens
saved conversation 96,260 (checkpoints 95,968 / 95,967 / anchor 67,110)
next prompt 95,979: the user edited the last message, "you run it" -> "you run it, with plain sudo. it will prompt me for pw"
shared prefix 95,966 (inside the edited message)
resumed at 67,110 (anchor): 28,869 tokens re-read in 31 s

A checkpoint at the end of the previous answer (95,962, where the last user message starts) would have left 17 tokens to read. Going back several turns is the same, only further: the next checkpoint behind the last prompt is the anchor, or nothing.

Two things make it worse:

  • slot_put drops every saved state that is a prefix of the one being saved, so the earlier states of a conversation, which could serve as resume points, are gone after the next save.
  • Apart from the anchor, a conversation keeps checkpoints only from its last prompt, so no turn before that can be resumed.

Proposal. Keep a checkpoint at the end of every turn (the end of each prompt, and the end of each answer), up to a cap per conversation (say the last 32), in the model and in the slot's .meta/.bin. slot_take already picks the latest checkpoint at or before the shared prefix; what is fixed at 3 today is Check ck[3] and the .meta reader's nc > 3 check. The GLM engine already keeps earlier checkpoints (MAYA_GLM_CKPTS, MAYA_GLM_CKPT_EVERY); this would be the same idea for DS4, at turn ends.

Cost. A checkpoint is the window rings plus the compressors' partial groups. Across our 124 slots, a slot's size is exactly 924 bytes per token plus 11.7 MB, whether its .meta lists 2 checkpoints or 3. That fixed part holds the checkpoints and the live window rings, so by our estimate one checkpoint is about 3 MB: 32 would add about 100 MB per conversation, against 0.2 GB of KV for a 200K-token conversation. Taking one is a device-to-host copy of that size per turn.

Happy to test a build.

Originally created by @mgabor3141 on GitHub (Oct 28, 2026). Original GitHub issue: https://github.com/mw00/project-maya/issues/606 **Setup:** v1.1.34 (no change to this code in v1.1.35), DeepSeek-V4.1-Flash Maya-S on 4x RTX 3090, `MAYA_DS4_SLOT_KEEP=1`. Client: pi coding agent; one user, long agent sessions (100-220K tokens). **What happens.** A conversation, in the model or in a slot, can be resumed only at its three checkpoints: the end of the last prompt, the position before it, and the anchor (from #394). When a client goes back to an earlier turn, or the user edits their last message, the prompt leaves the conversation before the last prompt's end. Maya then falls back to the anchor or to token 0 and re-reads everything after it. Example from today's slots (the token arrays in the `.meta` files): | | tokens | |---|---| | saved conversation | 96,260 (checkpoints 95,968 / 95,967 / anchor 67,110) | | next prompt | 95,979: the user edited the last message, "you run it" -> "you run it, with plain sudo. it will prompt me for pw" | | shared prefix | 95,966 (inside the edited message) | | resumed at | 67,110 (anchor): 28,869 tokens re-read in 31 s | A checkpoint at the end of the previous answer (95,962, where the last user message starts) would have left 17 tokens to read. Going back several turns is the same, only further: the next checkpoint behind the last prompt is the anchor, or nothing. Two things make it worse: - `slot_put` drops every saved state that is a prefix of the one being saved, so the earlier states of a conversation, which could serve as resume points, are gone after the next save. - Apart from the anchor, a conversation keeps checkpoints only from its last prompt, so no turn before that can be resumed. **Proposal.** Keep a checkpoint at the end of every turn (the end of each prompt, and the end of each answer), up to a cap per conversation (say the last 32), in the model and in the slot's `.meta`/`.bin`. `slot_take` already picks the latest checkpoint at or before the shared prefix; what is fixed at 3 today is `Check ck[3]` and the `.meta` reader's `nc > 3` check. The GLM engine already keeps earlier checkpoints (`MAYA_GLM_CKPTS`, `MAYA_GLM_CKPT_EVERY`); this would be the same idea for DS4, at turn ends. **Cost.** A checkpoint is the window rings plus the compressors' partial groups. Across our 124 slots, a slot's size is exactly 924 bytes per token plus 11.7 MB, whether its `.meta` lists 2 checkpoints or 3. That fixed part holds the checkpoints and the live window rings, so by our estimate one checkpoint is about 3 MB: 32 would add about 100 MB per conversation, against 0.2 GB of KV for a 200K-token conversation. Taking one is a device-to-host copy of that size per turn. Happy to test a build.
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mw00/project-maya#251
No description provided.