Repository navigation
feat(keepalive): hold a thread for the Ping button on request, with keep-alive off - #666
Merged
Merged
Conversation
…eep-alive off A request that carries x-context-guru-ping: 1 is held even where the account has no automatic keep-alive (Policy.ManualHold). The entry has no schedule, plan or pending ping, so nothing is ever pinged for it. It lives 300 s from the request start (even for a 1h cache), then the body and the held credential are released and zeroized; a new request or a press that read the cache restarts it. MaxBodyBytes, MaxSessions, MaxBytes and the per-ping ceiling apply as before. /api/cachestate: pingable is true only while held; ping_reason says why not (not opted in, too large, expired, over budget, unsupported). Replaces the boolean-only SetPingable with SetPingStates. Data dependence: unchanged for requests without the header; with it, the body and key are kept at most 300 s, for the button only (docs updated). Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Osher Elhadad <[email protected]>
…left The status line draws 'being pinged' from those fields, so a thread held only for the Ping button must not set them. Only pingable reflects it. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Osher Elhadad <[email protected]>
added 2 commits
October 22, 2026 12:23
…eep-alive on too ping_reason no longer calls every refusal 'not opted in'. New reasons: 'pings used' (planned pings ran out), 'stopped' (a miss, a refused ping or a failure), 'below limits' (the automatic gates refused it) and 'no entry' (nothing known: a restart, or no request since). 'over budget' now also covers a keep-alive-on thread over the ceiling. 'not opted in' stays for a request that carried no opt-in and met no automatic policy. A press stays allowed on an entry whose pings ran out while it is still held (same ceiling and 30 s gap); it is refused after a stop. Fixes #662 Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Osher Elhadad <[email protected]>
…extend the hold - Manual-only holds are evicted before any automatic hold, and one tenant holds at most 16 of them / 32 MiB (oldest first), so a client that sends x-context-guru-ping with many session ids cannot fill the shared caps. - The 300 s is measured from the last real request. A press no longer restarts it, so pressing cannot keep a credential held. - Forget and RetireSession clear the refusal reasons. - Every refusal says why: 'unavailable' (route failing / credential refused), 'no entry' (no cache usage, client ended). - Tests: cross-tenant flood, eviction order, byte cap, press at 250 s, the entry timer without a sweep, reasons cleared, and no held_until_ms or pings_left in /api/cachestate for a thread with no plan. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Osher Elhadad <[email protected]>
amiddavid
added a commit
that referenced
this pull request
Oct 22, 2026
Main moved the keeper core into package keepalive and added the manual ping (#655), the manual-only hold (#666), predictive campaigns and the per-tenant builder. This merge keeps those and re-applies the TTL-aware schedule in the new package: - keepalive: ResolveTier, Policy.ForOneHour, per-thread tier1h, entry.hold(), MaxHold1h. - Manual-only hold lives 59 min on a 1h thread (ManualHoldMax1h), 300 s otherwise. A press still never extends it. - Campaigns and overrides bound a 1h thread's ping count downward. - Tests for each interaction, confirmed by mutation. Assisted-By: Claude <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
amiddavid
added a commit
that referenced
this pull request
Oct 22, 2026
feat(keepalive): follow the cache TTL each session was billed at Read the cache lifetime per thread from the traffic. A thread is a 1h thread when every breakpoint asks ttl 1h and the response billed the 1h tier for the whole write. Anything else keeps the 5m schedule. Name strategies by ping count: auto (default), 1-ping, 2-ping. The old name 5-min-ping stays as an alias of auto. Default per TTL: 5m cache keeps today's schedule (270 s, 2 pings); 1h cache gets 1 ping at 59 min. The 59 min value is one constant in internal/modelinfo. Refs #505 Assisted-By: Claude <[email protected]> Signed-off-by: DAVID AMID <[email protected]> test(plugin): let the picker-skill check accept strategy aliases Assisted-By: Claude <[email protected]> Signed-off-by: DAVID AMID <[email protected]> fix(keepalive): address review of the TTL-aware schedule - Plugin/binary skew: write a 1-hour config key only when it differs from the proxy default, and have start-proxy.sh drop the keys and retry when an older binary rejects them. - Credential hold: cap keepalive_max_pings_1h at 3 (236 min), clamp it in forOneHour, state the per-tier hold in the consent copy, the arm dialog and the ctl API. An override does not change a 1h schedule. - Dashboard: the credit floor and kaSaved window follow the row's cache_ttl, so a 1h rescue is credited and insights stays honest. - tier1h: write it beside turns, keep the current thread on reset, and never grow it on refused requests. - Tests for each, confirmed by mutation. Assisted-By: Claude <[email protected]> Signed-off-by: DAVID AMID <[email protected]> fix(keepalive): apply a session override's ping count to 1h threads The override bounds a 1-hour thread's ping count downward; the 1-hour timing stays the account's. The arm dialog and ctl API state the hold. Owner accepted a hold of about 2 hours for a 1-hour thread. Assisted-By: Claude <[email protected]> Signed-off-by: DAVID AMID <[email protected]> fix(plugin): scope the 1h-key recovery to this start and to one proxy version - start-proxy.sh reads only the log written by the current launch, so a rejection from an earlier run cannot trigger the recovery. - The legacy marker records the proxy version. After an update the 1-hour keys are written again. Assisted-By: Claude <[email protected]> Signed-off-by: DAVID AMID <[email protected]> merge: bring feat/keepalive-ttl-aware up to origin/main Main moved the keeper core into package keepalive and added the manual ping (#655), the manual-only hold (#666), predictive campaigns and the per-tenant builder. This merge keeps those and re-applies the TTL-aware schedule in the new package: - keepalive: ResolveTier, Policy.ForOneHour, per-thread tier1h, entry.hold(), MaxHold1h. - Manual-only hold lives 59 min on a 1h thread (ManualHoldMax1h), 300 s otherwise. A press still never extends it. - Campaigns and overrides bound a 1h thread's ping count downward. - Tests for each interaction, confirmed by mutation. Assisted-By: Claude <[email protected]> Signed-off-by: DAVID AMID <[email protected]> merge: bring feat/keepalive-ttl-aware up to origin/main (v0.5.4 bump) Assisted-By: Claude <[email protected]> docs(keepalive): state the manual-only hold per cache tier The manual-only hold lasts 300 s on a 5-minute cache and up to 59 min on a 1-hour cache. Five texts still said 5 minutes. Fix the install consent note, the install skill, the dashboard doc, the data-dependence doc and the settings.py comment, plus two Go comments. The install test now pins the per-tier wording. Assisted-By: Claude <[email protected]> Signed-off-by: DAVID AMID <[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
The Ping button now works with keep-alive off, for requests that ask for it.
x-context-guru-ping: 1is held for the button. Nothing is pinged for it.Why
On CG2 in the last 24 h, 60% of idle gaps (83 of 138) had nothing held. A press got
409 not heldin most cases. Holding a body for everyone is not acceptable (consent, and the OOM history in #639), so the plugin opts in per request.What changed
keepalive/manualhold.go: the manual-only entry, its 300 s life, andPingStates(pingable plus a reason).keepalive.Policy.ManualHoldis set by the proxy from the header, only on the path that already passed the no-audit-sink rule, the client-ended check and the kill switch./api/cachestate:pingableis true only while held. When false,ping_reasonisnot opted in,too large,expired,over budgetorunsupported.SetPingablebecomesSetPingStates.x-context-guru-*header, socopyHeadersnever forwards it upstream (tested).Data dependence
Without the header: unchanged. With it, the body and key are kept at most 300 s, for the button only. No automatic ping is ever sent for such a thread.
docs/data-dependence.mdis updated.How it was tested
-race); not held without the header; body/entry/byte caps; ceiling; thinking-enabled refused; reasons; the entry is never pinged, planned or counted as pending, at any sweep time.TestManualHoldLeavesNoBodyBehindAfterItExpiresholds 85 threads of 1.5 MiB through a host with a realdash.Recorder(the case that hid fix(dash): stop retained events from pinning whole request bodies #639). Heap is 132 MiB at the peak and 4 MiB after expiry, equal to the start.claude -p(haiku): without the headerpingable=false,ping_reason="not opted in", press gives 409 and sends nothing. WithANTHROPIC_CUSTOM_HEADERS="x-context-guru-ping: 1"in the settingsenv,pingable=true, press gives 200, one upstream request withmax_tokens1 and the same prefix,cache_read37748, rowmanual_ping=1. About 300 s laterpingable=false,ping_reason="expired", and a press gives 409 cold.go build,go vet,go test ./...clean locally.For plugins
Write
x-context-guru-ping: 1intoANTHROPIC_CUSTOM_HEADERSin the settingsenv(Claude Code sends it on every request; verified).Fixes #662
Reasons (final)
not opted in,below limits,over budget,too large,unsupported,pings used,stopped,expired,no entry. A press is allowed on an entry whose planned pings ran out while it is still held; refused after a miss or a 4xx.