From 14f12b7b7971b6f907e58820c98f313a5a71d17f Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Sun, 15 Nov 2026 23:07:56 -0600 Subject: [PATCH 1/7] server: /slots reports each slot's context checkpoints (count, bytes) (continuum: price the checkpoint store from measurement) On the M5 (2026-11-16, Qwen3.6-35B-A3B, 5 slots, --ctx-checkpoints 32) the engine's host allocations held ~15 GB beyond its KV (MALLOC_LARGE in footprint), of which the 6.7 GB prompt cache is budgeted and the checkpoints (~110 MB each on this hybrid model, from the saved sidecars) are not: the host thrashed (11.5 GB swap, 14 GB compressor) and decode fell from ~80 to 1-4 tok/s per stream. The core can only budget what it can read: each slot now reports its checkpoints' count and bytes. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- tools/server/server-context.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/server/server-context.cpp b/tools/server/server-context.cpp index a5ea94329965..42f1921c9413 100644 --- a/tools/server/server-context.cpp +++ b/tools/server/server-context.cpp @@ -736,6 +736,16 @@ struct server_slot { res["kv_pos_max"] = llama_memory_seq_pos_max(mem, id); } + // The slot's context checkpoints as they sit in host memory now (Continuum fork): their count + // and their bytes, so the core prices the checkpoint store from what it holds, not a guess. + { + size_t bytes = 0; + for (const auto & ckpt : prompt.checkpoints) { + bytes += ckpt.size(); + } + res["checkpoints"] = { {"count", prompt.checkpoints.size()}, {"bytes", bytes} }; + } + const auto & ptask = task ? task : task_prev; if (ptask) { From a206006b640a3cd6c24d742d56350eac99921ef2 Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Sun, 15 Nov 2026 23:13:30 -0600 Subject: [PATCH 2/7] server: a checkpoint byte budget the engine keeps across every slot (continuum 4.10, the checkpoint store) POST /engine/checkpoint-budget {"bytes": n | null}. With a budget, each new context checkpoint is followed by erasing the oldest checkpoint of the slot holding the most checkpoint bytes until every slot's checkpoints fit; a checkpoint that alone exceeds the budget is not kept. null (and an engine never told) is unbounded: today's behaviour, so this merges inert until the core grants a budget in its one memory allocation. Live, so the engine stays up while the budget follows the host. Measured motive (the M5, 2026-11-16): ~110 MB per checkpoint x up to 32 x 5 slots unbudgeted; the host thrashed (11.5 GB swap) and decode fell from ~80 to 1-4 tok/s per stream. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- tools/server/server-context.cpp | 80 +++++++++++++++++++++++++++++++++ tools/server/server-context.h | 1 + tools/server/server.cpp | 2 + 3 files changed, 83 insertions(+) diff --git a/tools/server/server-context.cpp b/tools/server/server-context.cpp index 42f1921c9413..53c85d24cbb2 100644 --- a/tools/server/server-context.cpp +++ b/tools/server/server-context.cpp @@ -898,6 +898,57 @@ struct server_context_impl { // update_slots pass; the trainer reads it between batches (see server-train.h) std::atomic n_busy_slots{0}; + // The host bytes every slot's context checkpoints may hold together, as the core last granted + // them in its one memory allocation (continuum CONTINUUM-ENGINE 4.10, the checkpoint store); + // -1 is unbounded, today's behaviour. Set by POST /engine/checkpoint-budget. + std::atomic checkpoint_budget_bytes{-1}; + + // Keep every slot's checkpoints within the granted budget: past it, the oldest checkpoint of the + // slot holding the most checkpoint bytes goes first (its oldest is the least likely restore + // point), never `keep`, the checkpoint just made. Returns whether `keep` itself fits. + bool keep_checkpoints_within_budget(const common_prompt_checkpoint * keep) { + const int64_t budget = checkpoint_budget_bytes.load(std::memory_order_relaxed); + if (budget < 0) { + return true; + } + auto held = [&]() { + int64_t bytes = 0; + for (const auto & slot : slots) { + for (const auto & ckpt : slot.prompt.checkpoints) { + bytes += (int64_t) ckpt.size(); + } + } + return bytes; + }; + while (held() > budget) { + server_slot * largest = nullptr; + int64_t largest_bytes = -1; + for (auto & slot : slots) { + int64_t bytes = 0; + for (const auto & ckpt : slot.prompt.checkpoints) { + if (&ckpt != keep) { + bytes += (int64_t) ckpt.size(); + } + } + if (bytes > largest_bytes && !slot.prompt.checkpoints.empty() && !(slot.prompt.checkpoints.size() == 1 && &slot.prompt.checkpoints.front() == keep)) { + largest = &slot; + largest_bytes = bytes; + } + } + if (largest == nullptr || largest_bytes <= 0) { + return false; // only the new checkpoint is left and it alone exceeds the budget + } + auto victim = largest->prompt.checkpoints.begin(); + if (&*victim == keep) { + ++victim; + } + SLT_INF(*largest, "erasing context checkpoint over the checkpoint budget (%" PRId64 " bytes; pos_min = %d, pos_max = %d, size = %.3f MiB)\n", + budget, victim->pos_min, victim->pos_max, (float) victim->size() / 1024 / 1024); + largest->prompt.checkpoints.erase(victim); + } + return true; + } + // The most one sequence may hold: llama_n_ctx_seq capped at the model's training context. // ONE value, set at load: every slot is sized from it and context_geometry reports it, so // the report never names a size the slots refuse (it said 524288 while each slot capped at @@ -2610,6 +2661,12 @@ struct server_context_impl { } const auto & kept = slot.prompt.checkpoints.emplace_back(std::move(cur)); + if (!keep_checkpoints_within_budget(&kept)) { + SLT_WRN(slot, "a context checkpoint of %.3f MiB alone exceeds the checkpoint budget: not kept (a restore from here will be cold)\n", + (float) kept.size() / 1024 / 1024); + slot.prompt.checkpoints.pop_back(); + return; + } SLT_TRC(slot, "created context checkpoint %d of %d (pos_min = %d, pos_max = %d, n_tokens = %" PRId64 ", size = %.3f MiB)\n", @@ -6714,6 +6771,29 @@ void server_routes::init_routes() { }; // a read answers from the loop's last publication, never queued behind the chunk it reports on + // The checkpoint store's host byte budget (continuum 4.10), granted by the core in its one memory + // allocation. {"bytes": n} with n >= 0 sets it (checkpoints past it are erased oldest-first at the + // next checkpoint); {"bytes": null} returns to unbounded. + this->post_checkpoint_budget = [this](const server_http_req & req) { + auto res = create_response(); + const json body = req.body.empty() ? json::object() : json::parse(req.body); + if (!body.contains("bytes")) { + res->error(format_error_response("\"bytes\" is required (a count of at least 0, or null for unbounded)", ERROR_TYPE_INVALID_REQUEST)); + return res; + } + const json & bytes = body.at("bytes"); + if (bytes.is_null()) { + ctx_server.checkpoint_budget_bytes.store(-1); + } else if (bytes.is_number_integer() && bytes.get() >= 0) { + ctx_server.checkpoint_budget_bytes.store(bytes.get()); + } else { + res->error(format_error_response("\"bytes\" must be at least 0, or null", ERROR_TYPE_INVALID_REQUEST)); + return res; + } + res->ok({ { "bytes", bytes } }); + return res; + }; + this->get_learn_grants = [this](const server_http_req &) { auto res = create_response(); res->ok(ctx_server.ledger_as_published()); diff --git a/tools/server/server-context.h b/tools/server/server-context.h index a5c5a59370fe..eade2a6c6810 100644 --- a/tools/server/server-context.h +++ b/tools/server/server-context.h @@ -178,6 +178,7 @@ struct server_routes { server_http_context::handler_t post_learn_residency, release_learn_residency, revoke_learn_residency; server_http_context::handler_t get_learn_grants, post_learn_grants, revoke_learn_grant, post_learn_preflight; server_http_context::handler_t get_learn_events; + server_http_context::handler_t post_checkpoint_budget; server_http_context::handler_t post_prompt_cache_limit; server_http_context::handler_t get_train; server_http_context::handler_t post_train; diff --git a/tools/server/server.cpp b/tools/server/server.cpp index bae64ebe1c3f..0715d0c53e4c 100644 --- a/tools/server/server.cpp +++ b/tools/server/server.cpp @@ -225,6 +225,7 @@ int llama_server(common_params & params, int argc, char ** argv) { routes.post_learn = models_routes->proxy_post; routes.get_learn_grants = models_routes->proxy_get; routes.get_learn_events = models_routes->proxy_get; + routes.post_checkpoint_budget = models_routes->proxy_post; routes.post_learn_grants = models_routes->proxy_post; routes.post_learn_preflight = models_routes->proxy_post; routes.post_prompt_cache_limit = models_routes->proxy_post; @@ -298,6 +299,7 @@ int llama_server(common_params & params, int argc, char ** argv) { ctx_http.post("/learn/preflight", ex_wrapper(routes.post_learn_preflight)); ctx_http.post("/learn/grants", ex_wrapper(routes.post_learn_grants)); ctx_http.get ("/learn/events", ex_wrapper(routes.get_learn_events)); + ctx_http.post("/engine/checkpoint-budget", ex_wrapper(routes.post_checkpoint_budget)); ctx_http.post("/prompt-cache/limit", ex_wrapper(routes.post_prompt_cache_limit)); ctx_http.post("/learn/grants/revoke", ex_wrapper(routes.revoke_learn_grant)); ctx_http.get ("/train", ex_wrapper(routes.get_train)); From 0f4d9f82a314d30e995fc0c882ade97926de58d9 Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Sun, 15 Nov 2026 23:19:46 -0600 Subject: [PATCH 3/7] server: placed checkpoints only when the request carries view spans (continuum CONTINUUM-ENGINE 4.7.3) With view spans (view_end_pos >= 0) the prompt loop makes no upstream step checkpoint at user-message starts; it still checkpoints at the view end and at the prompt's end offsets (MTP rollback, learning). A new view-end checkpoint erases every checkpoint an earlier act left on the slot except the oldest (her head, the restore point when her next prompt diverges before her view end). Per slot: head + newest view end + this act's end checkpoints, ~4-5 instead of up to --ctx-checkpoints 32. A request without spans (an external driver) keeps upstream behaviour. Measured motive (the M5, 2026-11-16 05:00Z, Qwen3.6-35B-A3B): ~110 MB per checkpoint x up to 32 x 5 slots, host thrash (swap 11.5/12 GB, compressor 14 GB), decode ~80 -> 1-4 tok/s per stream. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- tools/server/server-context.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tools/server/server-context.cpp b/tools/server/server-context.cpp index 53c85d24cbb2..fbf582d3a845 100644 --- a/tools/server/server-context.cpp +++ b/tools/server/server-context.cpp @@ -2661,6 +2661,23 @@ struct server_context_impl { } const auto & kept = slot.prompt.checkpoints.emplace_back(std::move(cur)); + + // Continuum fork (CONTINUUM-ENGINE 4.7.3, placed checkpoints): her new view-end checkpoint + // supersedes every checkpoint an earlier act left on this prefix except her head's (the oldest, + // the restore point when her next prompt diverges before her view end). What stays per slot is + // her head, her newest view end, and this act's end checkpoints. + if (slot.prompt.view_end >= 0 && kept.n_tokens == slot.prompt.view_end) { + const common_prompt_checkpoint * head = &slot.prompt.checkpoints.front(); + for (auto it = slot.prompt.checkpoints.begin(); it != slot.prompt.checkpoints.end(); ) { + if (&*it != head && it->id_task != id_task) { + SLT_TRC(slot, "erasing a checkpoint her view end supersedes (n_tokens = %" PRId64 ", size = %.3f MiB)\n", + it->n_tokens, (float) it->size() / 1024 / 1024); + it = slot.prompt.checkpoints.erase(it); + continue; + } + ++it; + } + } if (!keep_checkpoints_within_budget(&kept)) { SLT_WRN(slot, "a context checkpoint of %.3f MiB alone exceeds the checkpoint budget: not kept (a restore from here will be cold)\n", (float) kept.size() / 1024 / 1024); @@ -4477,8 +4494,11 @@ struct server_context_impl { /* is_prompt = */ true); slot.prompt.tokens.push_back(cur_tok); - // break at the last user message, or at user messages at least min step past the last checkpoint - if (do_checkpoint && spans.is_user_start(slot.prompt.n_tokens())) { + // break at the last user message, or at user messages at least min step past the last checkpoint. + // Continuum fork: not when the request carries her view spans: then the view end below is + // where her next prompt diverges, and blind step checkpoints only pile up (CONTINUUM-ENGINE + // 4.7.2-4.7.3; the M5, 2026-11-16: up to 32 x ~110 MB per slot thrashed the host) + if (do_checkpoint && view_end_pos < 0 && spans.is_user_start(slot.prompt.n_tokens())) { const auto pos = slot.prompt.n_tokens(); const auto & checkpoints = slot.prompt.checkpoints; From 763e641e9ca0435801788eeed4dcd7ef9a9bbaef Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Sun, 15 Nov 2026 23:59:48 -0600 Subject: [PATCH 4/7] server: drop the checkpoint byte budget (the revert of a206006b6 never ran); placed checkpoints only and the /slots report remain The byte budget patched blind checkpoints instead of removing them (continuum #6068 replaced it with 4.7.3's placed checkpoints, 0f4d9f82a); its route, atomic, evictor and call site go. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- tools/server/server-context.cpp | 80 --------------------------------- tools/server/server-context.h | 1 - tools/server/server.cpp | 2 - 3 files changed, 83 deletions(-) diff --git a/tools/server/server-context.cpp b/tools/server/server-context.cpp index fbf582d3a845..78a45b788748 100644 --- a/tools/server/server-context.cpp +++ b/tools/server/server-context.cpp @@ -898,57 +898,6 @@ struct server_context_impl { // update_slots pass; the trainer reads it between batches (see server-train.h) std::atomic n_busy_slots{0}; - // The host bytes every slot's context checkpoints may hold together, as the core last granted - // them in its one memory allocation (continuum CONTINUUM-ENGINE 4.10, the checkpoint store); - // -1 is unbounded, today's behaviour. Set by POST /engine/checkpoint-budget. - std::atomic checkpoint_budget_bytes{-1}; - - // Keep every slot's checkpoints within the granted budget: past it, the oldest checkpoint of the - // slot holding the most checkpoint bytes goes first (its oldest is the least likely restore - // point), never `keep`, the checkpoint just made. Returns whether `keep` itself fits. - bool keep_checkpoints_within_budget(const common_prompt_checkpoint * keep) { - const int64_t budget = checkpoint_budget_bytes.load(std::memory_order_relaxed); - if (budget < 0) { - return true; - } - auto held = [&]() { - int64_t bytes = 0; - for (const auto & slot : slots) { - for (const auto & ckpt : slot.prompt.checkpoints) { - bytes += (int64_t) ckpt.size(); - } - } - return bytes; - }; - while (held() > budget) { - server_slot * largest = nullptr; - int64_t largest_bytes = -1; - for (auto & slot : slots) { - int64_t bytes = 0; - for (const auto & ckpt : slot.prompt.checkpoints) { - if (&ckpt != keep) { - bytes += (int64_t) ckpt.size(); - } - } - if (bytes > largest_bytes && !slot.prompt.checkpoints.empty() && !(slot.prompt.checkpoints.size() == 1 && &slot.prompt.checkpoints.front() == keep)) { - largest = &slot; - largest_bytes = bytes; - } - } - if (largest == nullptr || largest_bytes <= 0) { - return false; // only the new checkpoint is left and it alone exceeds the budget - } - auto victim = largest->prompt.checkpoints.begin(); - if (&*victim == keep) { - ++victim; - } - SLT_INF(*largest, "erasing context checkpoint over the checkpoint budget (%" PRId64 " bytes; pos_min = %d, pos_max = %d, size = %.3f MiB)\n", - budget, victim->pos_min, victim->pos_max, (float) victim->size() / 1024 / 1024); - largest->prompt.checkpoints.erase(victim); - } - return true; - } - // The most one sequence may hold: llama_n_ctx_seq capped at the model's training context. // ONE value, set at load: every slot is sized from it and context_geometry reports it, so // the report never names a size the slots refuse (it said 524288 while each slot capped at @@ -2678,12 +2627,6 @@ struct server_context_impl { ++it; } } - if (!keep_checkpoints_within_budget(&kept)) { - SLT_WRN(slot, "a context checkpoint of %.3f MiB alone exceeds the checkpoint budget: not kept (a restore from here will be cold)\n", - (float) kept.size() / 1024 / 1024); - slot.prompt.checkpoints.pop_back(); - return; - } SLT_TRC(slot, "created context checkpoint %d of %d (pos_min = %d, pos_max = %d, n_tokens = %" PRId64 ", size = %.3f MiB)\n", @@ -6791,29 +6734,6 @@ void server_routes::init_routes() { }; // a read answers from the loop's last publication, never queued behind the chunk it reports on - // The checkpoint store's host byte budget (continuum 4.10), granted by the core in its one memory - // allocation. {"bytes": n} with n >= 0 sets it (checkpoints past it are erased oldest-first at the - // next checkpoint); {"bytes": null} returns to unbounded. - this->post_checkpoint_budget = [this](const server_http_req & req) { - auto res = create_response(); - const json body = req.body.empty() ? json::object() : json::parse(req.body); - if (!body.contains("bytes")) { - res->error(format_error_response("\"bytes\" is required (a count of at least 0, or null for unbounded)", ERROR_TYPE_INVALID_REQUEST)); - return res; - } - const json & bytes = body.at("bytes"); - if (bytes.is_null()) { - ctx_server.checkpoint_budget_bytes.store(-1); - } else if (bytes.is_number_integer() && bytes.get() >= 0) { - ctx_server.checkpoint_budget_bytes.store(bytes.get()); - } else { - res->error(format_error_response("\"bytes\" must be at least 0, or null", ERROR_TYPE_INVALID_REQUEST)); - return res; - } - res->ok({ { "bytes", bytes } }); - return res; - }; - this->get_learn_grants = [this](const server_http_req &) { auto res = create_response(); res->ok(ctx_server.ledger_as_published()); diff --git a/tools/server/server-context.h b/tools/server/server-context.h index eade2a6c6810..a5c5a59370fe 100644 --- a/tools/server/server-context.h +++ b/tools/server/server-context.h @@ -178,7 +178,6 @@ struct server_routes { server_http_context::handler_t post_learn_residency, release_learn_residency, revoke_learn_residency; server_http_context::handler_t get_learn_grants, post_learn_grants, revoke_learn_grant, post_learn_preflight; server_http_context::handler_t get_learn_events; - server_http_context::handler_t post_checkpoint_budget; server_http_context::handler_t post_prompt_cache_limit; server_http_context::handler_t get_train; server_http_context::handler_t post_train; diff --git a/tools/server/server.cpp b/tools/server/server.cpp index 0715d0c53e4c..bae64ebe1c3f 100644 --- a/tools/server/server.cpp +++ b/tools/server/server.cpp @@ -225,7 +225,6 @@ int llama_server(common_params & params, int argc, char ** argv) { routes.post_learn = models_routes->proxy_post; routes.get_learn_grants = models_routes->proxy_get; routes.get_learn_events = models_routes->proxy_get; - routes.post_checkpoint_budget = models_routes->proxy_post; routes.post_learn_grants = models_routes->proxy_post; routes.post_learn_preflight = models_routes->proxy_post; routes.post_prompt_cache_limit = models_routes->proxy_post; @@ -299,7 +298,6 @@ int llama_server(common_params & params, int argc, char ** argv) { ctx_http.post("/learn/preflight", ex_wrapper(routes.post_learn_preflight)); ctx_http.post("/learn/grants", ex_wrapper(routes.post_learn_grants)); ctx_http.get ("/learn/events", ex_wrapper(routes.get_learn_events)); - ctx_http.post("/engine/checkpoint-budget", ex_wrapper(routes.post_checkpoint_budget)); ctx_http.post("/prompt-cache/limit", ex_wrapper(routes.post_prompt_cache_limit)); ctx_http.post("/learn/grants/revoke", ex_wrapper(routes.revoke_learn_grant)); ctx_http.get ("/train", ex_wrapper(routes.get_train)); From 5018f8bd3d654e7d517e51ef369bcca9beccb82d Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Mon, 16 Nov 2026 00:23:27 -0600 Subject: [PATCH 5/7] server: with view spans, count eviction keeps her head checkpoint (Codex on #121) The generic count eviction erased front() before the placed pruning ran, so a full store (today's 32-checkpoint state) lost the true head and the pruning then kept the next survivor as 'head'. With view spans the oldest checkpoint after the head goes first; the head goes only when it is the only one. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- tools/server/server-context.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/server/server-context.cpp b/tools/server/server-context.cpp index 78a45b788748..d41396d3abe7 100644 --- a/tools/server/server-context.cpp +++ b/tools/server/server-context.cpp @@ -2585,13 +2585,19 @@ struct server_context_impl { } while (slot.prompt.checkpoints.size() >= (size_t) params_base.n_ctx_checkpoints) { - // make room for the new checkpoint, if needed - const auto & cur = slot.prompt.checkpoints.front(); + // make room for the new checkpoint, if needed. Continuum fork (CONTINUUM-ENGINE 4.7.3): with + // view spans her head (the oldest) is her restore point when her next prompt diverges before + // her view end, so the oldest AFTER it goes first; the head goes only when it is all there is + const bool keep_head = slot.prompt.view_end >= 0 && slot.prompt.checkpoints.size() >= 2; + auto victim = slot.prompt.checkpoints.begin(); + if (keep_head) { + ++victim; + } SLT_WRN(slot, "erasing old context checkpoint (pos_min = %d, pos_max = %d, n_tokens = %" PRId64 ", size = %.3f MiB)\n", - cur.pos_min, cur.pos_max, cur.n_tokens, (float) cur.size() / 1024 / 1024); + victim->pos_min, victim->pos_max, victim->n_tokens, (float) victim->size() / 1024 / 1024); - slot.prompt.checkpoints.erase(slot.prompt.checkpoints.begin()); + slot.prompt.checkpoints.erase(victim); } // the copy is made aside and kept only once complete From d623761876eb1d808c71a4ac9cc3b8fb24519085 Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Mon, 16 Nov 2026 00:24:35 -0600 Subject: [PATCH 6/7] server tests: placed checkpoints bound the store, and her head survives a full store (Codex on #121) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- .../tests/unit/test_placed_checkpoints.py | 80 +++++++++++++++++++ tools/server/tests/utils.py | 6 ++ 2 files changed, 86 insertions(+) create mode 100644 tools/server/tests/unit/test_placed_checkpoints.py diff --git a/tools/server/tests/unit/test_placed_checkpoints.py b/tools/server/tests/unit/test_placed_checkpoints.py new file mode 100644 index 000000000000..4a4a92b4ca54 --- /dev/null +++ b/tools/server/tests/unit/test_placed_checkpoints.py @@ -0,0 +1,80 @@ +# Placed checkpoints (continuum CONTINUUM-ENGINE 4.7.3): with view spans the engine makes no blind +# step checkpoints, a new view-end checkpoint supersedes what earlier acts left, and her head survives +# both that pruning and the count eviction. tinygemma3 uses sliding-window attention, so its prompts +# checkpoint; a small --checkpoint-min-step makes the upstream step checkpoints visible. +import pytest +from utils import * + +server: ServerProcess + + +@pytest.fixture(autouse=True) +def create_server(): + global server + server = ServerPreset.tinygemma3() + server.jinja = True + server.n_slots = 1 + server.n_ctx = 4096 + server.server_slots = True + server.checkpoint_min_step = 16 + + +def conversation(acts: int) -> list[dict]: + messages = [{"role": "system", "content": "You keep notes about the garden, one line per entry."}, + {"role": "user", "content": "Start the notes with the roses along the south wall."}] + for act in range(acts): + messages.append({"role": "assistant", "content": f"Entry {act}: watered and checked for aphids."}) + messages.append({"role": "user", "content": f"Now add entry {act + 1} about the herb bed and the path."}) + return messages + + +def act(messages: list[dict], spans: bool): + body = {"messages": messages, "max_tokens": 4, "temperature": 0.0, "id_slot": 0, "cache_prompt": True} + if spans: + body["view_messages"] = len(messages) - 1 + res = server.make_request("POST", "/chat/completions", data=body) + assert res.status_code == 200, res.body + return res.body + + +def checkpoints() -> dict: + res = server.make_request("GET", "/slots") + assert res.status_code == 200, res.body + return res.body[0]["checkpoints"] + + +# what this catches: blind step checkpoints piling up while the caller names where her next prompt +# diverges (the M5, 2026-11-16: up to 32 x ~110 MB per slot thrashed the host). With spans the slot +# holds her head, her newest view end and this act's end checkpoints, never more than without them. +def test_view_spans_bound_the_checkpoints_a_slot_holds(): + global server + server.ctx_checkpoints = 32 + server.start() + for acts in range(1, 7): + act(conversation(acts), spans=False) + blind = checkpoints() + server.make_request("POST", "/slots/0?action=erase") + for acts in range(1, 7): + act(conversation(acts), spans=True) + placed = checkpoints() + assert placed["count"] <= 5, placed + assert placed["count"] < blind["count"], (placed, blind) + assert placed["bytes"] > 0 and placed["bytes"] < blind["bytes"], (placed, blind) + + +# what this catches (Codex on #121): a full store migrating to placed checkpoints, where the generic +# count eviction erased the true head before the placed pruning ran. Fill the store blind, act with +# spans, then diverge after her head but before her newest view end: the reply resumes from a +# checkpoint (some of the prompt is cached), never from position zero. +def test_her_head_survives_a_full_store_and_serves_a_divergence(): + global server + server.ctx_checkpoints = 4 + server.start() + for acts in range(1, 7): + act(conversation(acts), spans=False) + assert checkpoints()["count"] == 4 + for acts in range(7, 10): + act(conversation(acts), spans=True) + diverged = conversation(9)[:4] + [{"role": "user", "content": "Instead, list the tools in the shed."}] + reply = act(diverged, spans=True) + assert reply["timings"]["cache_n"] > 0, reply["timings"] diff --git a/tools/server/tests/utils.py b/tools/server/tests/utils.py index cb66d76874f4..7a27a654fccf 100644 --- a/tools/server/tests/utils.py +++ b/tools/server/tests/utils.py @@ -112,6 +112,8 @@ class ServerProcess: media_path: str | None = None sleep_idle_seconds: int | None = None cache_ram: int | None = None + ctx_checkpoints: int | None = None + checkpoint_min_step: int | None = None no_cache_idle_slots: bool = False log_path: str | None = None ui_mcp_proxy: bool = False @@ -274,6 +276,10 @@ def start(self, timeout_seconds: int = DEFAULT_HTTP_TIMEOUT) -> None: server_args.extend(["--sleep-idle-seconds", self.sleep_idle_seconds]) if self.cache_ram is not None: server_args.extend(["--cache-ram", self.cache_ram]) + if self.ctx_checkpoints is not None: + server_args.extend(["--ctx-checkpoints", self.ctx_checkpoints]) + if self.checkpoint_min_step is not None: + server_args.extend(["--checkpoint-min-step", self.checkpoint_min_step]) if self.no_cache_idle_slots: server_args.append("--no-cache-idle-slots") if self.ui_mcp_proxy: From e6cd328ce3c65291bca992366d8c20d7b1a6db9e Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Mon, 16 Nov 2026 00:28:54 -0600 Subject: [PATCH 7/7] server: /slots names each checkpoint's position and bytes; the Python replay goes (no Python, Codex on #121) checkpoints.at = [{n_tokens, bytes}] oldest first, so a native proof can assert the exact retained head boundary across a full-store migration (the earlier cache_n > 0 could not tell the original head from a later one). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- tools/server/server-context.cpp | 4 +- .../tests/unit/test_placed_checkpoints.py | 80 ------------------- tools/server/tests/utils.py | 6 -- 3 files changed, 3 insertions(+), 87 deletions(-) delete mode 100644 tools/server/tests/unit/test_placed_checkpoints.py diff --git a/tools/server/server-context.cpp b/tools/server/server-context.cpp index d41396d3abe7..eb00fde89e6e 100644 --- a/tools/server/server-context.cpp +++ b/tools/server/server-context.cpp @@ -740,10 +740,12 @@ struct server_slot { // and their bytes, so the core prices the checkpoint store from what it holds, not a guess. { size_t bytes = 0; + json at = json::array(); for (const auto & ckpt : prompt.checkpoints) { bytes += ckpt.size(); + at.push_back({ {"n_tokens", ckpt.n_tokens}, {"bytes", ckpt.size()} }); } - res["checkpoints"] = { {"count", prompt.checkpoints.size()}, {"bytes", bytes} }; + res["checkpoints"] = { {"count", prompt.checkpoints.size()}, {"bytes", bytes}, {"at", at} }; } const auto & ptask = task ? task : task_prev; diff --git a/tools/server/tests/unit/test_placed_checkpoints.py b/tools/server/tests/unit/test_placed_checkpoints.py deleted file mode 100644 index 4a4a92b4ca54..000000000000 --- a/tools/server/tests/unit/test_placed_checkpoints.py +++ /dev/null @@ -1,80 +0,0 @@ -# Placed checkpoints (continuum CONTINUUM-ENGINE 4.7.3): with view spans the engine makes no blind -# step checkpoints, a new view-end checkpoint supersedes what earlier acts left, and her head survives -# both that pruning and the count eviction. tinygemma3 uses sliding-window attention, so its prompts -# checkpoint; a small --checkpoint-min-step makes the upstream step checkpoints visible. -import pytest -from utils import * - -server: ServerProcess - - -@pytest.fixture(autouse=True) -def create_server(): - global server - server = ServerPreset.tinygemma3() - server.jinja = True - server.n_slots = 1 - server.n_ctx = 4096 - server.server_slots = True - server.checkpoint_min_step = 16 - - -def conversation(acts: int) -> list[dict]: - messages = [{"role": "system", "content": "You keep notes about the garden, one line per entry."}, - {"role": "user", "content": "Start the notes with the roses along the south wall."}] - for act in range(acts): - messages.append({"role": "assistant", "content": f"Entry {act}: watered and checked for aphids."}) - messages.append({"role": "user", "content": f"Now add entry {act + 1} about the herb bed and the path."}) - return messages - - -def act(messages: list[dict], spans: bool): - body = {"messages": messages, "max_tokens": 4, "temperature": 0.0, "id_slot": 0, "cache_prompt": True} - if spans: - body["view_messages"] = len(messages) - 1 - res = server.make_request("POST", "/chat/completions", data=body) - assert res.status_code == 200, res.body - return res.body - - -def checkpoints() -> dict: - res = server.make_request("GET", "/slots") - assert res.status_code == 200, res.body - return res.body[0]["checkpoints"] - - -# what this catches: blind step checkpoints piling up while the caller names where her next prompt -# diverges (the M5, 2026-11-16: up to 32 x ~110 MB per slot thrashed the host). With spans the slot -# holds her head, her newest view end and this act's end checkpoints, never more than without them. -def test_view_spans_bound_the_checkpoints_a_slot_holds(): - global server - server.ctx_checkpoints = 32 - server.start() - for acts in range(1, 7): - act(conversation(acts), spans=False) - blind = checkpoints() - server.make_request("POST", "/slots/0?action=erase") - for acts in range(1, 7): - act(conversation(acts), spans=True) - placed = checkpoints() - assert placed["count"] <= 5, placed - assert placed["count"] < blind["count"], (placed, blind) - assert placed["bytes"] > 0 and placed["bytes"] < blind["bytes"], (placed, blind) - - -# what this catches (Codex on #121): a full store migrating to placed checkpoints, where the generic -# count eviction erased the true head before the placed pruning ran. Fill the store blind, act with -# spans, then diverge after her head but before her newest view end: the reply resumes from a -# checkpoint (some of the prompt is cached), never from position zero. -def test_her_head_survives_a_full_store_and_serves_a_divergence(): - global server - server.ctx_checkpoints = 4 - server.start() - for acts in range(1, 7): - act(conversation(acts), spans=False) - assert checkpoints()["count"] == 4 - for acts in range(7, 10): - act(conversation(acts), spans=True) - diverged = conversation(9)[:4] + [{"role": "user", "content": "Instead, list the tools in the shed."}] - reply = act(diverged, spans=True) - assert reply["timings"]["cache_n"] > 0, reply["timings"] diff --git a/tools/server/tests/utils.py b/tools/server/tests/utils.py index 7a27a654fccf..cb66d76874f4 100644 --- a/tools/server/tests/utils.py +++ b/tools/server/tests/utils.py @@ -112,8 +112,6 @@ class ServerProcess: media_path: str | None = None sleep_idle_seconds: int | None = None cache_ram: int | None = None - ctx_checkpoints: int | None = None - checkpoint_min_step: int | None = None no_cache_idle_slots: bool = False log_path: str | None = None ui_mcp_proxy: bool = False @@ -276,10 +274,6 @@ def start(self, timeout_seconds: int = DEFAULT_HTTP_TIMEOUT) -> None: server_args.extend(["--sleep-idle-seconds", self.sleep_idle_seconds]) if self.cache_ram is not None: server_args.extend(["--cache-ram", self.cache_ram]) - if self.ctx_checkpoints is not None: - server_args.extend(["--ctx-checkpoints", self.ctx_checkpoints]) - if self.checkpoint_min_step is not None: - server_args.extend(["--checkpoint-min-step", self.checkpoint_min_step]) if self.no_cache_idle_slots: server_args.append("--no-cache-idle-slots") if self.ui_mcp_proxy: