Skip to content

server: POST /v1/prompt_cache/flush drops the prompt cache's kept states - #3210

Merged
ashhart merged 2 commits into
mainfrom
lead/prompt-cache-flush
Nov 21, 2026
Merged

ashhart merged 2 commits into
mainfrom
lead/prompt-cache-flush

Conversation

@ashhart

@ashhart ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner

POST /v1/prompt_cache/flush drops every prompt state the server keeps for resuming conversations: those in RAM, and its own states on disk when it keeps them (--prompt-cache-disk, --learn-conversations, --spill-gib). It answers {"object": "prompt_cache.flush", "states", "ram_bytes", "disk_bytes", "disk", "waited_seconds"}.

Who may call it: with API keys, a full or [admin] key (scoped keys get 403 insufficient_scope, no key 401, and the route checks the matched key itself). Without keys, only a caller whose socket is on loopback, using the same rule as the request cancel route: the socket address decides, and a request carrying a proxy header is refused with 403 loopback_only.

Why replies in flight are unchanged: the flush runs on the engine thread only once no request is running. While it waits, the lane host, family round planners and Flash Next's serial host admit nothing new; arrivals queue and start after it. The next turn of a conversation prefills its whole prompt and gives the same tokens it gave resumed. If the running requests have not ended within 10 minutes the flush is withdrawn: nothing is dropped, admissions go on, and the answer is 503. An engine without the shared prompt cache answers 501 at once, and a model unloaded by --idle-unload answers 503 without being loaded. States --learn keeps for shared prefixes stay on disk.

Tests (zig build test-prompt-cache-flush-host, also in test-lane-api-host, test-server-cpu, test-key-scopes-host and test-server-security): after a flush every kept state is gone and a resumed turn prefills cold with the same tokens; a request in flight finishes byte-identical to the same request run alone, the flush answers only after it, and a request queued behind it starts after it and prefills cold; a second flush finds nothing left; a withdrawn flush holds nothing and drops nothing; a host without a cache refuses at once; and each refusal above. Each test fails with its part of the change removed.

Stacked on #3193 (it reuses that PR's caller rule); review and land that first. A served check on a model started with a disk store is still owed.

Fixes #3183

  • Synthena (Ash's Agent)

POST /v1/prompt_cache/flush drops every prompt state kept in RAM and the server's own states on disk
(--prompt-cache-disk, --learn-conversations, --spill-gib), and answers what it dropped. The ask waits on the
engine thread until no request is in flight; while it waits, the lane host, a family's round planner and Flash
Next's serial host admit nothing new, so running replies finish unchanged and the next turn of any conversation
prefills cold with the same tokens. Two flushes asked together run in turn. A flush whose 10-minute wait runs
out is withdrawn untaken: nothing is dropped and admissions go on. An engine without the shared store answers
501 at once, and a model --idle-unload has parked answers 503 without being loaded.

Who may flush is the request cancel route's rule (cancel_ids.allowed): with API keys a full or [admin] key,
checked again by the route; without keys only a loopback socket that no proxy header relayed.

Fixes #3183
@ashhart
ashhart force-pushed the lead/prompt-cache-flush branch from 6291ae6 to 796463d Compare November 21, 2026 09:52
@ashhart
ashhart merged commit 36e17ec into main Nov 21, 2026
11 checks passed
@ashhart
ashhart deleted the lead/prompt-cache-flush branch November 21, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Admin route to drop the prompt cache's kept states

1 participant