Repository navigation
Conversation
…at the keeper holds Review fixes for rossoctl#2059: - Pass the 1-hour cache-write count to the keeper. Without it every thread billed at the 1-hour tier ran on the 5-minute schedule: two pings that bought nothing, and no 59-minute ping. - Do not track a request that inference-router translated or gave upstream headers to. Its body, path and headers in the pipeline are not what went upstream, so a ping could not replay it. - Keep keep_alive on by default on every install, and add an upgrade note for clusters that already run context-guru: they start pinging on their callers' credentials with no config change. - Close the window where a request that finishes during Shutdown could hold a credential after the keeper's sweep. - Cap the accountant snapshot file at 20 MiB, not the raw state, which the file carries as base64. - Fetch the LiteLLM map on the plugin's model transport, so on a local install it ignores HTTPS_PROXY. - Show a subscription ping's API equivalent in agentop when its units round to zero. - Docs: a keeper entry holds the masked credential and the last request body; its hold is 12 minutes on a 5-minute thread and 118 minutes (at most 236) on a 1-hour thread. The snapshot leaves out the oldest threads past 20 MiB. Fold the duplicated session-api.md paragraph. - Pin context-guru to the v0.7.5 release, not v0.7.5-beta.2. - Drop the development-log references from comments, and fix the accountant version in snapshot_trim.go. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: DAVID BOAZ <DAVIDBO@il.ibm.com>
Brings the named cache-strategy table (config.LookupStrategy / applyStrategy) and the per-wait ping plan (keepalive.Policy.WaitPlan), both of which the next commit wires up. No behavior change by itself: nothing here reads a cache: block yet. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Signed-off-by: DAVID BOAZ <DAVIDBO@il.ibm.com>
…ollow the wait plan
Two gaps against context-guru's own docs/how-to/cache-strategies.md:
1. keep_alive: had its own static policy (enabled/idle_seconds/max_pings/
max_usd_per_ping/min_prefix_tokens) and never touched context-guru's
named strategy table, so none of auto, none, 1-ping, 2-ping, 1-hour-head,
1-hour-on-wait, 1-hour-always or 30-min-ping could be picked.
2. The per-wait ping plan (keepalive.Policy.WaitPlan) was never turned on,
and recordFor filled none of the inputs it needs, so every wait got the
same flat ping count instead of following what the thread actually waits
for (its own tool, a person, background work, a teammate, done).
keepAliveConfig.policy now takes the engine's own resolved cache: block
(cgconfig.CacheConfig, already parsed by cgconfig.LoadBytes from engine:
in Configure -- context-guru's own config.applyStrategy resolves the named
strategy into it, so nothing here reimplements that table). Set
engine: {cache: {strategy: auto}} (or any other name) to pick one;
keep_alive: {enabled: false} still always wins as a kill switch. With no
cache.strategy set, policy() returns exactly what it always did -- the
per-wait plan's rossoctl#858 "no ping before the first tool call" rule changes
real scheduling, not just a tunable, so it only turns on through an
explicit strategy.
recordFor now carries Usage.StopReason (inf.FinishReason) and
ToolUseNames (inf.ToolCalls) so the keeper's WaitingFor can classify the
wait. ToolUseIncomplete is always false: that flag covers a host that
assembles ToolCalls from a spliced streaming-sniff window, which does not
describe this parser (inferenceparser fully assembles ToolCalls before
OnFinish runs). OpenTasks (background-task/teammate markers) is left
unset: that scanner lives in context-guru's internal/waitcause, which the
core does not export -- a background/teammate wait here falls back to
WaitingFor's unknown cause rather than a cortex-side approximation of a
scanner we cannot see.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: DAVID BOAZ <DAVIDBO@il.ibm.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
clawgenti
left a comment
There was a problem hiding this comment.
Summary
The strategy picker is wired cleanly for the ping-only strategies. auto, none, 1-ping, 2-ping and 30-min-ping resolve through context-guru's own applyStrategy, the enabled: false kill switch holds, and the no-strategy path keeps its old behaviour. recordFor now passes the right inputs to WaitPlan. There is one blocker. The strategies that rewrite the request (1-hour-head, 1-hour-always, and the costly-route fallback of 1-hour-on-wait) are not delivered, because the host never passes the matching apply.Opts hooks. They are accepted without a warning and behave like none or auto. I checked this with a probe test on head. Details are inline.
Author: boazdavid (CONTRIBUTOR association, admin permission on the repo, so maintainer)
Areas reviewed: Go (core/plugins/contextguru, core/accounting, cmd/agentop/money), go.mod/go.sum bump, Docs, CLAUDE.md
Agent/IDE config (.claude/.vscode): none (only the top-level CLAUDE.md doc changed)
Commits: 3 commits, all signed off: yes
CI status: only the metadata checks ran (DCO, title, label, project). No Go job runs against the cg/06-keepalive base. I ran the checks locally on 1bb9ee4. go build ./... in core and go vet both pass. go test -race ./plugins/contextguru/... ./accounting/... and go test ./cmd/agentop/money/... all pass.
| MaxUSDPerPing: resolved.KeepAliveMaxUSDPerPing, | ||
| MaxBodyBytes: resolved.KeepAliveMaxBodyBytes, | ||
| MinPrefixTokens: resolved.KeepAliveMinPrefixTokens, | ||
| HeadTTL1h: resolved.HeadTTL1h, |
There was a problem hiding this comment.
must-fix: HeadTTL1h, HeadTTLMinBytes, OneHourAlways and OneHourRebuildTokens are copied into the keeper Policy, but nothing in this host acts on them. In context-guru v0.7.6, request-side relabelling is done by apply, and only when the host sets apply.Opts.HeadTTL1h/HeadTTLMinBytes (apply.go upgradeHeadTTL) and apply.Opts.OneHourFirst (the hook that calls Keeper.OneHourFirst; the context-guru proxy wires it in proxy/keepalive.go oneHourFirstFor). OnRequest (plugin.go:496) sets neither. So:
1-hour-headresolves toKeepAlive: false, so no keeper is built and the head is never relabelled. It behaves likenone, and it also turns off the default keep-alive.1-hour-always: no request is ever relabelled to 1h, andoneHourFirst[key]is never set, so the keeper pings exactly likeauto.1-hour-on-waiton a costly route:oneHourMarkCostlyputs the probing main thread in the 1-hour-first mode, soRecordsetspol.KeepAlive = falsefor it. But its later requests are never relabelled to 1h, so that thread loses keep-alive without getting the 1-hour write that was meant to replace it. The D fallback (first cold rebuild ≥150k at 1h) never fires either.
I checked this with a probe on head. I configured engine.cache.strategy to each of these, then ran OnRequest on a 260 KB Anthropic body with cache_control on tools, system and the message. The forwarded body never contains "ttl":"1h". For 1-hour-head the keeper is nil. For 1-hour-always the keeper is on with OneHourAlways=true and nothing is relabelled.
The PR description and the policy() doc list all eight strategies as pickable, so this falls under what the PR claims to deliver. There are two ways to fix it:
- Wire
HeadTTL1h/HeadTTLMinBytesfromcfg.Cache.Resolved()intoapply.Opts. Add anOneHourFirstclosure that callsp.keeper.OneHourFirst(...)with the same endpoint, route and thread keysrecordForuses (watch the observe-mode path). Add a test that asserts the forwarded body carries 1h markers for1-hour-head(body over the size gate) and1-hour-always. - Or refuse
1-hour-head,1-hour-alwaysand1-hour-on-waitinConfigurewith a clear error until they are wired, and say so in the description and docs.
| // docs/how-to/cache-strategies.md) decides every field, INCLUDING whether keep-alive runs at all | ||
| // ("none" sets no cache key, so cache.KeepAlive is false). The one override kept across both | ||
| // paths is c.Enabled == false: an explicit `keep_alive: {enabled: false}` always wins, as a kill | ||
| // switch independent of the chosen strategy. Mixing the two tuning surfaces (a strategy AND |
There was a problem hiding this comment.
suggestion: "Mixing the two tuning surfaces is not supported", but nothing enforces or reports it. engine: {cache: {strategy: auto}} together with keep_alive: {max_pings: 5} drops max_pings without a word. A WARN in Configure would save an operator from a confusing debug session, for example: keep_alive.idle_seconds/max_pings/max_usd_per_ping/min_prefix_tokens are ignored while engine.cache.strategy is set. A config error would also work. Use cache: keys in the engine block instead, since applyStrategy already lets a key the file sets win over the strategy row.
|
|
||
| **Credential and content retention:** for each tracked thread, Cortex keeps in memory, masked, the caller's credential and the thread's last request body. The body is the whole forwarded conversation, which each ping re-sends. Both are released on that thread's next request, on plugin `Shutdown` or a config reload, or at the thread's hold deadline, whichever comes first. The deadline depends on the cache tier the provider billed: | ||
| - A thread with a 5-minute cache: `(max_pings + 1) × idle_seconds`, 12 minutes at the defaults above. | ||
| - A thread whose request asks `ttl: "1h"` on every cache breakpoint, and whose cache the provider billed at the 1-hour tier: the engine's 1-hour schedule, one ping at 59 minutes, so 118 minutes. It is never more than 236 minutes (context-guru's `keepalive.MaxHold1h`). The `keep_alive` block has no setting for this schedule. |
There was a problem hiding this comment.
suggestion: The new user-facing knob, engine: {cache: {strategy: <name>}}, is not documented anywhere in this file. Please cover the names, the keep_alive.enabled: false kill switch winning, the fact that the other keep_alive knobs are ignored under a strategy, and the default with no strategy (no WaitPlan). Two statements are also now out of date. "The keep_alive block has no setting for this schedule" still holds for that block, but a strategy now does set it: 2-ping sets keepalive_max_pings_1h: 2, which makes the 1-hour hold 177 minutes, not 118. The same 118-minute figure is in CLAUDE.md, docs/laptop-service.md and docs/session-api.md. Saying "118 minutes with one 1-hour ping (auto), up to 236" would keep all four accurate.
Depends on #2059 (
cg/06-keepalive)This branches off
cg/06-keepalive, notmain: it extends that PR's keep-alive plugin, so it can't build or make sense without it. Rebase/merge order: #2059 first.What
Two gaps against context-guru's own
docs/how-to/cache-strategies.md:keep_alive:had its own static policy (enabled/idle_seconds/max_pings/max_usd_per_ping/min_prefix_tokens) and never touched context-guru's named strategy table, so none ofauto,none,1-ping,2-ping,1-hour-head,1-hour-on-wait,1-hour-alwaysor30-min-pingcould be picked.keepalive.Policy.WaitPlan) was never turned on, andrecordForfilled none of the inputs it needs, so every wait got the same flat ping count instead of following what the thread actually waits for (its own tool, a person, background work, a teammate, done).How
context-guruto v0.7.6, which carries the strategy table andWaitPlan.keepAliveConfig.policynow also takes the engine's own resolvedcache:block (cgconfig.CacheConfig, already parsed bycgconfig.LoadBytesfromengine:inConfigure— context-guru's ownconfig.applyStrategyresolves the named strategy into it, so nothing here reimplements that table).engine: {cache: {strategy: auto}}(or any other name) to pick a strategy.keep_alive: {enabled: false}still always wins as a kill switch, independent of the strategy.cache.strategyset,policy()returns exactly what it always did. The per-wait plan's docs: 📝 Plugin doc updates #858 "no ping before the first tool call" rule changes real scheduling, not just a tunable — it only turns on through an explicit strategy, never silently.recordFornow carriesUsage.StopReason(inf.FinishReason) andToolUseNames(inf.ToolCalls) so the keeper'sWaitingForcan classify the wait.Known gap
OpenTasks(background-task/teammate markers in the transcript) is left unset. That scanner lives in context-guru'sinternal/waitcause, which the core does not export. A background/teammate wait here falls back toWaitingFor'sunknowncause rather than a cortex-side approximation of a scanner we can't see. Left as a follow-up rather than reimplementing it locally.Testing
go test ./plugins/contextguru/...— all green, including new tests for the strategy branch (auto,none, theenabled: falsekill switch) and forrecordFor's new fields.go test ./...incore/— clean except two pre-existing, unrelated DST fixture failures (cost/ledger,cost/usage, both tied toAmerica/Havana's tzdata, reproducible oncg/06-keepalivebefore this change too).go build ./...clean incore/,cmd/cortex/,cmd/cortex-envoy/.🤖 Generated with Claude Code