Repository navigation
feat(keepalive): weigh a ping chain against the miss it protects (#1420) - #1428
Conversation
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.332 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 64827896ffa5 |
blocking |
Verdict: blocking
Findings
-
dash/ui/tabs/strategies.js:170 — the strategy form still says "Max $/ping (0 = default)", but 0 now means "no flat cap".
- What fails: an operator edits a manager strategy and leaves the field at 0. The label says 0 = the default. Before this PR, 0 resolved to the $0.50 default. After it, 0 means no cap at all; only the value rule applies. The operator believes a $0.50 guard is in force while none is.
- Proof:
ApplyStrategy(keepalive/strategy.go:72) copies the stored 0 intoPolicy.MaxUSDPerPing.PingCap(keepalive/value.go:51) maps 0 to +Inf. The old path resolved 0 to $0.50 throughCeiling()(keepalive/types.go:300). The form writes 0 when the field is blank (Number(usdCap.value) || 0, strategies.js:224). The PR updated the arm text (dash/ui/tabs/keepalive.js:472) but not this label. - Fix: change the label to say 0 = no cap and the value rule applies. Update the hint the same way.
-
keepalive/types.go:141 — the
MaxUSDPerPingfield comment contradicts the new guard.- What fails: the comment says "Read it through Ceiling(), never directly: zero here means UNCONFIGURED, and for a spend guard that has to resolve to the default rather than to infinity." The ping guard this PR adds reads the field through
PingCap, and zero resolves to infinity there. A future editor who follows the comment undoes the value rule. - Proof: keepalive/value.go:51-55 (
PingCapmaps 0 to +Inf) and value.go:69 (PingVerdictreadsp.PingCap()).Ceiling()still resolves 0 to the default, but only the summary and sweep substitutes use it (keepalive/substitute.go:136, 462). - Fix: update the comment. Say: pings read it through
PingCap()(0 = no cap, the value rule applies); summary and sweep substitutes read it throughCeiling()(0 = the default).
- What fails: the comment says "Read it through Ceiling(), never directly: zero here means UNCONFIGURED, and for a spend guard that has to resolve to the default rather than to infinity." The ping guard this PR adds reads the field through
Non-blocking
- Stale comments left above the new code: proxy/keepalivectl.go:176-179 still tells the old
Ceiling()story ("the guard resolves to the default instead") directly above the newPingCap()code. dash/ui/tabs/keepalive.js:469-471 still says "The per-ping ceiling resolves to the service default on an account that configured none." TestReplayDecidesLikeTheLiveKeeper(campaign/campaign_test.go:398) is circular: both sides callPingVerdict, so it pinsDefaultKto the verdict, not the keeper. Also the replay'sStakeis priced at the row's own prompt size with no 1-hour rate (campaign/replay.go:185, 200), while the keeper'smissUSDis priced at the ping's prompt tier with the 1-hour rate (keepalive/keeper.go:1287). The "decide alike" claim holds through the shared function only, not through the same numbers.armedView(proxy/keepalivectl.go:182) reports the cap from the account document only. A manager strategy that sets its own cap is enforced (ApplyStrategy) but not reported. The drift is pre-existing; the gap widens from "0.50 reported vs 0.25 enforced" to "absent reported vs 0.50 enforced".- No test covers the positive branch of the arm response: an operator who sets a cap should see it reported. Only the absent case is tested (proxy/keepalivectl_test.go:166).
- docs/how-to/cache-keepalive.md says "On OpenAI the write rate is the input rate." GPT-5.6 and later charge 1.25x input (internal/modelinfo/cachefrac.go:57). The code is right; the sentence is not.
- The miss side uses the entry's billed tier (
ttl1h) but notHeadTTL1horOneHourOnWait, where a miss would rewrite at the 1-hour rate. This understates the miss, so the guard refuses more, not less. Conservative direction only. - Process: the behavior change is named at the top of the PR and the owner's yes is still an open question. Merge must wait for it (RELEASING.md, "Behavior changes need a human's permission").
What I checked
- The full diff base..HEAD and both commits. The merge (6482789) brings only #1426's two-parameter price callback in proxy/predictive_agent_test.go. No other content.
- value.go math:
PingCap,MissUSD,PingVerdict. Fail open holds: an unpriced ping (pingUSD 0) and an unknown miss (missUSD 0) are both allowed. The operator's cap applies on top. The>=boundary refuses a chain that costs exactly the miss, as the docs state. - Record paths: automatic, manual-hold and the press (
PingNow). The chain count K ispol.MaxPingsafterWaitPings, so the tool-wait and human/background extras are included. The 1-hour swap sets K to 1. The sweep stops atMaxPings, so the counted chain matches what is sent. The manual-only entry counts 1 ping and the cap it was admitted under; this matches the record-time press check. - Pricing: both sides read
Price.Atat the ping's prompt size (prefix + 1). A 1-hour entry prices its miss at the 1-hour write rate. The OpenAI write frac rules (1.0 before GPT-5.6, 1.25 from GPT-5.6) come fromCacheWriteFracFor, as before. - Config: the loader no longer fills 0.50; the five built-in strategies drop the key; an old file that wrote 0.5 keeps it as an explicit cap;
validatestill rejects negatives, so "no cap" by negative value stays a Policy-level escape hatch only. - Reason
not worth it: added to hooks/model.ts, both cg.py copies, the dashboard text and the docs. No consumer of the reason list was missed. max_usd_per_pingconsumers: the arm response omits the key when no cap is set; keepalive.js handles the absent key; strategies.js is finding 1.- The summary and sweep substitutes keep the $0.50 default through
Ceiling(). Deliberate and documented in the PR. - Data dependence: none. The rule reads prices, token counts and the planned count. The keep-alive row needs no edit. Stated in the PR.
- I did not run builds or tests. Live tests are not approved for this review.
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 @amiddaid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 | offload-review skill, @amiddaid's session | fresh | 1 of 2 | 1 of 2 | 64827896ffa5 |
blocking |
Verdict: blocking
Findings
- dash/ui/tabs/strategies.js:170 — the manager-strategy form still says "Max $/ping (0 = default)", but 0 now means "no flat cap"
- What fails: a manager creates a keep-alive strategy and leaves "Max $/ping" at its default 0. The label promises a default cap. The strategy now enforces none: only the value rule applies. A second effect:
ApplyStrategy(keepalive/strategy.go:72) copies the strategy's 0 onto the policy, so while the strategy's window is open it also removes an account's explicitkeepalive_max_usd_per_ping(say 0.25). Before this PR the same clobber landed on the $0.50 default; now it lands on "no cap". - Proof: the form input starts at
'0'(strategies.js:77) and the submit sendsmax_usd_per_ping: Number(usdCap.value) || 0(strategies.js:224).ApplyStrategywrites it straight onto the policy (keepalive/strategy.go:72).Policy.PingCap()(keepalive/value.go) maps 0 to +Inf, soPingVerdictnever refuses on a cap. Before this PR,Policy.Ceiling()mapped 0 toDefaultMaxUSDPerPing($0.50) andpingable()enforced it. The PR updates the account path, the arm dialog and the docs, but not this form or the manager-strategy path. The PR's own docs claim "No default and no strategy sets it" (docs/how-to/cache-keepalive.md:86); this UI tells a manager the opposite. - Fix: update the label and the hint to say 0 means no flat cap and the value rule decides. Decide whether a strategy's 0 should leave the account's own cap alone instead of replacing it. Name the manager-strategy path in the behavior-change note either way.
- What fails: a manager creates a keep-alive strategy and leaves "Max $/ping" at its default 0. The label promises a default cap. The strategy now enforces none: only the value rule applies. A second effect:
Non-blocking
- dash/cachestate.go:56 — the comment lists the
ping_reasonvalues and lacks the newnot worth it. - keepalive/keeper.go:181 — the
pingUSDfield comment still says "Checked against pol.MaxUSDPerPing before anything is sent". The check is nowPingVerdict. - campaign/campaign_test.go:64 —
TestReplayDecidesLikeTheLiveKeepercomparesDefaultK()with the samePingVerdictcall on the same inputs. Both sides call one function, so it cannot fail on a divergence. It also does not cover the live keeper's wait-plan count (K up to 8), which the liveverdict()weighs; the replay weighs the base K. The test's comment claims more than it tests. - keepalive/value.go:64-71 —
PingVerdicttreatsmissUSD <= 0as "unknown, fail open". A price list that stateswrite <= readalso gives 0 and then fails open, though the miss is known and free. Degenerate input; the comment names only the unknown case. - dash/keepalive.go:1540 — the comment says the replay gate is "the request path's, in the same order". The replay models neither the old $0.50 ceiling nor the new value rule. Pre-existing shape, unchanged by this PR.
- docs/dashboard.md:405 — "the per-ping cost ceiling" for manual holds now reads incomplete: with no operator cap, only the value rule applies.
What I checked
- Full diff
9c64a6a3..HEAD(26 files), including the merge commit's conflict resolution in proxy/predictive_agent_test.go (clean pick-up of #1426's price-callback signature). keepalive/value.go:PingVerdict,MissUSD,PingCapagainstinternal/modelinfo(CacheReadFor,CacheWrite5mFor,CacheWrite1hFor,Price.At, tier rules). OpenAI write = input rate (CacheWriteFracFor returns 1.0), as the docs claim. Tier pricing raises both sides together, as designed.keepalive/keeper.goRecord path:pol.MaxPingsis the wait-plan count before the entry is built (line 1095), soverdict()weighs the real planned chain. The manual-hold branch admits a press at pings=1;verdict()on a manual-only entry counts 1 (zeroed policy) and the cap it was admitted under — the two agree. Post-recordMaxPingsmutations (lines 1721, 1735, 1785) only touch 1-hour-on-wait entries, where the 1-hour miss is ~19x the ping.PingNow(manual.go): a live auto entry already passed the chain verdict at record, and a manual-only entry counts 1, so the press gate cannot refuse a press that was admitted.- Fail open: an unpriced model gives pingUSD 0 and missUSD 0 and passes; an unknown price gives missUSD 0 and passes; the operator's explicit cap still refuses.
- Config:
Resolved()no longer fills 0.50; old strategy files keep their 0.5 as the operator's own cap (config/strategy_test.go, the 1-hour-head exclusion matches its fixture, which never wrote the key).FromConfigpasses the raw value through. - Summary and sweep substitutes still use
Policy.Ceiling()($0.50 default), as the PR body and docs state (keepalive/substitute.go:136,462). - Reason plumbing:
not worth itadded to the TS hook model, bothcg.pycopies, the docs; the 409 press path mapsErrTooCostlyto "over budget" for both cap and value refusals, and the plugin handles that error string. - armedView:
max_usd_per_pingis now absent when no cap is set; the dash arm dialog handles absence (undefined > 0is false). - Repo rules: the verdict logic lives in the library (
keepalive), hosts only report; no client rule added; data dependence stated in the PR body (metadata only, no row change); the behavior change is named at the top of the PR with old/new behavior and how to turn it off. - No builds or tests were run (live tests not approved).
Replies to round 1 (both reviewers blocked)Fixed in Finding 1, both reviewers: the strategy form says "0 = default". Fixed.
Finding 2, reviewer 2: the Non-blocking notes:
Tests (macOS, Go 1.27.4):
Local tests: waived (owner rule) |
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.332 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 570df56926d2 |
approve |
Verdict: approve
Findings
None. The fix commit 570df56 addresses every round-1 finding from both reviewers, and it introduces no new defect I can show.
Earlier findings
- My finding 1 (strategies.js "0 = default" label) — fixed. The label now says "0 = no flat cap" and the hint names the value rule and that the account's own cap stays (dash/ui/tabs/strategies.js:170). Verified in the file.
- My finding 2 (types.go
MaxUSDPerPingcomment) — fixed. The comment now states both readers:PingCap()for pings (0 = no cap, the value rule decides) andCeiling()for the summary and sweep substitutes (0 = the $0.50 default). It matches the code. - Reviewer 1's finding 1 (same label, plus the strategy clobber of the account cap) — fixed, and I checked the deeper half myself.
ApplyStrategy(keepalive/strategy.go:72-75) now replaces the cap only when the strategy states a value other than 0; -1 still means "no cap".TestApplyStrategyKeepsTheAccountCapWhenTheStrategySetsNonecovers 0-keeps-0.25, 0.40-replaces, -1-clears and none-at-all. The behavior-change block in the PR body now names the manager-strategy path. An old stored strategy with 0.5 still replaces (0.5 != 0), which keeps the PR's promise to old files. - My non-blocking notes — all fixed: the stale comments (proxy/keepalivectl.go, dash/ui/tabs/keepalive.js, dash/cachestate.go, dash/keepalive.go, the
pingUSDfield, docs/dashboard.md manual holds); the OpenAI write-rate sentence (now "input rate before GPT-5.6, 1.25x from GPT-5.6", which matchesCacheWriteFracFor); the missing positive-branch arm test (TestArmingReportsAnAccountCap); thePingVerdictcomment on a miss ≤ 0; the armedView strategy drift. - The circular replay test — fixed beyond what I asked.
TestReplayDecidesLikeTheLiveKeepernow records through a real keeper with a stub host, so the live side iskaEntry.verdict()throughRecord, not the same function call. I checked the numbers meet: the stub prices every prompt size the same,pingOutputBudget("/v1/messages")is 1, so the replay'sprefix x CacheRead + out x 1equals the liveprojectedPingUSD, and itsStake(prefix, read, write)equals the liveMissUSDat the 5-minute rate. The newMissfield onRowFactsis priced at the ping's prompt tier (campaign/replay.go:177-184), as the keeper does. - The 1-hour miss under HeadTTL1h / OneHourOnWait — fixed.
missAtOneHour(keepalive/keeper.go:1302) prices the miss at the 1-hour write rate forHeadTTL1h,OneHourAlwaysand an entry whose plan swapped to the 1-hour ping.TestMissIsPricedAtOneHourWhenThePolicyWritesAtOneHourcovers both policy flags. The reply's wording "OneHourOnWait alone does not change the rate" is right: the rate changes only when the swap fired for this entry, which is whatoneHourcarries. - armedView — fixed. It now reports the effective cap through
keeper.resolvePolicy(proxy/keepalivectl.go:182-187), which layers the manager strategy and the session override exactly as the record path does. Campaigns do not touchMaxUSDPerPing(campaign/decision.goApplysets counts only), and the override never carries it, so the report matches enforcement.
Non-blocking
armedViewresolves with the provider hard-coded to Anthropic. For an OpenAI session armed by hand, enforcement skips the strategy layer (ResolvewithOpenAI: true) but the report applies it. A gap needs a strategy that sets a cap and an armed OpenAI session. Narrow, and the same class as the pre-existing drift.- Under
OneHourAlways, a subagent entry's miss is priced at the 1-hour write rate, though subagents keep the 5-minute cache under that policy. Some worthy subagent pings are refused. The code comment names the cautious side; spend-safe direction only. TestReplayChainNeverExceedsTheLiveWaitPlan's main property holds by construction:replayChainreturnsmax(pol.MaxPings, WaitPings(...))and the test compares it withmax(pol.MaxPings, live). The tool-wait K=8 assertion is the part that can fail. Harmless.- The owner's yes to the behavior change is still an open question in the PR body. Merge must wait for it (RELEASING.md). Not a code defect.
What I checked
- Last review: round 1,
64827896ffa500ab99e14e3128ad8a1e23a13267, 2026-11-25T17:26:35Z. - New commits read: 1 —
570df56"fix(keepalive): round 1 review fixes for the ping value rule (#1420)". Full diff read, plus the code around each change. - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review: reviewer 1's round-1 review (17:26:35Z order in the list; read in full, no finding I disagree with), the author's reply comment (17:37:49Z; every claim in it checked against the code, all confirmed), and the fix commit
570df56. ApplyStrategyandarmedViewread in the current files, not only the diff.resolvePolicy's signature and layering checked (proxy/keepalive.go:495); campaigns and overrides cannot change the cap, so the reported cap is the enforced one.replayChain(campaign/adapt.go): for Anthropic rows it ismax(base, WaitPings(cause, subagent)), which is never above the live count; OpenAI rows keep the base, as live does (the wait plan is Anthropic-only). On a 1-hour-billed row the replay weighs a 5-minute miss against the larger chain, so it is stricter than live, never looser — the commit's claim holds.- The new tests' math checked by hand: the stub price (no tiers), the output budget of 1 on
/v1/messages, the 5-minute and 1-hour miss formulas (3.75e-6 and 2x input minus 0.3e-6 read), and the prefix 49,776 inTestMissIsPricedAtOneHourWhenThePolicyWritesAtOneHour. RowFacts.Misshas one constructor (campaign/replay.go:207) and it sets the field; the dash replay documents that it models neither the value rule nor the cap (dash/keepalive.go).- No new behavior change beyond the ones already named: the strategy-at-0 change is in the PR body's behavior-change block, with an open question for the owner.
- I did not run builds or tests. Live tests are not approved for this review.
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 @amiddaid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 | offload-review skill, @amiddaid's session | resumed | 1 of 2 | 2 of 2 | 570df56926d2 |
blocking |
Verdict: blocking
Earlier findings
- My finding 1 (strategies form "0 = default" + the cap clobber): fixed. The label and hint now say 0 = no flat cap and that the account's cap stays (dash/ui/tabs/strategies.js:170).
ApplyStrategyreplaces the account's cap only when the strategy's value is not 0 (keepalive/strategy.go:72-76).TestApplyStrategyKeepsTheAccountCapWhenTheStrategySetsNonecovers 0-keeps, 0.40-replaces and -1-replaces. The PR body names the manager-strategy path and asks the owner to confirm the 0-keeps choice. - Reviewer 2's finding 1 (same form label): fixed the same way. Agree with reviewer 2, finding 1; it was also my finding 1.
- Reviewer 2's finding 2 (the
MaxUSDPerPingcomment): fixed. keepalive/types.go now says pings read it throughPingCap()(0 = no cap) and the substitutes throughCeiling()(0 = the $0.50 default). - Reviewer 2's non-blocking notes: all fixed — the stale comments (cachestate.go, pingUSD, keepalivectl.go, keepalive.js, dash/keepalive.go, docs/dashboard.md), the OpenAI write-rate sentence (now "input rate before GPT-5.6, 1.25x from GPT-5.6", which matches
chargesCacheWritePremium), thePingVerdictmiss-≤-0 comment, the circular replay test, the 1-hour miss underHeadTTL1h/OneHourAlways, and the arm answer's positive branch (TestArmingReportsAnAccountCap). - My non-blocking notes: all fixed except the process one below.
Findings
- proxy/keepalivectl.go:184 — the arm answer resolves the cap as an Anthropic session for every session, so on an OpenAI session it can state a cap nobody enforces
- What fails: a manager strategy sets
Max $/pingto 0.40 and its window is open. A user arms the Ping button on an OpenAI session of the same account.armedViewcallsresolvePolicywith the provider hardcoded tobschemas.Anthropic, so the strategy layer applies and the answer reportsmax_usd_per_ping: 0.40. The request path resolves the same session with provider OpenAI, andkeepalive.Resolveskips the strategy layer for OpenAI (keepalive/resolve.go:61). The enforced cap is the account's, possibly none. The arm dialog then says "No single ping may cost more than $0.40" while the pings on that session are not capped by it. This is the exact defect the round-1 fix set out to remove: a report that states a limit nobody enforces. - Proof:
pol, _ = h.keeper.resolvePolicy(tn, session, bschemas.Anthropic, tn.Cache, predDecision{}, false)(keepalivectl.go:183-185).resolvePolicyWindowsfillsin.Strategiesonly when the provider is not OpenAI (proxy/keepalive.go:508-514), andResolveapplies strategies only on the non-OpenAI branch (keepalive/resolve.go:56-61). Armed OpenAI sessions exist:Override.ApplyOpenAI(keepalive/override.go:165) is the arm path for them. - Fix: derive the provider from the session's own model —
armedViewalready fetches it (worstCasereturns the model of the session's last billed request) — or skip the strategy layer when that model is an OpenAI model. Failing that, say in the answer that the cap is the Anthropic-side one.
- What fails: a manager strategy sets
Non-blocking
- campaign/campaign_test.go:131 —
TestReplayChainNeverExceedsTheLiveWaitPlanmostly assertsreplayChain == max(base, WaitPings), which is the function's own definition. Only the tool-wait pin (K=8) and the OpenAI branch test behavior. The main parity test (TestReplayDecidesLikeTheLiveKeeper) is now genuine and good. - keepalive/strategy.go:72-76 — a strategy cannot carry a negative cap through the manager API (
ValidStrategyBoundsrefuses < 0), so the "-1 replaces" branch is reachable only by building atenant.Strategyby hand. The test covers it anyway. Harmless. - Process: the PR body still asks "Owner: yes to this behavior change?". Merge must wait for that yes (RELEASING.md, "Behavior changes need a human's permission").
What I checked
- Last review: round 1, 6482789, 2026-11-25T17:27:09Z.
- New commits read: 1 — 570df56 "fix(keepalive): round 1 review fixes for the ping value rule (#1420)". Full diff read, plus the code around each change.
- Read in full: 2 reviews, 1 comment, 0 inline comments (from the three saved files). The comment file holds only the author's reply at 17:37:49Z; the inline file is empty.
- New items since my last review: the author's reply comment (checked claim by claim below) and commit 570df56 (reviewed as a first review).
ApplyStrategy: the 0-keeps change and its test. A negative strategy cap still replaces; the API refuses negatives, so that branch is hand-built only.missAtOneHour(keeper.go):HeadTTL1h,OneHourAlwaysand the per-entry 1-hour-ping flag now price the miss at the 1-hour write rate.OneHourOnWaitalone does not, which matches the reply: the flag matters only when the plan actually switched this entry to the 1-hour ping, and that sets theoneHourvariable the code reads. The new test covers both policy flags through a real Record.- The rewritten
TestReplayDecidesLikeTheLiveKeeper: traced both sides. The live side records through a real keeper (stub host prices one flat rate; no ping fires becauseNowis fixed and the idle is 240 s), soEntryreturns held exactly when the entry's verdict is OK — turn 1, prefix 90k over the 80k floor, no tool gate (WaitPlan off), no thinking, no terminal tool. The replay side buildsPingandMissfrom the same rates and prefix, and both weigh K=2. The comparison is now real, not circular. replayChainanddefaultPlan:WaitPingsnever returns less than the base, somax(base, WaitPings)equals the live count for a matching cause. On a 1-hour entry the replay weighs a larger chain against a smaller (5-minute) miss, so it refuses more than live, never less — the comment's claim holds.RowFacts.Missincampaign/replay.go: priced at the ping's prompt tier through the same price callback (autoPricereturnsq.CacheWriteat that size), matching liveMissUSD's tier choice; rows without a ping-tier price fall back to the row's rates.armedView's newresolvePolicycall: locking is safe (strategyList,activeOverridetake their own locks), the nil-keeper guard is present, the just-armed override does not touchMaxUSDPerPing(Override.Applysets Idle, MaxPings, MinPrefixTokens, WaitPlan only), and the new test's fixture wiring exists. The provider hardcode is finding 1.- The PR body diff since round 1: the behavior-change block now names manager strategies, and the open question about a strategy's 0 is there.
- No builds or tests were run (live tests not approved).
Owner decisions (David Amid, 2026-11-25)
|
Replies to round 2Fixed in Reviewer 1, finding 1, and reviewer 2's matching note:
Reviewer 2: a subagent entry under Both reviewers: Reviewer 1: the "−1 replaces" branch is reachable only by hand. Kept. The test documents the branch. It is harmless. Owner decisions (David Amid, 2026-11-25), recorded in the comment above:
Tests (macOS, Go 1.27.4): build and Local tests: waived (owner rule) |
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.332 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 3 of 3 | 40a3473adf73 |
approve |
Verdict: approve
Findings
None. The round-3 commit 40a3473 fixes the one open finding and my two open notes, and it introduces no new defect I can show.
Earlier findings
- Reviewer 1's round-2 finding 1 (armedView hardcodes the Anthropic provider) — fixed, and I checked the fix myself.
armedViewnow reads the provider of the session's own last request through the newDB.LastBilledProvider(dash/keepalive.go:1961) and passes it toresolvePolicy(proxy/keepalivectl.go:184-190). I verified the whole chain:LastBilledProvidercopiesLastBilledPrefix's query shape: same table, sameFilter.where(), same ordering, sameErrNoRowshandling. The model and the provider therefore come from the same row, so the report is consistent withworstCasebeside it.- The stored value round-trips: the request path stores
string(provider)of abschemas.ModelProvider(proxy/dashcapture.go:246, proxy.go:1343), andbschemas.OpenAIis the string "openai" (bifrost schemas/bifrost.go:45). The cast back is safe. - No row: the provider stays Anthropic, as the comment states. A DB error also falls back to Anthropic (see Non-blocking).
TestArmingReportsTheStrategyCapOnlyWhereItIsEnforcedcovers both sides: a 0.40 strategy cap reported on an Anthropic session, absent on an OpenAI one. The helpers it uses exist (keeper.setStrategies,mgrFixture.record).
- My round-2 note (OneHourAlways priced a subagent's miss at the 1-hour rate) — fixed.
missAtOneHournow takes the subagent flag:OneHourAlwayscounts only on a main thread (keepalive/keeper.go:1305-1307). This matches the policy's design — subagents keep the 5-minute cache underOneHourAlways— andHeadTTL1hstill prices a subagent at 1 hour, which also matches its design ("it also applies to subagent requests"). The extended test covers all four combinations through a realRecord. The direction of the change is right too: the 5-minute miss is the true cost of a subagent's rewrite. - My round-2 note (the chain test restated its own definition) — fixed.
TestReplayChainFollowsTheWaitPlannow pins the two behaviors that can fail: K=8 on a tool wait and the base K=2 on an OpenAI row. - My round-2 process note (the owner's yes) — addressed. The owner decisions comment (2026-11-25) records: refuse the chain above the limit, do not trim; a strategy's 0 leaves the account cap; round 3 granted; the merge yes is given in the integrator session. That is the RELEASING.md path.
- Reviewer 1's round-2 note (the "-1 replaces" branch is reachable only by hand) — kept by the author, with a reason. I accept the reason:
ValidStrategyBoundsrefuses negative caps through the API, so the branch exists only for a hand-builttenant.Strategy, and the test documents it. No live path reaches it with a surprise.
Non-blocking
- On a DB error (not
ErrNoRows),LastBilledProviderreturns the error andarmedViewsilently falls back to Anthropic. An OpenAI session could then report a strategy cap that is not enforced. This needs a failing query on exactly the call whose twin (worstCase's) runs beside it, and the answer is a report, not a gate. Negligible. - The merge yes is still open by design: the owner gives it in the integrator session. The hand-off block must state where it stands.
What I checked
- Last review: round 2,
570df56926d27569bcb3123e0095a012c5883c33, 2026-11-25T17:42:49Z. - New commits read: 1 —
40a3473"fix(keepalive): round 2 review fixes for the ping value rule (#1420)". Full diff read, plus the code around each change. - Read in full: 4 reviews, 3 comments, 0 inline comments (from the three files
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). The first 79 lines of the reviews file are the two round-1 reviews, unchanged since I read them in full in round 2; the rest I read now. - New items since my last review: reviewer 1's round-2 review (17:45:15Z, read in full; its finding 1 matched my round-2 non-blocking note and I verified the fix), the owner decisions comment (17:54:33Z), the author's round-2 reply (17:55:10Z; every claim checked against the code, all confirmed), and the fix commit
40a3473. LastBilledProvidercompared line by line withLastBilledPrefix(dash/keepalive.go:1944-1972): same filter, same ordering, same no-row contract.- The provider round trip:
newCapturetakes the provider as a string fromstring(provider)(proxy/dashcapture.go:232-246),bschemas.OpenAI = "openai", sobschemas.ModelProvider(p)restores the exact value.resolvePolicycompares againstbschemas.OpenAIon the same type. missAtOneHour's new subagent parameter traced to its call site:IsSubagentThread(threadID)is in scope at thekaEntryliteral, andoneHour(the 1-hour-ping plan) can never be true for a subagent, sinceLongWaitreturns false for one — so no path double-counts.- The new and changed tests read for their math and fixtures:
TestArmingReportsTheStrategyCapOnlyWhereItIsEnforced(strategy helpers and window cover "now"),TestMissIsPricedAtOneHourWhenThePolicyWritesAtOneHour(four cases, 5-minute and 1-hour formulas),TestReplayChainFollowsTheWaitPlan(K=8 and OpenAI base pins). - No new behavior change beyond those already named and decided: the subagent miss fix is a correction inside the named value rule, in the refuse-more direction.
- I did not run builds or tests. Live tests are not approved for this review.
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 @amiddaid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 | offload-review skill, @amiddaid's session | resumed | 1 of 2 | 3 of 3 | 40a3473adf73 |
approve |
Verdict: approve
Findings
None. The round-2 fix commit 40a3473a fixes my round-2 finding and reviewer 2's two round-2 notes, and it introduces no defect I can show.
Earlier findings
- My round-2 finding 1 (armedView hardcoded the Anthropic provider): fixed.
armedViewnow asksDB.LastBilledProviderfor the provider of the session's own last request and passes it toresolvePolicy(proxy/keepalivectl.go:184-190). I checked the whole chain:capture.providercomes from the handler'sbschemas.ModelProviderstring, dash stores it on the row,bschemas.OpenAIis the string"openai", so the provider read back is the one the request path used, andResolveskips the strategy layer exactly when the report now does.LastBilledProvider(dash/keepalive.go:1963) mirrorsLastBilledPrefixrow for row, so the provider comes from the same latest row whose modelworstCaseshows. The new testTestArmingReportsTheStrategyCapOnlyWhereItIsEnforcedcovers both directions: an Anthropic session reports the strategy's 0.40, an OpenAI session reports no cap. All helpers it uses exist (setStrategies,mgrFixture.record,TargetAll, the all-day window). - Reviewer 2's round-2 note (a subagent under
OneHourAlwayspriced its miss at the 1-hour rate): fixed.missAtOneHournow takes the subagent flag and keepsOneHourAlwaysmain-thread only (keepalive/keeper.go:1306). The premise is right: under C a subagent is never relabelled and keeps the 5-minute cache (keepalive/onehour.go:497, 505-506), whileHeadTTL1hasks for the 1-hour tier on every request, subagents included — the fix keeps that one at 1 hour. The extended test covers all four combinations. - My round-2 non-blocking note (the replay-chain test restated its definition): fixed.
TestReplayChainFollowsTheWaitPlannow pins the two behaviors that can fail: K=8 on a tool wait and the base K=2 on an OpenAI row. - My round-2 non-blocking note (the "-1 replaces" branch is hand-reachable only): kept by the author, with the test documenting it. The reason is right: the branch is harmless and the API refuses negatives anyway. Accepted.
- Owner decisions (comment at 17:54:33Z): checked against the code. Refuse-don't-trim matches
PingVerdict(it returnsVerdictNotWorth, never a trimmed count). A strategy's 0 leaving the account cap matchesApplyStrategy. Round 3 was granted for the provider fix — this review is that round. The merge yes stays with the integrator session.
Non-blocking
- proxy/keepalivectl.go:186-190 — when the session has no request row, or the dashboard read fails,
armedViewfalls back to Anthropic and may state a strategy cap that an OpenAI session would not enforce. The code comment names the fallback. A session with no rows has nothing to ping yet (the turn gate), so the window is small. - Process: the merge yes for the behavior change is still open. The owner says it is given in the integrator session (comment at 17:54:33Z). Merge must wait for it (RELEASING.md).
What I checked
- Last review: round 2, 570df56, 2026-11-25T17:45:15Z.
- New commits read: 1 — 40a3473 "fix(keepalive): round 2 review fixes for the ping value rule (#1420)". Full diff read, plus the code around each change.
- Read in full: 4 reviews, 2 comments, 0 inline comments (from the three files
.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-2 review (17:42:49Z, approve; its two non-blocking notes are both fixed in 40a3473 — I verified both myself), the owner-decisions comment (17:54:33Z; each decision checked against the code, see above), the author's round-2 reply (17:55:10Z; every claim checked), and commit 40a3473 (reviewed as a first review).
LastBilledProvider: query shape,ErrNoRowshandling and theFiltermatchLastBilledPrefixexactly. The provider string round-trips: the proxy'scapture.provideris thebschemas.ModelProviderstring of the request,dash.Event.Providerstores it, and the comparison inresolvePolicyWindowsis againstbschemas.OpenAI("openai").missAtOneHour's subagent premise:OneHourAlwaysrelabels main threads only (onehour.go:497), subagents are never relabelled (onehour.go:505-506),HeadTTL1hhas no thread restriction. The test's four cases match.- The renamed
TestReplayChainFollowsTheWaitPlan: both assertions can fail on a real regression; the circular property is gone. - The new arm test's fixture wiring:
setStrategiesswaps under lock,mgrFixture.recordsets tenant and session, the strategy's target mode and window constants exist. - No builds or tests were run (live tests not approved).
The flat $0.50 per-ping cap blocked GPT-5.5 pings above about 500K tokens after #1407. Such a ping saves 9x to 11x its cost. - Value rule: allow the planned pings of one idle span when they cost less than one miss (prefix x (write rate - read rate)), both priced at the tier of the prompt size. Live keeper and replay call one function, Policy.PingVerdict. - keepalive_max_usd_per_ping is now an opt-in flat cap on top. The loader no longer fills 0.50 and no strategy sets it. - Summary and sweep calls keep their $0.50 default cap. - New reason "not worth it". "over budget" now means the operator cap. - keepalive.PingPrompt replaces the proxy's own prefix + 1 sum. Fixes #1420 Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
- A manager strategy's flat cap of 0 now leaves the account's own cap in place. Only a value other than 0 replaces it. - The strategy form says 0 = no flat cap. - A miss is priced at the 1-hour write rate when the policy writes at 1 hour (HeadTTL1h, OneHourAlways) or plans the 1-hour ping. - Replay weighs the miss at the ping's tier and the live wait-plan count (never more than live). The replay-versus-live test now goes through a real keeper. - The arm answer reports the effective cap after the manager strategy. - Fix stale comments and the OpenAI write-rate sentence. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
- The arm answer resolves the policy with the provider of the session's own last request, so the manager strategy cap is reported only where it is enforced (not on an OpenAI session). - A subagent keeps the 5-minute cache under OneHourAlways, so its miss is priced at the 5-minute rate. - Replace the replay chain test that restated its own definition with a pin on the K=8 tool wait and the OpenAI base count. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
40a3473 to
1239741
Compare
Round 3: both approve. Commits re-signed.
Local tests: waived (owner rule) |
chore(plugins): bump the plugin versions for v0.7.10 - Claude Code plugin: 0.7.9 -> 0.7.10 (#1428: "not worth it" reason for a skipped ping chain; #1461: shows "saving pending" for a ping) - Codex: 0.2.14 -> 0.2.15 (#1428: "not worth it" reason; cgcache test clock) - OpenCode: PINNED_VERSION v0.7.9 -> v0.7.10 (index.js, README, install how-to, tests). The new installer holds no proxy version. - Pi 0.1.8 and Bob 0.1.3: unchanged (no change since v0.7.9) Release bump for v0.7.10. docs(scripts): the cortex-with-cg.sh examples name v0.7.10 A review note on #1511. Comment lines only. Release bump for v0.7.10. Part A, heavy CI and the release dry run passed on 17e5633 except TestCGScriptsAreVendoredIntoCodex, fixed by #1518; the plugin step passed again on 97faea9 (one load flake, TestProjectThenUserScopeKeepsTwoPorts, passed 3 of 3 on a re-run). Part B passed 7 of 7. Owner: "notes are ok". Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
BEHAVIOR CHANGE: needs the owner's yes before merge
not worth it. A flat cap exists only if the operator setskeepalive_max_usd_per_ping.keepalive_max_usd_per_ping: 0.5in the account'scache:block. The flat cap applies again, on top of the value rule. An old strategy file that wrote 0.5 keeps that cap.Local tests: waived (owner rule)
Fixes #1420
Summary
keepalive.Policy.PingVerdict, decides. The live keeper, the manual Ping button and the replay all call it.What changed
keepalive/value.go(new):PingVerdict,MissUSD,PingCap.keepalive/keeper.go: the entry keepsmissUSD.pingable()and the record-time reasons use the verdict.PingPromptis exported.keepalive_max_usd_per_ping.campaign/replay.go,campaign/adapt.go) uses the same verdict, with the row's stake as the miss.proxy/keepalivectl.gouseskeepalive.PingPrompt(the cleanup) and reportsmax_usd_per_pingonly when the operator set one.not worth itadded to the plugin (TS and bothcg.pycopies), the dashboard text and the docs.Answers to the issue's questions
Policy.MaxPings). It is 1 when none is planned, and for a manual press. The cost: a long tool wait (K up to 8) on a small-margin prefix can now be refused where one ping would pass. Keep-alive never ends a chain early once the rule passes.PingState). The dashboard database has no column for it. Local databases are too small to estimate: thecg2database has 33 rows, all under 100K tokens. Only a totalskippedcounter exists. An operator can read the live reasons fromGET /api/cachestate(ping_reason) and countover budgetbefore andnot worth itafter.Miss / ping cost ratio, and where the rule refuses
Priced with the real
projectedPingUSD(output budget included) andprojectedMissUSD, in a throwaway test that is not committed.Price assumptions per million tokens: Sonnet $3 input and $15 output; GPT-5.5 $5 input, $0.50 read, $30 output; GPT-5.6 $4 input and $0.40 read (from the issue), output assumed at $24 (6x input). The repo has no real GPT-5.6 price.
No default planned chain is refused. Only an operator who raises K by hand to 24+ on Anthropic or 9+ on OpenAI can get a refusal, and the chain is then refused, not trimmed. The default maximum is K=8 (tool wait). On OpenAI K=8 would pass with under 10% margin.
How it was tested
macOS, Go 1.27.4.
go build ./...,go veton the changed packages.go testonkeepalive,campaign,config,tenant,dash,proxy(all ok).-race -runon the new tests (ok).go test ./proxydid not compile onorigin/mainuntil test(proxy): pass the prompt-size price callback in the predictive agent test #1426. I merged main (commit 6482789). Plaingo test ./proxy/ ./keepalive/ ./campaign/andgo vet ./...pass.claude plugin test context-guru-plugin: 128 pass.not worth it; an explicit cap refuses; no cap is not a cap; unpriced and unknown-miss pings pass; 1-hour miss uses the 2x write rate; Record path holds the $0.60 ping; replay and live agree on a grid.Data dependence
None. The rule reads prices, token counts and the planned ping count. No stored customer data. No row in
docs/data-dependence.mdchanges. Level off, metadata only, everything: the same.Open questions
max_usd_per_ping: 0.5keep it as an explicit cap. Clear it where the operator wants the value rule alone.Policy.Ceiling). They cost more than a ping, so I did not remove their cap without a yes.Technical notes
Price.At(prefix + 1). On OpenAI the write rate is the input rate (CacheWrite5mFor).MaxUSDPerPing > 0. Zero is unset, negative is "no cap", as before. The loader's fill of 0.50 is removed, so a set value is always the operator's. This follows the existing zero-means-unset pattern. A pointer would have changed the stored tenant schema.HeadTTL1h;OneHourAlwayson a main thread, since a subagent keeps the 5-minute cache) or plans the 1-hour ping. This is the cautious side.DB.LastBilledProvider), so a manager strategy's cap is reported only where it is enforced. Strategies do not apply to OpenAI.TestReplayDecidesLikeTheLiveKeeperruns a real keeper.