Skip to content

tests : check the byte counts and the place of the draft state appendix in a slot file - #311

Merged
dzannotti merged 1 commit into
halo-box:masterfrom
rcfa:pr/slot-draft-state-test
Nov 21, 2026
Merged

dzannotti merged 1 commit into
halo-box:masterfrom
rcfa:pr/slot-draft-state-test

Conversation

@rcfa

@rcfa rcfa commented Nov 20, 2026

Copy link
Copy Markdown

Follow-up to #171, which was closed as superseded by ggml-org#30574, with the suggestion to send its test separately.

test_slot_restore_draft_state checks that the draft state comes back after a restore. No test compares n_written / n_read with the file when the slot file holds the draft state appendix, so a save or a restore that leaves the draft bytes out of its count passes every test in test_slot_save.py.

test_slot_save_restore_draft_state_bytes (on swa_server, so the file also holds context checkpoints, with a draft-simple draft) checks:

  • n_written equals the size of the file;
  • the appendix ends the file: read at its magic, its version and two length-prefixed blocks stop exactly at EOF;
  • after an erase and a restore, n_read equals n_written.

Test only; no server change.

Verification (Strix Point, Ryzen AI 9 HX PRO 370 / Radeon 890M, gfx1150; not Strix Halo), CPU build of master b9f3c0e87 plus this commit, Release:

  • test_slot_save.py: 21 passed.
  • Mutants: res->n_bytes = nwrite + nwrite_ckpt; in the save handler, and res->n_bytes = nread + nread_ckpt; in the restore handler. Each fails the new test and passes test_slot_restore_draft_state.

Not verified: Windows and macOS. The test runs the server like the rest of the file; no GPU backend is involved.

Written by Claude Code (an AI agent) for rcfa; rcfa owns it.

Generated with Claude Code

@dzannotti dzannotti added in-review We are reviewing. testing labels Nov 21, 2026
…ix in a slot file

test_slot_restore_draft_state checks that the draft state comes back after a restore. No test compares n_written /
n_read with the file when it holds the draft state appendix, so a save or a restore that leaves the draft bytes out of
its count passes every test in test_slot_save.py.

test_slot_save_restore_draft_state_bytes saves a slot that holds checkpoints and a draft state, and checks that
n_written equals the file size, that the appendix ends the file, and that n_read equals n_written after a restore.

Assisted-by: Claude Code
@dzannotti
dzannotti force-pushed the pr/slot-draft-state-test branch from 176c18e to d2c1dea Compare November 21, 2026 02:39

@dzannotti dzannotti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict

Approved. The new test passes on both backends, and it fails on each of five broken server builds. Three of those break only the byte counts or the layout, and the existing draft state test still passes on them.

Direction

Accept. This is the follow-up test that #171 asked for, and it changes no server code.

Asks

  1. Should fix, not blocking. tools/server/tests/unit/test_slot_save.py:959: the place check catches an appendix in the wrong place only when the file also holds context checkpoints. Today the prompt makes 2 checkpoints, but the test does not assert that. If a later change makes no checkpoint for this prompt, a swapped layout passes. Add ckpt = data.find(struct.pack("<I", 0x504b4353)) and assert 0 < ckpt < offset.
  2. We pushed a rebase onto master. Run git fetch && git reset --hard origin/pr/slot-draft-state-test before you push again.

Nit: a failed assert n_written == len(data) prints the file bytes. Compare against a file_size variable instead.

Correctness

PASS. test_slot_save.py passes 21/21 on the rebased head and 20/20 on master, on Vulkan and on ROCm. The new test passes 10/10 repeats on Vulkan. The server code is the same on both sides, so logit, KLD and decode checks do not apply.

Mutation check. We built five servers with one defect each and ran the new test and test_slot_restore_draft_state on each:

Defect New test test_slot_restore_draft_state
save n_bytes leaves out the draft bytes FAIL (n_written != file size) pass
restore n_bytes leaves out the draft bytes FAIL (n_read != n_written) pass
draft appendix written and read before the checkpoints FAIL (walk ends at 7122496 of 17568748) pass
extra 4-byte field in the appendix, counted FAIL (bad length prefix) fail
no draft appendix FAIL (no magic) fail

Verification

Strix Halo (gfx1151). The PR was 7 commits behind master. We rebased it onto master 1fe05fa45 with no conflicts and pushed the rebase (176c18ee6 -> d2c1dea57). The numbers are for the rebased head against master.

Not tested

CPU-only build, Windows, macOS, and the full server pytest suite.

Thank you for the test.

Review made with AI on behalf of the strix-llama.cpp maintainers.

Full verification (for reproduction and agents)

Environment

  • Ubuntu 26.04.1 LTS, kernel 7.0.0-43-generic
  • ROCm: hipconfig 7.16.26385, AMD clang 24.0.0git (d6f6cb691863)
  • Vulkan: Mesa 26.0.8 RADV (Radeon 8060S, STRIX_HALO)
  • cmake 4.2.3, gcc 15.2.0, Python 3.14.4, pytest 8.3.5 (tests/requirements.txt in a venv)

Compared

  • master tip: 1fe05fa458c4d3c60957fdbb3a9bcc75e3d85f0c
  • PR head as reviewed: 176c18ee6a20db384a73d265f8a5149442dd72fc
  • merge base: b9f3c0e878f82f80ea1528969f305017a909b73e (7 commits behind)
  • rebased head (pushed): d2c1dea57

Rebase

No conflicts. git rebase origin/master applied the single commit unchanged. range-diff: 1: 176c18ee6 = 1: d2c1dea57. Pushed with a lease on 176c18ee6.

Build

cmake -S <dir> -B <dir>/build-vk -G Ninja -DCMAKE_BUILD_TYPE=Release -DGGML_VULKAN=ON -DGGML_HIP=OFF
cmake -S <dir> -B <dir>/build-hip -G Ninja -DCMAKE_BUILD_TYPE=Release -DGGML_HIP=ON -DGGML_VULKAN=OFF -DGPU_TARGETS=gfx1151 -DCMAKE_HIP_COMPILER=$(hipconfig -l)/clang -DCMAKE_PREFIX_PATH=$(hipconfig -R)
cmake --build <dir>/build-<be> -j 16 --target llama-server

The mutation servers are Vulkan builds of the rebased head, with one edit each to tools/server/server-context.cpp.

Models

  • ggml-org-dev/tinygemma3-GGUF, tinygemma3-Q8_0.gguf, sha256 7566ae7219c93ea2ecc692a931ee122d30c55261d0e2c3347acb8b939d2e9abd (target and draft, the swa_server preset)

Commands

cd tools/server/tests && mkdir -p tmp
LLAMA_SERVER_BIN_PATH=<build>/bin/llama-server python -m pytest -v unit/test_slot_save.py
LLAMA_SERVER_BIN_PATH=<build>/bin/llama-server python -m pytest -s -v unit/test_slot_save.py -k "draft_state"
# mutants: LD_LIBRARY_PATH=<mutant bin> LLAMA_SERVER_BIN_PATH=<mutant bin>/llama-server \
#   python -m pytest -s -v unit/test_slot_save.py -k "draft_state or preserves_context_checkpoints"

Results

Run Vulkan ROCm
master, test_slot_save.py 20 passed 20 passed
rebased head, test_slot_save.py 21 passed 21 passed
rebased head, new test alone, 10 repeats 10/10 passed not repeated

Server log of the new test on the rebased head (both backends): appended 2 context checkpoint(s) (9.962 MiB), appended the draft state (3.396 MiB), then restored 2 context checkpoint(s) and restored the draft state (3.396 MiB); file size 17568748 bytes. The speculative state block is empty for draft-simple, so the walk reads a zero length for it.

Mutants (Vulkan). Each row also ran the two test_slot_restore_preserves_context_checkpoints cases, which passed on every mutant.

Mutant Edit New test test_slot_restore_draft_state
M1 save: res->n_bytes = nwrite + nwrite_ckpt; FAIL assert 14007932 == 17568748 (n_written == len(data)) pass
M2 restore: res->n_bytes = nread + nread_ckpt; FAIL assert 14007932 == 17568748 (n_read == n_written) pass
M3 save the draft appendix before the checkpoints, and read it first FAIL assert 7122496 == 17568748 (pos == len(data)) pass
M4 write version twice in the draft appendix FAIL struct.error on the length prefix fail (draft_n differs)
M5 save_slot_draft writes nothing FAIL assert -1 > 0 fail (draft_n differs)

Correctness

Check Method Result
Functional, base vs head, both backends test_slot_save.py on master and on the rebased head PASS (20 -> 21, no new failure)
The test finds the defect five mutant servers PASS (5/5 caught, 3 only by the new test)
Flakiness 10 repeats on Vulkan PASS (10/10)
scripts/server-test-*.py not run N/A, no server code change
Full server pytest suite not run only test_slot_save.py ran
Logit parity, KLD, decode not run N/A, no server code change
Disk writes not measured N/A, no product code change

Findings in full

  1. Should fix: the place check depends on the file holding context checkpoints, which the test does not assert (see Asks).
  2. Nit: on a failed size assert, pytest prints the file bytes. Use a file_size variable.
  3. Nit: rfind can match the 4 magic bytes inside the 3.4 MiB draft payload, about 1 chance in 1000. The test then fails falsely. The run is deterministic, so it does not flake here.

Claims

  • n_written equals the file size: reproduced (M1 caught).
  • The appendix ends the file: reproduced (M3 caught).
  • n_read equals n_written after a restore: reproduced (M2 caught).
  • The file also holds context checkpoints: reproduced from the server log (2 checkpoints), not asserted by the test.
  • The two mutants from the PR description fail the new test and pass test_slot_restore_draft_state: reproduced (M1, M2).
  • No server change: reproduced; the diff touches only the test file.

Not tested

CPU-only build, Windows and macOS. The full server pytest suite did not run.

@dzannotti dzannotti added ready-to-merge Review done, low risk, approved. risk:low Risk: low verified The claims were reproduced. and removed in-review We are reviewing. labels Nov 21, 2026
@dzannotti
dzannotti merged commit 2c3dc19 into halo-box:master Nov 21, 2026
5 checks passed
@rcfa
rcfa deleted the pr/slot-draft-state-test branch November 27, 2026 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Review done, low risk, approved. risk:low Risk: low server testing verified The claims were reproduced.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants