Skip to content

fix(dsv41): protect retained cache extents during growth - #10

Closed
sayyidfareed wants to merge 1 commit into
bertholomus:deepseek-v41-zigfrom
sayyidfareed:fix/dsv41-retained-cache-extents
Closed

sayyidfareed wants to merge 1 commit into
bertholomus:deepseek-v41-zigfrom
sayyidfareed:fix/dsv41-retained-cache-extents

Conversation

@sayyidfareed

@sayyidfareed sayyidfareed commented Oct 11, 2026 •

Copy link
Copy Markdown

What this changes

Reserve each retained prompt's request extent, not only the consumed prefix. When a continuation grows beyond that reservation, place/copy it into free space and update the retained snapshot's ownership. This prevents one growing history from overwriting another retained prefix. Keep eviction at genuine capacity pressure. The new regression covers eight 100K reservations, growth relocation, and actual capacity pressure.

Receipt

  • Environment: native base 4e80f05ecba89a4e90d16375ade2eddbdc0a10c4, Zig 0.17.0, Ubuntu 24.04.5 LTS, kernel 7.0.0-1019-nvidia, NVIDIA driver 580.178.04; Linux ARM64 CUDA environment; two NVIDIA GB10 nodes for historical live tests, SM121, Mia EXL3 2.9 bpw revision 64ba41b6c916a587db06eae2e19b7845f7be6e6b, recipe v0.6.1 kit. Container ARM64 image sha256:1ad8c1382c09861dee9c342b59f6e5e3e65fe7fde4a07b5e379bc985b66902dd.
  • Exact standalone source tested: cd32df3e13e92ca8f8151442fc3d4145ab3e6ef7; command zig build test -j1 --summary all with a shared Zig cache.
  • Host result: Build Summary: 17/19 steps succeeded (1 failed); 135/136 tests passed (1 failed). Cached groups are additional; this count is executed tests, not an invented full-suite total.
  • Host regression covers nonoverlap of eight 100K histories, relocation on growth and eviction only under actual pressure. Combined installed configuration completed distinct long-history overlap tests; standalone PR device seam/equivalence gates have not been run.
  • Lean checker: pinned baseline 1,420 findings; this branch 1417; zero new findings. Existing oversized family modules are inherited. zig fmt --check passes changed Zig files.
  • The sole host failure is the independently reproduced upstream direct_io buffered-reference bug, submitted separately; this PR does not suppress it.
  • Exactness: full drafted/plain, resumed/fresh, concurrent/solo and tensor seam gates on this standalone commit remain unrun; historical combined-device checks are not claimed as substitutes.
  • Decode/prefill: no fresh prescribed benchmark matrix for this standalone commit; no prompt-speed non-regression claim.
  • Not run: Metal M1–M5 and a clean-machine release installation. test-golden was attempted on the pinned source but that step does not exist, despite CONTRIBUTING.md naming it.
  • Public recipe and evidence and qualification limits. Draft pending remaining device/release gates and maintainer review.

Checklist

  • Every token still goes through lane rounds; no serial bypass (test-only N/A where applicable).
  • Drafted equals plain, resumed equals fresh, concurrent equals solo (test-only N/A).
  • No precision reduction is introduced; any unverified output equivalence is disclosed above.
  • Prompt processing is no slower than the last release (test-only N/A).
  • Tested and untested platforms are named.
  • Red/green regression evidence is available; other missing device gates remain disclosed.
  • Added comments are single lines; measurements/history remain in receipts.
  • Outgoing commits use the public GitHub noreply identity; no private hosts, paths, credentials or tool attribution.

Merge considerations

Two-way source revert. Preserve both ranks at the same source/runtime identity. This PR has not changed the default deployed upstream recipe.

@bertholomus

Copy link
Copy Markdown
Owner

Thank you @sayyidfareed — the failure mode (one growing history silently overwriting another retained prefix) is exactly the kind of bug that's miserable to debug, and the eight-reservation regression is the right shape for it.

We're not merging it now: it changes cache placement and eviction at serving time, the device seam/equivalence gates are still open on your own list, and the repo is in maintenance mode — small fixes only, nothing that moves existing behavior. Leaving it open with your receipt attached for the maintainers. Thanks again.

@bertholomus

Copy link
Copy Markdown
Owner

Thank you again @sayyidfareed. Development is back on, so here is an update: our own branch now has a fix for this same overwrite. A kept prompt resumes in place only where no other kept prompt has rows, and kept prompts hold their whole extent back from placement while there is room. It is waiting for a test on two nodes. When it comes to this branch we will close this PR, with credit to you for finding the bug.

bertholomus added a commit that referenced this pull request Oct 19, 2026
…ther kept state has rows

