Repository navigation
feat(proxy): count warm returns that find no ping facts - #1099
Merged
Merged
Conversation
Add 2 /stats counters: keepalive_pings_priced (each PingSavings call that returned ok) and keepalive_rescue_facts_missing (a priced real request that followed keep-alive pings but found no ping facts for its thread). Both are also exported as cg_keepalive_*_total. A host that embeds the library can skip the ping side and get $0 credit with no error. A non-zero missing count now shows it. This closes gap G11 of the invariants doc (PR #820, check K11). Counts only. No default changes. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
amiddavid
commented
Nov 11, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 147d51945834 |
blocking |
Verdict: blocking
Findings
- docs/reference/reference.md:200 — the operator text says non-zero means the host does not wire the ping side. A wired host can make the counter rise.
- What fails: a host wired like
cmd/context-guru-proxysends one span's pings and they all fail with a non-2xx answer or no usage. The next priced request counts 1 inkeepalive_rescue_facts_missing. The operator reads reference.md or the Grafana HELP, concludes the ping side is unwired, and hunts a wiring bug that does not exist. The same happens when the store evicts the facts (4096 threads). - Proof:
proxy/dashcapture.go:850counts whenkaPings > 0 && accPingWindow == "".kaPingsis the keeper entry'se.pings, raised at dispatch for every scheduled ping (keepalive/keeper.go:1359) and kept for a ping that got a non-2xx answer —giveBackFailedPing(keepalive/keeper.go:1656) undoes only a transport failure.PingSavingsstores facts only for a converted ping (proxy/accountant_ping.go:133refuses non-2xx, no usage, zero window). Eviction:proxy/accountant_ping.go:54. The PR's own Technical notes admit this: "The missing count can also rise for a ping that was not priced (non-2xx, no usage) or whose facts were evicted from a full store." - Fix: keep the count, narrow the claim. In
docs/reference/reference.md:200, the HELP atproxy/promexport.go:696and the comment atmetrics/metrics.go:1106, say: non-zero means the ping credit was lost — the ping side is not wired, or the span's pings were not converted, or the store evicted the facts.
- What fails: a host wired like
Non-blocking
proxy/dashcapture.go:850— the count also fires whencomputeSafepanicked (accNoResult = "compute_panicked"), so the request was not priced. The field is defined as "priced real requests". Rare; the panic path books no figure.docs/reference/reference.md:199and the HELP atproxy/promexport.go:699say "priced and stored". A manual ping is priced but stores no facts (by design, #768 B3). The parenthetical "(each PingSavings call that returned ok)" is the accurate half.keepalive_pings_pricedcounts pings;keepalive_rescue_facts_missingcounts requests. Calling one "the denominator for" the other mixes units: one unwired request after 10 pings reads 1/10. As context the pair works; as a ratio it does not.proxy/pingunpriced_test.go:56— the comment says "The three ways a host fails to wire the ping side", but the table tests two. The key-mismatch case is untested.- A span served only by a substitute ping (sweep or summarizer) does not raise
kaPings, so an unwired host is not detected there. Under-count only; the doc makes no claim in that direction.
What I checked
- The full diff (10 files) and the code around each change:
accountant_ping.go,accountant_savings.go,dashcapture.go(finish and the priced path),accountant_wire.go(accEnd/accWait/entryFacts),promexport.go,proxy.go(stats),metrics.go, the new test file, both changed tests,docs/reference/reference.md. - The equivalence the count rests on:
accPingWindow == ""means no facts found.entryFactssets it only from a peek that succeeded, and every stored fact carries a non-empty window becausePingSavingsrefuses a zero-window ping. Holds. - Nil-safety of both counters:
Priced,RescueFactsMissing,notePriced,noteRescueFactsMissingall take a nil receiver.h.savingsis nil without a dashboard and the reads stay safe. - That the count fires for all three wiring failures it claims to detect: no
Options.Pings, noPingSavingscall, key mismatch. It does (traced the keys; put and peek both map the primary thread to "main"). - Race safety: both counters are
atomic.Int64;renderMetricsand/statsread them without the aggregator guard. /statsappend-only contract: fields are added, none renamed or removed; the golden list and the coverage map are updated consistently.- Data dependence and behavior change: counts only, no stored content, no request behavior change. The PR body states both. No
data-dependence.mdrow needed (no new feature or component). - The keeper's ping accounting (
e.pings,giveBackFailedPing, manual and substitute paths) to confirm which pings raisekaPingsand which pings store facts. - Live tests were not run (not approved). I read the PR body; no other review or comment on the PR was read.
amiddavid
commented
Nov 11, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 147d51945834 |
blocking |
Verdict: blocking
Findings
- docs/reference/reference.md:200 — the claim "Non-zero means the host does not wire the ping side" is false on a fully wired host
- What fails: a wired host sends one scheduled ping that the provider rejects (429 or 5xx) or that returns no usable usage. The next priced warm return on that thread increments
keepalive_rescue_facts_missing. The operator reads the counter, the docs say the wiring is broken, and the PR summary's own acceptance check ("a wired host showsfacts_missing == 0") fails. - Proof: trace.
Sweepcounts the ping before it fires:e.pings++(keepalive/keeper.go:1359).- A 429/5xx ping returns
outcomeTransientand a no-usage 2xx returnsoutcomeFailedRecorded; both still callrecord1, which emits theKeepAliveReportwith that status (keepalive/keeper.go:1576-1594, 1516-1524, 1743-1761). PingSavingsrefuses a non-2xx or zero-usage report, so it stores no facts (proxy/accountant_ping.go:133-136).- The user returns.
arriveAtreportspings ≥ 1askaPings. The request is priced withaccPingWindow == "", sonoteRescueFactsMissingfires (proxy/dashcapture.go:850-852). - The same happens when the full store evicts the thread's entry (proxy/accountant_ping.go:54-59,
pingStoreMax4096), or when a ping is still in flight while the request'saccEndpeeks the store. - The PR's own Technical notes admit both cases ("The missing count can also rise for a ping that was not priced (non-2xx, no usage) or whose facts were evicted"). But every operator-facing text states the strong claim: reference.md:200 ("Non-zero means the host does not wire the ping side …
0on a healthy host"), thecg_keepalive_rescue_facts_missing_totalHELP (proxy/promexport.go:696, "Above 0 means the host does not wire the ping side"), and the Snapshot comment (metrics/metrics.go:1105-1107).
- Fix: pick one.
- Weaken the text in all three places: non-zero means ping credit was lost; a value that keeps rising while
keepalive_pings_pricedalso rises means the host does not wire the ping side. - Or make the count precise: count only gaps whose pings were converted (for example, the host marks per thread that a converted ping exists for the gap).
- Add the missing test either way: a wired host, one rejected ping, the next return priced — the counter must read 0 (or the doc must say it reads 1). No test covers this case today.
- Weaken the text in all three places: non-zero means ping credit was lost; a value that keeps rising while
- What fails: a wired host sends one scheduled ping that the provider rejects (429 or 5xx) or that returns no usable usage. The next priced warm return on that thread increments
Non-blocking
- reference.md:199: "priced and stored" is wrong for a manual ping. A manual ping is priced and never stored (proxy/accountant_ping.go:140-142). The parenthetical ("each
PingSavingscall that returned ok") is right; the lead contradicts it. Also "denominator": the numerator counts requests and this field counts pings, so the ratio can pass 1. - proxy/pingunpriced_test.go:66: the comment says "The three ways a host fails to wire the ping side", but the table lists two. The third named way (a key mismatch) has no test.
- The missing counter cannot move on a host without
Options.Dashboard: the capture and the savings tracker are dashboard-bound (proxy/proxy.go:448-449). There,0means "not measured", not "healthy". One line in reference.md would close this. - The count also fires when
computeSafepanicked (proxy/dashcapture.go:843-852), so "priced real requests" in metrics/metrics.go:1105 is not exact. The request then books no saving.
What I checked
- The full diff of 147d519 against base 202087d, line by line, and the code around each change.
- The count condition in
finish:kaPings > 0 && accPingWindow == "". I traced wherekaPingscomes from (keeper.arriveAt, proxy.go:1593) and whereaccPingWindowis set (entryFacts→pings.peek, proxy/accountant_wire.go:119-120, 219-221). The key on both sides issession + "\x00" + accThreadID(thread), so the keys match. - Which pings
kaPingscounts: only scheduled ones.PingNow(manual) and the extra sweep question do not touche.pings(keepalive/manual.go, keeper.go:1314-1322). So a manual ping cannot fire the counter. A sweep substitute does count and does store facts (keepalive/substitute.go:276-292), so it cannot fire it either. - Placement in
finish: the count runs in therounds <= 1branch, afteraccWait, only whenaccReq != nil && usageOK && !accDone. Rejected, deferral-unplaced, multi-round and no-usage requests do not count and do not drop the facts. A second request in the same gap readskaPings == 0(the entry is cleared at the first arrival), so nothing counts twice. - Nil safety:
PingStore.PricedandsavingsTracker.RescueFactsMissing/noteRescueFactsMissingare nil-receiver safe.renderMetricsrenders the two series outside theh.aggguard, so they render at zero. - The new tests in proxy/pingunpriced_test.go: I read each one and traced what it exercises. They match the implementation. The
/statsand/metricstest follows the shape of the existing tests that callh.stats. - The coverage map and the stats golden list: both new Snapshot fields are listed, and the golden test now names both keys.
- The PR description (summary, data dependence, behavior change, technical notes). The data-dependence section is right: counts only, no content.
- I did not run builds or tests. Live tests were not approved for this review.
Round 1 review of #1099. The text claimed a non-zero value means the host does not wire the ping side. A wired host also counts a return after a rejected ping, an eviction, an in-flight ping, or a pricing panic. - Reword reference.md, the cg_* HELP and the Snapshot comment: non-zero means credit was lost on that many returns; rising while keepalive_pings_priced stays 0 means the ping side is not wired. - Drop "denominator" and "priced and stored". Say the dashboard must be on. - Test a wired host with a rejected ping (counts 1) and a key mismatch. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
Collaborator
Author
Round 1 repliesAll findings are fixed in Blocking (reviewer 1, finding 1; reviewer 2, finding 1): "Non-zero means the host does not wire the ping side" is false on a wired host. Fixed.
Non-blocking, all fixed in
Tests (on the eval box):
|
amiddavid
commented
Nov 11, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 6de565f60c64 |
approve |
Verdict: approve
Findings
None. The counter logic is unchanged; the fix touches text and tests only, and the new text is accurate.
Earlier findings
- My finding 1 and reviewer 1's finding 1 (the same finding): fixed. The author chose the weaker-text fix, one of the two fixes I proposed. I checked each case the new text lists against the code, and each is real:
- a ping with a non-2xx answer or no usage:
PingSavingsrefuses it, so no facts are stored (proxy/accountant_ping.go:133-136), whilekaPingsstill counts it (keepalive/keeper.go:1359, 1576-1594); - an eviction: proxy/accountant_ping.go:54-59;
- a ping still in flight when
accEndpeeked; - a request whose pricing panicked (the count sits after
computeSafe, proxy/dashcapture.go:843-852).
The claim is now "non-zero means keep-alive credit was lost on that many returns", which is what the code does. The same text is in all three places: reference.md:200, the HELP (proxy/promexport.go:695-696), and the Snapshot comment (metrics/metrics.go:1103-1108).
- a ping with a non-2xx answer or no usage:
- The author declined the "precise count" option (per-thread state marking a converted ping). The reason given: a larger change, and the weaker text is correct for what is counted. I accept the reason. The text now states exactly what the counter counts, so an operator is not misled.
- My non-blocking items: all fixed. "priced and stored" is now "priced … manual pings too"; "denominator" is dropped; the key-mismatch case has a test; the dashboard-bound caveat is in reference.md and the metrics comment; the panic case is documented.
- Reviewer 1's non-blocking items: all addressed (panic case, "priced and stored", denominator, the key-mismatch test, the substitute note). I checked each myself; the fixes match the code.
- New test, checked:
TestWiredHostCountsAReturnAfterARejectedPingasserts missing 1 and priced 0 for a 429 ping on a wired host. That is what the code does, and what the doc now says. The key-mismatch case stores under threadsub-1and returns on the main thread; the peek key differs, so missing reads 1.ptrclashes with nothing else in package proxy.
Non-blocking
- reference.md:200, "If it keeps rising while
keepalive_pings_pricedstays0, the host does not wire the ping side": a wired host whose pings all fail for a long stretch also shows this pattern. The same cell lists the non-2xx cause one sentence earlier, and the keeper's own counters show pings firing, so the reader can tell the two apart. No change required. - reference.md:200, "A span served only by a substitute ping does not raise it": true because a committed substitute stores facts (keepalive/substitute.go:276-292), not because
kaPingsstays 0 — a summarizer substitute is fired from a Sweep job that already rane.pings++(keepalive/keeper.go:1359). A committed substitute whose call reported no usage would store nothing and could raise the counter. The same cell's "no usage" clause covers the reading. No change required.
What I checked
- Last review: round 1, 147d519, 2026-11-11T18:01:32Z.
- New commits read: 1 —
6de565f6"fix(proxy): say what the missing-facts counter really means". - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt; the inline file is empty). - New items since my last review, and what I did about each:
- reviewer 1's round-1 review (posted 18:00:10Z, before mine): read in full now. Its finding matches mine; its non-blocking items overlap mine plus the substitute note. Checked each against the code.
- the author's round-1 reply (18:15:54Z): read in full. Verified every claim in it — the reworded text, the three places it appears, the new test, and the declined option.
- the fix commit
6de565f6: read the full diff (4 files) and the files around each change. The counter code in dashcapture.go, accountant_ping.go and accountant_savings.go is untouched; the diff rewords reference.md, the HELP, the Snapshot comment, and reworks the tests.
- The new doc claims, one by one, against the code: the four wired-host cases that count (traced in round 1 and re-confirmed), the dashboard-bound caveat (proxy/proxy.go:448-449), the "keeps rising while priced stays 0" rule, and the substitute sentence (traced
fireSubstitutefrom Sweep'se.pings++and the report it emits). - The reworked tests:
returnAfterPings's new signature, theptrhelper, the key-mismatch case's key (s\x00sub-1vss\x00main), and the rejected-ping case. Each matches the implementation. - That nothing else moved:
git diff 147d5194..6de565f6touches only the four files above; the base diff 202087d..HEAD is otherwise the round-1 code I already reviewed line by line. - I did not run builds or tests. Live tests were not approved for this review.
amiddavid
commented
Nov 11, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 6de565f60c64 |
approve |
Verdict: approve
Findings
None. The round-1 finding is fixed and correct.
Earlier findings
- My finding 1 (reviewer 2's finding 1, same defect): "non-zero means the host does not wire the ping side" was false on a wired host. Fixed in
6de565f6.- The three texts now say non-zero means keep-alive credit was lost on that many returns (
docs/reference/reference.md:200,proxy/promexport.go:696,metrics/metrics.go:1104). - They list the wired-host cases that count. I verified each against the code:
- a ping with a non-2xx answer or no usage —
PingSavingsrefuses it, so no facts (proxy/accountant_ping.go:133); - an eviction —
proxy/accountant_ping.go:54; - a ping still in flight —
ArriveAtdoes not wait for it (keepalive/keeper.go, the "does not wait for pings already in flight" note); - a pricing panic —
proxy/dashcapture.go:850runs whatevercomputeSafereturned.
- a ping with a non-2xx answer or no usage —
- The unwired diagnosis is now a pair rule: rising while
keepalive_pings_pricedstays 0. The new testTestWiredHostCountsAReturnAfterARejectedPinglocks the doc in: a wired host, one 429 ping, missing 1 and priced 0. - The author chose the weaker text over per-thread converted-ping state. I agree with that choice: the text is now true for every case the counter counts.
- The three texts now say non-zero means keep-alive credit was lost on that many returns (
Non-blocking
docs/reference/reference.md:200— the parenthetical on the pair rule lists "a key mismatch" as a cause of "priced stays 0". A key mismatch with a SHARED store (facts stored under another key) raisespricedtoo, so that signature cannot see it. Only the two-store mismatch keepspricedat 0. Wording precision only: the row's main claim (credit was lost) stays true.- The pair rule also matches a wired host whose every ping is rejected: there
pricedstays 0 andmissingrises. The row lists the rejected-ping case as counting, so a reader can reconcile the two. No false claim about the count itself remains. docs/reference/reference.md:200— "A span served only by a substitute ping does not raise it" is true on a wired host (the substitute is priced with status 200 and stores facts,keepalive/substitute.go:278-292). On an unwired host a substitute-served span does raise it, because a planned-ping substitute rides a Sweep job that already countede.pings(keepalive/keeper.go:1359,fireat 1428). The sentence is unconditional; the context is the wired-host reading.- Correction to my round-1 review: I wrote that a substitute ping does not raise
kaPings. That was wrong for a substitute that takes a planned ping — the Sweep job already incrementede.pings. Reviewer 2 had it right. Only an EXTRA-slot substitute (fireExtra) leavese.pingsalone.
What I checked
- Last review: round 1, 147d519, 2026-11-11T18:00:10Z
- New commits read: 1 —
6de565f6fix(proxy): say what the missing-facts counter really means - Read in full: 2 reviews, 1 comment, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt) - New items since my last review, and what I did about each:
- Reviewer 2's round-1 review (18:01:32Z): same blocking finding as mine. I checked its proof lines myself in round 1 (Sweep's
e.pings++, the 429/no-usage outcomes,PingSavingsrefusal, eviction). It holds. Its extra non-blocking notes (dashboard-bound counter, compute-panic wording) I verified then and they are fixed now. - The author's reply (18:15:54Z): I checked every claim in it against
6de565f6. Each reply line matches a real change in the diff, except the bold label "does not raise kaPings" on the substitute note, which misstates my note and the mechanism — the doc sentence itself ("does not raise it", the missing counter) is the correct one, so the label slip changes nothing in the code or docs. - Commit
6de565f6: full diff read; each changed file read around the change (reference.mdrows,metrics.gocomment,promexport.goHELP,pingunpriced_test.go).
- Reviewer 2's round-1 review (18:01:32Z): same blocking finding as mine. I checked its proof lines myself in round 1 (Sweep's
- The new tests:
TestWiredHostCountsAReturnAfterARejectedPing(429 ping stores nothing, priced 0, missing 1 — matches the doc), the key-mismatch case (stored undersub-1, read onmain, missing 1 — the keys behave as traced in round 1), and theptrhelper (generic, Go 1.26, fine). - The substitute-ping path in
keepalive/:firevsfireExtra,recordSubstitutePing's report (status 200, non-zero window, not manual), to settle the substitute sentence and correct my round-1 note. - The counter logic itself is unchanged by the fix commit; my round-1 verification of the count condition, nil-safety, key consistency and race safety still stands.
- Live tests were not run (not approved). The author reports vet, gofmt and
-raceruns green on the eval box; I could not verify that myself.
This was referenced Nov 11, 2026
amiddavid
added a commit
that referenced
this pull request
Nov 12, 2026
#1105) The docs-only follow-up to #1099: the wording of the keepalive_rescue_facts_missing row in docs/reference/reference.md, its /metrics HELP string and the code comment now say exactly what the lost-credit counters can and cannot tell. Behavior change: none (docs, a HELP string and a comment). Data dependence: none. Reviews: 4 offload review rounds (GLM; rounds 3 and 4 granted by the owner). Round 4: both approve at 29fb215, which is the PR head. Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Opus 5.5 <[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 2
/statscounters (new visible output). No default changes. The owner approved it.keepalive_rescue_facts_missing: priced real requests that followed keep-alive pings but found no ping facts for their thread.keepalive_pings_priced: pings thatPingSavingspriced (returned ok). Read it together with the other counter.Both are also exported as
cg_keepalive_rescue_facts_missing_totalandcg_keepalive_pings_priced_total.The invariants doc (PR #820) adds check K11. This counter closes its gap G11.
What we found
PingSavings, and the next real request reads the facts throughOptions.Pings.mainskipped this wiring. 286 pings went out. 0 of 48 warm returns got credit. No error, no log.What changed
proxy/dashcapture.go: when a request is priced,kaPings > 0, and no ping facts were found, count it.proxy/accountant_savings.go: the counter lives on the handler's savings tracker (non-nil even whenOptions.Pingsis nil).proxy/accountant_ping.go:PingStorecounts priced pings (nil-safe: a host with no store reads 0).metrics/metrics.go,proxy/proxy.go: the 2/statskeys.docs/reference/reference.mddocuments them.proxy/promexport.go: the 2cg_*counters. A fully wired host that gets no failed pings showsfacts_missing == 0andpings_priced > 0.How it was tested
On the shared Linux box, with
-race:go vet ./proxy/... ./metrics/... ./cmd/...: clean.gofmt -l: clean.go test -race ./proxy/...: ok.go test -race ./cmd/context-guru-proxy/... ./metrics/...: ok.proxy/pingunpriced_test.go):Options.Pingsnil, orPingSavingsnever called: missing 1;/statsand/metricscarry both values.Data dependence
Metadata only: counts. Same at every storage level (off, metadata only, everything). The counters read and store no content.
docs/data-dependence.mdholds rows for features and components, anddatadep_test.gochecks registered components only. This adds neither, so I added no row.Behavior change
New keys in
/statsand 2 new/metricsseries only. Requests and responses do not change. To turn it off: not needed (read-only counters).Technical notes
keepalive_pings_pricedstays 0, the ping side is not wired.kaPings, so an unwired host is not detected there.kaPingscomes fromnoteKeepAlive. The check runs wherefinishprices the request, once per request (rounds <= 1).promexport_coverage_test.goshows a larger diff because gofmt re-aligned the map.