Skip to content

glm: a kept state that goes stale drops its cache entry at once - #835

Merged
ashhart merged 3 commits into
ashhart:mainfrom
heitke:glm-cache-slot-guard
Oct 16, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
heitke:glm-cache-slot-guard

Conversation

@heitke

@heitke heitke commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Cache lifetime repair only. The branch is reset to 027ddea, exactly as requested in the maintainer review.

The maintainer reports that 8be4d32 and its 027ddea merge landed for 1.0.12, with the added deferred-admission regression. Dead saved states stop serving lookups immediately, active borrowers retain saved state through restore completion, and destruction/peer commands wait for a safe host boundary.

Sampling moved out

The later sampling commits fb3cc20 and 8e8dc68 are removed from this branch. Their feature work and the target-row/shared-sampler repairs are on heitke:glm-sampling-target-rows, with redacted one-Mac qualification results, for separate review.

Validation

  • This update moves the branch pointer to the requested existing commit and changes no cache implementation.
  • Merge check against main c7137bb: clean.
  • Historical validation at 027ddea: host suite, server suite (117/117), GLM expiry gate and formatting passed, as previously recorded.
  • The new sampling qualification belongs to its separate branch, not this cache-only PR.

The maintainer may close this PR as merged as described in the linked review.

A resident prompt state died (its slot's rows overwritten, or its pool
blocks given up) left the Store serving the dead entry: every later
lookup found it, its restore failed, and the pass prefilled the whole
prompt from the start — the repeated full-refill cascade seen on live
servers with long conversations. The backend now tells the prompt cache
the moment a state goes stale (Slots.expire), so the Store drops that
entry immediately and the next turn keeps a fresh state instead of
paying for the same failure again.
@heitke
heitke marked this pull request as draft October 14, 2026 12:31
@ashhart

ashhart commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Hello @heitke,

Thank you for this. Dropping a stale GLM snap from the prompt cache is the right end state: the next lookup misses once, prefills from the start, and never serves a state whose rows are gone. Two of us read it closely, and the order of the drop needs one more pass, in three places:

  1. The prefill that is restoring a snap can free it first. prefill casts reuse.saved, calls pool.reserve, then reads snap.at and usable (backend.zig:97, :107). When no free run fits, place calls evictHeld (pool.zig:107), which can pick that same snap, and wentStale frees it before the read.
  2. place can free its own from. If from is the only snap holding blocks, evictHeld picks it (pool.zig:124-130), the free runs, and the next loop reads f.held from freed memory (pool.zig:105).
  3. overwrite walks sl.snaps with a value iterator (kept.zig:67-71) while wentStale's chain ends in sl.drop's fetchRemove on the same map (kept.zig:159-161), so a second stale snap in that walk can be skipped and stay in the cache.

One way through all three: mark snaps stale during the walk and report them to the cache after it, and never free a snap that a prefill or a pending report still holds (lane_host.zig:90). A test for each order would pin it.

Thank you again, and please push an update when you have one.

The prefill path read a snap after pool admission could free it, and
overwrite walked snaps while expiry dropped them. A resident state that
dies now expires its cache entry at the host boundary; each lookup
borrows its entry and snap until resumed or release ends that ownership;
reclamation runs at host boundaries and skips active borrowers.
# Conflicts:
#	zig/src/core/prompt_cache.zig
@ashhart

ashhart commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks, @heitke. We landed the cache guard from 8be4d32 and its 027ddea merge for 1.0.12. It fixes a use-after-free present in 1.0.11 when another admission can evict a saved prefix before its prefill reads it. Our added regression covers that deferred-admission case.

The newer fb3cc20 and 8e8dc68 commits add sampled decoding, which needs a separate review. At 8e8dc68, the prompt samples its first reply token, but the one-token target head in zig/src/families/glm/slots.zig:347 still has no draw payload and falls through to argmax at forward.zig:507. The depth-zero standalone path clears draws at engine.zig:460 and reaches the same problem through plain_rounds.zig:28. Drafted windows already use keyed draws, so drafts on and off can disagree for a sampled request.

Could you move those two sampling commits into a new PR and reset #835 to 027ddea? That lets us close this PR as merged while keeping the sampling follow-up focused on drawing every target row with its absolute position and keyed rule.

@heitke

heitke commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

Commits have been moved to #892. I gave up on local AI on this one. These latest actions were done by GPT 6.1 Sol.

@heitke
heitke marked this pull request as ready for review October 15, 2026 20:03
@ashhart
ashhart merged commit 0731efe into ashhart:main Oct 16, 2026
8 checks passed
ashhart added a commit that referenced this pull request Oct 16, 2026
…ed-up state stays until its request restores it (#835)
ashhart added a commit that referenced this pull request Oct 16, 2026
… and GLM-5.3-Flash on CUDA (#804) onto the candidate

The saved conversations' disk recall evicts through the cache's victimBut, which #835 moved into
prompt_cache_policy.zig; prompt_cache.zig re-exports it, so that eviction also skips borrowed entries.
ashhart added a commit that referenced this pull request Oct 16, 2026
…ash images, image URLs and video (#598, #614, #618)

The lane host keeps #835's report (a looked-up entry is resumed or released on every path) with the image-aware
cache key; GLM's host keeps the stale-state expiry beside the image and video prepares; CHANGELOG in landing order.
ashhart pushed a commit that referenced this pull request Oct 16, 2026
Port the sampling follow-up from #835 (fb3cc20 and 8e8dc68), incorporating the queued-row and shared-sampler repairs from #524 (79e1004, 1e28ee6 and 0174809). Keep the cache lifetime repair separate.

Arm queued and pipelined standalone target rows at their absolute output positions. Pack canonical gpu_rule values without lossy conversions, bound dispatch-run copies, and preserve local greedy vocabulary widths on peers. Include host regressions and a Mac qualification recipe.
@ashhart

ashhart commented Oct 16, 2026

Copy link
Copy Markdown
Owner

Thank you, @heitke, for the cache lifetime fix and its regression coverage.

Your guard ships in TensorFold 1.0.12 under your name as 5477b36db and e5b968691; the second keeps your merge's resolution of the born argument. Your reset head (027ddea98) is merged too, with no change to the tree (0731efedc), so this pull request shows as merged.

Ours follow: 51e6f48b4 wraps long lines and shortens the restore report's expression without changing its three outcomes, dcea37f1c adds a lane host test that a queued request's kept prefix outlives another request's reservation, which fails without your guard and passes with it, and 21c7313b0 keeps the merged host under our file-size limit with the same admission order.

The expiry suite passes, and on an M3 Ultra a GLM-5.3-Flash state that goes stale now misses once and then resumes: a 3,794-token conversation sharing a slot resumed 3,781 tokens on its second turn after the interruption, where it prefilled in full twice, with the same reply tokens. Nemotron's CUDA replies, cached conversations and concurrent replies are unchanged.

Posted by Ash's AI Assistant Synthena

BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…ry (ashhart#835) and GLM-5.3-Flash on CUDA (ashhart#804) onto the candidate

The saved conversations' disk recall evicts through the cache's victimBut, which ashhart#835 moved into
prompt_cache_policy.zig; prompt_cache.zig re-exports it, so that eviction also skips borrowed entries.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…ash images, image URLs and video (ashhart#598, ashhart#614, ashhart#618)

The lane host keeps ashhart#835's report (a looked-up entry is resumed or released on every path) with the image-aware
cache key; GLM's host keeps the stale-state expiry beside the image and video prepares; CHANGELOG in landing order.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
ashhart#835 (@heitke) reset to 7d879fb: his two commits and public main merged in. The
candidate carries the guard as re-landed (99c8944, af0fecc) with the landing
work after it, so this merge changes no file: fourteen of its twenty files merge
to the tip's content as they are, and the six that conflict keep the tip's text,
which holds his change in the landed form (glm_expiry.zig and
prompt_cache_policy.zig wrapped under 120 columns; reported()'s three cases as
one condition on the cache key; the requeue teardown after the list removal, as
ashhart#738's landing ordered it; victimBut public for the disk rows; engine_api's test
imports in lane_host_test.zig; glm_host.zig's image offer, which his base lacks).
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
Port the sampling follow-up from ashhart#835 (fb3cc20 and 8e8dc68), incorporating the queued-row and shared-sampler repairs from ashhart#524 (79e1004, 1e28ee6 and 0174809). Keep the cache lifetime repair separate.

Arm queued and pipelined standalone target rows at their absolute output positions. Pack canonical gpu_rule values without lossy conversions, bound dispatch-run copies, and preserve local greedy vocabulary widths on peers. Include host regressions and a Mac qualification recipe.
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