Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ if (LLAMA_LLGUIDANCE)
endif ()

llama_build(test-recurrent-state-rollback.cpp)
llama_build_and_test(test-server-view-end.cpp)

# GGML_TENSOR_FLAG_GRAD: a leaf whose gradient the backward computes, never optimized (the walk reads the cached prefix K/V gradient)
llama_build_and_test(test-grad-leaf.cpp)
Expand Down
25 changes: 25 additions & 0 deletions tests/test-server-view-end.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// what this catches: a request that names no view end (a short side request resending a mind's prompt)
// erasing that mind's resume point, so its saved page drops the view-end checkpoint and its next act
// re-prefills from the head (regression, M5 engine b5534b5, 2026-11-16: 83 of 95 such pages; ~100k-token
// re-prefills). A named view end always wins; an old one survives only inside the reused prefix.
#include "../tools/server/server-view-end.h"

#include <cstdlib>
#include <iostream>

static void require(bool condition, const char * message) {
if (!condition) {
std::cerr << "FAILED: " << message << '\n';
std::exit(1);
}
}

int main() {
require(carried_view_end(120, 90, 100) == 120, "a request's own view end always wins");
require(carried_view_end(-1, 109190, 109200) == 109190, "a side request that reused the prefix keeps the mind's view end");
require(carried_view_end(-1, 109190, 109190) == 109190, "the view end exactly at the reused boundary survives");
require(carried_view_end(-1, 109190, 5000) == -1, "a request that diverged before the old view end drops it");
require(carried_view_end(-1, -1, 109200) == -1, "nothing known stays unknown");
std::cout << "test-server-view-end: ok\n";
return 0;
}
3 changes: 2 additions & 1 deletion tools/server/server-context.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <limits>
#include "server-context.h"
#include "server-view-end.h"
#include "../../src/llama-ext.h"
#include "server-train.h"
#include "server-adapter-file.h"
Expand Down Expand Up @@ -4051,7 +4052,7 @@ struct server_context_impl {
// saved page keeps (SLOT_SAVE). They describe the prompt these tokens now hold,
// so they travel with it (server_prompt).
const auto view_end_pos = slot.task->params.view_end_pos;
slot.prompt.view_end = view_end_pos;
slot.prompt.view_end = carried_view_end(view_end_pos, slot.prompt.view_end, slot.prompt.n_tokens());
slot.prompt.end_from = std::max(0, slot.task->n_tokens() - std::min(n_batch, 4 + n_ubatch));

// add prompt tokens for processing in the current batch
Expand Down
18 changes: 18 additions & 0 deletions tools/server/server-view-end.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <cstdint>

// Continuum fork: the view end a slot's tokens carry after a prompt pass that starts at `reused` (the
// prefix this request reused from the slot). A request that names its own view end sets it. One that
// names none (a short side request resending the mind's prompt, e.g. a one-token probe) keeps the
// previous view end while that point still lies inside the reused prefix: the mind's resume point is
// still in these tokens, and the page saved next must keep its checkpoint. Measured on the M5 (engine
// b5534b5, 2026-11-16): 83 of 95 pages that kept no view end were saved right after a <=8-token request,
// and the next act re-prefilled ~100k tokens from the head checkpoint (CONTINUUM-ENGINE 4.7.15).
// Otherwise the view end is unknown (-1).
inline int32_t carried_view_end(int32_t requested, int32_t previous, int32_t reused) {
if (requested >= 0) {
return requested;
}
return previous >= 0 && previous <= reused ? previous : -1;
}