Repository navigation
feat(keepalive): ping a 5-minute cache at 240 s, not 270 s - #719
Conversation
The owner chose 240 s. A ping and its whole 60 s timeout then fit inside the 5-minute cache: 240 + 60 = 300 s. At 270 s, a ping that timed out came back about 30 s after the cache expired, and on a live proxy 92 of 95 failed pings were 60 s timeouts (#707). 240 s lowers that risk; it does not remove it. A ping that runs to its timeout still leaves no time to retry. pingTimeout is unchanged. Changes the default (config.DefaultKeepAliveIdle) and every place that mirrors it: the plugin's strategy presets, the dashboard fallbacks and advice text, the campaign keepalive-5m arm and the auto-campaign spacing, the two recommendation defaults, and the docs. The hold time of a 5-minute thread, (K+1) x idle, goes from about 14 to about 12 minutes. The 1-hour and OpenAI schedules are unchanged. Refs #716 Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]>
amiddavid
left a comment
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.310 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 3975bc3bec23 |
blocking |
Verdict: blocking
The change itself is sound. DefaultKeepAliveIdle 270 → 240, and the mirrors I could trace (plugin STRATEGIES, dash recIdleSeconds, proxy recIdleSecondsDefault, campaign campaignKeepAlive5mIdle, autoX, goldens, UI fallbacks) all moved together. The arithmetic in the new rationale checks out: pingTimeout is 60 s (keepalive/ping.go:94), so 240 + 60 = 300 s. The hold at the defaults is (K+1) × X = 3 × 240 = 12 min, and the "12 minutes" copies are right. But the sweep for stale copies missed two user-facing surfaces and several comments.
Findings
-
proxy/adaptcache.go:211-214 — the adapt report still labels every plan "270 s"
- What fails: a user opens the cache adapt report (
/apiroute that buildsoptionsrows). The rows fordefault,K1,K2,K3say "2 pings 270 s apart", "one ping 270 s after every response", and so on. The plans those rows describe now space pings at 240 s. - Proof: the plans are built with
autoXas the spacing (proxy/adaptcache.go:294-295:fixed := func(k int, s bool) ... return k, autoX, s, anddefPlanlikewise).autoX = campaignKeepAlive5mIdle(proxy/campaignauto.go:33), which this PR sets to 240 (proxy/campaign.go:58). The labels override the computed ones atproxy/adaptcache.go:363-368and land in the JSON rows aslabel/detail. The commit message says "every place that mirrors it" was changed; this one was not. - Fix: change the four "270 s" strings to 240 s, or derive the number from
autoXso the copy cannot drift again.
- What fails: a user opens the cache adapt report (
-
docs/how-to/cache-keepalive.md:226 — the controls table still promises a 14-minute hold
- What fails: the "Hard deadline" row says "released at
(K+1) × X≈ 14 min regardless of traffic". At the new defaults (K=2, X=240) the hold is 720 s ≈ 12 min. This is the credential-retention promise, and the same PR changed the two other copies of it in this same file (lines 83 and 217). - Proof:
(K+1) × X = 3 × 240 = 720 s = 12 min(keepalive/keeper.go:196-197computes exactly this). The file now contradicts itself: 12 min at lines 83/217, 14 min at line 226. - Fix: change line 226 to "≈ 12 min".
- What fails: the "Hard deadline" row says "released at
Non-blocking
- Stale comments that still name the shipped interval as 270 s:
proxy/campaignauto.go:21and:92,proxy/predictive.go:443,predictive/autotune.go:18,predictive/README.md:170and:186,kvcache/strategy.go:506("the shipped config default is now 270 s / 80k floor"). proxy/keepalivectl_test.go:126: the comment says 3 × 280 s = 14 minutes "is what the Settings copy promises at the shipped defaults". The Settings copy now promises 12 minutes at the shipped defaults. The test itself arms 280 explicitly, so its assertion is still correct; only the justification is stale.scripts/analysis/turn_gate.py:59:DEFAULT_IDLE_SEC = 270.0. The replay still models the old interval by default. Anyone measuring #716 without--idle-secmeasures the 270 s policy.docs/proposals/adapt-cache.md:13,37: dated proposal, still says 270 s. Fine to leave as history.- Observation, no change asked:
strategy syncre-renders an armed strategy file fromSTRATEGIESon every proxy start (context-guru-plugin/scripts/settings.py:3937-3951). So an install already armed at 270 s moves to 240 s at its next proxy start. TheSTRATEGIEScomment's "cannot silently re-tune an already-armed install" promise covers onlyconfig.godefaults, notSTRATEGIESchanges. If re-tuning armed installs is not wanted, that is a separate decision; if it is wanted, nothing to do.
What I checked
- The full diff
28b1a493..HEAD(one commit) and the code around each hunk. - Every reachable copy of the old numbers: repo-wide grep for
270,280,14 min,810. Test files that use 270 as an arbitrary configured value (dash/cachestate_test.go,keepalive/manualhold_test.go,proxy/keepaliveplan_test.go,dash/demodb_test.go) are self-consistent and need no change. - The label flow in
proxy/adaptcache.gofrom plan construction (autoX) to the report rows. - The plugin path:
STRATEGIESvalues, the marker logic, andstrategy syncre-render semantics incontext-guru-plugin/scripts/settings.py;plugin_test.gonow expects 240 and matchesSTRATEGIES. - The arithmetic behind the new rationale:
pingTimeout = 60 * time.Second(keepalive/ping.go:94); hold =(K+1) × Idle(keepalive/keeper.go:196); dash coverage math derives fromrecIdleSecondsand so moved with it. - Goldens:
dash/testdata/golden/ka_recommend.jsonupdated; the other goldens carry tenant-configured 280 s values, not the shipped default. - I did not run Go builds or tests (live tests not approved; Go is not on this machine).
amiddavid
left a comment
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.310 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 3975bc3bec23 |
blocking |
Verdict: blocking
Findings
-
proxy/adaptcache.go:211 — the adapt report still labels its arms "270 s apart", but they now run at 240 s
- What fails: a manager reads
GET /api/adapt/cacheand sees "Default keep-alive: 2 pings 270 s apart …", "one ping 270 s after every response", etc. This PR moves the arms to 240 s, so every spacing in those four labels is wrong. Applying the "default" option also installs the 240 s policy, which the label then misdescribes. - Proof: the arms are built at
autoX—proxy/adaptcache.go:294-295(fixed := … return k, autoX, s,defPlan := … autoX);proxy/campaignauto.go:33setsautoX = campaignKeepAlive5mIdle;proxy/campaign.go:58setscampaignKeepAlive5mIdle = 240. The labels atproxy/adaptcache.go:211-214still say 270 s and are emitted verbatim into the report rows atproxy/adaptcache.go:363. No test pins this text, so nothing catches it. - Fix: change the four
adaptLabelsdetail strings from "270 s" to "240 s".
- What fails: a manager reads
-
docs/how-to/cache-keepalive.md:226 — the security-controls table still promises a hard deadline of "≈ 14 min"
- What fails: at the new defaults the hold is (K+1) × X = 3 × 240 s = 12 min. The controls table that governs credential retention states 14 min. A reader audits the hold against a number that is 2 minutes too high.
- Proof:
config/config.go:197(DefaultKeepAliveIdle = 240) andDefaultKeepAliveMaxPings = 2give 720 s. The PR updated every other "14 min" copy — same file line 217,docs/hosted.md:55,dash/ui/app.js:6467,keepalive/keeper.go:194,keepalive/types.go:213— but missed line 226. - Fix: change "≈ 14 min" to "≈ 12 min" in that table row.
Non-blocking
- Comments that still describe the shipped default as 270 s:
proxy/campaignauto.go:21and:92,proxy/predictive.go:443,predictive/autotune.go:18,predictive/README.md:170and:186,kvcache/strategy.go:506,docs/proposals/adapt-cache.md:13. The PR updated the same kind of comment in files it touched, so these read as misses, not choices. proxy/keepalivectl_test.go:126— the comment says the 14-minute hold "is what the Settings copy promises at the shipped defaults". The Settings copy now promises 12 minutes.proxy/adaptcache_test.go:359— comment says "first ping (at ~270 s)"; the test usesautoX, so the ping is now at ~240 s.proxy/keepalive_ttl_test.go:34— comment says "no ping at 270 s"; the probe sweep at 270 s still works, but the number the reader is told to expect is now 240 s.scripts/analysis/turn_gate.py:59—DEFAULT_IDLE_SEC = 270.0mirrors the shipped default it replays; it is now 30 s behind it.dash/keepalive.go:1058—keepAliveSoon = 330 sis documented as "one idle interval plus the margin a ping needs to land" (270 + 60 when written). At X = 240 that formula gives 300 s. Behavior does not change — both 330 and 300 exceed the 300 s maximum remaining life of a 5-minute entry, so every 5-minute row counts as "soon" either way, and 1-hour rows are unaffected. Only the comment's arithmetic is stale.
What I checked
- The full diff, 22 files, every changed line, plus the code around each change.
- Every copy of the default literal:
config.go:197,dash/keepalive.go:1570,proxy/keepalivectl.go:159,proxy/campaign.go:58,settings.py(3 strategies),dash/ui/app.js(7 sites), the two goldens, and the four updated tests. All now say 240. - The hold arithmetic: (K+1) × X = 3 × 240 s = 12 min, and every updated "12 minutes" copy matches it.
- The rationale arithmetic: 240 s +
pingTimeout60 s (keepalive/ping.go:94) = 300 s, the 5-minute lifetime. - The
ka_recommendgolden:lo_usd/hi_usdstaying identical is correct, not a missed regeneration. In the fixture, every addressable miss has a gap of 340, 380, 420 or 2400 s — all inside both coverage windows (240, 780] and (270, 840] — and every ping span fails the 80k prefix gate, so the bootstrap net is invariant to X. Onlyidle_secondscan change. - Keeper mechanics at the new X:
due/holdare constant-driven;maxSweepPingAge30 min still covers the 12-minute span; the 60–290 s override band andmaxOverrideHoldceiling are unchanged and their comments were updated. - Grep for leftover "270" and "14 min" across Go, JS, MD, PY, and the plugin tree. The remaining hits are either historical evidence citations (#435 replay numbers), deliberately-280 campaign arms and simulator defaults, or the items listed above.
- No live tests were run (not approved). No PR comments were read before posting this review.
Review round 1 of #719 found 2 stale copies of the old default: - the adapt arms' detail text said "270 s" while the arms run at autoX (240 s). The text now comes from autoX, and a test pins it. - the controls table in the keep-alive how-to said the hard deadline is about 14 min; it is about 12 min at 240 s. A repo-wide search found more text copies of the shipped spacing: the predictive autotune menu and its README, the campaign builder comments, the predictive campaign comment, the kvcache simulator note, and the adapt-cache proposal. They now say 240 s. Mentions of the earlier 270 s as history are kept. Refs #716 Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]>
|
Replies to round 1, at head Finding 1 (
Finding 2 ( A second repo-wide search for
What stays at 270, on purpose:
How it was tested (eval box):
|
amiddavid
left a comment
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.310 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 61b30d9cad93 |
approve |
Verdict: approve
Findings
None. Both round-1 findings are fixed, and the fix commit adds no new defect.
Earlier findings
- proxy/adaptcache.go:211 — adapt arms labeled "270 s" (mine, and reviewer 1's finding 1): fixed.
- The four detail strings now build the number from
autoXwithfmt.Sprintf(proxy/adaptcache.go:212-216), so the text cannot drift from the spacing the arms run at.fmtwas already imported. - New test
TestAdaptLabelsStateTheSpacingTheArmsRunAt(proxy/adaptcache_test.go:826) pins every spaced arm's text toautoX.fmtandstringsare already imported there. The author's mutation check (K2 back to a literal 270 s → test fails) matches what the test asserts.
- The four detail strings now build the number from
- docs/how-to/cache-keepalive.md:226 — "≈ 14 min" hard deadline (mine, and reviewer 1's finding 2): fixed. The row now says "≈ 12 min", which matches (K+1) × X = 3 × 240 s.
Reviewer 1's non-blocking items
- The stale comments (
campaignauto.go,predictive.go,autotune.go,predictive/README.md,kvcache/strategy.go,docs/proposals/adapt-cache.md): fixed in61b30d9. I read each hunk; the new text is accurate. Theadaptreplaydoc claim "j x 240 s (autoX)" matches the call sites (proxy/campaignauto.go:153,proxy/adaptcache.go:294-295). scripts/analysis/turn_gate.pystaying at 270 s: the author's reply excludes analysis scripts on purpose. Accepted — the flag--idle-secexists, and the script is offline tooling. See Non-blocking.- The
strategy syncobservation (armed installs re-tune at next proxy start): reviewer 1 asked for no change. The author did not answer it. It is a product decision, not a defect in this PR.
Non-blocking
proxy/keepalivectl_test.go:126— the comment still says the 14-minute hold "is what the Settings copy promises at the shipped defaults". The Settings copy now promises 12 minutes. The test's assertion (14 min for an explicit 280 s override) stays correct.proxy/adaptcache_test.go:359— comment still says "first ping (at ~270 s)"; the test usesautoX, so it is ~240 s.proxy/keepalive_ttl_test.go:34— comment still says "no ping at 270 s"; the probe sweep works at any time, and the shipped first ping is now 240 s.scripts/analysis/turn_gate.py:59—DEFAULT_IDLE_SEC = 270.0. Whoever measures #716 must pass--idle-sec 240, or they measure the old policy.dash/keepalive.go:1058—keepAliveSoon = 330 scomment arithmetic (270 + 60) no longer matches X = 240. No behavior change, as shown in round 1.
What I checked
- Last review: round 1, 3975bc3, 2026-10-25T19:57:32Z.
- New commits read: 1 —
61b30d9"fix(keepalive): name the 240 s spacing everywhere the default is stated". - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three saved files).
- New items since my last review: the commit
61b30d9(full diff read, every hunk), and the author's reply at 2026-10-25T20:10:23Z (each claim checked against the code). - The fix commit hunk by hunk: the
fmt.Sprintflabels and their imports, the new pinning test, the six comment/doc updates, and thecampaign.goevidence rewording ("measured at 270 s, now run at 240 s" — accurate). - That the new
fmt.Sprintflabel text compiles and renders "240 s":autoXis the untyped constant 240,%dapplies,fmtwas already imported in both files. - Leftover greps for "270" and "14 min" in Go, JS, MD and PY after the fix commit: the remaining hits are historical citations (#435), deliberate-280 campaign arms and simulator values, unrelated numbers, and the non-blocking items above.
- The author's eval-box test table is their run; I did not run Go tests (live tests not approved).
amiddavid
left a comment
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.310 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 61b30d9cad93 |
approve |
Verdict: approve
Both round-1 findings are fixed, and the fix is the better of the two shapes I proposed: the label text now derives from autoX, so it cannot drift again. No new defect in the fix commit.
Earlier findings
- Mine, finding 1 (
proxy/adaptcache.go, adapt labels said "270 s"): fixed. The four detail strings now build the number withfmt.Sprintf(..., autoX)(proxy/adaptcache.go:211-217).autoXis the spacing the arms run at, so text and behavior share one constant. The new testTestAdaptLabelsStateTheSpacingTheArmsRunAt(proxy/adaptcache_test.go:826-831) pins every spaced arm to it. I checked the test myself:fmtandstringsare already imported in both files,wantresolves to "240 s", and all four arms contain it. The author also reports a mutation test (K2 back to a literal "270 s" fails) and a passing-racerun of./proxy/...,./predictive/...,./kvcache/...on the eval box. - Mine, finding 2 (
docs/how-to/cache-keepalive.md:226, "≈ 14 min"): fixed. The row now says "≈ 12 min", which matches (K+1) × X = 3 × 240 s. The file no longer contradicts itself. - Reviewer 2's findings 1 and 2: same defects as mine, both fixed as above. I checked each myself before agreeing.
- My non-blocking stale comments (
campaignauto.go:21,92,predictive.go:443,autotune.go:18,predictive/README.md:170,186,kvcache/strategy.go:506,adapt-cache.md): fixed in61b30d9. The remaining "270 s" strings in shipped text are history notes (config/config.go:94-97,docs/how-to/cache-keepalive.md:93-95,proxy/campaign.go:50"measured at 270 s, now run at 240 s"), which the author keeps on purpose. I agree: they say when each number applied.
Non-blocking
dash/keepalive.go:1054-1058:keepAliveSoon = 330 sis documented as "one idle interval plus the margin a ping needs to land". That derivation read 270 + 60 when written; at X = 240 it gives 300, not 330. Behavior is unchanged (the constant is untouched, and every 5-minute row is inside both 330 s and 300 s of lapsing), so this is comment drift only. The author's second search looked for the text "270" and "14 min", and this comment names neither, which is why it was missed. Reviewer 2 raised it in round 1; I note one correction to that note: the 330 vs 300 threshold does matter for a 1-hour row with 300-330 s of life left, so if anyone ever "fixes" the constant to match the comment, that band changes. Leave the constant, reword the derivation.- Still at 270, scoped out by the author's reply (tests and analysis scripts):
proxy/keepalivectl_test.go:126(says 3 × 280 = 14 min "is what the Settings copy promises at the shipped defaults" — the Settings copy now promises 12 min; the test's own arithmetic is right because it arms 280 explicitly),proxy/adaptcache_test.go:359("at ~270 s" beside code that usesautoX),scripts/analysis/turn_gate.py:59(DEFAULT_IDLE_SEC = 270.0). Comment-only; accept the scope. - The round-1 observation about
strategy syncre-tuning armed installs to 240 at the next proxy start stands as an observation. No change was asked and none is needed.
What I checked
- Last review: round 1, 3975bc3, 2026-10-25T19:54:25Z (read from the PR reviews API, not memory).
- New commits read: 1 —
61b30d9"fix(keepalive): name the 240 s spacing everywhere the default is stated" (10 files). Full diff read, plus the code around each hunk. - Read in full: 2 reviews, 1 comment, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt— the inline file is empty). - New items since my last review: reviewer 2's round-1 review (19:57:32Z — same two findings as mine, plus extra non-blocking notes, all checked above), the author's reply (20:10:23Z — checked each claim against the code), and the fix commit.
- The fix commit itself:
fmt/stringsimports present in both changed files; thefmt.Sprintflabels reference theautoXconstant, so no init-order issue; the new test's assertion matches all four label strings as built. - A fresh repo-wide grep for "270 s" and "14 min" outside tests, results docs, analysis scripts and test data: only deliberate history notes remain (listed under Earlier findings, item 4).
keepAliveSoonusage (dash/keepalive.go:1147,RemainingSeconds <= SoonSeconds) to confirm the constant's behavior is untouched by this PR.- I did not run Go builds or tests (live tests not approved; Go is not on this machine). The author's eval-box run is quoted in the PR comment.
Summary
The keep-alive now pings a 5-minute cache at 240 s of idle, not 270 s. This is the owner's decision ("we decided to both measure and do 240"). A ping and its whole 60 s timeout now fit inside the cache: 240 + 60 = 300 s. This lowers the risk of a timed-out ping losing the cache. It does not remove it (see Limit). #716 measures the effect after #712 ships.
What we found
What changed
The default,
config.DefaultKeepAliveIdle, goes from 270 to 240. The places that mirror it change with it:config/config.gocontext-guru-plugin/scripts/settings.pyauto,1-ping,2-ping), their descriptions, and the header tablecontext-guru-plugin/skills/cache-strategy-picker/SKILL.mdautorowdash/ui/app.jsdash/keepalive.go,proxy/keepalivectl.goproxy/campaign.go,proxy/campaignauto.gokeepalive-5marm and the auto-campaign spacing, which mirror the defaultinternal/modelinfo/cachefrac.gocache-keepalive.md,kv-cache-keepalive-budget.md,test-subscription-sandbox.md,hosted.mdcache-keepalive.mdHold time. The credential hold of a 5-minute thread is (K+1) × idle. It goes from about 14 to about 12 minutes. I updated every place that states it.
Not changed:
pingTimeout(60 s).onceand stop-reason-gated arms. They stay at 280 s on their own evidence.Installed users.
strategy syncre-renders the strategy file from its name on every proxy start. So a user onauto,1-pingor2-pingmoves to 240 s at their next proxy start, with no action needed. A hand-written config keeps its own value.Limit: a timed-out ping still cannot be retried
At 240 s, a ping that runs to its 60 s timeout comes back at 300 s, exactly when the cache expires. A retry would then only re-write. So 240 s does not let #710 retry a timeout. It moves the timeout to the edge of the cache life instead of past it. To retry a timeout, the ping must time out sooner or start earlier.
pingTimeoutis outside the owner's decision, so this PR does not change it.How it was tested
All runs are on the eval box.
configdefault test (Resolved()expects 240, 2, 80000, 0.50)keepalive_idle_seconds: 240) and the plugin strategy testsdashrecommendation golden file (ka_recommend.json)proxycampaign tests (keepalive-5mexpects 240)go test -race ./config/... ./keepalive/...go test -race ./proxy/...go test ./context-guru-plugin/...TestInstallRefusesAnUnverifiedDownload,TestInstallReportsPATHFromTheSourceFallbackToo)go vet,gofmt -lData dependence
No change. The ping time is a number. The keeper stores nothing new.
Refs #716
Refs #707
🤖 Generated with Claude Code