Skip to content

server: a page carries the draft's KV once; checkpoints stop copying it (#79 on the shipping line, through #118's pipeline) - #130

Merged
joelteply merged 2 commits into
codex/s4-per-mind-integrationfrom
fable/draft-kv-once-s4
Nov 16, 2026
Merged

joelteply merged 2 commits into
codex/s4-per-mind-integrationfrom
fable/draft-kv-once-s4

Conversation

@joelteply

Copy link
Copy Markdown

#79 has been stale since 10-28 against a base that never shipped. It's re-implemented here on codex/s4-per-mind-integration through #118's page pipeline, because #118 moved the save its diff targeted. #79's own review fixes are kept: the sidecar is bound to the page's exact tokens, written whole, and bounded by the file.

What changes

  • Checkpoints: a draft that rolls back by trimming (the MTP head's plain KV) is no longer copied into every checkpoint. slot.mem.seq_rm trims it on restore.
  • The page: carries it once as .dft. The copy is made on the loop, counted in the quote and the IO admission; the write happens on the pool via a .partial file renamed over; the read on the pool must match the file's exact size.
  • Restore: the draft is applied only when the token count and hash match the restored tokens. Otherwise the draft sequence is cleared and starts cold.

Measured (qwen35-0.8b, draft-mtp, M5, 2026-11-16)

  • Save, erase, restore, continue at temperature 0:
    • with .dft, 47 of 47 drafts accepted;
    • without it, 43 of 59 (cold);
    • continuation text identical both ways.
  • The same save on the shipping line: .ckpt 43.9 MiB, against 38.5 MiB here plus a 3.3 MiB .dft, at about 1.7k tokens. The saving is about 2 KiB per token per checkpoint, so it grows with her context. server: a page carries the draft's KV once; checkpoints stop copying it #79 measured 246 MB per checkpoint at 118k tokens on the M5.
  • 0 warnings.

Measured after deploy

Owner: Fable, in the engine window. Host RSS of the engine at four residents, and the checkpoint bytes per slot from /slots (#127 adds that report).

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

…it (#79 on the shipping line, through #118's page pipeline)

A draft whose memory rolls back by trimming (plain attention KV: the MTP head) has nothing a checkpoint must
hold; on restore slot.mem.seq_rm trims its live KV to the checkpoint (common_memory holds both contexts).
Copying it made it 79% of every checkpoint (#79's M5 receipt: 246 MB at 118k tokens), up to
n_ctx_checkpoints copies per slot in host RAM. Now:
- create_checkpoint skips the draft's state when ctx_dft_seq_rm_type is PART;
- a saved page carries the draft KV once, the `.dft` sidecar, riding #118's pipeline: copied on the loop
  into the job (counted in the size quote and in the page IO admission), written on the pool to .partial
  and renamed over (never torn; a stale .dft is removed when a page has none);
- the header binds it to exactly the page's tokens (count + FNV-1a hash) and names the state's size; the
  pool reads it only when the file is exactly a header plus that state (never allocated from a claim);
  the loop applies it only when it covers exactly the restored tokens, else clears the draft sequence
  (never another occupant's KV at these positions): the draft then starts cold and the target still
  verifies every token.

Receipts (qwen35-0.8b, --spec-type draft-mtp, M5, 2026-11-16): generate, save the page, erase the slot,
restore it, continue at temperature 0: with the .dft sidecar the draft accepted 47 of 47; with it deleted
before the restore, 43 of 59 (cold); the continuation text identical both ways. The same save on the
shipping line without this change: .ckpt 43.9 MiB vs 38.5 MiB here with the draft carried once (3.3 MiB
.dft) at ~1.7k tokens; the saving is ~2 KiB per token per checkpoint, so it grows with her context. 0 warnings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Author

Independent review of exact3242ea2ca5a9bd01bb0f269bff96a0809c4a8c55: BLOCK on sidecar computation identity (P2).

Target page and adapter sidecar publish before .dft. Restore accepts draft by token count/hash only. Identical token history recomputed under another active adapter followed by a crash between those writes can pair a new target/adapter page with an old draft state that passes validation. MTP draft state depends on the computation, not only token IDs. Bind both to the same save generation/computation identity and add interrupted-overwrite coverage with identical tokens but different computation identity.

Target verification still checks proposals: this is foreign draft state/degraded drafting, not demonstrated output corruption. The PART no-copy rollback itself looks sound: existing memory owner trims, and empty draft checkpoint data is a no-op. Windows filesystem rename was checked and is not a blocker (MSVC replaces existing destination).

Reviewer: checkpoint_close_review. Exact-head visible CPU/server CI passed; reviewer did not independently reproduce M5 performance measurements.

…never outlive an interrupted save (Codex's review of #130)

- .dft v2 names an FNV-1a hash of the save's own .lora sidecar bytes (adapters + file revisions) beside the
  token hash; the restore applies the draft only when tokens AND computation match, else it drafts cold.
- page_write removes the old .dft before publishing the page, and writes the new one last (temp + rename):
  an interruption anywhere leaves no draft or this save's, never an earlier save's of the same tokens.

Receipt (qwen35-0.8b, draft-mtp, M5): clean save/erase/restore matched (no cold draft); the same .dft with its
computation hash changed was refused ("no draft sidecar matching this page ... the draft starts cold");
a re-save rewrote it and the next restore matched again. 0 warnings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Author

Independent reviewer checkpoint_close_review APPROVE source exact61b96f668ae982dcaacfc0a72e9426edcc9960d9: draft v2 binds token and adapter identities/revisions; old removal precedes target publish, new tmp+rename follows; existing page owner serializes same-file operations. Prior interrupted-save different-adapter blocker resolved. Consider checking ignored initial dft removal error as hardening. Exact-head CI and live comparison remain required; M5 receipt not independently reproduced.

@joelteply
joelteply merged commit f39cf25 into codex/s4-per-mind-integration Nov 16, 2026
11 checks passed
@joelteply
joelteply deleted the fable/draft-kv-once-s4 branch November 16, 2026 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant