Skip to content

fix(keepalive): let the cost cap decide for large bodies (#1100) - #1102

Merged
amiddavid merged 3 commits into
mainfrom
fix/1100-keeper-body-limit
Nov 11, 2026
Merged

amiddavid merged 3 commits into
mainfrom
fix/1100-keeper-body-limit

Conversation

@amiddavid

@amiddavid amiddavid commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

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.

  • Who it affects: keep-alive users whose request body is over 8 MiB. These are long sessions with images or large escaped tool output.
  • Old: a body over 8 MiB is never held and never pinged (too large). Every return after the cache lifetime pays a full rewrite.
  • New: the per-ping cost cap decides. The body is held and pinged when the cap allows. A per-body memory guard of 32 MiB stays. A model with no price keeps the 8 MiB limit, because the cost cap cannot judge it.
  • How to turn it off: set 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.

  • Keep-alive off: nothing is held. Same as before.
  • Metadata only / everything: the keeper holds the body as before. A body between 8 and 32 MiB is now held where before it was refused.

No row in docs/data-dependence.md changes.

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.

  • A ping costs $0.17. A cold rewrite costs $4.37.
  • The keeper refused it with too large every turn. It sent 0 pings in 2 days.
  • The thread came back cold 33 times.

What changed

  • MaxBodyBytes goes from 8 MiB to 32 MiB. The comment now says it is a memory guard.
  • New Policy.MaxBodyBytes and Policy.BodyLimit(). 0 means the 32 MiB default. The value is never above MaxBytes.
  • New config key keepalive_max_body_bytes (default 33554432). It is documented in docs/how-to/cache-keepalive.md. A negative value fails validation.
  • LegacyMaxBodyBytes (8 MiB) names the old limit.
  • An unpriced model (or a request with no usage) keeps the 8 MiB limit. The cost projection is 0 there, so the cap would pass any size.
  • cachePolicy carries MaxBodyBytes on the parked-block policy too, so the switch holds for manual holds and strategies on an account with keep-alive off.
  • Stale 8 MiB figures fixed in docs/how-to/cache-keepalive.md, docs/dashboard.md and code comments.
  • No change to the cost cap, the strategies, or the cache strategy. A ping still reads the same cache entry.

Design choice: raise the per-body limit. Do not count the body against MaxBytes at the door.

  • The total is already bounded. evictLocked drops the entry with the least imminent ping when k.bytes > MaxBytes.
  • The per-body limit stops one thread from taking more than a quarter of the budget.
  • Refusing at the door would turn a full budget into 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):

  • A 9 MiB body under the cost cap is held and gets a ping.
  • A 9 MiB body over the cost cap is refused, with a cost reason (not too large).
  • A body at the limit is refused as too large. Twelve near-limit bodies stay within MaxBytes.
  • MaxBodyBytes = 8388608 restores the old refusal.
  • Default and clamp of BodyLimit(). Default and validation of the config key.

Mutation checks (each reverted, each fails):

  • Default back to 8 MiB: TestABodyOver8MiBUnderTheCostCapIsPinged fails.
  • Per-body check removed: TestTheMemoryGuardHolds and TestTheLegacyLimitSwitchRestoresTheOldRefusal fail.
  • Switch ignored: TestTheLegacyLimitSwitchRestoresTheOldRefusal and TestBodyLimitDefaultsAndClamps fail.
  • Byte eviction removed: TestTheMemoryGuardHolds fails.

Added in round 1: unpriced model keeps 8 MiB (mutation: clamp removed, test fails). Parked-path wiring (mutation: line removed, TestCachePolicyCarriesTheBodyLimit fails). The cost-cap test now pins over budget.

Technical notes

  • Memory: one thread now costs up to 32 MiB. Four such threads fill MaxBytes (128 MiB). Then eviction applies.
  • A pin test ties config.DefaultKeepAliveMaxBodyBytes to keepalive.MaxBodyBytes.
  • The config key is not in the dashboard settings form (config/form.go). It is YAML only.
  • Strategies do not set the key. It is a global memory guard, not a per-strategy value.
  • proxy/ is not changed. The proxy.maxKeepAliveBodyBytes alias now shows 32 MiB.

Fixes #1100.

🤖 Generated with Claude Code

… 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 amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. 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: false gets the early-return plan, which sets no MaxBodyBytes. That is the Go proxy's default state. On such an account, a manual hold (the x-context-guru-ping header), a manager strategy, a session override or a campaign can still arm holds. Each hold then reads Policy.BodyLimit() = 32 MiB, not the operator's keepalive_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: cachePolicy returns plan at main.go:1216–1229, before the literal that sets MaxBodyBytes: r.KeepAliveMaxBodyBytes (main.go:1243). Record reaches the size check with a ManualHold-only policy (keepalive/keeper.go:822 passes because ManualHold is set, then keeper.go:863). BodyLimit() maps 0 to MaxBodyBytes = 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). MaxBodyBytes is the same kind of field: a guard that never turns anything on. (MaxUSDPerPing has the same pre-existing hole; this PR adds a new key into the same trap.)
    • Fix: set MaxBodyBytes: r.KeepAliveMaxBodyBytes on plan too. Add a cachePolicy test in the shape of TestCachePolicyCarriesTheWaitPlan (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.

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) duplicates keepalive.MaxBodyBytes with no test tying them together. DefaultMaxUSDPerPing has one (TestTheProxysPingCeilingDefaultMatchesTheConfigLoaders). If they drift, YAML-0 and a direct zero Policy disagree.
  • 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 ManualHold records no reason, and the button then reports "no entry". Coverage is still sound: TestABodyOver8MiBUnderTheCostCapIsPinged pins the door itself.
  • padBody in keepalive/bodylimit_test.go duplicates the pad helper in keepalive/manualhold_test.go:160.
  • Under a full 128 MiB budget, evictLocked drops 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, so MaxBodyBytes survives each. BodyLimit is 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 inside MaxBytes).
  • The config path: Resolved, validate, and the dashboard form — ApplyForm leaves stored keys the form does not state alone (config/form.go:414–440), so a YAML-set keepalive_max_body_bytes survives a settings save.
  • The new tests against the paths they pin: turn counts from recordOne/recordHold, the unpriced default fake vs setPrices, padBody byte 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 amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. 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.
  2. cmd/context-guru-proxy/main.go:1227 — the documented rollback switch is dropped on the parked policy path

    • What fails: a config with keepalive: false and keepalive_max_body_bytes: 8388608 still 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: cachePolicy returns plan at line 1228 when !c.KeepAlive && !c.HeadTTL1h, and plan carries no MaxBodyBytes. Policy.MaxBodyBytes stays 0, so BodyLimit() returns the 32 MiB default (keepalive/types.go:268-269). The size gate reads pol.BodyLimit() (keepalive/keeper.go:863) on the manual-hold path too, because pol.ManualHold passes the !pol.On() check at keeper.go:822. MaxUSDPerPing is 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 MaxBodyBytes on 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.
  3. 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: projectedPingUSD returns 0 when the model is not priced (keepalive/keeper.go:1080-1089, "lets the ping through"), so the ceiling check in pingable() (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.
  4. 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.For returns "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 (refuse at keeper.go:864 no-ops because pol.ManualHold is 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". In Record the size gate (keeper.go:863) runs before the cost gate (keeper.go:1001-1019).
    • Fix: assert st.Reason == ReasonOverBudget.

Non-blocking

  • config/config.go:273 mirrors keepalive.MaxBodyBytes with no pin test. The repo pins the analogous DefaultMaxUSDPerPing mirror (keepalive/types.go:298). If one constant is retuned, the proxy's default drifts from the library's.
  • keepalive/manualhold.go:47: ManualHoldMaxBytesPerTenant is 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 MaxBytes sizing 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 MaxBodyBytes at 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 second Record leaves an automatic entry (turn 1, pingable), so the twelve near-limit bodies in TestTheMemoryGuardHolds do exercise evictLocked and MaxBytes, not only the per-tenant manual cap. The other assertions match the traced behaviour.
  • Config: Resolved and validate; 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.md needs 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]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Round 1 fixes are in the new head.

  1. Parked path (both reviewers): cachePolicy now sets MaxBodyBytes on the parked plan. New test TestCachePolicyCarriesTheBodyLimit covers the default and the 8 MiB switch, parked and enabled. Mutation (line removed) fails it.
  2. Stale docs: fixed in docs/how-to/cache-keepalive.md (2 places), docs/dashboard.md (2 places) and the keeper.go comment. Also fixed the stale test comment and the MaxBytes sizing note.
  3. Unpriced model: the gate keeps the 8 MiB limit when the projected ping cost is 0 (no price, or no usage). Tests: unpriced 9 MiB is refused as too large, 7 MiB is held. Mutation (clamp removed) fails it. The PR text names this.
  4. Cost-cap test: it now uses a manual hold and asserts over budget. The old note about gate order was wrong. The size gate runs first. The PR text is corrected.

