Conversation cache: --conversation-cache-min-tokens parks only conversations of at least N tokens
Parking happens on a switch and every parked conversation costs one of
--conversation-cache-slots whatever its length. A client that interleaves
short side requests (an agent's tool-result follow-ups, often under 1k tokens)
with one long conversation therefore spends the cache on the side requests and,
once it is full, evicts the long one oldest-first - the reuse it wanted.
Measured on an RTX 4070 SUPER / 32 GB / Q2_0, --conversation-cache-slots 2,
one 19,198-token conversation interleaved with three ~700-token requests, then
the same conversation again:
min 0 skip nothing, side requests park, L is evicted
re-send L: 0 reused + 19198 read in 41,059 ms (wall 41.4 s)
min 12288 skip parking (703 tokens, below the 12288 minimum) x3
re-send L: 19193 reused + 5 read in 135 ms (wall 0.3 s, 304x)
The default 0 keeps the previous behaviour, so nothing changes without the flag:
wants() answers for the length alone and the gate stays enabled() && wants(),
exactly as the existing byte-budget and RAM-floor skips are. The check runs
before make_room(), so a skipped park neither evicts nor stores anything, and it
returns the same non-error path those skips take.
Tests: conversation_cache_test covers the inclusive boundary, 0, a negative that
never reaches the CLI, and that a disabled cache still answers for length; both
faults were reintroduced by hand to confirm the checks fail on them.
This commit is contained in:
1 parent
875d6a922a
commit
624070c5df
4 files changed
+59
-6
No files matched your search
@@ -241,6 +241,23 @@ int main() {
|
||||
check(!disabled.put(image({1,2,3})) && !no_slots.put(image({1,2,3})), "disabled cache stores nothing");
|
||||
check(disabled.best(a,{},true).tokens == 0, "disabled cache has no matches");
|
||||
}
|
||||
{
|
||||
// --conversation-cache-min-tokens: a conversation shorter than the minimum is not worth one of the slots.
|
||||
// Parking is a switch-time decision, so without this a client's short side requests park themselves and,
|
||||
// once the cache is full, evict the long conversation they were interleaved with (oldest first).
|
||||
ConversationCache any(1024, 4, 0), floor(1024, 4, 12288);
|
||||
check(any.enabled() && floor.enabled(), "the minimum does not disable the cache");
|
||||
check(any.wants(0) && any.wants(1) && any.wants(1 << 20), "0 parks every length, as before the flag");
|
||||
check(!floor.wants(0) && !floor.wants(1) && !floor.wants(12287), "below the minimum is not parked");
|
||||
check(floor.wants(12288) && floor.wants(12289), "the minimum itself and above are parked");
|
||||
// the CLI rejects a negative, but the predicate must not invert for one that reaches it another way
|
||||
ConversationCache negative(1024, 4, -1);
|
||||
check(negative.wants(0) && negative.wants(1), "a negative minimum parks everything, like 0");
|
||||
// wants() answers for the length alone; the gate is enabled() && wants(), so a disabled cache parks
|
||||
// nothing whatever the length - keep the two independent rather than folding one into the other
|
||||
ConversationCache disabled_min(0, 4, 12288);
|
||||
check(!disabled_min.enabled() && disabled_min.wants(1 << 20), "a disabled cache still answers for length");
|
||||
}
|
||||
{
|
||||
// layer-split parking: checkpoints moved apart into stage parts and put back, no running state copied
|
||||
auto running = [](std::initializer_list<int32_t> ids, uint8_t salt, size_t parts) {
|
||||
|
||||
Reference in new issue
Block a user