Repository navigation
fix(keepalive): book a timed-out ping at its projected cost (#754) - #1186
Conversation
A keep-alive ping that ran to its 60 s timeout was counted only as failed. It wrote no row and booked no cost, although it probably reached the provider and was billed (#532). So the dashboard and /stats undercounted keep-alive spend and overstated its net saving. When a ping fails with context.DeadlineExceeded, the keeper now books one row at e.pingUSD, its own projection of one ping on the prefix, and marks the report TimedOut. The row counts as spend, not as a refresh: no cache clock moves and Refreshed stays as it was. A fast failure (EOF, reset, refused) still books nothing. - /stats gets timed_out, the part of failed that timed out. - The dashboard row is stored with stop_reason = timeout_estimated, so it needs no schema change. The keep-alive ledger counts it in pings and ping_usd and in the new pings_timed_out, and no longer in pings_that_read_nothing. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (claude, user of @boazdavid) | Claude Code 2.1.241, opus[1m] | offload-review skill, @boazdavid's session | fresh | 2 of 2 | 1 of 2 | 383e4e2e011e |
blocking |
Verdict: blocking
The keeper change is correct. Booking, refresh, and fail-open logic are sound. Two findings remain. One is a wrong label in the central metrics. The other is a missing part of the PR description that CLAUDE.md requires.
Findings
-
proxy/inferencemetrics.go:210 — a timed-out ping is pushed as
outcome="failed", notoutcome="timeout"- What fails: before this PR, a timed-out ping wrote no row, so it never reached the push metrics. Now
dashEmitter.KeepAlivePingbuilds a row withStatus: 0and callsobserveMetrics→sinks.inference.Observe(ev, 0)→observePing.observePingsetsoutcome = "failed"for any status outside 2xx. So every timeout now adds 1 tollm_keepalive_pings_total{outcome="failed"}. - Proof:
docs/metrics/spec.md:326defines the label values.failedmeans "the provider returned an error".timeoutmeans "no answer in time". This PR creates the firsttimeoutcase, and the code labels itfailed. Also,llm_keepalive_cost_usd_totalnow includes the projected cost of a timeout, with no estimate mark. TheKeepAliveReport.TimedOutdoc (components/component.go:1256) says a sink should mark it as an estimate. The PR text does not mention any change to the central metrics. - Fix: in
observePing, setoutcome = "timeout"whene.StopReason == dash.StopTimeoutEstimated. Add a test for it, for example inproxy/inferencemetrics_test.go. Name the central metric change in the PR text.
- What fails: before this PR, a timed-out ping wrote no row, so it never reached the push metrics. Now
-
PR description — no behavior-change statement and no data-dependence statement
- What fails:
CLAUDE.mdasks for 2 things that the PR body does not have.- "Metadata first": every PR that changes a feature states its data dependence and what it does at each storage level. The PR body has no such section. Issue #754 says "Metadata only", but the PR does not.
- "No behavior change for an edge case without a human developer's permission": name the change at the top of the PR (who it affects, the old and the new behavior, how to turn it off).
- Proof: this PR changes what users see.
/statsspend_usd, the dashboardping_usdandnet_usd,KeepAliveNetUSDByTenant, the strategy ledgers (dash/keepalivestrategy.go:45,dash/campaignsavings.go:120), and the centralllm_keepalive_*metrics all go up by the projected cost of each timeout. A new ping row withstatus 0also appears. Issue #754 (by @amiddavid) proposes the/statsand dashboard parts. It does not mention the central metrics. - Fix: add a short "Behavior change" section at the top. List the figures that change, old and new, and say there is no switch (or add one). Add a "Data dependence" section: metadata only (a projected cost and counts, no new content stored). If you think the keep-alive row should say that timed-out pings are booked, edit
docs/data-dependence/features/keep-alive-pings.mdand rungo run ./cmd/gen-datadep. Ask @amiddavid to confirm the central-metric part.
- What fails:
Non-blocking
dash/event.go:370-376is now stale. It says a transport error on send returns "without writing a ping row". A timed-out ping now writes one. Update the comment.docs/how-to/cache-keepalive.md:244-246lists the/statskeep-alive fields. Addtimed_outthere.keepalive/manual.go:142-148: a manual ping (the Ping button) that times out still books nothing. Its own comment says "A deadline or cancel may have left a billed request behind". The same undercount remains for that path. A follow-up issue is enough.keepalive/keeper.go:1535:giveBackFailedPingruns before the booking. On an OpenAI thread (30 min cache, ping at 28 min), a 60 s timeout returns at about 29 min, inside the lifetime, so the keeper retries it. Then the timed-out row and the retry row carry the samePingsnumber, and the billed timeout does not use up one ofMaxPings. This is probably acceptable, but the commit text does not say it.keepalive/timedout_ping_test.gocovers onlyerrors.Is(err, context.DeadlineExceeded). No test covers thectxErrbranch (the dispatcher returns a different error after the deadline). The fake usesk.now(), andcontext.WithTimeoutuses the wall clock, so that branch is hard to test without a dispatcher that blocks onctx.Done(). Note also that the oldTestAFailureAfterTheCacheExpiredIsNotRetried(keepalive/failedping_test.go:59) returnserrors.New("context deadline exceeded"), a plain string. So it does not book a row, and its name suggests a timeout that this PR would now book.
What I checked
- I read the full diff (8 files, 1 commit
383e4e2e), the commit message, the PR body, and issue #754 with its comments. keepalive/keeper.go:fire,giveBackFailedPing,record1, the newrecordTimedOut,projectedPingUSD, andStats.ctx.Err()is read beforecancel(), which is correct.recordTimedOutreads the entry fields underk.mu. It does not moverefreshedAt, does not calltouch, and does not changee.refreshed.e.spentis report-only and is not a cap (keeper.go:163), so booking it changes no ping decision.keepalive/manual.go: the manual ping path, which this PR leaves unchanged.proxyapp/main_run.godashEmitter.KeepAlivePing: the newStopReasonoverride.ev.Price(..., false)setstoken_accounting = missing, thenCostUSDgets the projected cost.PingSavingsreturns no result forstatus 0, so the row gets no saving credit.dash/reprice.go:125only reprices rows withcost_usd = 0, so it does not wipe the estimate.proxy/inferencemetrics.goobservePinganddocs/metrics/spec.md§5.3 (finding 1).dash/keepalive.goledger SQL.stop_reasonisNOT NULL DEFAULT ''(dash/schema.go:366), so!=has no NULL problem. The refresh probe inkaSavedGateneedscache_read > 0(orcache_write > 0), so a timed-out row cannot credit a rescue.dash/capture.go:966uses the same gate for the cache clock.- Other readers of ping rows:
dash/keepalivestrategy.go,dash/campaignsavings.go,dash/overview.go,dash/kvcache.go(ping rows only withWithKeepAlive), andcontext-guru-plugin/scripts/insights.py. None breaks. Only the totals change. - The golden file
dash/testdata/golden/keepalive.jsonaddspings_timed_out: 0. - Data dependence:
docs/data-dependence/features/keep-alive-pings.md. The PR edits no row file and does not touch the generated page. - I did not run any build or test. Live tests are not approved.
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (claude, user of @boazdavid) | Claude Code 2.1.241, opus[1m] | offload-review skill, @boazdavid's session | fresh | 1 of 2 | 1 of 2 | 383e4e2e011e |
blocking |
Verdict: blocking
The code does what #754 asks, and I found no correctness defect in it. The one finding is the repo's behavior-change rule. The change reaches more figures than the issue names, and the PR does not name any of them at the top.
Findings
- PR body / proxyapp/main_run.go:1142 — the behavior change is not named at the top of the PR, and some side effects go past the scope of #754
- What fails:
CLAUDE.md("No behavior change for an edge case without a human developer's permission") says a fix that changes what is shown must name the change at the top of the PR: who it affects, the old and new behavior, and how to turn it off. The PR starts with "Problem" and "Change". It has no behavior-change header and no off switch. #754 (by @amiddavid) asks for the booking in "the dashboard and/stats". But the new row also changes these figures, and neither the issue nor the PR names them:- Pushed central metrics.
dashEmitter.KeepAlivePing→observeMetrics→InferenceMetrics.observePing(proxy/inferencemetrics.go:209-217). Each timed-out ping now adds 1 tollm.keepalive.pings{outcome="failed"}and adds the projected USD tollm.keepalive.cost.usd. Before this PR, a timed-out ping added nothing. The metric has no estimate label, so the central collector cannot tell the estimate apart from measured cost. - Month-to-date spend.
dash/store.go:727addse.CostUSDof every row totenant_spend. The control plane shows it asspent_usd(proxy/control.go:490). It now includes estimates, and it is monotonic, so a later fix cannot remove them. - Strategy and campaign ledgers.
StrategyLedger(dash/keepalivestrategy.go:45) andCampaignRealSavings(dash/campaignsavings.go:120) sumcost_usdoverkeepalive = 1rows. Their comments call this cost "EXACT" / "exact per row".adaptReport(proxy/adaptcache.go:370,568) andinsights.py(net_usd,losers) read the samePingUSD. These outputs feed the advice to keep or change a keep-alive strategy. pings_that_read_nothing. It changes meaning: timed-out rows are now left out of it (dash/keepalive.go:369).insights.py:1650reads it.
- Pushed central metrics.
- Proof: the trace is
keeper.fire(keepalive/keeper.go:1543-1546) →recordTimedOut(:1805-1826) →KeepAliveReport{TimedOut: true, CostUSD: e.pingUSD}→dashEmitter.KeepAlivePing(proxyapp/main_run.go:1106-1170). That function callsd.observeMetrics(ev, …)andd.rec.Record(ev)for every report, with noTimedOutcheck. The PR body's "Change" section names only the keeper,/statsand the dashboard ledger. - Fix: at the top of the PR, add a "Behavior change" section. List each affected figure above, with old → new. State that there is no off switch, or add one. Ask @amiddavid to confirm the side effects that #754 does not name, mainly the central metric and
tenant_spend. If the central metric must stay measured-only, skipobserveMetricscost forr.TimedOut, or label it.
- What fails:
Non-blocking
- Docs drift.
docs/how-to/cache-keepalive.md:245-246lists the/statskeepalive fields withouttimed_out. Line 190 says "A failed ping is logged and forgotten", which is no longer true for a timeout. Lines 195-196 say every ping row has "its own tokens, its own cost". A timed-out row has 0 tokens and a projected cost. - Data dependence is not stated in the PR.
CLAUDE.mdasks every PR that changes a feature to state its data dependence. #754 states it ("Metadata only"), but the PR body does not. The rowdocs/data-dependence/features/keep-alive-pings.mdneeds no edit: the new fields are a flag, a counter and a stop-reason string. - No test for the
ctxErrbranch.keepalive/keeper.go:1543also books whenctx.Err()isDeadlineExceededbuterrdoes not wrap it, for example a dispatcher that flattens its error with%v. Both new tests return an error that wrapscontext.DeadlineExceeded, so they never reach that branch. A fake dispatcher that blocks onctx.Done()and then returnserrors.New("upstream gone")would cover it. A short test timeout would needpingTimeoutto be injectable. - A timeout is not always a sent request. A 60 s dial or TLS hang (for example, a black-holed SYN) or a wait inside the host dispatcher also ends in
DeadlineExceeded. Neither one reached the provider. The comment "was sent" (keepalive/keeper.go:1539) is stronger than the facts. The report doc says "probably", which is the correct word. Consider using "probably" in the keeper comment too. - The ledger gives a count but no USD for estimates.
KeepAliveLedger.PingsTimedOutis a count only. BecausePingUSDmixes measured and projected cost, a reader cannot split them. APingTimedOutUSDfield (one moreSUM(CASE …)) would help the dashboard show the estimate apart, as #754 point 3 asks. recordTimedOutreadse.pingUSDwhen the ping ends, not when it starts. A real request during the 60 s wait can changee.prefix/e.pingUSD. The effect on an estimate is small.
What I checked
- I read the full diff (8 files, +209/−4) and the commit message. I also read the PR body and #754. I did not read other reviews or comments.
keepalive/keeper.go: all offire,noteOutcome,giveBackFailedPing,record1,addSpent,Stats.ctxErris read beforecancel(), which is correct.recordTimedOuttakesk.mufor theefields and does not touchrefreshed,refreshedAtorstartedAt, so no cache clock moves. A retry throughgiveBackFailedPingbooks a second row only when a second ping really goes out, which is correct.- I checked that
e.spent/k.spentUSD/tenant_spendgate nothing.SpendCheckeris "for display. Not a cap" (proxy/limits.go:275), andEntryView.Spenthas no reader that makes a decision. So the extra spend cannot stop pings or refuse requests. - Dash consumers of the new row (status 0, all tokens 0,
token_accounting = missing, cost > 0):CacheStateForneeds 2xx and cache tokens, so the row does not change the cold countdown.- The
kaSavedGateprobes needcache_read > 0/cache_write > 0, so the row gets no rescue credit. capture.go:379needs cache tokens.PingSavingsneeds a 2xx.noteUnpricedskips rows with 0 tokens, so the reprice pass never zeroes the estimate.DropUnbilledSavingsleaves status 0 alone.- The
stop_reasoncolumn isNOT NULL DEFAULT ''(dash/schema.go:366), so!= 'timeout_estimated'cannot drop old rows through NULL.
- Tests: the helpers
newFake,trackedRecord,reportSink,fixedPrice,proxyPricerandsetPricesexist with the signatures the new tests use. InTestATimedOutPingBooksItsProjectedCost, the clock moves to 281 s + 60 s = 341 s, which is pastrefreshedAt + 300 s. SogiveBackFailedPingrefuses, andfd.n() == 1holds. The golden file addspings_timed_out: 0, and no other golden file has the ledger. - Data dependence: the row file needs no change, and
docs/data-dependence.mdis not touched. - I ran no Go build or test, as this review's instructions say.
…imated cost (#754) Review round 1 on #1186. - proxy/inferencemetrics.go: a row marked timeout_estimated is pushed as llm_keepalive_pings_total{outcome="timeout"}, as docs/metrics/spec.md defines it, not as "failed" (the provider returned an error). - dash/keepalive.go: the keep-alive ledger adds ping_timed_out_usd, the part of ping_usd that is a projection, so a reader can split measured spend from estimated spend. - Comments and docs: a timed-out ping now writes a row (dash/event.go, docs/how-to/cache-keepalive.md), /stats lists timed_out, and the keeper says "probably sent", because a dial or TLS hang also ends in a timeout. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
Replies to round 1 (head
|
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (claude, user of @boazdavid) | Claude Code 2.1.241, opus[1m] | offload-review skill, @boazdavid's session | resumed | 2 of 2 | 2 of 2 | abd9de30d272 |
approve |
Verdict: approve
All round-1 findings of both reviewers are fixed or answered with a correct reason. The new commit abd9de30 adds no defect.
Merge gate, not a finding: the PR body asks a human developer to confirm the behavior change. This is mainly the central cost metric and tenant_spend, which #754 does not name. CLAUDE.md says that a reviewer agent cannot give this yes. Get @amiddavid's confirmation before merge.
Findings
None.
Earlier findings
- Reviewer 2, finding 1 (
outcome="failed"for a timeout): fixed.proxy/inferencemetrics.goobservePingnow checkse.StopReason == dash.StopTimeoutEstimatedfirst and setsoutcome = "timeout". Then it checks the status. This matchesdocs/metrics/spec.md§5.3.TestPingBooksKeepAliveAndNoRequestadds a status-0timeout_estimatedrow. It expects oneok, onefailedand onetimeout, and a cost of 0.005, which includes the 0.002 projection. The cost metric still has no estimate label. The PR body names this and gives it to a human to decide. I accept that. - Reviewer 2, finding 2 (no behavior-change or data-dependence statement): fixed. The PR body now starts with "Behavior change". It names who the change affects, the old and new behavior in a table of 9 figures, and that no switch exists for this change alone (
CONTEXT_GURU_KEEPALIVE=offturns off all of keep-alive). It names the open questions for a human. A "Data dependence" section says "Metadata only". I agree thatdocs/data-dependence/features/keep-alive-pings.mdneeds no edit. - Reviewer 1, finding 1 (behavior change not named, side effects past #754): fixed. I checked it as a part of my finding 2. The table names the central metrics,
tenant_spend, the strategy and campaign ledgers,adaptReportandinsights.py. - Non-blocking items:
dash/event.gostale comment: fixed./statstimed_outindocs/how-to/cache-keepalive.md: fixed, with a new sentence at line 191 on how a timeout is booked.- "was sent" changed to "probably sent": fixed (
keepalive/keeper.go:1539-1543). ping_timed_out_usdin the ledger: added. The SQL uses the sameautoPingandstop_reasongate aspings_timed_out. The scan order matches the column order. The golden file adds the key in alphabetical position.- Manual-ping timeout: listed as a follow-up under "Not in scope". I accept that.
- Retry gives the same
Pingsnumber twice: rejected with a reason. Two requests went out and both are booked, and the schedule is as before this PR. The reason is correct. - No test for the
ctxErrbranch: rejected with a reason.pingTimeoutis a constant, andcontext.WithTimeoutuses the wall clock. The real dispatcher returns thenet/httperror, and*url.Errorunwraps tocontext.DeadlineExceeded. The reason is correct. The branch is a safety net. - Plain-string error in
TestAFailureAfterTheCacheExpiredIsNotRetried: rejected. That test checks the retry schedule, not the booking. The reason is correct. e.pingUSDis read at the end of the ping (reviewer 1): kept, because the value is an estimate. I accept that.
Non-blocking
docs/how-to/cache-keepalive.md:195-196still says every ping row has "its own tokens, its own cost". A timed-out row has 0 tokens and a projected cost. Line 191 now says this, so a reader can find it.
What I checked
- Last review: round 1,
383e4e2e011eae7622ba7a720bc2e1fdbc8b498a, 2026-11-17T05:55:44Z - New commits read: 1 (
abd9de30fix(keepalive): report a timed-out ping as timeout, and split its estimated cost (#754)) - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
- New items since my last review:
- Reviewer 1 round-1 review (05:56:12Z). I read it. I checked its finding 1 as a part of my finding 2. I checked each of its non-blocking items against
abd9de30and the author's replies (listed above). - The author's reply comment (06:07:11Z). I checked each reply against the code and the PR body (listed above).
- The updated PR body. I read it in full: the "Behavior change", "Data dependence", "Change", "Not in scope" and "Tests" sections.
- Reviewer 1 round-1 review (05:56:12Z). I read it. I checked its finding 1 as a part of my finding 2. I checked each of its non-blocking items against
- Diff
383e4e2e..abd9de30: all 8 files. I readobservePingand the code around it, theKeepAliveLedgerSQL and itsScan, the doc text around lines 180-200 and 240-250 ofdocs/how-to/cache-keepalive.md, and the two test changes.proxy/inferencemetrics.goalready importsdash, so the import cycle rule holds (proxyimportsdash, not the reverse). - I ran no build or test. Live tests are not approved.
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (claude, user of @boazdavid) | Claude Code 2.1.241, opus[1m] | offload-review skill, @boazdavid's session | resumed | 1 of 2 | 2 of 2 | abd9de30d272 |
approve |
Verdict: approve
All round-1 findings from both reviewers are fixed. The new commit abd9de30 adds no new defect. One merge gate stays open, and it is not a code finding: a human developer must confirm the behavior change. The PR body asks for that confirmation.
Findings
None.
Earlier findings
- Reviewer 1, finding 1 (behavior change not named): fixed. The PR body now starts with "Behavior change (needs a human developer's yes before merge)". It has a table with the old and new value of each figure:
/stats, the dashboard ledger, the strategy and campaign ledgers,adaptReport,insights.py,tenant_spend, and both central metrics. It says there is no switch for this change alone, and thatCONTEXT_GURU_KEEPALIVE=offturns off all of keep-alive. It asks a human to confirm the central metrics andtenant_spend. This matches all the side effects I listed in round 1. - Reviewer 2, finding 1 (
outcome="failed"for a timeout): fixed. I checked it myself.observePing(proxy/inferencemetrics.go:210-217) testse.StopReason == dash.StopTimeoutEstimatedbefore the status test, so a row with status 0 getsoutcome="timeout".docs/metrics/spec.md:326definestimeoutas "no answer in time". The Grafana paneldeploy/central/grafana/dashboards/cache.json:242groups byoutcome, so it shows the new value with no edit.TestPingBooksKeepAliveAndNoRequestnow checks ok, failed and timeout, and a cost of 0.005, which includes the projection. - Reviewer 2, finding 2 (no behavior-change or data-dependence statement): fixed. The PR body has both sections. "Metadata only" is correct. The row
docs/data-dependence/features/keep-alive-pings.mdneeds no edit. - My round-1 non-blocking points:
- Docs drift: fixed in
docs/how-to/cache-keepalive.md:190-194,248-249. - Data dependence statement: fixed in the PR body.
- "Was sent" too strong: fixed.
keepalive/keeper.go:1539-1543now says "probably sent" and names the dial or TLS hang. - USD for estimates: fixed. The ledger adds
ping_timed_out_usd(dash/keepalive.go:312-314,375). The test checks 0.015. - No test for the
ctxErrbranch: rejected, with a reason. I accept the reason.net/httpreturns a*url.Errorthat unwraps tocontext.DeadlineExceeded, so production takes the testederrors.Is(err, …)branch. A test of the other branch needs a 60 s wait, or a seam that exists only for the test. e.pingUSDread at the end of the ping: kept by the author. I accept this, because the value is an estimate.
- Docs drift: fixed in
- Reviewer 2's non-blocking points: the author answered each one in the PR comment. The
dash/event.gocomment and the docs are fixed. The manual-ping timeout is named as a follow-up under "Not in scope". The retry with the samePingsnumber keeps the old schedule, and the PR changes only the booking. I agree with each answer.
Non-blocking
- Merge gate: the PR needs a human developer's yes on the "Behavior change" section before merge, as
CLAUDE.mdsays. The open item is whetherllm_keepalive_cost_usd_totalandtenant_spendshould include the estimate. Before this PR, those figures held measured cost only. A reviewer agent cannot give this yes. - The two keep-alive return panels on the central Grafana board read
llm_keepalive_cost_usd_total: the return-on-ping panel atcache.json:350and the net panel at:420. After this PR, both include projected cost. The PR body names the metric. If the owner keeps the estimate in the metric, a short note on that panel would help a reader. - The "Open for a human" text says the fix is to skip the cost in
observePing. That would also take the projection out of the central net figure. Name this side of the choice when you ask the owner.
What I checked
- Last review: round 1, 383e4e2, 2026-11-17T05:56:12Z
- New commits read: 1 (
abd9de30fix(keepalive): report a timed-out ping as timeout, and split its estimated cost (#754)) - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
- New items since my last review:
- Commit
abd9de30. I read the whole diff (8 files, +42/−20):dash/event.go,dash/keepalive.go, the golden file,docs/how-to/cache-keepalive.md,keepalive/keeper.go,proxy/inferencemetrics.gowith its test, andproxyapp/dashemitter_timeout_test.go. I also read the code around each change. - The author's reply comment (2026-11-17T06:07:11Z). I checked each reply against the code and the PR body (see "Earlier findings").
- The edited PR body. I checked the behavior-change table against the trace from round 1.
- Reviewer 2's round-1 review (05:55:44Z, earlier than my last review, but I had not read it before). I checked its findings myself.
- Commit
- The new ledger column:
SUM(CASE WHEN autoPing AND stop_reason = 'timeout_estimated' THEN r.cost_usd …)uses the same filter asPingUSD, so it is a true part ofPingUSD. The Scan order matches the SELECT order: 6 values, thenfrom. - The golden file: JSON keys are in sorted order, and
ping_timed_out_usdcomes beforeping_usd, which is correct. grep llm_keepaliveacross the repo found only the spec, the Grafana board and its generator. No alert rule readsoutcome="failed".- I ran no Go build or test, as this review's instructions say.
… the timeout outcome (#754) A ping that runs to its timeout is now booked at the keeper's projected cost, and llm_keepalive_cost_usd_total includes it. The spec's rule 6 says no figure may hide an estimate, so this adds the part that is a projection as its own counter, a sub-set of the cost, the same way llm_inference_estimated_cost_usd_total sits under the inference cost. - docs/metrics/spec.md §5.3: the new counter, what a timeout ping books and where, and that skipped is not emitted yet. §6.3: an "Estimated ping cost" panel. - proxy/inferencemetrics.go: llm.keepalive.estimated_cost.usd, booked for an outcome="timeout" ping only. - Central dashboard: the "Estimated ping cost" stat, and the "Ping outcomes" text no longer says a timeout leaves no row. JSON regenerated with gen_dashboards.py. - The central e2e test expects the new name, and its push fixture sends a timed-out ping. - docs/reference/reference.md: a timed-out ping leaves a row. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
|
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (claude, user of @boazdavid) | Claude Code 2.1.241, opus[1m] | offload-review skill, @boazdavid's session | fresh | 2 of 2 | 3 of 3 | f98f3b53e5f7 |
approve |
Verdict: approve
The new commit f98f3b53 adds the counter llm_keepalive_estimated_cost_usd_total. The code, the spec, the dashboard and the tests agree. I found no defect.
Findings
None.
Earlier findings
- Reviewer 2, finding 1 (
outcome="failed"for a timeout): fixed inabd9de30.f98f3b53keeps it.observePing(proxy/inferencemetrics.go) still testsStopTimeoutEstimatedbefore the status. - Reviewer 2, finding 2 (no behavior-change or data-dependence statement): fixed. The PR body now lists the 3 central metrics and the Grafana change in the table.
- Reviewer 1, finding 1 (behavior change not named): fixed. Same table.
- Reviewer 1, round 2, non-blocking (the return panels read a cost that now holds an estimate): fixed in effect. The new "Estimated ping cost" stat shows the projected share next to "Pings that paid".
- Earlier non-blocking items: all fixed or answered with a correct reason in round 2. Nothing in
f98f3b53changes those answers.
Non-blocking
- Merge gate, not a finding. The PR body says "approved by boazdavid, 2026-11-17". The author's session wrote that text, on the same account.
CLAUDE.mdsays an agent's report of a decision is not the decision. So the human developer should confirm on the PR in their own words before merge. #754 is from @amiddavid, so the central-metric part may also need their view. docs/metrics/spec.md:339says the projection is "the prompt prefix at the model's cache-read rate".projectedPingUSD(keepalive/keeper.go:1112) also adds the route's output budget at the output rate. Add "plus the output budget" to the spec text.- An unpriced model gives
e.pingUSD = 0. Then the timeout counts inllm_keepalive_pings_total{outcome="timeout"}but adds no cost and no estimated cost. This is correct (e.CostUSD > 0guard). The spec does not say it. It is a small point. - The "Estimated ping cost" stat shows "no data" until the first timeout is pushed, because the counter does not exist before that. A reader can take that as "not measured" rather than 0%. An
or vector(0)on the numerator would show 0%. This is cosmetic.
What I checked
- Last review: round 2,
abd9de30d2727dc8e6d9316c00ce176ab3a87581, 2026-11-17T06:08:25Z - New commits read: 1 (
f98f3b53feat(metrics): add llm_keepalive_estimated_cost_usd_total and specify the timeout outcome (#754)) - Read in full: 4 reviews, 2 comments, 0 inline comments (from the three files)
- New items since my last review:
- Reviewer 1 round-2 review (06:08:32Z). I read it. Its panel note is answered by the new stat (see "Earlier findings").
- The author's comment (06:16:42Z) on
f98f3b53. I checked each of its 4 points against the diff. Its claim that a human approved the change is from the author's session. I list it as a merge gate. - The edited PR body. I read it in full. The table, "Change" and "Tests" sections match the code.
- Diff
abd9de30..f98f3b53: all 7 files.proxy/inferencemetrics.go: the new counter uses thef64helper with no unit, likellm.inference.estimated_cost.usd, so it exports asllm_keepalive_estimated_cost_usd_total. It is booked only whenoutcome == "timeout"andCostUSD > 0, inside the same block aspingCost. So it is always a sub-set of the cost.proxy/inferencemetrics_test.go: expects 0.002 estimated and 0.005 total. That matches the 3 events.central_e2e_test.go:dash.Metais embedded indash.Event(dash/event.go:548), soMeta: dash.Meta{StopReason: …}compiles. The new name is in the expected list.gen_dashboards.pyandcache.json: the JSON matches the generator output for panel 8. Panel id 8 is unique on the board. Panels 5 (y=8, h=4) and 8 (y=12, h=4) fill the old 8-high slot at x=18, so no panel overlaps panel 6 at y=16.docs/metrics/spec.md§5.3 and §6.3, anddocs/reference/reference.md: the row text matches the code (status 0,timeout_estimated,/statstimed_out).pingTimeoutis 60 s (keepalive/ping.go:95).- Other readers of
llm_keepalive_cost_usd_total:deploy/central/prometheus/rules/recording.yml(net rate), its alert test, andproxyapp/metricspush_test.go. None needs a change.
- I ran no build or test. Live tests are not approved.
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (claude, user of @boazdavid) | Claude Code 2.1.241, opus[1m] | offload-review skill, @boazdavid's session | fresh | 1 of 2 | 3 of 3 | f98f3b53e5f7 |
approve |
Verdict: approve
The new commit f98f3b53 adds the counter llm_keepalive_estimated_cost_usd_total, its spec text, and a Grafana stat. I found no defect in it. All earlier findings stay fixed.
Findings
None.
Earlier findings
- Reviewer 1, round 1, finding 1 (behavior change not named): fixed. The PR body still has the "Behavior change" table. It now also names the new counter and the Grafana change. It says boazdavid approved the change on 2026-11-17, including the central metrics and
tenant_spend. - Reviewer 2, round 1, finding 1 (
outcome="failed"for a timeout): fixed.observePing(proxy/inferencemetrics.go:212-230) still testsStopReason == dash.StopTimeoutEstimatedbefore the status test. - Reviewer 2, round 1, finding 2 (no behavior-change or data-dependence statement): fixed. Both sections are in the PR body. "Metadata only" is still correct. The new counter holds a cost figure only.
- Round 2: both reviewers approved with no findings. My round-2 non-blocking point about a missing estimate mark on the central cost is now solved by the new counter. The commit follows spec rule 6, in the same way as
llm_inference_estimated_cost_usd_total.
Non-blocking
- Merge gate record. The approval of the behavior change is written only in the PR body and in an author comment. Both come from the author's agent session. No comment on the PR comes from the person directly.
CLAUDE.mdsays that an agent's report of a decision does not count as the decision. If the team wants a clear record, ask boazdavid to write the "yes" on the PR. docs/metrics/spec.md:339says the projection is "the prompt prefix at the model's cache-read rate".projectedPingUSD(keepalive/keeper.go:1112) also adds the 1-token output budget at the output rate. The difference is very small. The text could say "plus one output token".- The recording rule
proxy:llm_keepalive_net_usd:rate1h(deploy/central/prometheus/rules/recording.yml:82-90) and the Grafana "net" line now subtract the projected cost too. The PR body names the cost metric change, so this is expected. I note it only so the owner knows that the net figures move as well.
What I checked
- Last review: round 2,
abd9de30d2727dc8e6d9316c00ce176ab3a87581, 2026-11-17T06:08:32Z - New commits read: 1 (
f98f3b53feat(metrics): add llm_keepalive_estimated_cost_usd_total and specify the timeout outcome (#754)) - Read in full: 4 reviews, 2 comments, 0 inline comments (from the three files)
- New items since my last review:
- Commit
f98f3b53. I read the whole diff: 7 files, +84/−10. - The author comment at 2026-11-17T06:16:42Z. It says boazdavid approved the behavior change and asked for the spec entry. I checked each of its 4 points against the commit. Point 4 (the e2e test was not run) is true and is said in the PR body.
- The updated PR body. I read it in full. The table, "Decision", "Change" and "Tests" sections match the code.
- Reviewer 2's round-2 review (06:08:25Z). Its one non-blocking point (
docs/how-to/cache-keepalive.md:195-196) is not changed by this commit. I agree it is non-blocking.
- Commit
proxy/inferencemetrics.go: the new counter is registered with the samef64helper and the same name pattern asllm.inference.estimated_cost.usd. So its exported name isllm_keepalive_estimated_cost_usd_total. It is booked only whenoutcome == "timeout"andCostUSD > 0, and it is never added topingCosta second time. The test checks 0.002 for it and 0.005 for the total.proxyapp/metricspush/central_e2e_test.go:dash.Meta{StopReason: …}is valid, becauseEventembedsMeta(dash/event.go:548) andMetahasStopReason.Observesends everyKeepAliveevent toobservePingbefore it reads the status, so the status-0 event books no request metric.- Grafana: I ran
python3 deploy/central/grafana/gen_dashboards.py --check. It exits 0. I loadedcache.jsonand listed every panel. Panel ids are unique. Panel 5 (x=18, y=8, h=4) and the new panel 8 (x=18, y=12, h=4) fill the old 8-row space with no overlap. The new query follows the "Spend priced from a fallback rate" stat ininference.json. grepforllm_keepalive_cost_usd_totalacross the repo: the spec, the Grafana generator and its JSON, one recording rule, and one alert test. No alert readsoutcome="failed". No collector allow-list blocks a new name.- Spec §5.3 text: a fast transport error books no row, so it books no metric. This matches
docs/reference/reference.mdand the keeper code. - I ran no Go build or test. Live tests are not approved.
Fixes #754.
Behavior change (approved by boazdavid, 2026-11-17)
Who it affects: every proxy that runs keep-alive, on a ping that runs to its 60 s timeout. On the owner's proxy, that was 92 of 95 failed pings (#719).
Old: a timed-out ping adds 1 to
failedand books nothing: no row, no cost, no metric.New: it books one row at the keeper's projected cost of one ping (
e.pingUSD), markedstop_reason = timeout_estimated, with status 0 and no tokens. These figures change:/statskeepalive.spend_usd/statskeepalive.timed_outfailed)pings,ping_usd,net_usdpings_timed_out,ping_timed_out_usdpings_that_read_nothingdash/keepalivestrategy.go,dash/campaignsavings.go),adaptReport,insights.pynet_usd/loserstenant_spend/ control-planespent_usdproxy/limits.go). It is a rollup, so rows booked now stay in it.llm_keepalive_pings_totaloutcome="timeout", asdocs/metrics/spec.md§5.3 definesllm_keepalive_cost_usd_totalllm_keepalive_estimated_cost_usd_totalWhat does not change: a timed-out ping is not a refresh. No cache clock moves, it gets no rescue or saving credit, and it does not stop or restart pinging. Fast failures (EOF, reset, refused) still book nothing.
How to turn it off: there is no switch for this change alone.
CONTEXT_GURU_KEEPALIVE=offturns off keep-alive as a whole.Decision: boazdavid approved the change on 2026-11-17, including the central metrics and
tenant_spend, and asked that the new metric be added to the metrics spec.Data dependence
Metadata only: a projected cost (prompt size × a price), a counter and a stop-reason string. Nothing new is stored. The data dependence of keep-alive does not change, so
docs/data-dependence/features/keep-alive-pings.mdneeds no edit.Problem
A keep-alive ping that runs to its 60 s timeout is counted only as
failed. It writes no row and books no cost. But it probably reached the provider and was billed (#532). So the dashboard and/statsundercount keep-alive spend and overstate its net saving.Reproduced on
main(f3f108cd) with a fake dispatcher: the same thread with the same price books $0.015015 on a successful ping and $0.000000 on a timed-out one. The keeper's own projection for that ping is $0.015015.Change
keepalive/keeper.go). If the error iscontext.DeadlineExceeded, or the ping's context ran out,recordTimedOutbooks one row ate.pingUSDand setsKeepAliveReport.TimedOut. It adds the cost tospend_usdand to the entry's spend. No cache clock moves, andRefreshedstays as it was./stats: newtimed_out.failedstill counts timeouts.stop_reason = "timeout_estimated"(dash.StopTimeoutEstimated). A timed-out ping has no provider stop reason, so this column is free, and no schema change is needed. The refresh probes needcache_read > 0orcache_write > 0, andPingSavingsneeds a 2xx, so the row gets no refresh or saving credit.proxy/inferencemetrics.go): the row is pushed asoutcome="timeout". Its cost goes tollm_keepalive_cost_usd_totaland also to the newllm_keepalive_estimated_cost_usd_total.docs/metrics/spec.md): §5.3 adds the new counter, says what a timeout ping books and where, and notes thatskippedis not emitted yet. §6.3 adds the "Estimated ping cost" panel.deploy/central/grafana/): the "Estimated ping cost" stat, and corrected "Ping outcomes" text. The JSON is regenerated, andgen_dashboards.py --checkpasses.docs/how-to/cache-keepalive.mdliststimed_outand says how a timeout is booked.docs/reference/reference.mdsays that a timed-out ping leaves a row.Not in scope
pings_timed_out/ping_timed_out_usdyet. The API returns them.keepalive/manual.go) that times out still books nothing. That is a follow-up.Tests
TestATimedOutPingBooksItsProjectedCost: 1 row, coste.pingUSD,TimedOut,timed_out1,failed1,Refreshedunchanged.TestAFastFailedPingBooksNothing: EOF books no row and no cost.TestDashEmitterBooksATimedOutPingAsEstimatedSpend: report → dash row →KeepAliveLedger, includingping_timed_out_usd.TestPingBooksKeepAliveAndNoRequest: a timeout row is pushed asoutcome="timeout", its cost is in the cost metric, and only its cost is in the estimated cost metric.TestCentralNamesMatchTheSpecnow expectsllm_keepalive_estimated_cost_usd_total. It needs a live central stack, so it was not run here (it skips).timeoutlabel, or the estimated cost booking each makes a test fail.keepalive,dash,proxy,componentsandmetricspass. Inproxyapp,TestPreflightResolvesToolsOnTheServicePATHandTestPreflightReadsKeyEnvFromConfigNotCommentsfail locally (bash 3.2 on macOS). They fail the same way on cleanmain.Assisted-By: Claude (Anthropic AI) [email protected]