mirror of
https://github.com/mw00/project-maya.git
synced 2026-12-03 21:08:26 +07:00
[GH-ISSUE #375] DS4: keep a few conversation states, so agents with sub-agents stop re-reading their prompts #146
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
mw00/project-maya#146
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 @talisp on GitHub (Oct 22, 2026).
Original GitHub issue: https://github.com/mw00/project-maya/issues/375
In short
The problem. We run DeepSeek-V4.1-Flash on Maya with DeepSeek Harness, DeepSeek's own agent client. It routinely starts sub-agents: a main agent hands 4 small tasks to 4 helpers, then continues. That gives the server 5 conversations taking turns. Maya queues them correctly, but the DeepSeek engine keeps only one conversation's state. So every time the turn passes to another agent, the engine reads that agent's whole prompt again.
How much it costs. In one session, 12 requests in a row reused nothing from the cache. 70% of the time went to re-reading prompts (310 s) and 30% to writing answers (135 s). The main agent's ~73K-token conversation took 54 s to come back on every turn, when only a few hundred tokens were new.
Why this is common. Sub-agents are standard in agent clients now: DeepSeek Harness, Claude Code, OpenCode and Hermes all use them. Strata saw the same thing with DeepSeek Harness (Niko1221/Strata#3493:
Reused = 0on 12 of 12 requests, 73% of the time in prefill). Maya's GLM path already solves it withMAYA_GLM_SLOTS; the DeepSeek engine just doesn't have the equivalent yet.The proposal, in short:
Steps 1 and 2 alone would turn most of those 310 s into a few seconds. We're glad to test any branch on our machine and report the same numbers before and after. The technical details follow, written so that whoever implements or studies this, a person or an AI agent, has everything we found in one place.
Technical notes
All code references are to v1.1.21 (
451f9cb).1. Measurements
Hardware:
maya-ds4, unsloth UD-Q8_K_XL,--max-context 262144 --mmap-experts off --dspark none, vision on.Client: DeepSeek Harness v0.2.1-rc.2, pi-ai
openai-completionsprovider pointed at Maya's/v1.The engine log of one cycle, in order (
maya ds4 serve: prompt ... reused ... read):What the workload looks like:
2. Why it happens: the current DS4 path
src/ds4/ds4_main.cppanswersREADY <max_context> stop.serve/server.py(around L471-472) setscan_pauseandmultifrom that line, so for DS4 both stay off.FairLockthen has capacity 1, andMAYA_FAIR_SLICE_Snever applies, because it needscan_pause.ds4_main.cpp(L9-12) says: "A prompt that continues the state (the conversation so far) reuses it; one that only shares the last prompt's start goes back to that prompt's end; anything else starts over." A different conversation, or a sibling that shares only a prefix ending inside the last prompt, starts over.Model::checkpoint(int slot)andModel::restore(int64_t limit)are insrc/ds4/ds4_model.cu(around L5035 and L5072). There are only two checkpoints (ck[slot & 1]). Each holds "the window rings and the compressors' partial groups". The comment adds that "the rest of the state is indexed by position, and what lies past a restored position is written again". In other words, a checkpoint can rewind within the one resident conversation. It cannot hold a second conversation, because the position-indexed caches (the compressed KV and the indexer's cache) exist once and the next conversation overwrites them.3. How the sibling projects handle it
MAYA_GLM_SLOTS(4, SSD files, or RAM withSLOT_RAM_GB)--conversation-cache-mib N --conversation-cache-slots K(host RAM)MAYA_GLM_CKPTS(system prompt end, last turn start, everyCKPT_EVERYtokens)--prompt-cache N, turn-boundary checkpoint (docs/MESSAGE_BOUNDARY_CACHE.md)READY ... pause)--parallel/MAYA_GLM_SEQS(READY ... multi=N)"parallel": N/--batch N(batch slots, 0.1.39+,docs/BATCHING.md)MAYA_GLM_SPLIT_ROWSbatches per part--batch-groups: pipelined groups on a layer split; parked conversations restored on every stage--tp(tensor parallel) onlyPointers:
src/program/generate.cpparound L1243-1250 describes the slot design. A request that does not continue the resident conversation first sets it aside (Glm5Model::slot_save: its snapshot and DSA caches), then loads the slot it does continue (slot_load). The limits areMAYA_GLM_SLOT_MIN(1024 tokens),SLOT_GB,SLOT_DIRandSLOT_RAM_GB. Conversations with pictures are not set aside there. Checkpoints are described around L1557-1572.docs/DETAILS.md, "Multiple conversations (opt-in)". It parks up to K conversations in a bounded host-RAM cache; reuse needs no session id, only exact token and image prefixes. A 9,276-token conversation was restored in 51 ms on a 4-GPU split, and the follow-up decodes exactly the same tokens (tools/parking_test.py).docs/BATCHING.md, "Together with conversation parking": a parked conversation is restored on every stage of a layer split. Two alternating long conversations had their follow-ups at 0.46-0.53 s to the first token.docs/DEEPSEEK_V41.md. "A conversation that extends the last request continues from it; one whose re-rendered history differs (DeepSeek's encoder drops earlier turns' thinking) restores the snapshot taken at the end of the last prompt." Same model as Maya DS4 today: one resident conversation.Lessons from Strata's tracker:
Reused = 0on 12 of 12, 73% in prefill) was fixed by conversation parking alone, with no batching.docs/DETAILS.md: parking copies can stall when the host is short of memory and the OS pages them. The fix was progress reporting to the watchdog and a bounded budget.4. Possible paths for DS4
Step 1: K conversation slots (the main win).
pos(the compressed KV and the indexer's cache for every layer, and every tensor-parallel member);checkpoint()already copies);pos, the live token ids and the picture keys (for the existing "same picture at the same place" rule).--max-context. A 73K-token conversation should be roughly 70 MB, if the 0.24 GB per 256K reported at start is the full per-sequence cache.MAYA_GLM_SLOTSdoes (also covering #3027).reused N (slot k)on the existingprompt ... reused ... readline, so the server's Monitor and users can see hits and misses.Step 2: checkpoints at turn boundaries.
MAYA_GLM_CKPTSdoes.Step 3:
pause. With states that can be set aside, the engine can announcepause, and the existingMAYA_FAIR_SLICE_Slogic inserve/server.pyworks for DS4 too, so a short sub-agent request does not wait behind a 2,000-token answer.Step 4: several sequences at once (#332).
READY ... multi=N, with per-sequence caches, on one GPU or with--tp.MAYA_GLM_SEQSand Strata with--batch-groups.--mmap-experts auto), so the host expert tier is shared through the page cache instead of being copied once per engine. Requests would go to the engine that holds their conversation.5. How to check it
tools/parking_test.pydoes this at temperature 0, and the same check can be done through/v1/chat/completions.We can run any of these on the machine above and post the logs.
@mgabor3141 commented on GitHub (Oct 22, 2026):
We found two more causes of this (retries, and the reasoning dropped at a new user message); a patch on top of #356 is in #394. Your step 2 is the piece still missing for new sessions.
@mw00 commented on GitHub (Oct 22, 2026):
Thank you for the clear write-up and the numbers - the sub-agent pattern is exactly where a single conversation slot hurts. There is an open pull request for this, #356 (conversations cached across switches and restarts), and we are reviewing it for the next release. Keeping this issue open until it lands.
@mw00 commented on GitHub (Oct 23, 2026):
This shipped in v1.1.25 with #356:
MAYA_DS4_SLOT_KEEP=1keeps several conversations (in RAM, and in a folder across restarts), and with #394's patch a retried prompt or a re-rendered turn is taken back at the conversation's checkpoints. Thank you for the clear write-up - closing; feel free to reopen if your sub-agent workload still re-reads.@talisp commented on GitHub (Oct 23, 2026):
Thank you, this works. A short follow-up with numbers from the same machine (one L40S-48Q, UD-Q8_K_XL), now on v1.1.25 with
MAYA_DS4_SLOT_KEEP=1(andMAYA_DS4_SLOT_CAP=8).Switching conversations (two ~15K-token conversations alternating, measured the same way before and after):
MAYA_DS4_SLOT_KEEP=1Real agent traffic (DeepSeek Harness, 112-127K-token context): each turn reads only what is new, typically 14-600 tokens, with the rest reused.
While retuning after the update we also found that our earlier decode speed, 15 tok/s, came from our own configuration, not from Maya. With fewer CPU-lane threads plus DSpark, it is now ~41 tok/s on the same hardware. Details are in a separate issue, #433, so others don't repeat our mistake.
One small observation, in case it's useful. After we changed engine settings (
--cpu-threads,--dspark), the next start dropped the kept conversations ("5 not this model's or incomplete - removed"), so the first agent turn re-read 112K tokens (88 s). That seems reasonable if the state depends on those settings. We mention it only so it can be documented: changing those settings costs one full re-read.