cg-cache-campaign

command
v0.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

cg-cache-campaign

Builds a keep-alive campaign file for the dashboard's Campaigns tab, and a report of what every cache policy would have cost on the same history.

Run it

go build -o cg-cache-campaign ./cmd/cg-cache-campaign
nice -n 19 ./cg-cache-campaign -db /var/lib/context-guru/cg.db -days 30 \
  -out campaign.json -report report.json -md report.md
  • It opens the database read-only (dash.OpenReadOnly). It is safe beside a live proxy.
  • Upload campaign.json in the dashboard: Campaigns → upload a file.
  • Read report.md.
Flag Default Meaning
-db — The dashboard database. Required.
-days 30 History to read. Retention can keep less; the report says what it read.
-holdout 0.3 Share of the history, at its end, used to score the campaign out of sample. 0 = skip.
-baseline fixed-5m The arm every saving is measured against.
-prices — A MODEL_PRICES table, the same file the proxy reads.
-offline false Do not fetch the public price map.

What the report compares

All numbers come from core. The tool only adds cells up.

  • campaign: each (account, hour) cell runs its own best arm. This is the upload.
  • Candidates (default): fixed-5m, keepalive-5m-x1 … -x11 (1 to 11 pings per idle gap) and stop-reason-gated. No no-cache, no 1-hour arm. Every one can run live.
  • One arm everywhere (keepalive-5m, fixed-1h, ...): the naive policies.
  • observed-policy: the cache tier each request asked for.
  • current_keepalive: what the proxy's live keep-alive pings measured (core's keep-alive ledger).
  • optimal: the cheapest plan in hindsight. No policy can reach it.
  • campaign-by-weekday / -model / -agent: the best arm per (account, hour, key). The upload format has no such key, so these show what the key is worth.
  • campaign-if-every-arm-were-live: the campaign if simulation-only arms could run.

Breakdowns: by account, hour (UTC), weekday, model and agent.

What it refuses to do

  • Write an unpriced upload. If no model in the history has a price, it stops.
  • Report against a broken ceiling. If any arm beats optimal in a cell, it stops.
  • Write a file the dashboard rejects. The create route takes at most 256 KiB, so the upload has no per-arm candidates. They are in the report.
  • Name an arm the campaign cannot run. Such a cell gets the best arm that can run, from core's own per-arm costs.

Documentation

Overview

cg-cache-campaign reads a dashboard database READ-ONLY and writes two files:

  • a campaign file the dashboard's Campaigns tab uploads as-is: the best keep-alive arm for every (account, hour of day), in exactly the GET /api/kvcache/suggest format;
  • a report: what every policy would have cost over the same history — the per-cell winners (the campaign), every single arm applied to everything (the naive policies), what actually ran (observed-policy), and the exact ceiling (optimal) — plus the same comparison broken down by account, hour, weekday, model and agent, and an out-of-sample check of the campaign.

NOTHING HERE DECIDES OR PRICES ANYTHING. Every number comes from core: dash.OpenReadOnly reads the file, dash.DB.KVCacheSuggest picks the per-cell winners, dash.DB.KVCacheSuggestHoldout scores them out of sample, and kvcache.Simulate replays every arm with kvcache's own registry and price list. A second copy of any of that here would agree with itself rather than with what the dashboard and the live campaign enforce.

SAFE BESIDE A LIVE PROXY. OpenReadOnly opens the file with SQLite mode=ro and query_only, runs no migration and no checkpoint, and holds at most 4 connections.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL