Repository navigation
fix(keepalive): let the cost cap decide for large bodies (#1100) - #1102
Conversation
… memory guard The keeper refused any body over 8 MiB. Bytes are a poor proxy for cost: images and escaped text are big in bytes and cheap in tokens. The per-ping cost cap already refuses an expensive ping. - Raise the per-body memory guard from 8 MiB to 32 MiB (a quarter of MaxBytes). evictLocked keeps the total within MaxBytes. - Add Policy.MaxBodyBytes and config keepalive_max_body_bytes. 8388608 restores the old limit. Fixes #1100. Assisted-By: Claude Opus 5.5 <[email protected]> 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.322 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 84c8b680ac20 |
blocking |
Verdict: blocking
Findings
- cmd/context-guru-proxy/main.go:1227 — the parked-block policy drops
MaxBodyBytes, so the off-switch the PR names does not work where the new behavior can still appear.- What fails: an account with
keepalive: falsegets the early-returnplan, which sets noMaxBodyBytes. That is the Go proxy's default state. On such an account, a manual hold (thex-context-guru-pingheader), a manager strategy, a session override or a campaign can still arm holds. Each hold then readsPolicy.BodyLimit()= 32 MiB, not the operator'skeepalive_max_body_bytes: 8388608. So the PR's "how to turn it off" is inert for every parked account, in single-tenant mode (main.go:716) and hosted mode (main.go:1168,buildTenantConfig→cachePolicy). - Proof:
cachePolicyreturnsplanat main.go:1216–1229, before the literal that setsMaxBodyBytes: r.KeepAliveMaxBodyBytes(main.go:1243).Recordreaches the size check with a ManualHold-only policy (keepalive/keeper.go:822 passes becauseManualHoldis set, then keeper.go:863).BodyLimit()maps 0 toMaxBodyBytes= 32 MiB (keepalive/types.go:266–271). The strategy, override and campaign layers all copy the struct and keep the field (proxy/keepalivestrategy.go:146–158, proxy/keepaliveoverride.go:179–199, proxy/predictive.go:431–457), so the only place it goes missing is the parked plan. The file's own rule carries the wait-plan fields on every parked policy for exactly this reason: "a manager strategy can switch the keep-alive on for an account whose own block has it off" (main.go:1212–1215).MaxBodyBytesis the same kind of field: a guard that never turns anything on. (MaxUSDPerPinghas the same pre-existing hole; this PR adds a new key into the same trap.) - Fix: set
MaxBodyBytes: r.KeepAliveMaxBodyBytesonplantoo. Add acachePolicytest in the shape ofTestCachePolicyCarriesTheWaitPlan(cmd/context-guru-proxy/terminal_tools_test.go:41) that pins the key on both the parked and the enabled path. No test today covers the new wiring line at main.go:1243; dropping it would fail nothing.
- What fails: an account with
Non-blocking
- Stale comments after the raise: keepalive/manualhold_test.go:165 says "over 8 MiB" (the limit is now 32 MiB); keepalive/keeper_test.go:678–679 says a big body "must not spend a fifth of the whole memory budget" (32 of 128 MiB is a quarter).
config.DefaultKeepAliveMaxBodyBytes(config/config.go:273) duplicateskeepalive.MaxBodyByteswith no test tying them together.DefaultMaxUSDPerPinghas one (TestTheProxysPingCeilingDefaultMatchesTheConfigLoaders). If they drift, YAML-0 and a direct zeroPolicydisagree.- The PR's mutation note says "the cost check runs at record time, before the size check". In the code the size check runs first (keeper.go:863 vs keeper.go:1004). The cost-cap test survives the 8 MiB mutation only because a door refusal without
ManualHoldrecords no reason, and the button then reports "no entry". Coverage is still sound:TestABodyOver8MiBUnderTheCostCapIsPingedpins the door itself. padBodyin keepalive/bodylimit_test.go duplicates thepadhelper in keepalive/manualhold_test.go:160.- Under a full 128 MiB budget,
evictLockeddrops the newest entry and records no reason, so the Ping button reports "no entry" for a thread memory pressure just refused. Pre-existing policy, but now reachable with 4 large threads where before it took 16.
What I checked
- The full diff (8 files) and the code around each change:
Keeper.Record's gate order,evictLocked,evictManualLocked,pingable,Policy.ForOneHour,BodyLimit,Ceiling. - Every policy layer between config and
Record:applyStrategyWindows,overrideFor,overrideForOpenAI,predDecision.apply,ForOneHour. All copy the struct, soMaxBodyBytessurvives each.BodyLimitis read only at keeper.go:863, so later policy resets (keeper.go:1024) cannot change a hold's limit. - The memory story: per-body 32 MiB, per-tenant manual cap 32 MiB (
ManualHoldMaxBytesPerTenant), global 128 MiB with eviction after every insert (keeper.go:1036, 1044). The new tests' arithmetic checks out (4 near-limit bodies fit, the 12-body run stays insideMaxBytes). - The config path:
Resolved,validate, and the dashboard form —ApplyFormleaves stored keys the form does not state alone (config/form.go:414–440), so a YAML-setkeepalive_max_body_bytessurvives a settings save. - The new tests against the paths they pin: turn counts from
recordOne/recordHold, the unpriced default fake vssetPrices,padBodybyte arithmetic. docs/data-dependence.md: the keeper's body hold is already documented ("Keep-alive pings" row). A size change adds no new data dependence. I agree with the PR's statement.- The behavior change (8 → 32 MiB default) is named at the top of the PR with the off-switch, as RELEASING.md requires. I did not read the PR conversation (round 1), so I cannot confirm the owner's yes. The integrator must hold it before merge.
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.322 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 84c8b680ac20 |
blocking |
Verdict: blocking
The mechanism is sound. I traced the gate order, the eviction paths and the policy chain; they hold. The defects are around the change: stale docs, a rollback switch that does not reach one path, a guard that is silent without prices, and one loose test.
Findings
-
docs/how-to/cache-keepalive.md:278 — the doc this PR edits still states the old 8 MiB limit, twice, beside the new one
- What fails: a reader of the file the PR changes sees two limits. Line 65 (added by this PR) says 32 MiB. Lines 278 and 304 still say 8 MiB.
- Proof: line 278: "It is up to 8 MiB of that session's last request". Line 304: "a single body over 8 MiB is not held". The code now holds up to
MaxBodyBytes = 32 << 20(keepalive/types.go:256). The same stale figure is in docs/dashboard.md:319 ("the body is over 8 MiB") and :335 ("8 MiB per body"), and in the code comment at keepalive/keeper.go:91 ("up to 8 MiB of the user's conversation"). - Fix: update all five places to the new limit and name
keepalive_max_body_bytes. The "What is held in memory" section is the privacy statement of what content the service holds; it now understates it 4x.
-
cmd/context-guru-proxy/main.go:1227 — the documented rollback switch is dropped on the parked policy path
- What fails: a config with
keepalive: falseandkeepalive_max_body_bytes: 8388608still holds a manual hold (the ping header) up to 32 MiB. The PR's "How to turn it off" does not restore the old limit there. - Proof:
cachePolicyreturnsplanat line 1228 when!c.KeepAlive && !c.HeadTTL1h, andplancarries noMaxBodyBytes.Policy.MaxBodyBytesstays 0, soBodyLimit()returns the 32 MiB default (keepalive/types.go:268-269). The size gate readspol.BodyLimit()(keepalive/keeper.go:863) on the manual-hold path too, becausepol.ManualHoldpasses the!pol.On()check at keeper.go:822.MaxUSDPerPingis dropped the same way (pre-existing), but that drop fails safe: the ceiling falls back to the $0.50 default. This drop fails unsafe: the limit rises to 32 MiB. - Fix: put
MaxBodyByteson the parked plan too. It is a memory guard; it cannot switch anything on. Or state in the docs that the key applies only when keep-alive is on.
- What fails: a config with
-
keepalive/types.go:253 — for an unpriced model, no guard at all decides between 8 and 32 MiB
- What fails: a deployment whose price list has no entry for the model holds and pings a body of 8 to 32 MiB with no cost cap. Each ping reads the whole prefix at the provider's cache-read rate. Two pings at the defaults.
- Proof:
projectedPingUSDreturns 0 when the model is not priced (keepalive/keeper.go:1080-1089, "lets the ping through"), so the ceiling check inpingable()(keeper.go:329) passes for any size. Before this PR the 8 MiB gate refused these bodies regardless of prices. The new comment at types.go:251-255 says "the per-ping cost cap (Policy.Ceiling) decides whether a ping is worth it" — that is not true without prices. The unpriced-lets-through stance predates this PR for bodies under 8 MiB; this PR widens it 4x and names it nowhere. - Fix: name the gap in the PR and the code comment, or keep a byte ceiling when the price is unknown.
-
keepalive/bodylimit_test.go:42 — the cost-cap test does not pin the cost reason
- What fails: the test accepts any reason that is not "" and not "too large". When no reason is recorded,
PingStateMap.Forreturns "no entry" (keepalive/manualhold.go:77-81), which also passes. So the test cannot tell "refused over budget" from "refused with no reason recorded". - Proof: the assertion is
st.Reason == "" || st.Reason == ReasonTooLarge. Under the 8 MiB default mutation the size gate refuses first and records no reason (refuseat keeper.go:864 no-ops becausepol.ManualHoldis false in this test), and the test still passes through the "no entry" default. The PR's technical note explains this with a false claim: "The cost check runs at record time, before the size check". InRecordthe size gate (keeper.go:863) runs before the cost gate (keeper.go:1001-1019). - Fix: assert
st.Reason == ReasonOverBudget.
- What fails: the test accepts any reason that is not "" and not "too large". When no reason is recorded,
Non-blocking
- config/config.go:273 mirrors
keepalive.MaxBodyByteswith no pin test. The repo pins the analogousDefaultMaxUSDPerPingmirror (keepalive/types.go:298). If one constant is retuned, the proxy's default drifts from the library's. - keepalive/manualhold.go:47:
ManualHoldMaxBytesPerTenantis 32 MiB and its comment says "a few large contexts". With bodies now up to 32 MiB it is one context. A tenant's second large manual hold evicts the oldest. Worth a sentence in the PR, or a retune. - keepalive/types.go:241-245: the
MaxBytessizing rationale ("~100 KB to 1 MiB of body ... binds around 130 large sessions") is stale beside a 32 MiB per-body limit. It binds at 4 such bodies.
What I checked
- The full diff, and the code around each hunk:
Record's gate order,evictLocked,evictManualLocked,pingable,Ceiling,projectedPingUSD. - The policy chain preserves
MaxBodyBytesat every layer:applyStrategyWindows(proxy/keepalivestrategy.go:146, in place),overrideFor(proxy/keepaliveoverride.go:179, in place),predDecision.apply(proxy/predictive.go:431, in place),ForOneHour(keepalive/types.go:198, value copy). - The new tests, traced by hand.
recordHold's secondRecordleaves an automatic entry (turn 1, pingable), so the twelve near-limit bodies inTestTheMemoryGuardHoldsdo exerciseevictLockedandMaxBytes, not only the per-tenant manual cap. The other assertions match the traced behaviour. - Config:
Resolvedandvalidate; the settings-form merge (config/form.go:431-440) leaves stored keys it does not model alone, so a YAML-set key survives a form save. - The PR body: the behavior change is named at the top, with old and new behavior and the off-switch, as CLAUDE.md requires.
docs/data-dependence.mdneeds no row change; the keep-alive row names no byte figure. I agree with the PR on that. - Fail-open: the change touches a refusal gate and config plumbing only. No error path or fallback changed.
- I did not run tests (not approved) and did not read the other review or the PR comments.
…n a parked block - An unpriced model has no cost cap to judge a big body, so the old 8 MiB limit stays for it. - cachePolicy now carries MaxBodyBytes on the parked-block policy, so the 8 MiB switch holds there too. - Fix the stale 8 MiB figures in docs and comments. - The cost-cap test pins the over-budget reason. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
|
Round 1 fixes are in the new head.
Non-blocking: added a pin test for the config default against |
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.322 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | c1c85e0b0874 |
approve |
Verdict: approve
All four of my round-1 findings are fixed, and reviewer 1's finding is fixed the same way. The new clamp is correct in every corner I could construct. I found no new defect in the new commit.
Findings
None.
Status of earlier findings
Mine, round 1:
- Stale 8 MiB figures — fixed. cache-keepalive.md:278 and :304, dashboard.md:319 and :335, and keeper.go:91 all state the new limit and name
keepalive_max_body_bytes. The stale test comment and theMaxBytessizing note are fixed too. - Rollback switch dropped on the parked path — fixed.
cachePolicynow setsMaxBodyByteson the parked plan (main.go:1223-1224).TestCachePolicyCarriesTheBodyLimitcovers parked and enabled, default and 8 MiB switch. - No guard for unpriced models — fixed. The size gate now falls back to
LegacyMaxBodyByteswhen the projected ping cost is 0 (keeper.go:864-871): no price for the model, or no usage to size the prefix. This restores the pre-#1100 refusal for exactly the case the cost cap cannot judge. The PR body names it (lines 5 and 35). Traced by hand:- Unpriced, 9 MiB, manual hold → refused
too large. Unpriced, 7 MiB → held. (TestAnUnpricedModelKeepsThe8MiBLimit.) - Priced cheap (1e-6), 9 MiB → held and pinged; the clamp does not fire because the projection is above 0. (
TestABodyOver8MiBUnderTheCostCapIsPinged, now with prices.) - Priced expensive, 9 MiB → passes the size gate, refused
over budgetat the cost gate. (TestABigBodyOverTheCostCapIsStillRefused.) - An operator-set limit of exactly 8 MiB skips the clamp (
limit > LegacyMaxBodyBytesis strict) and refuses at the gate anyway. Same result. - A priced model with zero cache-read and output rates projects 0 and gets the 8 MiB clamp. That ping would cost $0 at those rates, so the clamp only refuses a free ping. Conservative, harmless.
- A price list that loads late refuses large bodies until it loads. Safe direction: a lost hold, not an unbounded ping.
- Unpriced, 9 MiB, manual hold → refused
- Cost-cap test did not pin the reason — fixed. The test now uses a manual hold and asserts
ReasonOverBudgetexactly. The PR's false gate-order claim is gone from the body.
Reviewer 1, round 1: the parked-path finding is my #2, fixed. Of the non-blocking items: the manualhold_test.go comment, the config-default pin test (TestTheConfigBodyLimitMirrorsTheLibrary) and the PR-text correction are done. The author deferred ManualHoldMaxBytesPerTenant to the owner's call, with a correct statement of what it does. I accept that deferral.
Non-blocking
- keepalive/keeper_test.go:678-679 still says a multi-million-token request "must not spend a fifth of the whole memory budget". 32 of 128 MiB is a quarter. Reviewer 1 named this in round 1; it is the one stale figure the fix commit missed.
padBody(bodylimit_test.go) still duplicatespad(manualhold_test.go). Reviewer 1's round-1 note, trivial.
What I checked
- Last review: round 1, 84c8b68, 2026-11-11T18:30:59Z.
- New commits read: 1 — c1c85e0 "fix(keepalive): keep 8 MiB for unpriced models, wire the body limit on a parked block". Full diff read, plus the code around each hunk.
- Read in full: 2 reviews, 1 comment, 0 inline comments (the inline file is empty), and the current PR body.
- New items since my last review: the fix commit (reviewed above); the author's comment at 2026-11-11T18:37:18Z (each claim checked against the diff — all four hold); the updated PR body (the unpriced rule is named, the false gate-order claim is removed).
- The new clamp against the gates around it: it runs after the route-breaker gate and before
eligible(), uses the same prefix and the sameDispatcher.Pricecall the later cost projection uses, and applies to manual and automatic holds alike. No path holds more than before #1100 without a price backing it. - The new tests traced by hand, including the price setup each now needs: without
setPrices, the memory-guard test's twelve near-limit bodies would hit the unpriced clamp and the test would fail — the cheap prices are load-bearing, and they are there. - No import cycle:
configdoes not importkeepalive, so the new test import compiles. - I did not run 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.322 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | c1c85e0b0874 |
blocking |
Verdict: blocking
Earlier findings
- Mine, parked path (
cachePolicydropsMaxBodyBytes): fixed. The parkedplannow carriesMaxBodyBytes: r.KeepAliveMaxBodyBytes(cmd/context-guru-proxy/main.go:1222-1223), with the comment stating the reason.TestCachePolicyCarriesTheBodyLimitpins the default and the 8 MiB switch on the parked and the enabled path. All three return paths out ofcachePolicy(parked, head-TTL-only, enabled) now carry the field; I traced each. - Reviewer 2, finding 1 (stale 8 MiB figures): fixed.
docs/how-to/cache-keepalive.md(2 places),docs/dashboard.md(2 places), thekeeper.go:91comment and theMaxBytessizing note intypes.goall name the new limit. One stale figure survives, see Non-blocking. - Reviewer 2, finding 2 (parked path): fixed, same change as mine.
- Reviewer 2, finding 3 (unpriced model, no guard between 8 and 32 MiB): fixed, the stronger way.
Recordnow clamps the limit toLegacyMaxBodyByteswhen the projected ping cost is 0 (keeper.go:866-870): no price, or no usage to size the prefix. I traced the clamp: it fires only when the policy limit is above 8 MiB and the body is above 8 MiB, so an operator's explicit 4 MiB limit is untouched, and a priced model keeps the 32 MiB limit.TestAnUnpricedModelKeepsThe8MiBLimitpins both sides. The PR body names the rule in the behavior-change section. The conservative direction is right: without a price the cap cannot judge, so the old limit stays. - Reviewer 2, finding 4 (cost-cap test does not pin the reason): fixed. The test now uses a manual hold and asserts
ReasonOverBudgetexactly. Under the 8 MiB mutation the size gate recordstoo large(therefuseclosure runs becauseManualHoldis set), so the test is now mutation-sensitive. The PR's false gate-order note is gone from the PR body. - Reviewer 2, non-blocking (
ManualHoldMaxBytesPerTenantunchanged): accepted. The author left it for the owner's call and said so. It is a tuning question, not a defect.
Findings
- keepalive/manualhold_test.go:181-191 — the new unpriced clamp made the "bytes" section of
TestManualHoldRespectsTheBodyEntryAndByteCapsvacuous, and nothing replaced its coverage.- What fails: the section records 20 manual-only holds of ~32 MiB bodies with
offPolicyand the default unpriced fake, then assertsk.bytes <= MaxBytes. Since commit c1c85e0, the clamp at keeper.go:866-870 refuses every one of those bodies at the door (no price → projected cost 0 → limit 8 MiB). Nothing is held,k.bytesstays 0, and the assertion passes on an empty map. Before this commit the section exercisedevictManualLockedwith near-limit bodies. The test still passes, so the loss is silent. - Proof:
big := pad(MaxBodyBytes - 4096)is ~32 MiB, overLegacyMaxBodyBytes.recordHoldusesoffPolicyandtestKeeper's fake has no prices, sok.projectedPingUSDreturns 0 and the clamp setslimit = LegacyMaxBodyBytes. The remaining coverage of the manual byte cap uses 6 MiB bodies (TestAManualFloodByBytesEvictsThatTenantsOldestHoldFirst, manualhold_test.go:426), which pass the door.TestTheMemoryGuardHoldspart 2 covers only the automatic path (kaPolicyis on, so the entry is notmanualOnly). No test now holds a manual-only entry with a body over 8 MiB, which is exactly the admission this PR changes. - Fix: in that section, build the keeper and call
fd.setPrices(...)with the cheap 1e-6 price asTestTheMemoryGuardHoldsnow does. The bodies then pass the door (projected ~$0.05, under the default $0.50 ceiling) and the per-tenant cap is exercised again.
- What fails: the section records 20 manual-only holds of ~32 MiB bodies with
Non-blocking
- keepalive/keeper_test.go:678-679: the comment still says a big body "must not spend a fifth of the whole memory budget". With the 32 MiB limit it is a quarter of 128 MiB. Carried from round 1, still unfixed.
padBody(bodylimit_test.go) still duplicatespad(manualhold_test.go:160). Carried from round 1.
What I checked
- Last review: round 1, 84c8b68, 2026-11-11T18:30:44Z
- New commits read: 1 — c1c85e0 "fix(keepalive): keep 8 MiB for unpriced models, wire the body limit on a parked block"
- Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files; the inline file is empty)
- New items since my last review, and what I did about each:
- Reviewer 2's round-1 review (18:30:59): read in full; each of its four findings checked against the fix commit above.
- The author's comment (18:37): read; each claimed fix verified in the diff, except the vacuous-test gap above, which the fix introduced.
- Commit c1c85e0: full diff read, plus the code around each hunk.
- The updated PR body: read; the unpriced rule and the corrected mutation notes match the code.
- The clamp at keeper.go:866-670 traced against its callers' states: priced model (no clamp), unpriced model (8 MiB), no usage (8 MiB), explicit operator limit below 8 MiB (untouched), exactly-8 MiB body (held, same
>comparison as before). The reason shown for an unpriced, ineligible, oversized body changes fromunsupportedtotoo large; cosmetic. - The new tests traced by hand:
TestCachePolicyCarriesTheBodyLimit(bothcachePolicypaths),TestAnUnpricedModelKeepsThe8MiBLimit(turn counts, pingable gates), the rewrittenTestABigBodyOverTheCostCapIsStillRefused(mutation-sensitive now), thesetPricesadditions toTestABodyOver8MiBUnderTheCostCapIsPingedandTestTheMemoryGuardHolds(needed, or the clamp would refuse those bodies), andTestTheConfigBodyLimitMirrorsTheLibrary(no import cycle:configimportscomponentsandinternal/modelinfo, notkeepalive). - The other tests that touch the limit, re-traced under the clamp:
TestOversizedBodyIsNotHeldstill refuses (body over 32 MiB),TestManualOnlyEntriesAreEvictedBeforeAutomaticOnesunaffected (tiny bodies),TestAManualFloodByBytesEvictsThatTenantsOldestHoldFirstunaffected (6 MiB bodies) — andTestManualHoldRespectsTheBodyEntryAndByteCapspart 3 went vacuous, the finding above. - Fail-open and cache strategy: the change touches a refusal gate, config plumbing and tests only. No request path, no ping body, no cache-entry renewal changed.
The unpriced 8 MiB clamp made the bytes section of TestManualHoldRespectsTheBodyEntryAndByteCaps vacuous: the bodies never reached the per-tenant byte cap. Set a price, and assert the per-tenant cap. Fix a stale "fifth" in a comment. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
|
Round 2 fix is in the new head.
|
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.322 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 3 of 3 | 5afd47978367 |
approve |
Verdict: approve
Findings
None.
Status of earlier findings
- Mine, round 2 (vacuous "bytes" section of
TestManualHoldRespectsTheBodyEntryAndByteCaps): fixed. The section now sets the cheap price (manualhold_test.go:183), so the ~32 MiB bodies pass the door and the per-tenant byte cap is what acts. I traced it: one body is ~33,550,826 bytes, under the 32 MiB cap, so exactly one entry survivesevictManualLocked;bytes > 0andbytes <= ManualHoldMaxBytesPerTenantboth hold. The newbytes == 0guard (manualhold_test.go:191-193) also fails the test if the section ever goes vacuous again. The author's mutation figure matches my trace: with the per-tenant check removed, the global 128 MiB cap holds four bodies, 134,203,076 bytes, over the 32 MiB assertion. - Mine, rounds 1-2, non-blocking (stale "a fifth of the budget" comment): fixed (keeper_test.go:679 now says "a quarter").
- Mine, non-blocking (
padBodyduplicatespad): declined by the author as trivial. I accept that; it is a test-helper duplication. - All round-1 findings (mine and reviewer 2's four): fixed in c1c85e0, verified in round 2. Nothing in the new commit touches those fixes.
ManualHoldMaxBytesPerTenantretune: deferred to the owner, now answered. The PR body records the owner's yes of 2026-11-11 ("approve the behavior change") and states the owner kept the per-tenant cap as it is, with #1103 tracking it. That closes the open question from rounds 1 and 2.
Non-blocking
- The
padBody/padduplication stands, by the author's choice.
What I checked
- Last review: round 2, c1c85e0, 2026-11-11T19:08:04Z
- New commits read: 1 — 5afd479 "test(keepalive): price the manual-hold byte-cap section so the cap acts"
- Read in full: 4 reviews, 2 comments, 0 inline comments (from the three files; the inline file is empty)
- New items since my last review, and what I did about each:
- Reviewer 2's round-2 review (19:07:00, approve): read in full. Its traces of the clamp's corners match mine from round 2. It missed the vacuous test; no conflict with my round-2 finding.
- My own round-2 review (19:08:04): re-read for the finding status above.
- The author's comment (19:14:02): read; each claim checked against the diff — the fix, the mutation output and the owner's yes all hold.
- Commit 5afd479: full diff read (2 files, test-only), plus the whole test function around the change.
- The fixed test traced end to end:
offPolicy+ManualHold+ prices 1e-6 → projected ~$0.05, no clamp, no ceiling refusal → manual-only entries held;evictManualLockedbounds tenant "t1" at one ~32 MiB body. The:=redeclaration ofkandclockbeside the newfdis legal Go (one new variable on the left). - The PR body: the owner's yes is recorded with its date and quote, and #1103 tracks the per-tenant cap question. RELEASING.md's requirement is met at the PR level; the integrator still quotes the yes in the squash-merge body.
- The cumulative diff base..HEAD re-checked for anything I had not seen: rounds 1-3 diffs together cover all of it; the new commit changes no production code.
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.322 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 3 of 3 | 5afd47978367 |
approve --> |
Verdict: approve
The new commit is test-only plus one comment fix. Reviewer 1's round-2 finding is fixed, and I verified the fix independently. Nothing is left open except one trivial duplication the author declined.
Findings
None.
Status of earlier findings
- Reviewer 1, round 2 (vacuous bytes section of
TestManualHoldRespectsTheBodyEntryAndByteCaps): fixed, and the finding was right. I checked it myself before reading the fix: at head c1c85e0, that section recorded 20 manual holds of ~32 MiB bodies with no prices, so the unpriced clamp refused every body at the door and thek.bytes <= MaxBytesassertion passed on an empty map. The fix (manualhold_test.go:181-196) sets the cheap price so the bodies pass the door, assertsbytes != 0so the section cannot go vacuous again, and asserts the per-tenant capManualHoldMaxBytesPerTenantinstead of the global one. I traced it: all 20 entries aremanualOnlyunder tenant "t1",evictManualLockedleaves one ~33.55 MB entry, under the 33,554,432 cap. The author's mutation output (4 entries, 134,203,076 bytes, when the per-tenant check is removed) matches my own arithmetic: the global 128 MiB budget then holds 4 bodies and the assertion fails. The edit compiles:fdis the one new variable,kandclockare reassigned in the same scope. - My round-2 non-blocking, stale "fifth" comment: fixed. keeper_test.go:679 now says "a quarter of the whole memory budget".
ManualHoldMaxBytesPerTenant(my round-1 non-blocking): closed the right way. The PR body now records the owner's yes on 2026-11-11 and the owner's choice to keep the cap as it is, with #1103 tracking it. That is a decision with an owner and a ticket, not an open item.padBody/padduplication: not done, by the author's choice ("trivial"). I agree it is trivial.
Non-blocking
padBody(bodylimit_test.go) still duplicatespad(manualhold_test.go:160). Carried from round 1; the author declined it as trivial.
What I checked
- Last review: round 2, c1c85e0, 2026-11-11T19:07:00Z.
- New commits read: 1 — 5afd479 "test(keepalive): price the manual-hold byte-cap section so the cap acts". Full diff read (2 files), plus the whole test function around the change.
- Read in full: 4 reviews, 2 comments, 0 inline comments (the inline file is empty), and the current PR body.
- New items since my last review, and what I did about each:
- Reviewer 1's round-2 review (19:08:04Z): read in full. Its one finding I re-derived from the code at c1c85e0 before checking the fix — the vacuity claim holds, and the fix is correct (above). Its non-blocking notes match mine.
- The author's comment (19:14:02Z): read; each claim verified — the test fix, the "fifth" comment, and the owner's yes now in the PR body with #1103.
- Commit 5afd479: reviewed as a first review (above). Test-only; no production path changed.
- The updated PR body: the behavior-change section now leads with the owner's approval, satisfying the repo's rule that a human decides a behavior change.
- The changed test traced end to end: prices 1e-6 give a projected ping of ~$0.05, under the default $0.50 ceiling, so the manual branch holds; the clamp does not fire; the per-tenant cap is what evicts.
- I did not run tests (not approved).
Apply #1102's cachePolicy change (MaxBodyBytes on the parked and the enabled policy) to proxyapp/main_run.go, where commit 1 moved the code. cmd/context-guru-proxy/main.go stays the single proxyapp.Main call. The #1102 test moved to proxyapp/terminal_tools_test.go through the rename. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
…t hooks (#1109) The proxy's startup moves from cmd/context-guru-proxy into proxyapp.Main. A host can now run the standard proxy and add its own parts through proxyapp.Hooks, without a copy of main.go. cmd/context-guru-proxy/main.go is one call: proxyapp.Main(proxyapp.Hooks{}). Why: the IBM deployment copied our main.go to add its own parts, and missed later upstream steps (ping rows in v0.5.2; no ping saving booked since v0.7.0, MLT/cg#75; about 15 more since v0.7.2). - Commit 1: a pure move of every file of cmd/context-guru-proxy to proxyapp/ (package clause and test paths only). - Commit 2: main() becomes Main(hooks Hooks); proxyapp/hooks.go adds Hooks, Defaults and App; stampActivityThrough lets the idle-exit stamp wrap a host's handler. - CI and part-a.sh run the moved tests under ./proxyapp/. - The merge of main re-applied #1102's cachePolicy MaxBodyBytes lines in proxyapp/main_run.go; nothing from main was lost. Behavior change: none. With no hooks, Main runs the same code as the old main(). Data dependence: none. Reviews: 3 offload review rounds. Round 3 (Bob backend; GLM was down, the owner approved the fallback): both approve at 3715e43, which is the PR head and the merge of main with the hand-applied #1102 lines. The owner named this PR the release's critical fix. Signed-off-by: DAVID BOAZ <[email protected]> Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Opus 5.5 <[email protected]>
Behavior change
Approved by the owner on 2026-11-11 ("approve the behavior change"). He kept the manual-hold per-tenant cap as it is; see #1103.
too large). Every return after the cache lifetime pays a full rewrite.cache.keepalive_max_body_bytes: 8388608. This restores the old limit.Data dependence
No change. The keeper already holds the request body in memory to replay it. This change only raises the size of body it holds.
No row in
docs/data-dependence.mdchanges.Summary
The keeper refused any body over 8 MiB. That treats bytes as cost. This PR lets the cost cap decide, and keeps a byte limit only to guard memory.
What we found
On a hosted deployment, one main thread had 874,720 tokens.
too largeevery turn. It sent 0 pings in 2 days.What changed
MaxBodyBytesgoes from 8 MiB to 32 MiB. The comment now says it is a memory guard.Policy.MaxBodyBytesandPolicy.BodyLimit(). 0 means the 32 MiB default. The value is never aboveMaxBytes.keepalive_max_body_bytes(default 33554432). It is documented indocs/how-to/cache-keepalive.md. A negative value fails validation.LegacyMaxBodyBytes(8 MiB) names the old limit.cachePolicycarriesMaxBodyByteson the parked-block policy too, so the switch holds for manual holds and strategies on an account with keep-alive off.docs/how-to/cache-keepalive.md,docs/dashboard.mdand code comments.Design choice: raise the per-body limit. Do not count the body against
MaxBytesat the door.evictLockeddrops the entry with the least imminent ping whenk.bytes > MaxBytes.too large. That is the wrong reason for the user.How it was tested
Run on the box with
-race:./keepalive/...and./config/...pass.go vet ./...and./cmd/...pass.New tests (
keepalive/bodylimit_test.go,config/config_test.go):too large).too large. Twelve near-limit bodies stay withinMaxBytes.MaxBodyBytes = 8388608restores the old refusal.BodyLimit(). Default and validation of the config key.Mutation checks (each reverted, each fails):
TestABodyOver8MiBUnderTheCostCapIsPingedfails.TestTheMemoryGuardHoldsandTestTheLegacyLimitSwitchRestoresTheOldRefusalfail.TestTheLegacyLimitSwitchRestoresTheOldRefusalandTestBodyLimitDefaultsAndClampsfail.TestTheMemoryGuardHoldsfails.Added in round 1: unpriced model keeps 8 MiB (mutation: clamp removed, test fails). Parked-path wiring (mutation: line removed,
TestCachePolicyCarriesTheBodyLimitfails). The cost-cap test now pinsover budget.Technical notes
MaxBytes(128 MiB). Then eviction applies.config.DefaultKeepAliveMaxBodyBytestokeepalive.MaxBodyBytes.config/form.go). It is YAML only.proxy/is not changed. Theproxy.maxKeepAliveBodyBytesalias now shows 32 MiB.Fixes #1100.
🤖 Generated with Claude Code