Repository navigation
feat(keepalive): recommended policy as default (270 s, K=2, 80k floor, $0.50 ceiling) (#435) - #444
Conversation
|
Verification update (#446): the recommended policy's dollars are confirmed independently ($2,144 [1,294, 3,068] vs never-ping over 54 days, counterfactual). The claim in this PR body that 270 s beats 280 s by +$273 is withdrawn: over the full window the two tie (−$19 [−462, 326]). We keep 270 s for robustness — if the TTL cliff sits at 290 s, 280 s loses about $420 and 270 s loses nothing material. The PR stays a draft until the live paired validation lands. |
|
Live paired validation landed (see #446): hits and ping counts match the simulator; observed saving is ~15–25% below the model, so the honest estimate is ~$1.6–1.8K over 54 days (3.5–3.9% of the bill). Ready for review. Not deployed; deployment is for owners. |
|
Reviewer: CHANGES REQUESTED. Tests are fine (go test config, kvcache, tenant, proxy keep-alive/campaign, dash keep-alive green; gofmt clean; CI pass). The PR body repeated the withdrawn '270 beats 280 by +273' claim, so I rewrote that part myself (VERIFY: tie -19 [-462, 326] all, +299 ex-poller; REDTEAM: -425..+780 depending on the cliff; 270 kept as the minimax choice; live run did not test the margin) and dropped the 'draft' wording. Remaining defects are in the code: Must fix
Heads-up (no action needed): the new campaign tests pin keepalive-5m (270) and once (280) only; add a stop-reason-gated assertion too. |
|
Addressed review: config comment now states the tie (-19 [-462, +326]) and cliff-robustness rationale; remaining 280/20k/0.25 sites updated (keepalivectl fallback, KeepAliveCalc/behaviour fallbacks, plugin settings.py, dashboard form defaults and fallbacks, how-to doc); once/stop-reason-gated/1h campaign arms keep the 20k floor via a per-arm field, with a test; note added at the kvcache schedule constant. Tests and gofmt pass (one unrelated SQLITE_BUSY flake under load passed on rerun). |
|
Reviewer: approved after re-review. Full runs on this branch: go test ./dash -count=1 (137 s) and ./proxy (96 s) pass, plus config, kvcache, tenant; gofmt clean; CI all pass. Under heavy box load (load avg ~11, other agents running) one earlier dash run failed in the timing-sensitive TestJanitorPassCheckpointsWAL (WAL size) and a concurrent proxy run failed; both pass on rerun at lower load, the WAL test passes 3/3 in isolation on this branch and on origin/main, and none of it touches keep-alive code. Treat as the existing load flake. Checked: the config.go comment now states the robustness rationale (tie -19 [-462, +326], not a gain; K=1 prefers 280); proxy/keepalivectl.go, dash/keepalive.go (calc fallback, coverage), settings.py preset, app.js and docs/how-to/cache-keepalive.md moved to 270 / 80k / $0.50; deliberate exceptions are documented in code: keepalive-5m-once, stop-reason-gated and 1h stay at their old idle and a 20k floor (campaignLegacyMinPrefixTokens, new per-arm test), and the kvcache suggester carries a NOTE that it still scores at 280 s / 20k. PR body no longer claims 270 beats 280. Non-blocking leftovers: docs/how-to/kv-cache-keepalive-budget.md and docs/how-to/test-subscription-sandbox.md still show 280 / 20000 / 0.25 as example config (harmless, but they read as the defaults); dash/keepalive.go comments around the 20k analytic bucket still call 20k the shipped gate. |
… 80k floor, $0.50 ceiling) Defaults move from 280 s / 20k / $0.25 to 270 s / 80k / $0.50 (K stays 2): config, the proxy ceiling mirror, the keepalive-5m campaign arm (idle 270; shared 80k floor), the dashboard replay gate and recommender. The 280 rationale in config.go is superseded. keepalive-5m-once and stop-reason-gated stay at 280 (K=1 prefers 280; the gate loses). The kvcache simulator keeps its 280 s schedule (W1 clock). Counterfactual; pending verification (#435). Signed-off-by: Osher-Elhadad <[email protected]>
Replace the withdrawn 270-beats-280 comment with the cliff-robustness rationale; arm and calc fallbacks, plugin settings, dashboard form defaults and the how-to now use 270 s / 80k / $0.50. once, stop-reason-gated and 1h campaign arms keep a 20k floor (80k evidence is K=2 only). Note at the kvcache schedule constant that the simulator still scores at 280 s. Signed-off-by: Osher-Elhadad <[email protected]>
…ults Signed-off-by: Osher-Elhadad <[email protected]>
7c6595e to
4d29023
Compare
Results: recommended keep-alive defaultsWhat it does. Makes the keep-alive policy that won the replay the default: ping when idle 270 s, at most 2 pings per idle span, only for prefixes of 80,000 tokens or more, and never above $0.50 per ping. Accounts that set their own values are unaffected. Evidence (issue #446, counterfactual replay on 54 days of real traffic, independently verified):
What changed since review. Rebased on main (one test-file conflict, both tests kept). The two how-to docs now show 270 / 80000 / 0.50 as example config, and the comments in Not deployed; deployment is for the owners. |
|
Reviewer: APPROVAL UPDATED for the rebased head 4d29023 (earlier approval was for the old head). CI all pass; go test ./config ./proxy ./kvcache ./tenant and the full ./dash -count=1 (66 s) green; gofmt clean. Both TestKeepAliveRecommendedDefaults and the existing config test survived the rebase. The 280 / 20000 / 0.25 leftovers I listed are gone (docs examples and dash comments aligned; only the documented exceptions remain: once, stop-reason-gated and 1h arms, and the kvcache suggester with its NOTE). The PR body keeps the corrected 270-vs-280 statement (the +273 claim appears only as withdrawn). |
Lets turn_gate.py run against the production dashboard DB, which has no transcripts and no exact per-thread turn index. Mirrors wait_causes.py's own DB-only approach: - Group real request rows (keepalive=0, status=200) by `thread_id` where the DB has that column, else by (session_id, model) as an approximate thread proxy. Pings never form a turn boundary. - Turn index is 1-based row order within a group; also switched transcript mode to the same 1-based convention, so both modes report into the same turn buckets. - Gaps use the previous request's own response-arrival time (ts + upstream_ms, wait_causes.py's approx_response_ts), not its raw request start, to the next request's start. - Simulated ping cost is now gated by the keeper's 3 live checks (issue #444's defaults): a prefix floor (80,000 tokens), a minimum idle time before the first ping (270s), and a per-ping USD ceiling ($0.50) -- configurable via --prefix-floor/--idle-sec/--ping-ceiling-usd. A pause that fails a gate is still counted, with zero simulated cost. - Added real keep-alive ping attribution (keepalive=1 rows, priced from their own cost_usd) per turn bucket, reusing wait_causes.py's DBIndex, plus a USD column alongside the existing x-unit cost/avoided/net, and a gate-at-5/gate-at-10 net-change comparison against today's baseline. - Extended --self-test with DB-only fixtures and gate coverage. Assisted-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
TL;DR
Make the policy recommended by the held-out re-analysis (#435, workstream B) the default:
keepalive_idle_seconds270 (was 280),keepalive_max_pings2 (unchanged),keepalive_min_prefix_tokens80000 (was 20000),keepalive_max_usd_per_ping0.50 (was 0.25).keepaliveitself stays off by default (consent decision, unchanged).Independent verification (VERIFY-B-policy-r2), a red-team pass and a live paired run (B-live-validate) have landed for K=2, the 80k floor and the $0.50 ceiling. The 270-vs-280 choice is NOT confirmed by any of them (see Caveats). Not deployed; deployment is for owners.
What changed
config/config.go: the four defaults; the "X=280 wastes 53 pings, +$125.08" rationale (W1 clock) replaced by the W3 one.proxy/keepalive.go:DefaultMaxUSDPerPingmirror (pinned to config by an existing test).proxy/campaign.go:keepalive-5marm idle 270 (campaignKeepAlive5mIdle);campaignDefaultMinPrefixTokens80000 (shared by all campaign arms).keepalive-5m-onceandstop-reason-gatedstay at 280: the 270 evidence covers K>=2 only, K=1 prefers 280, and the gate loses.dash/keepalive.go: replay gatekaGateMinPrefixandrecIdleSeconds(the shipped policy they mirror).CGO_ENABLED=1 go testpasses for config, proxy, dash, kvcache, tenant, cmd, components, plugin; gofmt clean.kvcachesimulator/suggester keeps its 280 s schedule (its hazard windows are fixed at the W1 clock; it cannot represent the W3 cliff), so suggest cells are still scored at 280 whilekeepalive-5mnow runs at 270.Evidence (counterfactual, model dollars at deployed gateway prices, same denominator: never-ping model total over the 54-day union window)
Savings vs never-ping, 95% CI by session bootstrap.
X=270 vs 280 at K=2, floor 80k: the earlier "+273 [-21, +488]" is WITHDRAWN. Independent re-derivation: all -19 [-462, +326] (a tie), ex-poller +299 [225, 365]; red team: between about -$425 and +$780 depending on the unknown ping cliff (295-305 s). 270 is kept as the cliff-robust (minimax) choice, not as a demonstrated gain. The recommended rule captures about 47-50% of the oracle.
Caveats