A kept prompts state now reserves its streams whole extent (rows and tail) from placement while another placement still fits, so a growing history cannot overwrite another retained prefix; a resume in place is taken only where no other kept state has rows, a duplicate of a live streams prompt waits when its copy would fill the pool, and kept states stay through a full window. A long prompt pass also lets streams near their max_tokens finish before the next pass. The Linux host build now runs the engine APIs tests too.

The overwrite was reported by @sayyidfareed (TensorFold PR #10); its regression (eight 100K histories, growth relocation, eviction only under capacity pressure) is kept as a host test here.

Host: zig build test -j1 --summary all, 21/21 steps, 217/217 tests (Zig 0.17.0 x86_64).
@bertholomus

Copy link
Copy Markdown
Owner

Thank you @sayyidfareed — closing this as superseded by our fix on deepseek-v41-zig, commit 9f82099. A kept prompt now reserves its stream's whole extent (rows and tail) from placement while another placement still fits, resumes in place only where no other kept state has rows, and relocates on growth; eviction still happens only under real capacity pressure. The eight-reservation regression from your PR (eight 100K histories, growth relocation, eviction only under pressure) is kept as a host test on the branch, adapted to our placement API, and passes; the host suite is green (21/21 steps, 217/217 tests). You found the bug and the regression is the right shape for it — credit is yours. It ships in the next engine update. Thanks again!

hashd1ve added a commit to hashd1ve/DeepSeek-V4.1-Flash-1017-EXL3-2x-DGX-Sparks-TensorFold that referenced this pull request Oct 19, 2026
…ns keep their kept prompt states

On 3ff3b2a a growing history could take the rows of another kept prompt: with two conversations taking turns
(40K tokens growing by 10K, 4 turns each) every turn of the second was prefilled again from token 0, 25-36 s
instead of 6.6 s. 9f82099, the direct child of 3ff3b2a on the same branch, is Bertholomus AI's fix (it
supersedes bertholomus/TensorFold#10): a kept prompt holds its whole extent while another placement fits,
resumes in place only where no other kept state has rows, and relocates on growth.

On our pair with 9f82099 at 1M x 4: 12 greedy prompts byte-identical to 3ff3b2a, the interleaved turns equal to
each conversation alone and 6.5-6.7 s each, 10/10 tool calls, decode 86.7 / 57.0 / 104.9 tok/s (set a, as
before), prefill 2,145 tok/s at 32K. The image tag follows the pin, so prepare.sh rebuilds the image; the rank
caches stay valid (their key does not include the Zig engine).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bertholomus pushed a commit that referenced this pull request Oct 19, 2026
…st one's kept states (#26)

A new conversation with the same system prompt and tools resumes from the shared cut, a mark inside the first
conversation's extent. keptOver skipped every state with the same base, so the second conversation resumed in place,
wrote over the first one's longer marks and staled them, and the first conversation's next turn ran from 0 (with an
agent client, a subagent or a new session started while the main session was idle). A sibling longer than the state
being resumed now counts: a conversation's own next turn still resumes in place, another one copies the shared rows
to a free extent.

Placement is first fit, so a new stream often landed flush against a kept extent's end; that conversation's next
turn then clashed with it and had to move, and a large one found no contiguous room and staled its own state.
placeSoft first tries to leave growth_rows (16 chunks) past each kept extent, then falls back to the extents and the
rows as before, so a full pool packs as it did.

A kept state of 64K tokens or more that goes stale is logged with the reason.

Tests: two new (a shared prefix, room to grow); the PR #10 test follows the new layout (the eight histories sit
growth_rows apart, a larger continuation resumes in place within that room, under pressure the oldest states still
go first).
bertholomus pushed a commit that referenced this pull request Oct 21, 2026
…st one's kept states

A new conversation with the same system prompt and tools resumes from the shared cut, a mark inside the first
conversation's extent. keptOver skipped every state with the same base, so the second conversation resumed in place,
wrote over the first one's longer marks and staled them, and the first conversation's next turn ran from 0 (with an
agent client, a subagent or a new session started while the main session was idle). A sibling longer than the state
being resumed now counts: a conversation's own next turn still resumes in place, another one copies the shared rows
to a free extent.

Placement is first fit, so a new stream often landed flush against a kept extent's end; that conversation's next
turn then clashed with it and had to move, and a large one found no contiguous room and staled its own state.
placeSoft first tries to leave growth_rows (16 chunks) past each kept extent, then falls back to the extents and the
rows as before, so a full pool packs as it did.

A kept state of 64K tokens or more that goes stale is logged with the reason.

Tests: two new (a shared prefix, room to grow); the PR #10 test follows the new layout (the eight histories sit
growth_rows apart, a larger continuation resumes in place within that room, under pressure the oldest states still
go first).

(cherry picked from commit 8dd20d2, TF PR #26, onto the served TP4 build 5c976359;
its two hunks that update a host test this line does not have are left out, its new tests are kept)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 2060ba0fc17ef4f2b5de41985fd99a42a2fc1216)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants