Repository navigation
tests : check the byte counts and the place of the draft state appendix in a slot file - #311
Conversation
…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
176c18e to
d2c1dea
Compare
dzannotti
left a comment
There was a problem hiding this comment.
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
- 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. Addckpt = data.find(struct.pack("<I", 0x504b4353))andassert 0 < ckpt < offset. - We pushed a rebase onto master. Run
git fetch && git reset --hard origin/pr/slot-draft-state-testbefore 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, sha2567566ae7219c93ea2ecc692a931ee122d30c55261d0e2c3347acb8b939d2e9abd(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
- Should fix: the place check depends on the file holding context checkpoints, which the test does not assert (see Asks).
- Nit: on a failed size assert, pytest prints the file bytes. Use a
file_sizevariable. - Nit:
rfindcan 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_writtenequals the file size: reproduced (M1 caught).- The appendix ends the file: reproduced (M3 caught).
n_readequalsn_writtenafter 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.
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_statechecks that the draft state comes back after a restore. No test comparesn_written/n_readwith 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 intest_slot_save.py.test_slot_save_restore_draft_state_bytes(onswa_server, so the file also holds context checkpoints, with adraft-simpledraft) checks:n_writtenequals the size of the file;n_readequalsn_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
b9f3c0e87plus this commit, Release:test_slot_save.py: 21 passed.res->n_bytes = nwrite + nwrite_ckpt;in the save handler, andres->n_bytes = nread + nread_ckpt;in the restore handler. Each fails the new test and passestest_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