Repository navigation
fix(keepalive): read an OpenAI cache as 30 minutes in the substitute's phase check - #717
Conversation
…s phase check cachePhaseAt treated every cache off the one-hour tier as a 5-minute cache. An OpenAI Responses cache lives 30 minutes and is pinged at 28, so the check read it as Cold, and a pre_expiry summary never took an OpenAI ping. The lifetime rule now lives in one function, cacheLifetime(provider, ttl1h), which both kaEntry.cacheTTL (the failed-ping retry guard) and the substitute's phase check call. cachePhaseAt takes the lifetime instead of a one-hour flag. Fixes #715 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 | e0d957f65676 |
approve |
Verdict: approve
Findings
None. I could not prove a defect in the change.
Non-blocking
keepalive/substitute.go:27-31— the old comment still saysCtx.CachePhase'sCacheTTLMinimumcase "never arises here". After this change it does: OpenAI's 30 minutes is a minimum, andcachePhaseAttreats it as an exact life. That is safe here — PreExpiry at 2 minutes left is inside the guarantee, and Cold past 30 minutes only refuses a substitute, so the ordinary ping still goes out. But the comment now misdescribes the function. Fix the comment in a later pass.- Default settings still refuse the substitute on OpenAI. The keeper pings at 28 minutes (
OpenAIDefaultKeepAliveIdle), so 2 minutes remain. The default pre-expiry window is 1 minute (components.DefaultPreExpiry), so the phase reads Warm, not PreExpiry. Apre_expirycandidate substitutes only whenpre_expiry_secondsis about 120 or more, as in the new test (180). The fix is still correct — the window is the tenant's knob — but a reader of the PR may expect default behavior to change, and it does not.
What I checked
- The full diff:
keepalive/keeper.go,keepalive/substitute.go,keepalive/openaiphase_test.go. cacheLifetimekeepscacheTTLbyte-for-byte equivalent for every input: OpenAI 30 min, 1 h tier, 5 min default.giveBackFailedPing(the only othercacheTTLcaller) is unchanged in behavior.cachePhaseAthas one caller,fireSummarySubstitute. No test or code still passes the oldttl1h boolshape.- The old OpenAI behavior:
Recordforcesttl1h = falsefor OpenAI (keeper.go:790), so the oldcachePhaseAtused 5 minutes. At the 28-minute ping it returned Cold. The PR's claim of the bug is real. - The new 30-minute reading cannot mis-spend: PreExpiry fires only inside the guaranteed window, and Cold only falls back to the ordinary ping. Fail open holds.
- The phase-check input
e.ttl1h || e.pol.HeadTTL1his unchanged from before, so the non-OpenAI paths behave exactly as they did. - The end-to-end test, by trace: two
Recordcalls (turn 0 refused, turn 1 held),Idle28 min, sweep at 28 min 1 s,prevStartedAt12:00:00, remaining 1 min 59 s, window 3 min, so PreExpiry. Eligibility holds:/v1/responsesroute,azure/gpt-5.6-lunapassesOpenAI30MinuteCache. Prices default to unset, so the cost gate passes. No checkpoint is seeded, soIsRefreshis false. The substitute commits,summarySubstitutedis 1, andfs.n()is 0. The registry key matches:thread.Primaryis"", the same as the test's empty thread. - The unit test: 28 of 30 minutes with a 3-minute window gives PreExpiry. The arithmetic is right.
- Test isolation:
kaCandidateWithCacheStateclears the global registry entry viat.Cleanup, the same as the existing substitute tests. - Reachability in production:
proxy/keepalive.go:440-445sets OpenAIIdleto 28 minutes, andregisterKeepAliveCandidateis not provider-gated, so an OpenAI thread with apre_expirycandidate does reach this check. - The PR states its data dependence (no change). That matches the diff: no storage or metadata change.
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 | e0d957f65676 |
blocking |
Verdict: blocking
Findings
- keepalive/substitute.go:94 — with the default pre-expiry window, the fixed phase check still refuses every OpenAI ping
- What fails: an OpenAI thread,
cache_aware_summarizerwithcache_state: pre_expiryand nopre_expiry_seconds. The keeper pings at 28 minutes of idle. The cache then has about 2 minutes left. The default window is 60 seconds. The phase reads Warm, not PreExpiry, so the substitute is refused and the ordinary ping goes out. Issue #715's symptom ("a pre_expiry substitute never runs on an OpenAI thread") stays for the default configuration. - Proof:
OpenAIDefaultKeepAliveIdleis 28 minutes (internal/modelinfo/cachefrac.go:12), and the proxy sets that as the OpenAI idle (proxy/keepalive.go:443). The sweep ticks every 2 seconds (keepalive/types.go:236), so the ping runs at 28–28.03 minutes of idle.cachePhaseAtthen computes remaining = 30 min − ~28 min ≈ 118–120 s.preExpiryFor(0)returnsDefaultPreExpiry, which is 60 s (components/trigger.go:107; the field default atcomponents/trigger.go:341is 60). 120 s > 60 s, so the phase is Warm. Production registration carries the operator'sPreExpirySecondsverbatim, 0 when unset (components/offload/cache_aware_keepalive.go:171). The new end-to-end test passes only because it setspre_expiry_secondsto 180. The fail-open path is intact — the ordinary ping still keeps the cache — so this is a lost substitute, not a lost ping. - Fix: either state the requirement in the PR and the component docs (on OpenAI,
pre_expiry_secondsmust be at least ~120 for the substitute to ever take a ping), or widen the effective window on OpenAI (for example, clamp it to the keeper's own 2-minute slack plus a margin). Add a test for the default-window case, whatever the answer is.
- What fails: an OpenAI thread,
Non-blocking
keepalive/substitute.go:99— the comment namescachePhaseLocked. No such function exists in the repo. It also says the check uses "the SAME phase arithmetic Ctx.CachePhase itself uses". On OpenAI the two now differ on purpose:Ctx.CachePhasetreats the 30 minutes as a minimum and never returns PreExpiry (components/cachephase.go:119-124). Reword the comment so the next reader does not hunt for a function that is not there.keepalive/substitute.go:38—cachePhaseAtreturns Cold past 30 minutes on OpenAI. A minimum cannot prove expiry (apply/cachelifetime.go:29-33). This is harmless here because the only caller compares against PreExpiry, so Cold and Unknown behave the same. One sentence in the comment would pin that.keepalive/openaiphase_test.go:24— the second assertion (e.cacheTTL() != cacheLifetime(...)) cannot fail today, becausecacheTTLcallscacheLifetime. It is still useful as a pin against a future re-divergence; a short comment saying so would make that intent clear.
What I checked
- The full diff (one commit) and the code around each change.
- Both callers of the new
cacheLifetime: the retry guard (keepalive/keeper.go:1450) and the phase check. They now share one rule, which is the PR's goal. - The OpenAI branch order in
cacheLifetime:ttl1his never set for OpenAI (keepalive/keeper.go:790), andpol.HeadTTL1his an Anthropic-only ask, so the provider branch winning over the tier is safe. - That a provider-wide 30-minute rule cannot hit an older OpenAI model:
eligible(keepalive/ping.go:82-90) admits OpenAI only on/v1/responseswith GPT-5.6+. - The two new tests by hand: helpers exist (
testKeeper,kaCandidateWithCacheState,fakeOf,kaHeader), the phase arithmetic lands as asserted (remaining 119 s against a 180 s window), the candidate registry is cleaned up per test, and a nilRecord.Storeis safe (apply.RecordCacheTouchreturns on nil store). - That no other test or caller uses the old
cachePhaseAtsignature, so the change breaks nothing else. - The PR body and issue #715. The PR does what the issue proposes; the finding above is the part of the symptom the proposal did not cover.
- That no other TTL derivation in
keepalive/still reads OpenAI as 5 minutes (holdForsizes manual holds only;Ctx.CachePhasehandles the OpenAI minimum by design).
…lack With the default 60 s pre-expiry window, an OpenAI ping at 28 minutes still had about 2 minutes of cache left, so the phase read Warm and a pre_expiry substitute was still refused. When pre_expiry_seconds is not set, the substitute's window is now at least the keeper's own slack (cache lifetime minus idle) plus two sweep ticks. An operator's value is kept as set. On Anthropic at the defaults the slack is 30 s, inside the 60 s default, so nothing changes there. Also rewords the phase-check comment, which named a function that does not exist, and notes that Cold past an OpenAI minimum is not proof of expiry. Fixes #715 Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]>
|
Replies to round 1, at head Reviewer 2, finding 1 (the default 60 s window still refuses every OpenAI ping): fixed in code.
Non-blocking, fixed:
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 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 | ac01f2e07729 |
approve |
Verdict: approve
Findings
None in the new commit. I could not prove a defect.
Earlier findings
- Reviewer 2, finding 1 (the default 60 s window still refuses every OpenAI ping): fixed.
substituteWindowwidens the unset window to the keeper's slack plus 2 ticks. I checked the numbers myself:tickis 2 s (keepalive/types.go:236), OpenAI slack is 30 min − 28 min = 120 s, so the window is 124 s. At the default ping the cache has 118–120 s left, so the phase reads PreExpiry. An operator's explicitpre_expiry_secondsis returned unchanged. Anthropic at the defaults keeps the 60 s window (slack 34 s). The end-to-end test now uses the default window (pre_expiry_seconds0), so it proves the fixed case. - Reviewer 2, non-blocking (the
cachePhaseLockedcomment, the Cold-past-minimum note, the tautology comment on thecacheTTLassertion): fixed. All three comments are reworded as promised. I read each new comment; each now matches the code. - My round-1 non-blocking note 2 (default settings still refuse the substitute on OpenAI): fixed by the same change.
- My round-1 non-blocking note 1 (the doc comment above
cachePhaseAtstill says theCacheTTLMinimumcase "never arises here"): not fixed. The sentence atkeepalive/substitute.go:27-31is still there and is still inaccurate — OpenAI's 30-minute minimum now flows through this function. The two new comments (incachePhaseAtand at the call site) document the same fact correctly, so a reader is no longer misled for long. Still non-blocking.
Non-blocking
keepalive/substitute.go:58-64— the comment justifies the widening with "the keeper pings exactly that far before expiry". That holds only when Idle sits just under the cache life (270/300 s, 28/30 min). A manager strategy may set Idle to 60 s on an Anthropic 5-minute cache (the band is 60–290 s,proxy/keepalive.go:432-436). The slack is then 244 s, so the window is 244 s and every ping reads PreExpiry — the substitute takes every ping, not only those near expiry. The spend stays bounded (per-ping ceiling, refresh break-even, MaxPings), and an operator who wants the old behavior setspre_expiry_secondsexplicitly. Consider capping the widening, or saying in the comment that a schedule much faster than the TTL makes the window cover most of the cache's life.- An OpenAI manual override with a shortened Idle has the same shape (
proxy/keepaliveoverride.go:209-210allows any Idle up to 28 min). At 5 min, the window becomes about 25 minutes. The config comment marks that knob "for a controlled test", so the exposure is small.
What I checked
- Last review: round 1, e0d957f, 2026-10-25T18:38:08Z.
- New commits read: 1 —
ac01f2e0"fix(keepalive): widen the default pre-expiry window to the keeper's slack". - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files).
- New items since my last review, and what I did about each:
- Reviewer 2's round-1 review (blocking, the default-window finding). Checked the fix myself, numbers above. Fixed.
- The author's reply comment. Each claim in it matches the code and the tests, including the mutation claims — with the widening removed, the OpenAI end-to-end test sees 119 s remaining against a 60 s window, so Warm, so a mismatch.
- The new commit's full diff and the code around it:
substituteWindowhas one production caller (fireSummarySubstitute);idleis read under the keeper lock;e.pol.Idleis fixed at record time for a scheduled entry. - The arithmetic of all three new tests, by hand:
- Anthropic default window: max(60 s, 300−270+4 s) = 60 s, unchanged. Correct.
- OpenAI default window: 124 s, at least the asserted 2 minutes. Correct.
- An explicit 30 s stays 30 s. Correct.
- OpenAI end to end: window 124 s, remaining 119 s at the 28 min 1 s sweep, so PreExpiry and the substitute commits. Correct.
- Anthropic end to end: window 60 s (Idle 280 s gives slack 24 s), remaining 19 s at the 281 s sweep, so PreExpiry. Correct.
- Edge cases of
substituteWindow: a negative slack (Idle above the TTL) returns the 60 s default; the 1 h tier's Idle (about 59 min) gives a 64 s window. Both harmless. - That the widening touches nothing else:
substituteWindowis used only by the phase check. The turn-path phase check (Ctx.CachePhase) and the component's own trigger window still usepreExpiryFor/DefaultPreExpiry. - That a reserved checkpoint created earlier is still safe:
tryReusegraduates it only on a cold-or-untracked turn's own phase (components/offload/cache_aware_summarizer.go:1068-1084), so the wider creation window cannot splice a reserve into a warm turn. - Fail open: a Warm or Cold reading still falls through to the ordinary ping. The new code changes only when the substitute may spend, never whether a ping goes out.
- The base..HEAD diff is exactly the two commits I reviewed across both rounds (
keeper.go,substitute.go,openaiphase_test.go). Nothing else changed.
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 | ac01f2e07729 |
blocking |
Verdict: blocking
Findings
- keepalive/substitute.go:70 — the widened default window has no upper bound, so a short ping schedule turns
pre_expiryinto "every ping"- What fails: a 5-minute thread with a keep-alive override or strategy idle of 60 s (the band allows 60–290 s,
proxy/keepaliveoverride.go:55),cache_aware_summarizerwithcache_state: pre_expiryandpre_expiry_secondsunset. The first ping fires at 60 s of idle, with 240 s of cache life left.substituteWindow(0, 300 s, 60 s)returns 300 − 60 + 4 = 244 s, so the phase reads PreExpiry and the substitute takes the ping. Before this commit the window was 60 s, the phase read Warm, and the ordinary ping went out. The candidate now spends on every ping from the first, 4 minutes before expiry. The same happens on an OpenAI thread with a shortened idle (the override clamps it only from above,proxy/keepaliveoverride.go:209), and on a thread whose 1-hourHeadTTL1hask was not granted (window ≈ 55 min). - Proof:
substituteWindowreturnsttl - idle + 2*tickwhenever that exceeds 60 s, with no cap (substitute.go:70-72).duefires a ping atidle(keepalive/keeper.go:188-190), so the remaining life at the ping isttl - idle— always inside the widened window, whatever the schedule. That defeats the contract the state documents: "only a summary reserved for a cache about to expire" (components/offload/cache_aware_summarizer.go:499), and the comment six lines below the new call still promises the window is live "not merely whenever the keeper happens to be sending a ping" (substitute.go:115-117). No matched schedule needs a window wider than about 124 s: the shipped slacks are 30 s (Anthropic 5 min), 60 s (1 h tier), 120 s (OpenAI) — the last is the design marginOpenAIMinimumCacheTTL - OpenAIDefaultKeepAliveIdle. The spend is bounded byMaxUSDPerPingand the refresh break-even, so this is a wrong-schedule spend, not an unbounded one — but it is exactly the divergence the phase check exists to catch. - Fix: cap the widened default at a value that still covers every matched schedule, for example
2*DefaultPreExpiry + 2*tick(128 s, above OpenAI's 120 s slack). Add a test: a 60 s idle on a 5-minute thread must leave the first ping refused as Warm.
- What fails: a 5-minute thread with a keep-alive override or strategy idle of 60 s (the band allows 60–290 s,
Non-blocking
- Reviewer 1, round 1, first item (agree, checked myself):
substitute.go:27-31still says theCacheTTLMinimumcase "never arises here". OpenAI's 30 minutes is a minimum andcachePhaseAtnow feeds it in directly. The author did not address this one; reviewer 1 asked for a later pass, so this only records that it is still open. substitute.go:115-117— after this commit, the comment's claim that the window is "not merely whenever the keeper happens to be sending a ping" holds only for an operator-setpre_expiry_seconds. For the default it is now false by construction (see finding 1). Whichever way the finding is resolved, this comment andsubstituteWindow's doc should tell the same story.
What I checked
- Last review: round 1, e0d957f, 2026-10-25T18:38:26Z
- New commits read: 1 (
ac01f2e0fix(keepalive): widen the default pre-expiry window to the keeper's slack) - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
- New items since my last review: the commit
ac01f2e0(full diff and surrounding code, below); the author's reply comment at 2026-10-25T18:47:26Z (each claim checked); reviewer 1's round-1 review at 18:38:08Z (older than my last review, read now in full; both non-blocking items checked). - My round-1 finding 1 (default 60 s window refuses every OpenAI ping): fixed in code.
substituteWindowwidens the default to the keeper's slack plus two ticks; the end-to-end test now usespre_expiry_seconds0, so it discriminates (the author's mutation run confirms it fails without the widening). I verified the arithmetic: the ping fires atidle(due, keeper.go:188-190), remaining is at mostttl - idle, and the window isttl - idle + 4 s, so every scheduled ping lands inside it. The fix works for every matched schedule — and only matched ones need it (finding 1 is the over-generalization). - My round-1 non-blocking items: all three fixed — the
cachePhaseLockedcomment is reworded and now states the OpenAI difference fromCtx.CachePhaseon purpose;cachePhaseAtnotes Cold past an OpenAI minimum is not proof of expiry; the test pin carries the "cannot fail today" comment. - That no existing test breaks: every existing
pre_expiryregistration passes an explicit 60 (substitute_test.go:189,232,324,358,417), whichsubstituteWindowkeeps as set, soTestKeepAliveSubstituteRespectsPreExpiryPhaseNotJustKeeperTimingstill gets its mismatch. The two new tests with 0 are the only widened ones. - The new tests by trace: OpenAI window 124 s against remaining 119 s → PreExpiry, substituted 1, ordinary pings 0. Anthropic window max(60 s, 300−280+4) = 60 s against remaining 19 s → PreExpiry.
TestTheSubstituteWindowCoversTheKeepersOwnSlack: Anthropic 270 s idle → 34 s < 60 s → unchanged; OpenAI 124 s ≥ 120 s; explicit 30 s kept. - That the manual path cannot reach
substituteWindowwith a zero idle:PingNowsends its own ordinary ping and never calls the substitutes (keepalive/manual.go:80-134), and the sweep skipsmanualOnlyentries (keeper.go:1117), whose policy carries noIdle. - The 1-hour tier at the defaults: slack 3600 − 3540 + 4 = 64 s, so the window moves from 60 s to 64 s — tick-jitter cover only, no behavior change of substance.
- The author's test table (eval box) is consistent with my traces; I could not run Go here, as before.
Review round 2 of #717: the default window grew to the keeper's whole slack with no upper bound. A short schedule (a 60 s idle on a 5-minute cache, or a 1-hour ask that was not granted) then read its first ping as PreExpiry, and a pre_expiry summary took every ping from the first. The widened default is now capped at twice the 60 s default plus two sweep ticks (124 s). That still covers OpenAI's 120 s slack. Also fixes 2 comments: Ctx.CachePhase's CacheTTLMinimum case does reach cachePhaseAt (OpenAI), and the phase-check comment now says how the default window is bounded. Fixes #715 Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]>
|
Replies to round 2, at head Reviewer 2, finding 1 (the widened default window has no upper bound): fixed.
Non-blocking, fixed:
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 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 | 3 of 3 | a0a16220488e |
approve |
Verdict: approve
Findings
None in the new commit. I could not prove a defect.
Earlier findings
- Reviewer 2, round-2 finding 1 (the widened default window has no upper bound, so a short schedule turns
pre_expiryinto "every ping"): fixed. This was my round-2 non-blocking note raised as blocking; I agree with their reading and checked the fix myself.maxSubstituteWindowis 2 × 60 s + 2 × 2 s = 124 s (the author's reply is right that reviewer 2's "128 s" was a slip; the code and tests say 124). The cap is applied to the slack before the comparison with the 60 s default. - My round-2 non-blocking notes (the 60 s strategy idle, the shortened OpenAI override, the ungranted 1-hour ask): fixed by the same cap. All three cases now get a 124 s window, so their early pings read Warm.
- My round-1 note and reviewer 2's round-2 note on the doc comment above
cachePhaseAt("CacheTTLMinimum... never arises here"): fixed. The comment now says the minimum case does reach this function, and why this function still reports PreExpiry for it. - Reviewer 2's round-2 note on the call-site comment (the window is live "not merely whenever the keeper happens to be sending a ping"): fixed. The comment now names the short idle override and states the cap, telling the same story as
substituteWindow's doc.
Non-blocking
keepalive/substitute.go:85— the cap (124 s) is exactly OpenAI's slack (120 s) plus two ticks, but it is derived fromDefaultPreExpiry, not from the OpenAI constants. IfOpenAIDefaultKeepAliveIdleis ever shortened, the cap stops covering the slack and the default OpenAI ping reads Warm again. The tests would catch it (TestAPreExpirySubstituteTakesAnOpenAIPingwould see a phase mismatch), so this is only a maintenance coupling. Deriving the cap asmodelinfo.OpenAIMinimumCacheTTL - modelinfo.OpenAIDefaultKeepAliveIdle + 2*tickwould make it track on its own.
What I checked
- Last review: round 2, ac01f2e, 2026-10-25T18:51:42Z.
- New commits read: 1 —
a0a16220"fix(keepalive): cap the widened pre-expiry window". - Read in full: 4 reviews, 2 comments, 0 inline comments (from the three files).
- New items since my last review, and what I did about each:
- Reviewer 2's round-2 review (18:54:51Z, blocking, the unbounded widening). Checked the fix and the arithmetic myself; it is the same defect I had rated non-blocking, and their blocking call was the safer one. Fixed.
- The author's reply (18:59:54Z). Each claim matches the code; the 124 s correction of reviewer 2's 128 s is right (a tick is 2 s).
- The new commit's full diff and the code around it. The cap sits inside
substituteWindow's slack branch; an operator's explicitpre_expiry_secondsstill bypasses it, as before. - The cap's arithmetic, by hand, for every schedule that reaches it:
- OpenAI default: min(120 s + 4 s, 124 s) = 124 s; the ping has 118–120 s left, so PreExpiry. The fix for #715's default case still holds.
- Anthropic default (270 s idle): slack 34 s, below the 60 s default, so the window stays 60 s.
- 1 h tier (about 59 min idle): slack 64 s, window 64 s, the ping's 60 s remaining still reads PreExpiry.
- Short schedule (60 s idle on a 5-minute cache): window 124 s, the first ping's 240 s remaining reads Warm — the pre-round-2 behavior restored, which is what
pre_expirymeans. - Ungranted 1-hour ask (1 h ttl, 270 s idle): window 124 s, about 55 min remaining, Warm. Same as before round 2.
- The new test
TestAShortIdleLeavesTheFirstPingWarm, by trace: all four assertions hold with the numbers above, and it discriminates — the author's mutation output (4m4s, want at most 2m4s) matches the uncapped slack of 244 s. - That no other behavior moved:
substituteWindowstill has one production caller; the turn-path phase check and the component's trigger window are untouched; a Warm or Cold reading still falls through to the ordinary ping, so fail open holds. - The base..HEAD diff is exactly the three commits I reviewed across the three rounds (
keeper.go,substitute.go,openaiphase_test.go). Nothing else changed.
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 | 3 of 3 | a0a16220488e |
approve |
Verdict: approve
Findings
None. I could not prove a defect in the new commit.
Earlier findings
- My round-2 finding 1 (the widened default window has no upper bound): fixed.
substituteWindownow takesmin(ttl-idle+2*tick, maxSubstituteWindow), withmaxSubstituteWindow = 2*DefaultPreExpiry + 2*tick= 124 s. I checked every configuration by hand:- OpenAI at the defaults: slack 120 s + 4 s = 124 s, at the cap exactly; the ping's remaining life is at most 120 s, so it still reads PreExpiry. The cap can never cause a missed OpenAI ping:
duefires only at or afteridle, so remaining is at mostttl - idle, and delay only makes it smaller. - Anthropic 5 min, 60 s idle (my finding's case): window 124 s, remaining 240 s → Warm, refused. Correct.
- A 1-hour ask not granted, 270 s idle: window 124 s, remaining about 55 min → Warm. Correct.
- 1-hour granted (59 min idle): window 64 s, unchanged from round 2.
- Anthropic defaults (270 s idle): window 60 s, unchanged from before this PR.
- An operator-set
pre_expiry_secondsis still returned uncapped, as designed.
- OpenAI at the defaults: slack 120 s + 4 s = 124 s, at the cap exactly; the ping's remaining life is at most 120 s, so it still reads PreExpiry. The cap can never cause a missed OpenAI ping:
- My round-2 non-blocking items: both fixed. The
cachePhaseAtdoc no longer claimsCacheTTLMinimum"never arises here" — it now says OpenAI's minimum reaches this function and why this function reports PreExpiry whereCtx.CachePhasedoes not. The phase-check comment names a short idle override as a divergence case and states the cap. - Reviewer 1's round-2 non-blocking items (the same unbounded-widening concern, plus an OpenAI override with a shortened idle): fixed by the same cap.
- Reviewer 1's round-1 note (the
CacheTTLMinimumcomment): fixed in this commit, as above. - My round-1 finding and non-blocking items, and reviewer 1's round-1 items: all fixed in round 2 and unchanged there.
Non-blocking
TestAShortIdleLeavesTheFirstPingWarm, first and third assertions comparesubstituteWindow's result againstmaxSubstituteWindow, which the function cannot exceed by construction. They are pins, like thecacheTTLassertion; the substantive checks are the Warm reading and the OpenAI lower bound. No change needed.
What I checked
- Last review: round 2, ac01f2e, 2026-10-25T18:54:51Z
- New commits read: 1 (
a0a16220fix(keepalive): cap the widened pre-expiry window) - Read in full: 3 reviews, 2 comments, 0 inline comments (from the three files)
- New items since my last review, and what I did about each:
- The commit
a0a16220: full diff and the code around it, below. - The author's reply at 2026-10-25T18:59:54Z: each claim checked. The 124 s figure is right — my round-2 fix proposal said 128 s, which was my own arithmetic slip (120 + 2×2 = 124); the author corrected it.
- Reviewer 1's round-2 review at 18:51:42Z: read in full. Its two non-blocking items match my finding and the OpenAI-override case; both are fixed by the cap.
- The commit
- The new test by trace:
substituteWindow(0, 300 s, 60 s)= 124 s;cachePhaseAtat 60 s of a 300 s life gives remaining 240 s > 124 s → Warm. Without the cap the window would be 244 s and the phase PreExpiry, so the test discriminates — the author's mutation run confirms it. - That the cap introduces no new miss: a schedule whose slack exceeds 124 s (for example a 170 s idle on a 5-minute cache) now never substitutes — but no ping of such a schedule lands near expiry, so refusing is what
pre_expiryasks for. An operator who wants substitution there setspre_expiry_seconds. - That the
minbuiltin and the const placement compile in this repo:minis already used on durations and ints (keepalive/types.go:178), Go 1.26. - The full base..HEAD diff is exactly the three commits reviewed across the three rounds (
keeper.go,substitute.go,openaiphase_test.go). Nothing else changed. - Fail open is untouched in all three commits: every refusal path falls through to the ordinary ping, and the substitute only replaces a ping that was going out anyway.
) Owner decision 2026-10-30: "give it more time, it can run on the 210 sec mark". - The hold extension is removed: the re-armed timer, keepalive_hold_extensions and its tests. Every span keeps today's hold limit. - One extra slot for every substitute: 30 s before the normal hold deadline (210 s after the last ping at the 5-minute defaults). - For the summary's extra request only, the pre-expiry window widens to cover that slot (94 s at the defaults: 90 s left plus two ticks). Planned-ping summaries keep the #715/#717 window. - The summary goes first. The sweep question goes only if the summary declines, in the same slot. Nothing after it. - Kept: a missed slot is never sent late; OpenAI is out of scope. Refs #776 Assisted-By: Claude Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
…776) (#779) fix(keepalive): the sweep question takes the last ping, never ping 1 (#776) The sweep question took ping 1 of an idle span. It reads the turn's cache entry but does not renew one that ends at a text turn. After a text turn the entry then expired, and the plain ping 2 wrote the whole conversation again: 22 of the 80 misses in #776 ($50.18 in 3.9 days on one laptop), which #777 could not fix. Ping 1 is now always plain. The question takes the last planned ping of the span. A one-ping plan (the 1-hour tier's default) sends no question, so the question is never the only ping. The summarizer's substitute, the already_asked latch, the cost ceiling and the batch rules are unchanged. Owner decision 2026-10-30. Fixes #776 Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]> fix(keepalive): after a text turn the sweep question comes third (#776) Owner decision 2026-10-30: the sweep must not contradict the caching strategy. Where the question cannot renew the cache, it runs as an extra request after the strategy's last ping. - After a turn that ends at a text turn (the last non-system message is not a tool_result; roles and block types only), every planned ping is plain. The question goes out once at the slot after the last planned ping, 30 s before the hold ends. No ping follows it, and it sends nothing if the copy is gone or there is no candidate. - After a tool_result turn the question may take ping 1, as on main: it renews the entry (#777). - This replaces the "plain ping 1, question on the last ping" rule of the first commit, which is reverted. New counters: keepalive_sweep_extra_asked, keepalive_sweep_extra_skipped. Refs #776 Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]> docs: keep-alive never shortens the cache strategy (#776) The owner asked for the rule in the development docs, so a later change that breaks it is caught. - docs/design.md: a new section, "Keep-alive: the cache strategy comes first". It names the summarizer's substitute as a known gap. - CLAUDE.md, Hard boundaries: one bullet that points at it. - RELEASING.md, Part B: the live check confirms that after a text turn every planned ping is plain and reads the full prefix. - A guard test for the sweep on 1-, 2- and 3-ping plans. Refs #776 Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]> fix(keepalive): the summarizer follows the cache strategy too (#776) Owner decisions 2026-10-30: "summerizer as well so a)" and "a1 it is". - After a text turn the summarizer's keep-alive substitute no longer takes a planned ping. Every planned ping is plain, and the summary goes out once as the extra request after the last one. - A cache_state any summary uses the sweep's slot: 30 s before the normal hold deadline. - A cache_state pre_expiry summary (the medium preset) runs only in its pre-expiry window. Its slot is the middle of that window: 268 s after the last ping at the 5-minute defaults, 32 s before expiry. - The one exception to the hold limit: only for a span that ended at a text turn and still has a pre_expiry summary waiting, the deadline timer re-arms once, to 15 s past the slot (43 s longer at the defaults), never past the cache expiry. Every other span keeps the limit. Counted as keepalive_hold_extensions. - One request in the extra slot. The summary owns it before the sweep. A declining pre_expiry summary is not followed by the sweep. - A missed extra slot is never sent late. - OpenAI is out of scope: its cache has no text-turn rule. - docs/design.md: the known gap is gone. The guard covers every substitute kind. Refs #776 Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]> test(proxy): the summary-at-a-ping tests use a tool_result turn (#776) After a text turn the summary now waits for the extra slot after the last planned ping. These two tests are about a planned ping dispatching the summary, so their last real turn now ends at a tool_result. Refs #776 Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]> fix(keepalive): the summary uses the 210 s slot, no hold extension (#776) Owner decision 2026-10-30: "give it more time, it can run on the 210 sec mark". - The hold extension is removed: the re-armed timer, keepalive_hold_extensions and its tests. Every span keeps today's hold limit. - One extra slot for every substitute: 30 s before the normal hold deadline (210 s after the last ping at the 5-minute defaults). - For the summary's extra request only, the pre-expiry window widens to cover that slot (94 s at the defaults: 90 s left plus two ticks). Planned-ping summaries keep the #715/#717 window. - The summary goes first. The sweep question goes only if the summary declines, in the same slot. Nothing after it. - Kept: a missed slot is never sent late; OpenAI is out of scope. Refs #776 Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]> fix(keepalive): only the summary takes a summary's slot; extra re-checks the breaker (#776) Owner rule 2026-10-30: "as for sweep after summary. dont do that. it can probably have the sweep question pay a cache write like the problem with the ping... so we should probably just do summary at that point". - When a summary is due in the extra slot, only the summary goes, even if it declines. The sweep question takes the slot only when no summary is registered for the thread. Review round 1 on #779: - The extra slot now runs the same route-breaker and dead-credential re-check as a planned ping. On a trip it sends nothing and stops the span. - A short Idle: the slot is at least two ticks after the last ping, and the extra waits until that ping's response is in (pingRunning). - SweepExtraSkipped: the doc names every case it counts. - docs/design.md: endsAtTextTurn is an internal flag, not a metric. - RELEASING.md: the Part B check is numbered like its siblings. Refs #776 Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]>
Summary
On an OpenAI thread, a
pre_expirysummary never took the keep-alive ping. The substitute's phase check treated the 30-minute OpenAI cache as a 5-minute one, so at the 28-minute ping it read the cache asCold. This PR puts the cache-lifetime rule in one function that both the retry guard and the phase check use.What we found
kaEntry.cacheTTL()(from fix(keepalive): retry a ping that failed fast while the cache lives #710) gives 30 minutes for OpenAI.cachePhaseAt(keepalive/substitute.go) chose 5 minutes or 1 hour from a one-hour flag only. That flag is never set on OpenAI.modelinfo.OpenAIDefaultKeepAliveIdle). There,cachePhaseAtreturnedCold, so apre_expirycandidate was refused as a phase mismatch, and an ordinary ping went instead.What changed
cacheLifetime(provider, ttl1h)inkeepalive/keeper.go: 30 minutes on OpenAI, else 1 hour on the one-hour tier, else 5 minutes. This is the one place for the rule.kaEntry.cacheTTL()now callscacheLifetime(e.provider, e.ttl1h).pre_expiry_secondsunset, the window is now the larger of 60 s and (cache lifetime - idle + 2 sweep ticks). An explicit value is kept as set. On Anthropic at the defaults this stays 60 s (300 - 270 = 30 s). The widened default is capped at 124 s (round 2), so a short schedule, such as a 60 s idle override, still reads its early pings as Warm.cachePhaseAttakes the lifetime instead of a one-hour flag.fireSummarySubstitutepassescacheLifetime(e.provider, e.ttl1h || e.pol.HeadTTL1h). TheHeadTTL1hpart is unchanged: the substitute already counted the host's one-hour ask, and the retry guard did not, so each caller keeps its own input.How it was tested
All runs are on the eval box.
TestAnOpenAIThreadAtTwentyEightMinutesIsNotColdorigin/main+ testreads cold, want PreExpiryTestAPreExpirySubstituteTakesAnOpenAIPing(end to end)origin/main+ testrefused as a phase mismatch 1 time(s)cacheLifetimeTestAnOpenAIFastFailureIsRetriedInsideItsThirtyMinuteCache. One rule now drives both.TestAPreExpirySubstituteTakesAnOpenAIPing, now with the default window (round 1)TestAPreExpirySubstituteStillTakesAnAnthropicPingWithTheDefaultWindow(round 1)TestAShortIdleLeavesTheFirstPingWarm(round 2)go test -race ./keepalive/...a0a16220488ego test -race ./proxy/ -run 'KeepAlive|Keepalive|Ping|Keeper|Manual|Substitute'go vet,gofmt -lThe unit test on
origin/mainusesmain's old signature (ttl1h bool). The end-to-end test runs unchanged on both trees.Data dependence
No change. The rule reads the provider and a tier flag, which the keeper already holds.
Fixes #715
🤖 Generated with Claude Code