Skip to content

feat(dash): suggest the cheapest KV-cache strategy per user, per hour of day - #109

Merged
OsherElhadad merged 1 commit into
rossoctl:mainfrom
itay-nakash:feat/kvcache-hourly-strategy-suggest
Aug 26, 2026
Merged

OsherElhadad merged 1 commit into
rossoctl:mainfrom
itay-nakash:feat/kvcache-hourly-strategy-suggest

Conversation

@itay-nakash

Copy link
Copy Markdown
Collaborator

Summary

Adds a new read, KVCacheSuggest (mounted at GET /api/kvcache/suggest), that 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.

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

  • Candidates are derived, not hardcoded. kvSuggestCandidates() reuses KVCacheArms() -
    the same probe the picker already uses - filtered to arms that are both reachable and
    buildable from a name (drops optimal, replay, and custom). A strategy added to the
    registry 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.
  • Friday and Saturday requests are excluded outright, not down-weighted and not folded into
    a separate group: the work week's traffic shape should not be informed by the weekend's.
  • Each (user, hour) cell replays kvcache.Simulate on only its own rows. Simulate derives
    a 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 a
    real replay of exactly that population, not an approximation bolted onto the simulator.
  • 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, so nothing is silently withheld.
  • 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 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/simulate uses, mapped to 400 by
    the route the same way.

Test plan

  • go build ./...
  • go vet ./dash/... ./kvcache/...
  • gofmt -l clean on all touched files
  • go test ./dash/... ./kvcache/... - full suite green
  • New tests cover: Friday/Saturday exclusion, the insufficient-data floor, a case where a
    keep-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
    (KVCacheSuggest error -> HTTP 400), and the route answering on both an empty and a
    populated database.
  • Ran ad hoc against a live snapshot of production traffic (67.8k requests / 17 users over
    ~9 days) to sanity-check the output shape and magnitude before opening this PR.

… 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]>
@OsherElhadad
OsherElhadad merged commit 7229a10 into rossoctl:main Aug 26, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants