Skip to content

feat(keepalive): hold a thread for the Ping button on request, with keep-alive off - #666

Merged
OsherElhadad merged 4 commits into
mainfrom
feat/manual-only-hold
Oct 22, 2026
Merged

OsherElhadad merged 4 commits into
mainfrom
feat/manual-only-hold

Conversation

@OsherElhadad

@OsherElhadad OsherElhadad commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The Ping button now works with keep-alive off, for requests that ask for it.

  • A request with the header x-context-guru-ping: 1 is held for the button. Nothing is pinged for it.
  • The proxy keeps the body and the key for at most 300 s from the request start, even for a 1-hour cache. Then it releases and zeroes them.
  • A new request, or a press that read the cache, starts the 300 s again.
  • A request without the header behaves exactly as before.

Why

On CG2 in the last 24 h, 60% of idle gaps (83 of 138) had nothing held. A press got 409 not held in 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, and PingStates (pingable plus a reason).
  • keepalive.Policy.ManualHold is 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: pingable is true only while held. When false, ping_reason is not opted in, too large, expired, over budget or unsupported.
  • SetPingable becomes SetPingStates.
  • The header is an x-context-guru-* header, so copyHeaders never 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.md is updated.

How it was tested

  • Held and released at 300 s (-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.
  • Memory: TestManualHoldLeavesNoBodyBehindAfterItExpires holds 85 threads of 1.5 MiB through a host with a real dash.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.
  • End to end on a local proxy, keep-alive off, real claude -p (haiku): without the header pingable=false, ping_reason="not opted in", press gives 409 and sends nothing. With ANTHROPIC_CUSTOM_HEADERS="x-context-guru-ping: 1" in the settings env, pingable=true, press gives 200, one upstream request with max_tokens 1 and the same prefix, cache_read 37748, row manual_ping=1. About 300 s later pingable=false, ping_reason="expired", and a press gives 409 cold.
  • Full go build, go vet, go test ./... clean locally.

For plugins

Write x-context-guru-ping: 1 into ANTHROPIC_CUSTOM_HEADERS in the settings env (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.

…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]>
Osher Elhadad 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]>
@OsherElhadad
OsherElhadad merged commit b2dd1e8 into main Oct 22, 2026
8 of 9 checks passed
@OsherElhadad
OsherElhadad deleted the feat/manual-only-hold branch October 22, 2026 13:52
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 22, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Plugin band says "keep-alive off" while keep-alive is on

1 participant