Skip to content

serve: Qwen3.8 slots save to a file and restore from it, the MTP draft's side with them - #1027

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-usab-prompt-state-disk
Oct 30, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-usab-prompt-state-disk

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Qwen3.8 서버가 POST /slots/0?action=save|restore에서 501 대신 slot 상태를 파일로 저장하고 복원합니다. 새 프로세스에서 복원해도 이어지는 요청이 저장 없이 이어간 요청과 같습니다.

What and why

bloomery-serve-qwen38 and bloomery-serve answered 501 to a slot save or restore on a Qwen3.8 model, so a long conversation could not outlive the process. With --slot-save-path DIR the seat now writes the state its prompt cache already holds (the body's sequence state and, with BLOOMERY_DRAFT=mtp, the parked MTP draft) as a file, and a restore puts it back through the prompt cache's own resume path. A slot that holds an image is refused, as a snapshot is.

A restore reads the whole file before it touches the slot, and refuses a bad file by name with HTTP 400 while the server keeps answering: a short stream, trailing bytes, another model's identity (arch, file, card, ctx), a token id past the vocabulary, an image placeholder in a saved text history, positions past the context, a draft state saved with the draft on put back with it off, and a parked draft whose refresh, last unit or row mapping does not match the restored body.

Release notes: Added: Qwen3.8 slot save and restore (--slot-save-path DIR), including the MTP draft's state.

Code shape

The review reads these first. A box left unticked needs one line of why.

  • No second copy. Logic two models (or two call sites) share has one common owner; I lifted it there instead of
    copying it (AGENTS.md "Common code first", docs/rust-quality.md R14). Where I found an existing copy, I
    named it below.
  • Model code holds only architecture facts. A model's own files carry only what its architecture forces
    (tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
  • Dead code is gone. Nothing I made unused is left behind (functions, flags, gate clauses, docs).
  • No silent failure. Undefined input is a named error or panic, never a defined-looking output.
  • Comments state what is true now. No dates, issue numbers or how a bug was found (tools/check-comments.sh).
  • No relaxed gate. No band, tolerance or lint moved to relax a check; a re-pin carries PIN(YYYY-MM-DD):
    and its reason.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line):

  • The little-endian state writer and reader existed twice: privately in crates/gpu-deepseek41/src/body/snap.rs and, as this change needed it, for SeqState and the MTP draft. They are one owner now, crates/gpu/src/checkpoint/bytes.rs, and the V4.1 snapshot uses it (about 170 lines fewer in snap.rs; its header bytes are unchanged).
  • slot_action was copied in crates/gpu-gates/src/bin/gate_qwen38_serve.rs and crates/gpu-gates/src/bin/gate_ds41_serve.rs; it lives in crates/gpu-gates/src/serve_client.rs and both gates call it.

What I ran

Tested head e7afc962f007d8937a1f8edb308dbef746b7cebf on base 9fa4e0036cea9712f683a3443593031429de3bf3.

Slot file on a Qwen3.8 fixture file, GB10. The drafted arm of gate_qwen38_serve starts its own server (BLOOMERY_DRAFT=mtp, --cache-ram 0, fixed width) and saves, erases and restores slot 0. Command, as the gate-gpu-qwen38-serve recipe runs the drafted arm:

BLOOMERY_BOX_LOCAL=1 BLOOMERY_TIER=fixture BLOOMERY_MODEL=qwen4exp ./tools/box.sh '... cargo oxide build --arch sm_121a ... --bin bloomery-serve-qwen38 --bin gate_qwen38_serve ...; bash tools/gpu-gate.sh generate_qwen3moe --place gate --tokens "$I" -n 16 > gen.log && bash tools/gpu-gate.sh gate_qwen38_serve --arm drafted --gen gen.log --prompt "$T" --ids "$I" --dir ...'
slot file: the continuation straight: tokens [143015, 234137, ..., 125052] cache_n=20 draft_n=45 joins [] offs [] keeps []
slot file: the continuation after the restore: tokens [143015, 234137, ..., 125052] cache_n=20 draft_n=45 joins [] offs [] keeps []
check slot_file_round_trip: PASS
check slot_file_restore_is_the_straight_run: PASS
slots restore of slot 0: HTTP 400: {"error":{"code":400,"message":"Unable to restore slot: state bytes: a short stream: it ends inside the draft's off reason, past byte 18159828", ...
check slot_file_cut_short_is_refused_by_name: PASS
slots restore of slot 0: HTTP 400: ... "state bytes: a saved draft id 4294967295 past the vocabulary of 248320" ...
check slot_file_past_vocab_refresh_id_is_refused_by_name: PASS
slots restore of slot 0: HTTP 400: ... "qwen4exp slot restore: rows 1..2 of the Pass arena as positions 19..20 for a walk from 20: the arena holds positions 19..20" ...
check slot_file_shifted_refresh_rows_are_refused_by_name: PASS
slots restore of slot 0: HTTP 400: ... "a saved PLE history: token 4294967295 is past the 248320-token vocabulary: not a token of this model" ...
check slot_file_past_vocab_ple_history_is_refused_by_name: PASS
slots restore of slot 0: HTTP 400: ... "a saved PLE history: token 248056 is the image placeholder; the n-gram hash runs on text only, and an image position has no token id to hash" ...
check slot_file_image_ple_history_is_refused_by_name: PASS
slot file off: the off slot saved 117 positions, the turn's file 82; restore HTTP 200
check slot_file_off_draft_round_trip: PASS
gate checks PASS 37, FAIL 0

Each refusal is followed by a fresh request on the same server with the same ids and cache_n=0, so the server kept serving. To show the restore checks catch what they are for, I removed one line in serve_seats/drafted.rs (turn_off no longer clears the waiting refresh) and ran the same gate:

slots restore of slot 0: HTTP 400: ... "state bytes: a parked draft's refresh of 1 rows from position 82 on a state of 117" ...
check slot_file_off_draft_round_trip: FAIL
gate-mutant checks PASS 35, FAIL 1

Real binary, FP4-Local, GB10. bloomery-serve with the release features glm5next,clef,vision,mimo2,solar2,minimaxm3,flint,gemma-embedding2,hf,checkpoint on the folder nvidia/Qwen3.8-Flash-Next-FP4-Local (revision b9ce18a6):

BLOOMERY_RESIDENCY=off bloomery-serve -m <folder> --host 127.0.0.1 --port 18753 --parallel 1 --ctx-size 16384 --slot-save-path <dir>

One server saved slot 0 after a 36-id prompt and its first answer, a second server in a new process restored it, and the follow-up request was sent to both a server that never saved (the straight run) and the restored one:

continuation straight: HTTP 200 48 ids cache_n=83 draft 43/30
save: HTTP 200 {'n_saved': 83, 'n_written': 297563492, 'timings': {'save_ms': 147.777585}}
restore: HTTP 200 {'n_restored': 83, 'n_read': 297563492, 'timings': {'restore_ms': 143.393958}}
continuation after the restore in a new process: HTTP 200 48 ids cache_n=83 draft 36/26
check a_mtp_save_and_restore_answer: PASS
check b_mtp_restored_continuation_is_the_straight_run: PASS cache_n 83 vs 83
cut restore: HTTP 400 ... "state bytes: a short stream: it ends inside the draft's off reason, past byte 297563127" ...
check d_cut_file_refused_by_name: PASS
draft-on file on a draft-off server: HTTP 400 ... "a slot restore: a state saved with the MTP draft on put back with it off" ...
check e_draft_on_file_refused_by_a_draft_off_server: PASS
off: save 200 n_written 297350075; erase 200; restore 200 n_read 297350075
check f_off_round_trip_is_the_straight_run: PASS cache_n 83 vs 83

The draft proposed 36 tokens and accepted 26 after the restore, so the draft's state came back with the slot. The width chooser picks the draft width from a clock, so the proposal counts differ from run to run on this server; the fixed-width gate above shows draft_n=45 on both sides.

Host tests and FAIL-first, x86_64:

bash tools/gate.sh --oxide -p bloomery-app --release --lib -- mtp::policy::tests::a_parked_draft_is_checked_against_its_state --test-threads=1
bash tools/gate.sh --oxide -p bloomery-gpu --release --lib -- arch::qwen3moe::mtp38::tests::target_rows_are_read_where_their_final_rows_hold_them --test-threads=1
bash tools/gate.sh --oxide -p bloomery-gpu-gates --release --bin bloomery-serve-qwen38 --features deepseek41,gemma-embedding2,hf -- parked_sides_refuse_ids_past_the_vocabulary --test-threads=1
test mtp::policy::tests::a_parked_draft_is_checked_against_its_state ... ok
test arch::qwen3moe::mtp38::tests::target_rows_are_read_where_their_final_rows_hold_them ... ok
test drafted::tests::parked_sides_refuse_ids_past_the_vocabulary ... ok
(refresh end position check removed)  a_parked_draft_is_checked_against_its_state ... FAILED
(final rows check removed)            target_rows_are_read_where_their_final_rows_hold_them ... FAILED
(vocab bound >= changed to >)         parked_sides_refuse_ids_past_the_vocabulary ... FAILED
SIDE-CHECK PASS: 3 tests, 3 mutants rejected

Hardware (if the change is for a machine)

NVIDIA GB10, 595.84
CUDA Version 13.3.1

Built with cargo oxide build --arch sm_121a.

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 30, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: MUST_FIX: Restore accepts an image placeholder in a saved text history and uses it without a named refusal.

Must fix

1. Reject image placeholders in saved text histories

crates/gpu/src/arch/qwen3moe/body38.rs:5610 passes true for every history token's image-span flag. On a model with ple.image_token_id, changing a current or checkpoint history token to that reserved ID therefore passes restore. Slot snapshots refuse images and carry no image rotation state. Resume installs the history at body38.rs:4022. A continuation reusing that history reaches crates/engram/src/hash.rs:608, which hashes its prior tokens without validating them again. This is a kind A failure: invalid text history affects inference instead of producing a named error.

Enforce the existing text-token contract while this file format is new. Replace line 5610 with:

                .check(t)

Extend the PLE corruption clause to substitute the image placeholder in both current and checkpoint histories and require HTTP 400. Its present past-vocabulary mutation passes on this defect.

Checked

Duplicates: diagnostics report no dryer pairs; gpu and gpu-gates were excluded from that scan.

Complexity: diagnostics flag six functions. Complexity alone supplies no finding.

Silent failure: saved PLE IDs traced through seq_take, load_state, and Hash::ple_rows_spanned; the image-span bypass reaches the consumer.

Tests: the PLE corruption clause at gate_qwen38_serve.rs:5475 substitutes u32::MAX; it does not exercise the reserved image ID. Validation was static; no build or GPU gate was run.

Gates: no tolerance, threshold, lint level, or existing gate clause relaxed; no re-pin required.

Escape catalog: C1–C4 do not apply to the retained finding. No ledger lessons are in force.

Notes

The supplied GPU gate command contains ...; attach the complete invocation and resolved model file for verification evidence. The PR also supplies no PTX sameness output for the extracted walk check.

Card check: needs-gpu. This pull request changes crates/app/src/mtp.rs, crates/app/src/mtp/policy.rs, crates/gpu-deepseek41/src/body/snap.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

Comment thread crates/gpu/src/arch/qwen3moe/body38.rs Outdated
};
for &t in state.values().flat_map(History::tokens) {
window
.check_at(t, true)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Slot snapshots refuse image state; validate saved history IDs as text so the reserved image placeholder is refused.

Suggested change
.check_at(t, true)
.check(t)

@juliankang4
juliankang4 force-pushed the dgx-spark-q38-usab-prompt-state-disk branch from c838a9d to e7afc96 Compare October 30, 2026 22:11
github-actions[bot]
github-actions Bot previously approved these changes Oct 30, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since the last review: the image-placeholder must-fix is fixed. body38.rs:306 uses the existing text-token validator for every current and checkpoint history.

Verdict: CLEAN: The restore bypass is closed, and no new must-fix survives the interdiff review.

Checked

Duplicates: 2 new functions checked; no duplicate owner. The validator reuses EosWindow::check. Dryer reports 0 pairs; gpu and gpu-gates were excluded, so the new items were searched manually.

Complexity: slot_file (76) adds corruption-test branches. The other flags are unchanged by this interdiff: SeqState::take (43), SeqState::put (30), slot_file_off_draft (28), Parked::take (21), and drafted_main (20).

Silent failure: 2 error paths followed. Invalid histories produce a named HTTP 400 before resume; model-metadata failures return a gate error.

Tests: Static mutation check: replacing .check(t) at body38.rs:306 with .check_at(t, true) makes the new unit test's image rejection and the HTTP image-refusal clause fail. Checking only the current history makes the checkpoint-corruption clause fail. Dropping the length check or checking only one token makes unit assertions fail. No build or GPU test was run in this review.

Gates: No band, threshold, lint level, or existing clause was relaxed. No PIN required.

Adversarial checks: Image IDs in older history positions and checkpoints are rejected; EOS and the last valid text ID pass. Wrong history lengths and mapped windows return named errors. The changed production path is file restore, outside decode and prefill.

Escape catalog: C1–C4 have no matching pattern in the interdiff.

Notes

The GPU command remains abbreviated with ... and unresolved model/input paths, so the supplied evidence is incomplete. The earlier PTX sameness evidence is still absent. The new image-refusal clause has PASS output, but no FAIL-first output for reinstating the image-span bypass.

Card check: needs-gpu. This pull request changes crates/app/src/mtp.rs, crates/app/src/mtp/policy.rs, crates/gpu-deepseek41/src/body/snap.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since the last review: the image-placeholder fix remains present in body38.rs:306. The previous review had no open must-fix or non-blocking items.

Verdict: CLEAN: The import-only rebase resolution preserves the chain symbols and restore validator.

Checked

Duplicates: 0 new definitions in the interdiff. Imported symbols resolve to their existing owners. Dryer reports 0 pairs; gpu and gpu-gates were excluded from its search.

Complexity: All crapper flags are unchanged by this interdiff: slot_file (76), SeqState::take (43), SeqState::put (30), slot_file_off_draft (28), Parked::take (21), drafted_main (20). No function body gained branches.

Silent failure: 0 new sites. The interdiff changes no error handling.

Tests: No new or changed tests. Static mutation check: removing the final-row guard at mtp38.rs:988 makes the existing final-row refusal assertion fail; allowing image placeholders at body38.rs:306 makes the existing saved-history rejection assertion fail. No build or GPU gate was run.

Gates: No thresholds, clauses, tests or lint levels changed; no PIN required.

Adversarial checks: Zero-position and overflowing-row draft reads are rejected before subtraction or access. Restore still validates every current and checkpoint history. The import resolution preserves both chain_spans and check_target_rows; it adds no work to decode or prefill.

Escape catalog: No C1–C4 pattern matches the interdiff.

Notes

GPU evidence remains incomplete: commands contain ... and unresolved inputs, and the reported hashes predate this head. The earlier PTX sameness evidence and image-refusal FAIL-first output remain absent.

Card check: needs-gpu. This pull request changes crates/app/src/mtp.rs, crates/app/src/mtp/policy.rs, crates/gpu-deepseek41/src/body/snap.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit c084a8e into midagedev:main Oct 30, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset needs-gpu Changes code a card must check, and carries no gate run on a card

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant