Repository navigation
feat(dash): suggest the cheapest KV-cache strategy per user, per hour of day - #109
Merged
OsherElhadad merged 1 commit intoAug 26, 2026
Conversation
… of day Add KVCacheSuggest, which sweeps the KV-cache page's own strategy registry per (user, hour-of-day) cell and reports which arm would have cost the least, replaying only that account's own Sunday-Thursday history in that one hour. - Candidates come from KVCacheArms(), the same probe the picker already uses, filtered to reachable and buildable arms. A strategy added to the registry becomes a candidate automatically, with nothing to update here. - Friday and Saturday requests are excluded outright, not down-weighted: the work week's traffic shape should not be informed by the weekend's. - Each cell replays kvcache.Simulate on only its own rows. Simulate derives conversation gaps from whatever slice it is given rather than from precomputed fields, so this is a real replay of that population, not an approximation. - A 5-request floor flags a cell as insufficient_data rather than hiding it; every candidate's own numbers are still reported below the floor. - The baseline is always folded into the comparison set, even one an operator names explicitly that the picker would not offer on its own (e.g. optimal, to see the exact ceiling) - otherwise a "best" could show a saving against a baseline it was never measured against. An unresolvable baseline now fails the whole request up front with the same "unknown baseline strategy" error /api/kvcache/simulate uses, mapped to 400 by the route the same way. Mounted as GET /api/kvcache/suggest, alongside the tab's other three routes. Signed-off-by: Itay Nakash <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new read,
KVCacheSuggest(mounted atGET /api/kvcache/suggest), that sweeps theKV-cache page's own strategy registry per (user, hour-of-day) cell and reports which arm
would have cost the least, replaying only that account's own Sunday-Thursday history in
that one hour.
This is a first cut at turning the KV-cache page's simulator into a per-account recommendation
rather than a whole-window comparison - one entry per user per hour of the day, with the
possible dollar saving against the baseline for that specific slice of history.
How it works
kvSuggestCandidates()reusesKVCacheArms()-the same probe the picker already uses - filtered to arms that are both reachable and
buildable from a name (drops
optimal,replay, andcustom). A strategy added to theregistry becomes a candidate the day it lands, with nothing here to update - the same reason
the picker itself is registry-driven rather than a second, driftable list of arm names.
a separate group: the work week's traffic shape should not be informed by the weekend's.
kvcache.Simulateon only its own rows.Simulatederivesa conversation's gaps from whatever slice of requests it is handed (it does not read the
dataset's own precomputed
HasNext/IdleMs/NextTS), so handing it one cell's own rows is areal replay of exactly that population, not an approximation bolted onto the simulator.
insufficient_datarather than hiding it - everycandidate's own numbers are still reported below the floor, so nothing is silently withheld.
explicitly that the picker would not offer on its own (e.g.
optimal, to see the exactceiling) - otherwise a cell could report a "best" that costs more than a baseline it was
never measured against. An unresolvable baseline now fails the whole request up front with
the same
"unknown baseline strategy"error/api/kvcache/simulateuses, mapped to 400 bythe route the same way.
Test plan
go build ./...go vet ./dash/... ./kvcache/...gofmt -lclean on all touched filesgo test ./dash/... ./kvcache/...- full suite greenkeep-alive arm beats the naive fixed-5m default (verified by hand-tracing the ping
schedule), a case where the baseline is already optimal, cross-checking the winner
against its own candidate row, an operator-chosen baseline the picker wouldn't offer on
its own (
optimal) never being beaten, an unknown baseline being rejected end to end(
KVCacheSuggesterror -> HTTP 400), and the route answering on both an empty and apopulated database.
~9 days) to sanity-check the output shape and magnitude before opening this PR.