Non-blocking: added a pin test for the config default against keepalive.MaxBodyBytes.
Not done: ManualHoldMaxBytesPerTenant (32 MiB) is unchanged. A tenant's second large manual hold evicts the oldest. This needs the owner's call.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  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 the MaxBytes sizing note are fixed too.
  2. Rollback switch dropped on the parked path — fixed. cachePolicy now sets MaxBodyBytes on the parked plan (main.go:1223-1224). TestCachePolicyCarriesTheBodyLimit covers parked and enabled, default and 8 MiB switch.
  3. No guard for unpriced models — fixed. The size gate now falls back to LegacyMaxBodyBytes when 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 budget at the cost gate. (TestABigBodyOverTheCostCapIsStillRefused.)
    • An operator-set limit of exactly 8 MiB skips the clamp (limit > LegacyMaxBodyBytes is 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.
  4. Cost-cap test did not pin the reason — fixed. The test now uses a manual hold and asserts ReasonOverBudget exactly. 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 duplicates pad (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 same Dispatcher.Price call 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: config does not import keepalive, so the new test import compiles.
  • I did not run tests (not approved).

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (cachePolicy drops MaxBodyBytes): fixed. The parked plan now carries MaxBodyBytes: r.KeepAliveMaxBodyBytes (cmd/context-guru-proxy/main.go:1222-1223), with the comment stating the reason. TestCachePolicyCarriesTheBodyLimit pins the default and the 8 MiB switch on the parked and the enabled path. All three return paths out of cachePolicy (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), the keeper.go:91 comment and the MaxBytes sizing note in types.go all 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. Record now clamps the limit to LegacyMaxBodyBytes when 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. TestAnUnpricedModelKeepsThe8MiBLimit pins 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 ReasonOverBudget exactly. Under the 8 MiB mutation the size gate records too large (the refuse closure runs because ManualHold is 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 (ManualHoldMaxBytesPerTenant unchanged): accepted. The author left it for the owner's call and said so. It is a tuning question, not a defect.

Findings

  1. keepalive/manualhold_test.go:181-191 — the new unpriced clamp made the "bytes" section of TestManualHoldRespectsTheBodyEntryAndByteCaps vacuous, and nothing replaced its coverage.
    • What fails: the section records 20 manual-only holds of ~32 MiB bodies with offPolicy and the default unpriced fake, then asserts k.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.bytes stays 0, and the assertion passes on an empty map. Before this commit the section exercised evictManualLocked with near-limit bodies. The test still passes, so the loss is silent.
    • Proof: big := pad(MaxBodyBytes - 4096) is ~32 MiB, over LegacyMaxBodyBytes. recordHold uses offPolicy and testKeeper's fake has no prices, so k.projectedPingUSD returns 0 and the clamp sets limit = LegacyMaxBodyBytes. The remaining coverage of the manual byte cap uses 6 MiB bodies (TestAManualFloodByBytesEvictsThatTenantsOldestHoldFirst, manualhold_test.go:426), which pass the door. TestTheMemoryGuardHolds part 2 covers only the automatic path (kaPolicy is on, so the entry is not manualOnly). 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 as TestTheMemoryGuardHolds now does. The bodies then pass the door (projected ~$0.05, under the default $0.50 ceiling) and the per-tenant cap is exercised again.

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 duplicates pad (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 from unsupported to too large; cosmetic.
  • The new tests traced by hand: TestCachePolicyCarriesTheBodyLimit (both cachePolicy paths), TestAnUnpricedModelKeepsThe8MiBLimit (turn counts, pingable gates), the rewritten TestABigBodyOverTheCostCapIsStillRefused (mutation-sensitive now), the setPrices additions to TestABodyOver8MiBUnderTheCostCapIsPinged and TestTheMemoryGuardHolds (needed, or the clamp would refuse those bodies), and TestTheConfigBodyLimitMirrorsTheLibrary (no import cycle: config imports components and internal/modelinfo, not keepalive).
  • The other tests that touch the limit, re-traced under the clamp: TestOversizedBodyIsNotHeld still refuses (body over 32 MiB), TestManualOnlyEntriesAreEvictedBeforeAutomaticOnes unaffected (tiny bodies), TestAManualFloodByBytesEvictsThatTenantsOldestHoldFirst unaffected (6 MiB bodies) — and TestManualHoldRespectsTheBodyEntryAndByteCaps part 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]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Round 2 fix is in the new head.

  • Vacuous bytes section (reviewer 1): the section now sets the cheap price, so the 32 MiB bodies pass the door. It asserts that something is held and that the manual bytes stay within ManualHoldMaxBytesPerTenant. Mutation: remove the per-tenant byte check in manualhold.go. The test fails with "134203076 manual bytes held, per-tenant cap 33554432".
  • Fixed the stale "fifth" comment in keeper_test.go.
  • The PR text now records the owner's yes (2026-11-11) and links keepalive: the 32 MiB per-tenant manual-hold cap now fits only one large body #1103.
  • Not done: padBody still duplicates pad. It is trivial.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 survives evictManualLocked; bytes > 0 and bytes <= ManualHoldMaxBytesPerTenant both hold. The new bytes == 0 guard (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 (padBody duplicates pad): 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.
  • ManualHoldMaxBytesPerTenant retune: 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/pad duplication 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; evictManualLocked bounds tenant "t1" at one ~32 MiB body. The := redeclaration of k and clock beside the new fd is 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 amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 the k.bytes <= MaxBytes assertion passed on an empty map. The fix (manualhold_test.go:181-196) sets the cheap price so the bodies pass the door, asserts bytes != 0 so the section cannot go vacuous again, and asserts the per-tenant cap ManualHoldMaxBytesPerTenant instead of the global one. I traced it: all 20 entries are manualOnly under tenant "t1", evictManualLocked leaves 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: fd is the one new variable, k and clock are 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/pad duplication: not done, by the author's choice ("trivial"). I agree it is trivial.

Non-blocking

  • padBody (bodylimit_test.go) still duplicates pad (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).

@amiddavid
amiddavid merged commit ea50959 into main Nov 11, 2026
9 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 11, 2026
amiddavid added a commit that referenced this pull request Nov 11, 2026
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]>
amiddavid pushed a commit that referenced this pull request Nov 11, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

keep-alive: the 8 MiB body limit refuses cheap pings on large-in-bytes threads

1 participant