server: DELETE /sessions forgets one stored conversation

A client that deleted a conversation, or compacted it past a prefix, knows the
rest is dead before --prefix-cache-ttl does. DELETE /sessions/<label> (or
?label=, ?id=<engine id>) walks the session's chain from the tip inwards like
expiry: VRAM blocks to the pool, the host copy with them, the session's
snapshots to the store. ?keep_tokens=N keeps the chain's start in whole blocks.
Blocks another stored session shares (the system prompt) and blocks a live
request reads stay and are counted apart; the row is cut at the deepest block
that stayed, so a later release reaches it. A request of the same conversation
in flight is 409. IScheduler::release_session beside reset_prefix_cache,
PrefixCache::release_session over the tiers' session table (find_sessions,
shared_prefix_blocks, cut_session). Counters released{entries,snapshots} on
/sessions and /stats, prefix_cache_released_total{what} on /metrics.
This commit is contained in:
Nunze committed 2026-10-22 09:58:08 +00:00
1 parent 123c439684
commit 3aded1bbf8
20 files changed
+722 -2

No files matched your search

+34
View File
@@ -174,6 +174,23 @@ CheckpointSlots checkpoint_slots_auto(const CheckpointPolicy& policy, int64_t ma
int64_t ctx, int64_t interval, int64_t slot_bytes,
int64_t share_bytes, int64_t room_bytes);
/* ------------------------------------------------------------------ a release */
/* What PrefixCache::release_session took out and what it left. Blocks are left for three
* reasons, counted apart so a caller can tell a half-shared conversation from a busy one: the
* caller asked for them (`keep_tokens`), another stored session's chain runs through them (a
* system prompt two conversations open with belongs to both), or a live sequence holds them. */
struct SessionRelease {
int64_t sessions = 0; /* rows the label or id named */
int64_t entries = 0; /* blocks forgotten, from VRAM or the host tier */
int64_t tokens = 0; /* entries x block size */
int64_t device_bytes = 0; /* pool bytes given back */
int64_t host_bytes = 0; /* host-tier slots given back */
int64_t snapshots = 0;
int64_t kept_tokens = 0; /* the chain's start, as asked, whole blocks */
int64_t kept_shared = 0; /* blocks beyond that on another stored session's chain */
int64_t kept_live = 0; /* blocks a running or waiting request holds */
};
/* ------------------------------------------------------------------ the cache */
class PrefixCache {
public:
@@ -315,6 +332,21 @@ public:
* than what follows it: conversations expire from the tip inwards and a shared system prompt
* outlives its readers. Returns how many entries went. */
int64_t expire(uint64_t now_ns, uint64_t ttl_ns);
/* ---------------- release on request ----------------
*
* Forget one stored conversation now instead of at the TTL: a client that deleted it, or
* replaced everything past a prefix (a compaction) and knows the rest is dead. `label` names
* every row carrying it, `id` (nonzero) one row by its engine id (IdleTiers::SessionInfo).
* The chain goes from the tip inwards like expire(): VRAM blocks to the pool, the host copy
* with them, the session's snapshots on the released blocks to the store. `keep_tokens`
* leaves the chain's first blocks standing (rounded up to whole blocks), so the prefix the
* client kept still hits. A block another stored session's chain shares stays, as does one a
* live sequence holds or a waiting request has restored; snapshots handed out or reserved
* this step stay too. RAD_E_NOTFOUND when nothing matches, RAD_E_UNSUPPORTED without the
* session table (no tiers attached). */
int release_session(const std::string& label, uint64_t id, int64_t keep_tokens,
SessionRelease* out);
/* ---------------- linear checkpoints ---------------- */
/* The next position strictly after `pos` at which the scheduler must split a chunk so that a
* checkpoint lands on a boundary (spec §7.1, §7.3). */
@@ -359,6 +391,8 @@ public:
int64_t expired = 0, ckpt_expired = 0;
/* Restores from the host tier cut short because the pool could not hold the chain. */
int64_t restore_cuts = 0;
/* Entries and snapshots a client released (release_session). */
int64_t released = 0, ckpt_released = 0;
};
const Stats& stats() const { return stats_; }