Skip to content

feat(kv): the context switch — page KV to disk on eviction, restore on return - #2719

Merged
joelteply merged 2 commits into
canaryfrom
feat/kv-disk-paging-context-switch
Sep 1, 2026
Merged

joelteply merged 2 commits into
canaryfrom
feat/kv-disk-paging-context-switch

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

The designed tier that was never wired

The restore economy's whole premise — many personas context-switching over few slots like OS threads over registers, near-instant page-in/out — hinges on llama-server's slot save/restore. That needs --slot-save-path at launch and explicit /slots/{id}?action=save|restore calls. The tree had zero references to either. Every rotation was a full re-prefill: last night's measured hit_rate 0.0 on every act, 35–45s prefill each, decodes starved to 2–7 t/s.

What lands

  • --slot-save-path in the unconditional lane spine, geometry-keyed dir (model + per-slot ctx) so pages can't restore into mismatched slots; stale generations swept at spawn.
  • Paging ledger in slots.rs: lease_paged() names the evictee to save and whether the returner restores; warm re-leases do neither.
  • Adapter performs the switch around the Turn pin — ordered on the slot, exactly the FIFO inference already imposes; nothing else waits. Probed: inference.kv_page.action.
  • kv-pages tracked + eviction-decided (spawn sweep owns stale geometries; broker pool deferred under Add genome visualization to root README with live video #155).

Companion to #2717 (re-home guard counts lanes). Together: plans actuate, and when residents still exceed slots, rotation costs ~0.1s instead of ~35s.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

joelteply and others added 2 commits September 1, 2026 08:04
…n questions

The field's complaints (subagent context copies, 48GB vanishing, hand-
configured vision models, 2-3x slow loops, dotfile setup) are symptoms
of disposable sessions. Map each question their users actually ask to
the mechanism that answers it structurally: warm KV slots instead of
context copies, demand-derived serving instead of spawn-and-pray,
sensory bridge instead of a vision checkbox, probed loop economics
instead of vibes, configuration-as-activities instead of dotfiles.
Honesty line: instrumented, not finished; beta re-measures.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…n return

The restore economy's designed tier, never wired: llama-server's slot
save/restore (measured ~0.1s at 20k tokens) requires --slot-save-path
at launch and explicit /slots/{id}?action=save|restore calls, and the
tree had ZERO references to either. So rotation on an oversubscribed
server — 5 residents, 2-3 citizen slots, all last night — cost a full
re-prefill per act: hit_rate 0.0 on every turn, 21-28k tokens and
35-45s each, prefill traffic starving every decode to 2-7 t/s.

The OS shape (Joel: 'many threads but one at a time … they page in and
out per persona; seamless like an os is with registers'):

- lane_args: --slot-save-path joins the unconditional spine — a lane
  without it silently amputates the whole paging tier (pinned by test).
- llama_server: the dir is GEOMETRY-KEYED (model + per-slot ctx) so a
  page can never restore into a mismatched slot; stale geometry
  generations are swept at spawn (the class's eviction owner).
- slots.rs: the paging ledger — holders (who warmed each slot) + saved
  (who has a page). lease_paged() names who to SAVE before the new
  turn overwrites the slot and whether to RESTORE the returner's page;
  warm same-holder re-leases do neither (the in-slot KV is fresher).
- openai_adapter: performs the switch around the Turn pin — save the
  evictee, restore the returner, both ordered on the slot exactly like
  the inference they bracket (the only FIFO; nothing else waits).
  Probes: inference.kv_page.action {action, ok, ms}.
- disk_reporters + disk_eviction: kv-pages tracked, eviction decided
  (spawn sweep owns stale geometries; broker pool deferred under #155).

Tests: slot_recycling_pages_the_evictee_out_and_the_returner_in,
slot_save_path_is_part_of_the_unconditional_spine. inference:: 378/378,
disk_eviction 11/11.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply enabled auto-merge (squash) September 1, 2026 13:24
@joelteply
joelteply merged commit fe71779 into canary Sep 1, 2026
5 checks passed
@joelteply
joelteply deleted the feat/kv-disk-paging-context-switch branch September 1, 2026 13:38
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