Repository navigation
feat(keepalive): record the subscription limit headers on ping rows - #1012
Merged
Merged
Conversation
A keep-alive ping is a real request, so its answer carries the anthropic-ratelimit-unified-5h-* and -7d-* headers. The ping row now stores them, so GET /api/me/limits stays current while the user is idle. - components.KeepAliveReport gets the ping response's Header. - The keeper passes it from scheduled and manual pings. - The proxy host reads it with the same parser as the request path (proxy.PingLimits wraps readLimitHeaders) and sets Event.Limits. - auth_subscription stays 0 on ping rows; the user's request decides it. Closes #995 Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
amiddavid
commented
Nov 10, 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 | 74db21ccaf7d |
approve |
Verdict: approve
Findings
None. I found no defect that blocks this PR.
Non-blocking
components/component.go:1240— the field doc says Header is nil "when there was no response to read (a substitute call...)". A substitute call does get an answer with headers; the summary result type (offload.KeepAliveSummaryResult) just does not carry them. The behavior is right and the PR names the gap. Only the wording is loose.proxy/pinglimits_test.go:16— the test comparesPingLimitswithreadLimitHeaderson the same input. That part cannot fail while the delegation stays. The nil and bad-header cases are the real checks. Fine as is.dash/limits.go:88—LatestLimits, unlikeLatestAuthSubscription, has noprovider = 'anthropic'filter. Pre-existing, and only Anthropic sends these headers, so ping rows change nothing here.
What I checked
- The full diff, one commit, and the PR description.
- Every emitter call site:
record1(keeper.go:1690),PingNow(manual.go:184), andrecordSubstitutePing(substitute.go:273). All report paths that have a response now passresp.Header; the substitute path leaves it nil on purpose, and the PR says so. - All four
record1call sites infire(transient, failed-recorded, missed, normal) pass the header. The transport-error path emits no report, which is right: no response exists. - Header ownership and races. The proxy dispatcher clones the upstream header before returning it (
proxy/dispatcher.go:322), so the keeper holds the only reference.dashEmitterreads it insidePingLimitsbeforeRecord, synchronously. The fake test clones under its lock. No sink mutates the map. - The parser.
PingLimitsreusesreadLimitHeaders; no second parser. Status words are allow-listed (limitStatusOK), utilization is bounded, so no free text reaches a row. - The dash side.
limitArgswriteslimit_seenand the seven columns for any row, ping rows included (dash/store.go:682).LatestLimitsreads the newestlimit_seen = 1row with no keep-alive filter, so a ping row now wins while the user is idle — the feature.LatestAuthSubscriptionkeeps itskeepalive = 0filter, so the auth kind still comes from the user's own request; the test asserts this. - Fail open.
PingLimitsis a pure parse and cannot fail.dashEmitter.KeepAlivePingkeeps its panic recover (issue #918). A ping without headers recordslimit_seen = 0, which stays apart from a share of 0. - The 429 and 5xx path.
noteOutcomemaps them tooutcomeTransient, which still books the row, so the provider's refusal headers are recorded — same as the request path. - Tests. I read all three new test files and the helpers they use (
manualKeeper,reportSink,fakeOf, the 281-second sweep pattern from the existing tests). ThedashEmittertest leavespingsnil, butPingSavingsreturns beforest.putbecauseWindowis zero. I did not run the tests; live runs were not approved. - Data dependence.
docs/data-dependence.mdrow #984 now names ping rows. Same kind: numbers, short status words, a flag. No direction change, so no new "Decided by" confirmation is needed. - The behavior change is named at the top of the PR:
/api/me/limitsreturns fresher values while the user is idle. Who it affects, the old and new behavior, and the scope are all stated.
amiddavid
commented
Nov 10, 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 | 74db21ccaf7d |
approve |
Verdict: approve
Findings
None. I could not prove a defect in the changed lines.
Non-blocking
- PR body, What changed — the turn-off path is not named. RELEASING.md asks the author to name each behavior change with "how to turn it off". The Summary names the change and the new behavior, but not the off switch. It exists: the feature needs the dashboard, and ping rows stop when keep-alive is off. One line in the PR body would close the gap. The behavior itself is what issue #995 (filed by @amiddavid) asks for, so the human's request is on record.
keepalive/pingheader_test.go:41— the comment names a case the test does not run. The comment says a refused ping's headers carry the status "rejected".limitHeader()sets "allowed", and the test asserts "allowed". A "rejected" status word never runs through this path in the tests. Cosmetic: the parser's status handling is covered inproxy/pinglimits_test.goandproxyrequest-path tests.components/component.go:1240— the core report type now importsnet/http.dispatchalready speakshttp.Header, so this adds no new dependency direction. Noted only, because the repo keeps the core API surface small.
What I checked
- Read
CLAUDE.md,docs/design.mdsections on keep-alive and the dispatch design, and the full diff (1 commit, 10 files). - Header flow, keeper side.
fire()passesresp.Headeron all fourrecord1outcomes that book a row (transient, failed-recorded, missed, read);PingNowpasses it on its success path. The transport-error path calls norecord1, so a zero-valuerespis never read. Allrecord1call sites got the new argument.dispatch.Responsehas theHeaderfield, and the proxy'sDispatcher.Doreturns a private clone (proxy/dispatcher.go:324), so no other holder can mutate the map the report carries. - Substitute paths.
substitute.go's report andfireExtraset noHeader, soPingLimitsreturns nil there. This matches the field's doc and the PR's "Not covered" note. - Host side.
dashEmitter.KeepAlivePingsetsev.Limitsfromproxy.PingLimits, which calls the samereadLimitHeadersas the request path (proxy.go:2228,noteLimits). No second parser. A nil or bad header yields nil limits, andlimitArgsthen storeslimit_seen = 0, so the row stays clean. - The auth-kind gate.
LatestAuthSubscriptionfilterskeepalive = 0, so an account that moves to an API key still gets{}fromGET /api/me/limitseven while old ping rows carry limit values.LatestLimitshas no keep-alive filter, so a newer ping row wins — which is the feature. Both are asserted indashemitter_limits_test.go. - Credential consistency. A ping dispatches with the credential the hold took from the client's own request (
heldAuth,proxy/dispatcher.go:133), so the ping's limit headers describe the same account the client's requests do. A server-held key (up.setKey) affects the request path the same way, so the two paths cannot disagree. - Tests. All four new keeper tests use existing helpers (
manualKeeper,fakeOf,sess1); the fake's change clones under the lock and is nil-safe. The dash test's polling loop, filter flags (RequestsforcesWithKeepAlive = true), andPingSavingsearly-return on a zeroWindowall check out against the current code. - Docs and rules. The data-dependence row is updated in plain words and the kind stays metadata. No new component, so
datadep_test.goneeds no row. Fail-open is untouched: this change only adds recorded values, and a parse failure stores nothing.
The Header field doc now says why a substitute call has no headers. The 429 test comment no longer names a "rejected" status that it does not run. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
Collaborator
Author
|
Both round-1 reviews approve 74db21c. The non-blocking notes are fixed:
|
Collaborator
Author
|
Owner decisions on the two open questions:
|
This was referenced Nov 10, 2026
amiddavid
added a commit
that referenced
this pull request
Nov 10, 2026
Conflict in docs/data-dependence.md: kept the Pi row and main's updated limit-headers row. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
amiddavid
added a commit
that referenced
this pull request
Nov 10, 2026
#1012 is merged. Keep this branch's text for the KeepAliveReport.Header comment and the data-dependence row. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
amiddavid
added a commit
that referenced
this pull request
Nov 10, 2026
At each Pi session start, the Pi extension now checks the local proxy with one GET /healthz (5-second limit). If the proxy does not answer, it restarts the proxy's user service once and checks again. If the proxy is still down, Pi shows one warning, not only a connection error on every routed request. Behavior change: Pi users who installed context-guru with /context-guru setup, and only when a Pi model goes to the proxy. Old: nothing checked the proxy, and a down proxy showed only connection errors. New: the check, one restart, and one warning. No switch; pi --no-extensions turns off the whole extension, and /context-guru uninstall removes the install record and so the check. Owner's yes, 2026-11-10, in the integrator session: "1011 behavior change approved". Data dependence: metadata only. A bare GET /healthz to localhost with no body. It reads the install record and the model URLs Pi knows. No change to stored data. Reviews: 2 offload reviews (GLM), round 3 (owner granted round 3), both approve at 655a6a9. Round 3 reviewed the merge of main after #1010, which changed the same 5 pi-package files. Two later merges of main (1077d80 after #1012, d4124cd after #1014) change no #1011 code: their remerge-diff outside docs/data-dependence.md is 0 lines; the one doc conflict kept both rows. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
amiddavid
added a commit
that referenced
this pull request
Nov 10, 2026
…rs (#1021) When a keep-alive ping is replaced by a cache_aware_summarizer summary or an extract_llm_sweep question, the substitute's dashboard row now records the subscription limit headers of its own answer, as an ordinary ping row does (#1012). So GET /api/me/limits stays current while the user is idle. Only an answer sent with the user's own credential counts; a summary on a config-sourced model does not. Behavior change: users on a Claude subscription whose keep-alive pings are replaced by a summary or a sweep question. Old: a substitute's row had no limit values, so the share could be older. New: it has them. Off: turn keep-alive off (no pings and no substitutes), or the dashboard off (no rows kept). Owner's yes, 2026-11-10, in the integrator session: "#1021 is ready to merge" and "1021 and 988 in this order are also ready". Data dependence: metadata only (numbers and short status words from response headers). No change in kind. Reviews: 2 offload reviews (GLM), round 3, both approve at f320374. After it: 2 merges of main with no hand resolution (remerge-diff 0), each tested on the merged tree (./keepalive, ./components, ./cheapmodel, ./dash, ./proxy). Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
This was referenced Nov 10, 2026
Merged
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
Keep-alive pings now record the subscription limit headers. A ping is a real request, and its answer carries the
anthropic-ratelimit-unified-5h-*and-7d-*headers. The proxy stores them on the ping row.GET /api/me/limitsreads the newest row with values, so the 5-hour share stays current while the user is idle.What changed
components.KeepAliveReporthas a new field,Header: the ping response's headers.nilwhen there was no response to read.keepalive: scheduled pings (record1) and manual pings (PingNow) put the response headers on the report. The keeper reads nothing from them.proxy.PingLimitsreads the report's headers with the parser from feat(proxy): record the subscription limit headers and serve GET /api/me/limits #991 (readLimitHeaders). No second parser.cmd/context-guru-proxy(dashEmitter) setsEvent.Limitson the ping row fromproxy.PingLimits.auth_subscriptionstays 0 on ping rows. The auth kind still comes from the user's own newest request (LatestAuthSubscriptionalready skips ping rows). So an account that moves to an API key still gets{}at once.Header.Data dependence
Metadata only: numbers and short status words from response headers. The same at every storage level. No change in kind. The row in
docs/data-dependence.mdnow also names ping rows.How it was tested
New tests:
keepalive/pingheader_test.go: a scheduled ping, a 429 ping and a manual ping carry the response headers on the report. A ping with no headers carries none.proxy/pinglimits_test.go:PingLimitsgives the same result as the request parser, and nil for no header or a bad header.cmd/context-guru-proxy/dashemitter_limits_test.go: a ping row stores the limits.LatestLimitsreturns the ping's values (newer than the user's request).LatestAuthSubscriptionis still true from the user's request. A ping without headers stores no limits.On the eval box:
go build ./...andgo vet ./...: clean.go test -raceon./keepalive/...,./components/...,./cmd/...: all pass.go test -race ./proxy/...: all pass (531 s)../dash/...is not changed.Closes #995
🤖 Generated with Claude Code