Skip to content

dsv41: kept prompt states: rank 0 copies before the frame, a failed follower restore stops - #41

Merged
Elevatormusic merged 4 commits into
dsv41-zigfrom
dsv41-zig-snapfix
Oct 24, 2026
Merged

Elevatormusic merged 4 commits into
dsv41-zigfrom
dsv41-zig-snapfix

Conversation

@Elevatormusic

@Elevatormusic Elevatormusic commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Two error-path defects in the kept prompt states (the prompt cache's saved states) of the dsv41 TP=2 engine. Both can make rank 0 and rank 1 hold different states. An audit of the session cache for rank divergence found them. The audit context is Refs jayleaton/deepseek-v41-tensorfold-spark#65. That fault (each rank trims its disk tier by its own file sizes) cannot occur here: rank 0 makes every keep, evict, budget and restore decision, and dsv41 has no disk tier.

  1. lanes.zig snapSaveFn (rank 0). The new state went into self.snaps before the frame flush and before rank 0's copy. If the flush or the copy failed, the errdefers freed the state, but its pointer stayed in the list. The next usable, placeKept or staleOver then read freed memory. Also, rank 1 kept that id's buffer (snapBytes of device memory), and no drop was ever sent for it.
    Fix: make room in the list first, then rank 0's copy, then the frame, then add the state to the list. next_snap goes up before the save, so an id is never used again.
  2. lanes.zig restore, both ranks. Rank 0 sent snap_restore before its own copies. Rank 1 logged a failed copyExtent or snapCopy (follow_refused) and continued with a state different from rank 0's: a silent divergence for that stream.
    Fix: rank 0 does its copies first, so a failed copy on rank 0 sends no frame. A follower whose restore copy fails returns the error and stops.

kept_order.zig (new, std only) holds the order of these steps. The three call sites in lanes.zig use it.

Known gaps

Receipt

  • Environment: dsv41-zig @ 84ded67d plus this branch. Zig 0.17.0, CPU only (no GPU work).
  • zig test kept_order.zig with the old order in the helpers: 1 passed, 5 failed. With this change: 6 of 6 pass.
    • a save whose copy fails sends no frame and keeps no state
    • a save whose frame fails keeps no state
    • a save copies, then sends, then keeps the state
    • a restore whose copy fails on rank 0 sends no frame
    • a follower whose restore copy fails stops
    • a follower without the kept state stops (passes on both orders: a guard)
  • zig ast-check and zig fmt --check on the changed files: pass.
  • zig build test-cuda-host at da420678 (CPU container, no GPU work, run without the GPU lock): rc 0 in 173 s. Its 5 "failed command" lines are the usual notes for test steps that print warnings.

Checklist

  • Every token still goes through the lane rounds.
  • No precision traded for speed.
  • No GPU kernel change.
  • Prompt processing is no slower: the same copies and frames, in a different order.
  • Platforms: CUDA on GB10 at TP=2. Metal not affected (dsv41 is CUDA only).
  • New tests: 6 CPU tests in kept_order.zig. 5 fail on the old order.

…ollower restore stops

snapSaveFn put the new state into self.snaps before the frame and before
rank 0's copy. When the flush or the copy failed, the errdefers freed the
state, but its pointer stayed in the list (a use after free in the next
placement), and rank 1 kept a buffer that was never dropped. Now the list
has room first, rank 0 copies, then sends, then appends.

The rank 0 restore sent its frame before its own copies, and rank 1 logged a
failed restore copy and continued with a state different from rank 0's.
Now rank 0 copies first (a failed copy sends no frame), and a follower whose
restore copy fails stops.

kept_order.zig holds the order, with 6 CPU tests (std only).
@Elevatormusic Elevatormusic added the type: fix a correction after review findings or a bug fix label Oct 23, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T18:43:09.399531Z 8e5680f Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Elevatormusic

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: da420678d7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…very pull request)

zig fmt 0.17.0 changes only layout and @intFromEnum to @backingInt.
The Zig format check fails on these five base-branch files in every
open dsv41-zig pull request, also where the pull request does not touch them.
@Elevatormusic

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 8e5680ffc3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Elevatormusic
Elevatormusic merged commit de491bf into dsv41-zig Oct 24, 2026
6 checks passed
@Elevatormusic
Elevatormusic deleted the dsv41-zig-snapfix branch October 24, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix a correction after review findings or a bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant