diff --git a/tools/server/server-context.cpp b/tools/server/server-context.cpp index a5ea94329965..eb00fde89e6e 100644 --- a/tools/server/server-context.cpp +++ b/tools/server/server-context.cpp @@ -736,6 +736,18 @@ 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; + 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}, {"at", at} }; + } + const auto & ptask = task ? task : task_prev; if (ptask) { @@ -2575,13 +2587,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 @@ -2601,6 +2619,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; + } + } + SLT_TRC(slot, "created context checkpoint %d of %d (pos_min = %d, pos_max = %d, n_tokens = %" PRId64 ", size = %.3f MiB)\n", (int) slot.prompt.checkpoints.size(), params_base.n_ctx_checkpoints, kept.pos_min, @@ -4410,8 +4445,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;