R1: a pinned shared prefix for many suffix queries (opt-in pin=N / "strata_prefix")

The engine's GEN line takes pin=N: the first N prompt tokens are a shared read-only prefix (a long document many
short questions follow). The prompt is read in two parts at N and the checkpoint there is pinned: retention never
evicts it, a parked conversation holding it stays parked, the session file keeps it, and a later request that resumes
from it does not park the branch it leaves, so N queries keep one prefix. One pin at a time. Without pin= nothing
changes.

The server takes "strata_prefix" in a chat, messages or responses request: {"messages": K}, {"message": I,
"chars": N} or {"tokens": N}, resolved to the longest common start of the prompt's ids. A prefix that cannot be
marked is said in the log and ignored; a malformed field is a 400.

Tests: conv_cache_test (pinned eviction), conversation_cache_test (a pinned parked conversation is not evicted),
conversation_file_test (the pinned checkpoint is the one saved), serve.test_server.SharedPrefix.
This commit is contained in:
Niko1221 committed 2026-10-07 00:01:12 +02:00
1 parent efe7839905
commit 13d14a4944
9 files changed
+306 -14

No files matched your search

+15
View File
@@ -72,6 +72,21 @@ int main() {
check(eviction_victim(st.data(), st.size(), 6, t4) == 1, "the root is never the victim, tail flag or not");
check(eviction_victim(st.data(), st.size(), 6, nullptr) == 1, "no tail flags: the plain policy");
}
{ // pin=N: a pinned shared prefix is never the victim, however stale its stamp
const std::vector<uint64_t> st = {1, 2, 30, 4, 5, 6, 7};
const bool pin1[7] = {false, true, false, false, false, false, false};
check(eviction_victim(st.data(), st.size(), 6, nullptr, pin1) == 3,
"the oldest checkpoint is pinned: the next least recently used leaves");
check(eviction_victim(st.data(), st.size(), 6, nullptr, nullptr) == 1, "no pin flags: the plain policy");
const bool pin2[7] = {false, true, false, true, false, false, false};
check(eviction_victim(st.data(), st.size(), 6, nullptr, pin2) == 4, "two pins: the third oldest leaves");
const bool tail3[7] = {false, false, false, true, false, false, false};
check(eviction_victim(st.data(), st.size(), 6, tail3, pin2) == 4, "a pinned item is not taken as the tail either");
const bool all[4] = {false, true, true, true};
const std::vector<uint64_t> s4 = {1, 9, 3, 5};
check(eviction_victim(s4.data(), s4.size(), 4, nullptr, all) == 2, "everything pinned: the oldest pin leaves, never the root");
check(eviction_victim(s4.data(), s4.size(), 1, nullptr, all) == 0, "a one-slot budget keeps no pin: the oldest leaves");
}
std::printf(g_fail ? "FAIL\n" : "PASS\n");
return g_fail ? 1 : 0;
}