Skip to content

refactor(apply): size gates say bytes; the split floor counts real tokens (#798) - #848

Merged
amiddavid merged 6 commits into
mainfrom
feat/token-estimate
Nov 2, 2026
Merged

amiddavid merged 6 commits into
mainfrom
feat/token-estimate

Conversation

@amiddavid

@amiddavid amiddavid commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Behavior changes (need a human developer's yes)

  1. The prefix split floor now follows the model family, in o200k tokens.
    • Who: requests with a system block that has a volatile tail (Current branch:, Recent commits:) and a cache breakpoint (the cachesplit step).
    • Old: split when the block and the stable half had at least 1024 bytes/4.
    • New: split when the stable half reaches the provider's minimum cacheable prefix for the model: 4096 billed tokens on Haiku-class and unnamed models, 1024 on others. It is converted to o200k units with the measured factor. This is the same rule cheapmodel uses. It now lives once, in internal/modelinfo/cachefloor.go.
    • Effect: on Haiku, a stable half under about 3.4k o200k tokens no longer splits (the provider would ignore that breakpoint). On Sonnet-class models the floor is about 853 o200k tokens, so a split now fires for smaller halves than before.
    • Turn off: disable cachesplit and cacheinject. The floor has no switch.
  2. The reported splitStableTokens changes scale: it is a real o200k count (tokens.Count), not bytes/4. The dashboard prices the saving from it (dash.Event.cachesplitSavedUSD), so the number shown moves for the same block.
  3. A settings save no longer erases cache tuning keys it does not send. Keys: keepalive_idle_seconds, keepalive_openai_idle_seconds, keepalive_max_pings, keepalive_min_prefix_tokens, keepalive_max_usd_per_ping, head_ttl_min_bytes, head_ttl_min_tokens. Before, ApplyForm deleted them when the form stated 0, and the settings page does not send them. This bug is older than this PR. Now 0 means "not stated" and leaves the key alone. 0 is also the default for each key, so a new form field cache_reset (a list of key names) says "back to the default" and deletes the named keys. The settings page does not use it yet.
  4. A new upper bound: head_ttl_min_bytes over 1 GiB, or head_ttl_min_tokens over 268435456, is refused at load.

The head-TTL gate itself does not change: default 200000 bytes (old 50000 x 4). An old config with head_ttl_min_tokens gates at the same size.

Summary

Closes #798. Size gates now say bytes. A provider rule now counts real tokens.

What changed

  • apply/headttl.go: gate is len(body) >= minBytes.
  • New key cache.head_ttl_min_bytes (default 200000) in config/config.go, config/form.go, apply/opts.go, apply/apply.go, keepalive/types.go, proxy/modes.go, cmd/context-guru-proxy/main.go, plugin settings.py. The plugin does not write the new key (see Open questions).
  • head_ttl_min_tokens is deprecated and still works. If head_ttl_min_bytes is unset, the gate is tokens x 4. If both are set, bytes wins.
  • Stored keep-alive strategies (database column, manager API) keep head_ttl_min_tokens. resolveHeadTTL reads it as tokens x 4 bytes. No schema change.
  • apply/prefixsplit.go: cheap check first: the block and its stable half must each hold at least as many bytes as the model's floor, modelinfo.MinCacheableO200k(model) (a block never has more tokens than bytes). Then tokens.Count on the stable half, only for the block that has a marker.
  • internal/modelinfo/cachefloor.go (new): MinCacheableO200k(model) and friends, moved from cheapmodel. cheapmodel/cachecontrol.go keeps thin aliases, so its callers and values are unchanged.
  • keepalive.Policy.HeadTTLMinTokens stays as a deprecated alias. HeadTTLGateBytes() converts it (tokens x 4) when HeadTTLMinBytes is 0, so a downstream host that sets it still builds and behaves as before.
  • internal/coref/coref.go approxTokens and cmd/cg-selarm/main.go tok: comments say they are bytes proxies on purpose. Values are unchanged.
  • components/offload/collapse.go: untouched, as agreed. It re-measures with the real tokenizer.
  • Docs: new section in docs/how-to/cache-keepalive.md.

Other /4 estimates found on main: none that gate a request. internal/extract/elide.go:207 is a character budget, not a token estimate. components/offload/dedup.go:169 is *3/4 of a string, not tokens.

Data dependence

No change. Both gates use sizes only. At every storage level (off, metadata only, everything) the behavior is the same.

How it was tested

On the eval box, -race: ./apply/..., ./config/..., ./internal/..., ./cmd/..., ./keepalive/..., ./context-guru-plugin/..., ./proxy/... all pass. gofmt -l is clean. go vet is clean on the touched packages.

New tests:

  • TestSplitFloorCountsRealTokensNotBytesOverFour: fails on old prefixsplit.go, passes now (both directions).
  • TestHeadTTLGateIsBytesOfTheBody.
  • TestHeadTTLMinBytesResolution, TestHeadTTLMinKeysLoadFromYAML: old key only = 200000, new key wins, negative refused.
  • TestFormRoundTripsHeadTTLMinBytes: the settings form round-trips the new key.
  • TestCachePolicyCarriesTheHeadGateInBytes.
  • Updated: TestResolveHeadTTLMatchingStrategyOverridesTheAccount (50000 tokens = 200000 bytes), plugin 1-hour-head gate test.

Open questions

  • The plugin and the proxy binary are released separately. A new plugin can run with an older proxy, and an older proxy rejects head_ttl_min_bytes (strict YAML). So settings.py keeps writing head_ttl_min_tokens: 50000 for 1-hour-head. A new proxy reads it as the 200000-byte gate, so nothing changes. The plugin should write head_ttl_min_bytes in a later release, when no supported proxy is older than this one.
  • The settings form writes head_ttl_min_bytes only when the user sets it. It is served by the proxy that holds the config, so it cannot talk to an older proxy.

Assisted-By: Claude Opus 5.5 [email protected]

…kens (#798)

- upgradeHeadTTL gates on len(body) >= head_ttl_min_bytes (default 200000).
  head_ttl_min_tokens is deprecated and still works: x4 when the new key is unset.
- splitVolatileTail counts both checks with tokens.Count behind a cheap byte pre-check.
- coref approxTokens and cg-selarm tok say they are bytes proxies on purpose.

Assisted-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid
amiddavid force-pushed the feat/token-estimate branch 2 times, most recently from e8004f9 to dc65236 Compare November 2, 2026 10:26
…ts the config (#798)

The plugin and the proxy binary are released separately. An older proxy
rejects head_ttl_min_bytes (strict YAML). A new proxy reads 50000 tokens
as the 200000-byte gate, so nothing changes.

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 2 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.316 offload-review skill, @amiddavid's session fresh 2 of 2 1 of 2 736cd2cd23fa approve

Verdict: approve

Findings

None. The rename is exact and the one behavior change is disclosed.

What I verified, in proof form:

  1. The head-TTL gate does not move. Old gate: len(body)/4 < minTokens refuses, so the upgrade fires when len(body) >= 4*minTokens (integer division makes this exact). New gate: bytes = minTokens * 4, fires when len(body) >= 4*minTokens. I checked all three sources of the value:
    • default: old 50000, new 200000 = 50000 x 4 — same boundary (apply/headttl.go:93, config/config.go:234);
    • an old config key: Resolved() gives HeadTTLMinTokens * 4 (config/config.go:273-278) — same boundary;
    • a stored strategy: resolveHeadTTL returns best.HeadTTLMinTokens * headTTLBytesPerToken (proxy/keepalivestrategy.go:159) — same boundary.
  2. Every tenant path resolves before use. r.tn.Cache is built only by cachePolicy (cmd/context-guru-proxy/main.go:1116,1130), which calls c.Resolved(). So HeadTTLMinBytes is never 0-by-accident where the old code passed tokens. headTTLMin(on, n) keeps the "off means 0" rule, and apply still tests HeadTTL1h && HeadTTLMinBytes > 0 (apply/apply.go:433). No other host sets these apply.Opts fields (proxy/modes.go, cmd/cg-transcript-replay, dash/adaptcompaction.go checked).
  3. The byte prefilter in the split is sound. len(txt) >= minSplitTokens and at >= minSplitTokens are necessary conditions: one o200k token covers at least one byte, so a text under 1024 bytes cannot hold 1024 tokens (apply/prefixsplit.go:109,120). The tokenizer then runs only on a block that has a marker, and its count is memoized (internal/tokens/tokens.go).
  4. The split-floor change is the PR's stated purpose and is disclosed at the top of the PR, with who it affects, old and new behavior, and how to turn it off — the CLAUDE.md rule for behavior changes. Dense text now splits below 4096 bytes; repetitive text no longer splits above it. Both directions have a test (apply/prefixsplit_test.go:529) whose fixtures self-check their premise.
  5. Existing split fixtures still clear the new floor. Every existing test uses blockWithGitTail(6000) (~29 KB of English, well over 1024 real tokens), writeback_test.go:112 (10 KB of English) and ccbody_test.go:29 (7.2 KB of English). The conformance test's "small first block that names a volatile marker" stays out: it is under 1024 bytes, so the new byte prefilter refuses it before any counting.
  6. The form cannot corrupt an old document. ParseForm reads the raw (unresolved) cache block, so an old head_ttl_min_tokens: 50000 round-trips as 50000 with head_ttl_min_bytes unset; ApplyForm writes only positive values (config/form.go:402-411), so a re-save keeps the same 200000-byte gate. When both keys exist, the new key wins, and TestHeadTTLMinKeysLoadFromYAML pins it.
  7. The plugin's choice is safe in both directions. settings.py keeps head_ttl_min_tokens: 50000. An old proxy gates at len/4 >= 50000; this proxy gates at >= 200000 bytes. Identical. Writing the new key would break an old proxy's strict YAML load, so keeping the old key is the correct order.
  8. No data-dependence change. Both gates read sizes only. docs/data-dependence.md needs no row change.
  9. The strategy view, manager API and DB column keep the token name on purpose, and the only reader (resolveHeadTTL) converts. EntryView/Policy are not JSON-marshaled on any route, so the field rename leaks nowhere.

Non-blocking

  • tenant/keepalivestrategy.go:86 — the field comment still says "gates HeadTTL1h on request size". It does not say the proxy reads it as tokens x 4 bytes. That fact lives only in proxy/keepalivestrategy.go:157. Add one clause, so a reader of the tenant package alone cannot miss it.
  • HeadTTLMinTokens * HeadTTLBytesPerToken (config/config.go:275, proxy/keepalivestrategy.go:159) can overflow for values near 2^62. validate() rejects only negatives. A wrapped value disables the upgrade where the old code enabled it everywhere. Not reachable with a sane config; an upper bound would close it.
  • minSplitTokens = 1024 is Anthropic's minimum for Opus/Sonnet. Haiku's documented minimum is 2048, and tokens.Count (o200k) under-counts Claude by ~1.4-1.7x per internal/tokens/billedfactor.go. So on Haiku a stable half just over the floor may still not be cached. The constant is unchanged by this PR; the new comment's claim "copies the provider's minimum" is now load-bearing, so this edge is worth a line there.
  • The whole-block check tokens.Count(txt) < minSplitTokens (apply/prefixsplit.go:125) is almost unreachable given the stable-half check, because the stable half is a prefix of the block. Harmless and defensive; keep or drop as you prefer.
  • Per CLAUDE.md, the disclosed split-floor behavior change still needs a human developer's yes before merge. The PR asks for it.

What I checked

  • Full diff 7b682ae5..HEAD, both commits, and the code around every change: apply/apply.go, apply/headttl.go, apply/opts.go, apply/prefixsplit.go, config/config.go, config/form.go, proxy/modes.go, proxy/keepalivestrategy.go, proxy/campaign.go, cmd/context-guru-proxy/main.go, keepalive/types.go, tenant/keepalivestrategy.go, internal/coref/coref.go, cmd/cg-selarm/main.go, context-guru-plugin/scripts/settings.py.
  • Every non-test reference to HeadTTLMin* and head_ttl_min* in the repo, to prove the rename is complete and the deprecated key has exactly one reader per path.
  • All constructors of apply.Opts and proxy.CachePolicy (CachePolicy = keepalive.Policy alias), to prove no host passes an unresolved value.
  • Every test fixture that uses a volatile-tail marker, to prove the new real-token floor does not silently break an existing test.
  • Boundary arithmetic for the deprecated-key conversion (integer division: len/4 >= m iff len >= 4m), so old and new gates fire on the same requests.
  • The PR description's behavior-change section (disclosure check only).
  • dash/redact.go's config allowlist: no cache keys were listed before or after, so the new key changes nothing there.

I did not run builds or tests. Live tests are not approved for this review, and Go is not installed on this machine. I read the code only, as instructed.

@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.316 offload-review skill, @amiddavid's session fresh 1 of 2 1 of 2 736cd2cd23fa approve

Verdict: approve

Findings

None. I traced every changed path and found no defect.

Non-blocking

  1. proxy/keepalivestrategy.go:219-226 — stale comment names renamed fields. The validStrategyBounds doc says "the same convention CachePolicy.HeadTTLMinTokens follows" and quotes o.HeadTTLMinTokens > 0. Both fields are now HeadTTLMinBytes. A reader tracing the "zero means never upgrade" rule lands on a field that no longer exists. Same for tenant/keepalivestrategy.go:86, which does not say the stored value is read as tokens x 4 bytes.
  2. A settings-page save deletes a tuned head gate (pre-existing, not this PR). dash/ui/app.js saveSettings posts cache: {keepalive, head_ttl_1h} only. config.ApplyForm (form.go:400-413) deletes every tuning key the form states as 0, so head_ttl_min_bytes and head_ttl_min_tokens are removed from the stored document. A manager who sets a custom gate on the account page, then saves the Settings page, silently loses it. This predates the PR (head_ttl_min_tokens had the same loss), and the plugin's 50000 equals the default, so no live harm today. Worth its own issue.
  3. keepalive.Policy.HeadTTLMinTokens renamed to HeadTTLMinBytes is a breaking API change for any external host that sets it. Nothing in this repo sets it. The sidecar-plugin repo depends on this repo and I cannot read it from here; verify it does not reference the old field before merge.
  4. splitStableTokens changed scale. It now reports real BPE tokens, not bytes/4. The dashboard's cachesplitSavedUSD numerator shifts slightly for text far from 4 bytes per token. The new number is the more accurate one; only series comparisons across the change date are affected.

What I checked

  • Full diff base 7b682ae5..head 736cd2cd (both commits), plus the code around each hunk.
  • Head-TTL gate equivalence. Old: len(body)/4 < minTokens skips. New: len(body) < minBytes skips. With minBytes = tokens x 4, len/4 >= t holds exactly when len >= 4t, so old and new fire on the same bodies, boundary included. Verified in apply/headttl.go:93.
  • Config resolution chain. YAML -> CacheConfig -> Resolved() (old key x 4, else default 200000; new key wins) -> cachePolicy -> keepalive.Policy.HeadTTLMinBytes -> resolveHeadTTL -> apply.Opts.HeadTTLMinBytes. Every hop carries bytes. LoadBytes validates negatives for both keys. cachePolicy resolves only when something is switched on, so a parked block stays parked.
  • Strategy path. resolveHeadTTL returns best.HeadTTLMinTokens * 4 for a matching strategy. That is the same size gate the old code enforced. validStrategyBounds still refuses HeadTTL1h=true with a floor <= 0, so the x4 result is always positive. The manager API and the database column keep the token-named field; no schema change.
  • Plugin compatibility. settings.py keeps writing head_ttl_min_tokens: 50000. An old proxy rejects unknown keys (strict YAML, KnownFields(true)), so keeping the old key is required. A new proxy reads 50000 as the 200000-byte gate — the same size as before. The field still exists, so the new loader accepts the old key.
  • Split floor. The byte pre-filters are sound: a BPE count never exceeds the byte count, so len(txt) < 1024 or at < 1024 proves the real count is under the floor. The tokenizer runs only on the one block that carries a marker, and tokens.Count memoizes by content hash, so repeat turns hit the cache. internal/tokens falls back to (len+3)/4 only when the tokenizer fails to init, which also respects count <= bytes.
  • New tests. TestSplitFloorCountsRealTokensNotBytesOverFour checks its own premise and fails loudly if the tokenizer changes. TestHeadTTLGateIsBytesOfTheBody pins the boundary both ways. The config, form, and cachePolicy tests cover default, old-key, new-key-wins, and negative-refused. Existing split fixtures (28 KB+ stable halves) stay far above the real-token floor.
  • Behavior-change rule. The split-floor change is named at the top of the PR, with old and new behavior and how to turn it off. The PR author is the human owner.
  • Data dependence. The PR states no change; both gates read sizes only. I agree — no row in docs/data-dependence.md needs an update.
  • Fail open. upgradeHeadTTL and splitVolatileTail still return the input untouched on every parse problem. The split keeps concatenation byte-identical, so the model sees the same prompt.

…eapmodel (#798)

- Move the minimum cacheable prefix and the o200k factor from cheapmodel to
  internal/modelinfo. cheapmodel and apply's prefix split call the same function.
- The split floor now follows the model family (Haiku 4096, others 1024 billed tokens).
- ApplyForm keeps head_ttl_min_bytes and head_ttl_min_tokens when the form does not send them.
- Bound both head-gate keys so tokens x 4 cannot overflow.
- keepalive.Policy keeps HeadTTLMinTokens as a deprecated alias (HeadTTLGateBytes).
- Fix stale comments.

Assisted-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Fixed in 5058827. One reply per item:

  1. Split floor, one rule. The floor and the o200k factor moved to internal/modelinfo/cachefloor.go (MinCacheableO200k). cheapmodel keeps thin aliases, so its values are unchanged (its tests pass). splitVolatileTail reads the model from the body. The byte pre-check uses the floor. New tests: Haiku, Sonnet, unnamed model, bytes-not-tokens. With the old flat 1024, TestSplitFloorFollowsTheModelFamily and TestSplitFloorOnSonnetIsInO200kUnits fail. Named at the top of the PR.
  2. Stale comments fixed in proxy/keepalivestrategy.go and tenant/keepalivestrategy.go.
  3. Upper bound. head_ttl_min_bytes max 1 GiB, head_ttl_min_tokens max 268435456, in config.validate() and validStrategyBounds. Tests added.
  4. Whole-block check dropped. The stable-half check covers it, because the floor on the stable half is the provider's rule.
  5. Settings save. ApplyForm writes the head-gate keys when the form states them and leaves them alone otherwise. Test: TestApplyFormKeepsTheHeadGateWhenTheFormDoesNotSendIt.
  6. Alias. keepalive.Policy.HeadTTLMinTokens stays, deprecated. HeadTTLGateBytes() converts it. Test added. Stated in the PR.
  7. splitStableTokens scale is on the behavior list.

Tests, -race on the box: apply, cheapmodel, internal, cmd, config, keepalive, components, tenant, dash, plugin, full proxy all pass. gofmt -l and go vet are clean. The repo has no dash JS test runner, so the JS side is not tested.

@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.316 offload-review skill, @amiddavid's session resumed 1 of 2 2 of 2 5058827a903b approve

Verdict: approve

Findings

None. The fix commit is correct and I found no new defect in it.

Earlier findings, and their state

Mine (round 1, all non-blocking):

  1. Stale comments naming HeadTTLMinTokens. Fixed. proxy/keepalivestrategy.go:220-233 now names HeadTTLMinBytes and says the stored field is read as tokens x 4 bytes. tenant/keepalivestrategy.go:86-89 says the same.
  2. A settings save erased a tuned head gate. Fixed for both head keys. config/form.go:412-420 writes head_ttl_min_bytes / head_ttl_min_tokens only when the form states them, and leaves them alone otherwise. TestApplyFormKeepsTheHeadGateWhenTheFormDoesNotSendIt covers both spellings. The behavior change is on the PR's list (item 3).
  3. keepalive.Policy.HeadTTLMinTokens rename broke external hosts. Fixed. The field stays as a deprecated alias, and HeadTTLGateBytes() (keepalive/types.go:281-286) resolves it. I checked the boundary: an external host that set 50000 got the old gate "len(body)/4 >= 50000", which is len >= 200000; the alias returns 200000 bytes against len(body) >= minBytes — the same bodies. TestHeadTTLGateBytes pins it.
  4. splitStableTokens changed scale. Now disclosed as behavior change 2 in the PR body.

Reviewer 2's (round 1, all non-blocking), checked myself:

  1. tenant comment — fixed, same as my item 1.
  2. tokens x 4 overflow — fixed. config.validate() refuses head_ttl_min_bytes over 1 GiB and head_ttl_min_tokens over 268435456 (config/config.go:298-301); validStrategyBounds refuses the same for strategies (proxy/keepalivestrategy.go:255-258). Tests cover both. Resolved() can no longer overflow.
  3. Flat 1024 floor ignored the family and the unit. Fixed, and beyond the note: the measured rule moved to internal/modelinfo/cachefloor.go, and the split now uses MinCacheableO200k(model). Reviewer 2 cited a documented Haiku minimum of 2048; the author used the measured 4096 that cheapmodel already ships. I checked the direction: with the 1.20 divisor, the derived Haiku floor (3413 o200k) is above the true one (3555 billed at 1.152x would be 3568 o200k — the comment's own arithmetic), so it errs toward demanding more, never less. Accept.
  4. Whole-block check almost unreachable. Dropped by the author. Sound: the stable half is a prefix of the block, so count(txt) >= count(txt[:at]) >= floor always held; the check could never fire.
  5. Human yes for the behavior change. The PR body now lists four behavior changes at the top, each with who, old, new, and turn-off. The author is the human owner.

Non-blocking

  • proxy/conformance_test.go:249 — stale comment. It still says "the split's minSplitTokens floor (1024)". The constant is gone; the floor is now 853-3413 o200k tokens by family. The property it documents still holds (the small block stays under the byte pre-filter), so this is a doc fix only.
  • The other cache tuning keys are still erased by a settings save. ApplyForm still deletes keepalive_idle_seconds, keepalive_max_pings, keepalive_min_prefix_tokens and keepalive_max_usd_per_ping when the form states 0, and the settings page does not send them. The fix covered only the head-gate keys. Pre-existing on main; worth its own issue, not this PR.

What I checked

  • Last review: round 1, 736cd2cd23faa0fd623fc5a40b25ce5dba556236, 2026-11-02T10:50:59Z.
  • New commits read: 1 — 5058827a "refactor(modelinfo): one cache-floor rule for the prefix split and cheapmodel (#798)".
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files; the inline list is empty).
  • New items since my last review: the fix commit and the author's reply comment of 2026-11-02T11:30:24Z. I read both in full and checked every claim in the reply against the code.

On the new commit:

  • The moved rule is byte-identical for cheapmodel. internal/modelinfo/cachefloor.go carries the same constants (4096/1024), the same 1.20 divisor, and the same family switch that cheapmodel had. The aliases in cheapmodel/cachecontrol.go point at them, so cheapmodel's behavior cannot move.
  • The split's new floor is sound at every step. MinCacheableO200k reads the model from the body; Family matches a substring after Normalize, so aws/claude-sonnet-5 reads as Sonnet and an unplaceable alias gets the larger Haiku floor (conservative). The byte pre-filters still hold: a BPE count never exceeds the byte count, so len(txt) < floor or at < floor proves the real count is under it. apply.go already reads model from the body the same way in three other places, so the Converse-shaped path is no worse than existing practice, and a miss fails toward not splitting.
  • The dropped whole-block check is provably dead. The stable half is a prefix of the block, so its count bounds the block's count from below.
  • The new tests self-check their premises. stableOf computes the repeat count from the measured tokens-per-line, and TestSplitFloorFollowsTheModelFamily asserts the fixture sits between the two floors before using it. writeback_test.go now names a Sonnet model because its fixture was sized for the split — the right fix, not a fixture shrunk to pass.
  • The upper bounds close the overflow. Both keys are bounded in config.validate() (reached by LoadBytes and by Form.validate), and the strategy create and update paths call validStrategyBounds. A pre-existing database row above the bound would overflow to a non-positive gate, which apply's own > 0 test then treats as off — the fail-safe direction.
  • HeadTTLGateBytes is applied once. modes.go passes r.tn.Cache.HeadTTLGateBytes(); cachePolicy always fills HeadTTLMinBytes when the upgrade is on, so the deprecated path only matters for an external host. The keeper's strategy resolution still converts on its own and does not double-convert.
  • No leftover references. minSplitTokens is gone from non-test code; the one remaining mention is the stale conformance-test comment above.

@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.316 offload-review skill, @amiddavid's session resumed 2 of 2 2 of 2 5058827a903b approve

Verdict: approve

Findings

None. The fix commit is correct, and every round-1 item is addressed.

Status of earlier findings

My round-1 non-blocking items:

  1. Stale comment in tenant/keepalivestrategy.go:86 — fixed. The comment now says the proxy reads the stored value as tokens x 4 bytes.
  2. Overflow of HeadTTLMinTokens * 4 — fixed. config.validate() refuses head_ttl_min_bytes over 1 GiB and head_ttl_min_tokens over 268435456 (config/config.go:298). validStrategyBounds refuses the same bound for strategies (proxy/keepalivestrategy.go:255). Tests pin both (config/headgate_test.go, proxy/keepalivestrategy_test.go:187). The bound is exact: 2^28 x 4 = 2^30, no wrap.
  3. Haiku's 2048/4096 minimum vs the flat 1024 floor — fixed beyond my note. The floor is now per family, in one rule shared with cheapmodel (internal/modelinfo/cachefloor.go).
  4. Redundant whole-block token check — dropped by the author. I checked the reason: the breakpoint sits after the stable half, and the cached prefix at that point covers everything before it, which is at least the stable half. Gating on the stable half alone is the provider's own rule. The reason is right. Accepted.
  5. Human yes on the behavior change — still pending. The PR body lists four behavior changes at the top and asks for it.

Reviewer 1's round-1 items (I checked each myself):

  1. Stale comments in proxy/keepalivestrategy.go and tenant/keepalivestrategy.go — fixed. Both now name HeadTTLMinBytes and the tokens-x-4 reading.
  2. A settings save erased a tuned head gate — fixed. ApplyForm writes the head-gate keys only when the form states them and leaves them alone otherwise (config/form.go:412-419). TestApplyFormKeepsTheHeadGateWhenTheFormDoesNotSendIt pins both spellings. Named as behavior change 3 in the PR.
  3. Breaking rename of keepalive.Policy.HeadTTLMinTokens for external hosts — fixed. The field stays as a deprecated alias, HeadTTLGateBytes() converts (tokens x 4 when only the old field is set, new field wins), and proxy/modes.go:56 reads through it. TestHeadTTLGateBytes pins all four cases. Old downstream code compiles and behaves as before: tokens x 4 bytes is the same boundary the old len(body)/4 gate enforced.
  4. splitStableTokens changed scale — disclosed as behavior change 2 in the PR.

The new commit (5058827)

I read the full diff and the code around each change. What I verified:

  1. The per-family floor is sound. MinCacheableO200k converts the billed floor (Haiku-class 4096, Sonnet/Opus 1024) with the measured 1.20 divisor: 3413 and 853 o200k tokens. On Sonnet, 853 x 1.20 = 1024 billed exactly, and the measured Sonnet factor (1.56) makes the true floor lower, so the split never demands less than the provider caches. The loose-divisor trade-off on Haiku (a breakpoint between 3413 and 3555 o200k is ignored, not charged) is the same measured, documented choice cheapmodel already made.
  2. The byte prefilter still holds. The floor is now up to 3413, and one o200k token still covers at least one byte, so len(txt) >= floor and at >= floor remain valid necessary conditions (apply/prefixsplit.go:103,116).
  3. The model is read from the right place. gjson.GetBytes(body, "model") runs before anything rewrites the body (the envelope transforms and upgradeHeadTTL do not touch model). modelinfo.Family matches tier words inside prefixed ids ("aws/claude-sonnet-5"). A body with no model, or an alias, gets the Haiku floor — the documented conservative default, the same rule cheapmodel applies to an unnameable model. Claude Code's real snapshot block (~6.9k stable tokens) still clears even the Haiku floor, so the common case still splits.
  4. The cheapmodel move changes no value. MinCacheableHaiku/MinCacheableSmall/RealTokensPerO200k/MinCacheablePrefix are the same numbers, now in internal/modelinfo; cheapmodel keeps unexported aliases. No import cycle: modelinfo imports nothing from cheapmodel or apply.
  5. The form fix cannot corrupt a document. A gate key is written only when the form states a positive value; otherwise the stored key stands. A plain settings save (which posts only keepalive and head_ttl_1h) keeps either spelling. Removing a gate now needs a YAML edit — that is the disclosed trade-off, and no UI ever sent these fields.
  6. The bounds close the overflow. MaxHeadTTLMinBytes = 1<<30; the tokens bound is MaxHeadTTLMinBytes/4. The form's validate() goes through the same CacheConfig.validate(), so the bound covers the settings path too.
  7. Tests match the new behavior. TestSplitFloorFollowsTheModelFamily and TestSplitFloorOnSonnetIsInO200kUnits fail against the old flat 1024 (the author's claim; the fixtures sit between 853 and 3413, so a flat 1024 would split the Haiku case and refuse the 900-token Sonnet case — the claim checks out by arithmetic). The writeback fixture's model was renamed from claude-x to claude-sonnet-5 because claude-x is unnameable and would take the 3413 floor, which its ~2.6k-token stable half misses — the right fix, and it shows the unnamed-model path was considered. All other split fixtures use claude-sonnet-5 or stable halves far above 3413.

Non-blocking

  • Stale test comments: proxy/conformance_test.go:249 still says "the split's minSplitTokens floor (1024)", and proxy/ccbody_test.go:25 says "over cachesplit's 1024-token floor (~4 chars/token)". The floor is now per-family in o200k tokens. Comments only.
  • The PR body's "What changed" still says the cheap check is len(txt) >= 1024. The behavior list at the top is correct and detailed; this middle line lags the fix commit.
  • A user cannot clear a head gate through the settings form any more; it needs a YAML edit. Disclosed as behavior change 3. Acceptable, worth knowing.
  • The four behavior changes still need the human developer's yes before merge. The PR asks for it.

What I checked

  • Last review: round 1, 736cd2c, 2026-11-02T10:50:12Z.
  • New commits read: 1 (5058827 "refactor(modelinfo): one cache-floor rule for the prefix split and cheapmodel (#798)").
  • 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:
    • Commit 5058827 — full diff plus the code around each hunk: apply/prefixsplit.go, apply/prefixsplit_test.go, apply/writeback_test.go, cheapmodel/cachecontrol.go, config/config.go, config/form.go, internal/modelinfo/cachefloor.go, keepalive/types.go, proxy/keepalivestrategy.go, proxy/modes.go, tenant/keepalivestrategy.go, and the three new test files.
    • The author's reply comment (2026-11-02T11:30:24Z) — all seven items checked against the code, as listed under "Status of earlier findings".
    • The updated PR body — the four behavior changes are named at the top, per the CLAUDE.md rule.
  • modelinfo.Family/Normalize (prefix and alias handling), schema/wire.go (the model key exists on every wire shape the split runs on; a missing model falls to the documented Haiku default).
  • Every test fixture that asserts a split, to prove the per-family floor does not silently break one: prefixsplit_test.go, writeback_test.go, ccbody_test.go, conformance_test.go, and the small-block fixtures in keepalive and proxy tests.
  • The floor arithmetic: 1024/1.20 = 853 and 4096/1.20 = 3413 o200k, and the direction of the divisor error against the measured 1.148-1.56 factors.
  • The overflow bound: 2^28 x 4 = 2^30, no int wrap; bound enforced in config load, form validate, and strategy create/patch.
  • No leftover minSplitTokens references in code (one stale test comment, listed above); no direct HeadTTLMinBytes read that should go through HeadTTLGateBytes.

I did not run builds or tests. Live tests are not approved for this review, and Go is not installed on this machine. I read the code only, as instructed.

… send (#798)

- ApplyForm writes a tuning key only when the form states it (above 0).
  0 means "not stated" and leaves the stored key alone. One loop covers all keys.
- Form.CacheReset names keys to delete, so "back to the default" stays possible.
- Reword a stale comment in proxy/conformance_test.go.

Assisted-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Fixed in the new head.

  1. Stale comment in proxy/conformance_test.go now names the per-family floor (modelinfo.MinCacheableO200k).
  2. Other cache keys. ApplyForm now uses one loop for all seven tuning keys. A value above 0 is written. 0 means "not stated" and leaves the stored key alone.
    • Meaning of 0: for every key, 0 is the default, not "off". Nobody can set 0 on purpose to mean something else.
    • Reset: "back to the default" was possible before (0 deleted the key). To keep it, Form.CacheReset names the keys to delete. The settings page does not use it yet.
    • Tests: TestApplyFormKeepsEveryCacheTuningKeyItDoesNotSend saves a form with no tuning keys and checks all five stay. TestApplyFormCacheResetDeletesNamedKeysOnly checks the reset path.
    • Named on the behavior list (item 3).

-race: ./config/... and full ./proxy/... pass. gofmt -l and go vet are clean.

@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.316 offload-review skill, @amiddavid's session resumed 1 of 2 3 of 3 e4cc8437d176 approve

Verdict: approve

Findings

None. The fix commit is correct and I found no new defect in it.

Earlier findings, and their state

My round-2 non-blocking items:

  1. Stale comment in proxy/conformance_test.go:249. Fixed. It now names the per-family floor (modelinfo.MinCacheableO200k).
  2. The other cache tuning keys were still erased by a settings save. Fixed. ApplyForm now uses one loop for all seven tuning keys: a value above 0 is written, 0 means "not stated" and leaves the stored key alone (config/form.go:404-424). Form.CacheReset names keys to delete, so "back to the default" stays possible. Two tests pin both directions. The behavior change is item 3 on the PR's list, updated to name all seven keys and the new field.

Reviewer 2's round-2 non-blocking items, checked myself:

  1. proxy/ccbody_test.go:25 stale comment ("cachesplit's 1024-token floor, ~4 chars/token") — not fixed. The fixture uses claude-sonnet-5 and a ~6.7 KB stable half (~1,500 o200k tokens), so it still clears the 853 floor and the test holds. Comment only.
  2. PR body "What changed" still says the cheap check is len(txt) >= 1024 — not fixed. The behavior list at the top is correct and detailed; this middle line lags the per-family floor. Doc only.
  3. A head gate cannot be cleared from the settings form — now it can, through cache_reset. The settings page does not send it yet; the account editor and the API can.

What I checked

  • Last review: round 2, 5058827a903b5d37f64b4d8016f9775b1640846c, 2026-11-02T11:34:33Z.
  • New commits read: 1 — e4cc8437 "fix(config): a settings save keeps every cache tuning key it does not send (#798)".
  • Read in full: 3 reviews, 2 comments, 0 inline comments (from the three files; the inline file is empty).
  • New items since my last review: commit e4cc8437 and the author's reply comment of 2026-11-02T11:46:37Z. I read both in full and checked every claim in the reply against the code.

On the new commit:

  • The one-loop rule is sound for every key. A value above 0 is written; 0 leaves the stored key alone; a key named in CacheReset is deleted only when the form does not also state a positive value (the v > 0 cases come first). An unknown name in CacheReset matches nothing in the loop and is ignored, so the field cannot delete keepalive, head_ttl_1h, or any key outside the seven.
  • The float64 detour cannot lose precision. Every field except keepalive_max_usd_per_ping is an int in CacheForm, and JSON decoding refuses a fractional number for an int field, so float64(int) and back is exact. The head-gate keys are bounded by validate() (1 GiB, far under 2^53), and Form.validate runs before ApplyForm writes anything, so no unbounded value reaches the loop.
  • No caller relied on the old delete-on-0. The settings page posts only keepalive and head_ttl_1h, and its own comment ("the tuning fields are omitted, which leaves the document's own values alone") now matches the server for the first time. ctlKeepAliveOff re-saves a form read by ParseForm, which states every key the document carries, so its round trip is unchanged.
  • The tests match the behavior. TestApplyFormKeepsEveryCacheTuningKeyItDoesNotSend covers the five keepalive keys (the two head keys were covered by the round-2 test); TestApplyFormCacheResetDeletesNamedKeysOnly checks that a reset deletes only the named keys.
  • The conformance comment fix matches the code. The floor is modelinfo.MinCacheableO200k per family; the small-block case it documents still holds, because the block stays under the byte pre-filter.
  • PR body updated. Behavior item 3 now names all seven keys and cache_reset, and states that the settings page does not use the reset field yet.

I did not run builds or tests. Live tests are not approved, and Go is not installed on this machine. I read the code only.

@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.316 offload-review skill, @amiddavid's session resumed 2 of 2 3 of 3 e4cc8437d176 approve

Verdict: approve

Findings

None. The new commit is correct, and it closes the last open review item.

Status of earlier items

My round-2 non-blocking items:

  1. Stale test comments — half fixed. proxy/conformance_test.go:249 now names modelinfo.MinCacheableO200k and the per-family floor. proxy/ccbody_test.go:25 still says "over cachesplit's 1024-token floor (~4 chars/token)". Comment only.
  2. PR body's "What changed" lags — not fixed. It still says the cheap check is len(txt) >= 1024. The behavior list at the top is correct; only this middle line is stale.
  3. A head gate cannot be cleared from the form — now addressed with a real mechanism: Form.CacheReset names the keys to delete (config/form.go:115-118). The settings page does not use it yet; that is disclosed.
  4. Human yes on the behavior changes — still pending. The PR body still heads the list with "need a human developer's yes".

Reviewer 1's round-2 non-blocking items (I checked each myself):

  1. Stale conformance comment — fixed in this commit.
  2. The other cache tuning keys were still erased by a settings save — fixed. This is what e4cc8437 exists for, and it is the subject of the verification below.

The new commit (e4cc843)

I read the full diff, the code around it, and every caller. What I verified:

  1. One rule for all seven tuning keys, and it is the right rule. A value above 0 is written. 0 means "not stated" and leaves the stored key alone. A key named in Form.CacheReset is deleted (config/form.go:410-427). For every key, 0 is also the default, so the author's claim holds: 0 could never say "back to the default" on purpose, and the reset list is the only way to say it.
  2. Every ApplyForm caller survives the change. Four call sites, each checked:
    • proxy/keepalivectl.go:301 and proxy/toolfilterctl.go:213 build the form with ParseForm from the current document, so their tuning fields carry the document's own values. A key present in the document is written back as before; a key absent from it had a 0 that used to "delete" a key that was not there — a no-op either way. No regression.
    • proxy/adaptctl.go:153 sets f.Cache = nil, so the cache block is never touched.
    • proxy/control.go:1297 is the settings save the fix targets: the page posts only keepalive and head_ttl_1h, and the stored tuning keys now survive. That is the intended behavior change, named as item 3 in the PR body with all seven keys listed.
  3. CacheReset cannot delete anything arbitrary. The reset map is consulted only inside the loop over the seven known keys, so a name outside that set is ignored. No path deletes preset, pipeline or a component block through it.
  4. Invalid input still cannot reach the write. ApplyForm calls f.validate() first (config/form.go:381), and Form.validate runs the cache block through CacheConfig.validate(), which rejects negative values and the new upper bounds.
  5. The float64 conversion is exact. The int keys hold values bounded well below 2^53, so float64(int) and int(float64) round-trip. keepalive_max_usd_per_ping keeps its float type, as before. The switch order puts the float case first, so the dollar value is never truncated to an int.
  6. Both new tests match the code. TestApplyFormKeepsEveryCacheTuningKeyItDoesNotSend saves a form with no tuning fields and checks all five stored keys plus the keepalive switch. TestApplyFormCacheResetDeletesNamedKeysOnly checks that a reset deletes only the named keys. The earlier round-trip tests still hold: a form parsed from a document carries that document's values, so a plain re-save writes them back unchanged.
  7. The conformance comment reword says what the code now does.

Non-blocking

  • proxy/ccbody_test.go:25 still says "over cachesplit's 1024-token floor (~4 chars/token)". The floor is per-family in o200k tokens now. Comment only.
  • The PR body's "What changed" still says the split's cheap check is len(txt) >= 1024; it is the per-family floor. The behavior list at the top is correct.
  • A typo in cache_reset (for example keepalive_max_ping) is silently ignored: the save reports success and the key keeps its value. Validating the names against the seven-key set would turn that into a 400. No UI sends the field today, so nothing can hit it yet.
  • The four behavior changes still need the human developer's yes before merge. The PR asks for it.

What I checked

  • Last review: round 2, 5058827, 2026-11-02T11:35:00Z.
  • New commits read: 1 (e4cc843 "fix(config): a settings save keeps every cache tuning key it does not send (#798)").
  • Read in full: 4 reviews, 2 comments, 0 inline comments (from the three files; the inline list is empty).
  • New items since my last review:
    • Reviewer 1's round-2 review (2026-11-02T11:34:33Z) — read in full. Its two non-blocking items are the conformance comment and the other cache keys; both are addressed by this commit, and I verified each myself above.
    • The author's reply comment (2026-11-02T11:46:37Z) — read in full. Both items and the meaning-of-0 argument checked against the code. The argument is right: 0 is the default for every key, so it cannot carry a separate "off" meaning, and the reset list is the only clean way to say "back to the default".
    • Commit e4cc843 — full diff plus the code around each hunk: config/form.go, config/headgate_test.go, proxy/conformance_test.go.
  • All four ApplyForm call sites (proxy/control.go:1297, proxy/keepalivectl.go:301, proxy/adaptctl.go:153, proxy/toolfilterctl.go:213), to prove the leave-alone rule breaks none of them.
  • Form.validate and its place inside ApplyForm, so negative or out-of-bound values cannot reach the write path.
  • The CacheReset consumption path, to prove it can only name the seven known keys.
  • The updated PR body — behavior change item 3 now lists all seven keys and the new cache_reset field, per the CLAUDE.md rule.

I did not run builds or tests. Live tests are not approved for this review, and Go is not installed on this machine. I read the code only, as instructed.

…mment

Round-3 note on #848: the volatileSystemText comment still named the
old flat 1024-token floor. It now names modelinfo.MinCacheableO200k.
Comment only.

Assisted-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Round 3 notes from reviewer 2, fixed:

  1. proxy/ccbody_test.go:26 still named the flat 1024-token floor. Fixed in 354e1fc. The comment now names modelinfo.MinCacheableO200k. Comment only.
  2. "What changed" still said len(txt) >= 1024. Fixed in the PR body. The line now says the byte pre-check uses the model's floor from modelinfo.MinCacheableO200k(model).

@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.316 offload-review skill, @amiddavid's session resumed 2 of 2 4 of 4 354e1fce3f81 approve

Verdict: approve

Findings

None. The new commit changes one comment line, and it says what the code does.

Status of earlier items

My round-3 non-blocking items:

  1. proxy/ccbody_test.go:25 stale comment — fixed in 354e1fce. The comment now names the per-family floor (modelinfo.MinCacheableO200k) instead of the old flat "1024-token floor (~4 chars/token)". The fixture itself is untouched: claude-sonnet-5 with a ~1,500-o200k-token stable half still clears the 853 floor, so the test holds as before.
  2. PR body's "What changed" lag — fixed. The line now says the byte pre-check uses the model's floor from modelinfo.MinCacheableO200k(model). I read the current body back from the server.
  3. A typo in cache_reset is silently ignored — still open. A reset name outside the seven known keys matches nothing and the save reports success. No UI sends the field, so nothing can hit it today. Non-blocking.
  4. Human yes on the four behavior changes — still pending. The PR body still heads the list with "need a human developer's yes". Merge should not happen without it.

Reviewer 1's round-3 review (11:48:43Z) raised nothing new; it approved and flagged the same two stale-doc items, both now fixed.

The new commit (354e1fc)

One changed line, proxy/ccbody_test.go:26, a comment on a test fixture. No code, no behavior, no test logic. The new wording is accurate: the split floor comes from modelinfo.MinCacheableO200k per model family. Nothing else in the commit.

Non-blocking

  • A typo in cache_reset is still silently ignored. Validating the names against the seven-key set would turn it into a 400. Nothing can hit it until a UI sends the field.
  • The four behavior changes still need the human developer's yes before merge. The PR asks for it.

What I checked

  • Last review: round 3, e4cc843, 2026-11-02T11:49:07Z.
  • New commits read: 1 (354e1fc "test(proxy): name the per-family split floor in the ccbody fixture comment").
  • Read in full: 5 reviews, 3 comments, 0 inline comments (from the three files; the inline list is empty).
  • New items since my last review:
    • Reviewer 1's round-3 review (2026-11-02T11:48:43Z) — read in full. It approved e4cc8437 and listed the same two stale-doc items I did. Nothing new to check beyond that.
    • The author's reply comment (2026-11-02T11:50:29Z) — read in full. Both claims verified: the ccbody comment against the commit diff, and the PR body line against the server.
    • Commit 354e1fc — full diff (one comment line) plus the fixture around it: the model is claude-sonnet-5 and the stable half is ~7.2 KB of English, far over the 853-o200k Sonnet floor, so the test's premise is unchanged.
  • The current PR body, read back from the server: behavior item list intact, the "What changed" line fixed, the header still asking for the human yes.

I did not run builds or tests. Live tests are not approved for this review, and Go is not installed on this machine. I read the code only, as instructed.

@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.316 offload-review skill, @amiddavid's session resumed 1 of 2 4 of 4 354e1fce3f81 approve

Verdict: approve

Findings

None. The new commit changes one comment, and the comment is now right.

Earlier findings, and their state

  • My round-3 items (conformance comment, settings-save erasure of tuning keys) — both fixed in e4cc8437, verified in round 3. Nothing new on them.
  • Reviewer 2's round-3 items, checked myself:
    1. proxy/ccbody_test.go stale comment — fixed in 354e1fce. The comment now names modelinfo.MinCacheableO200k.
    2. PR body "What changed" lag — fixed. The line now says the byte pre-check uses the model's floor from modelinfo.MinCacheableO200k(model). Verified on the server.
    3. A typo in cache_reset is silently ignored — I agree, after checking the code myself in round 3: a name outside the seven-key set matches nothing in the loop, so the key keeps its value. The failure is silent but safe, and no UI sends the field today. Non-blocking.
    4. The human yes on the four behavior changes — still pending, and the PR asks for it. The author is the human owner.

Non-blocking

  • Agree with reviewer 2, round 3, item 3: validating cache_reset names against the seven-key set would turn a typo into a 400 instead of a silent no-op. Worth a follow-up when a UI starts sending the field.

What I checked

  • Last review: round 3, e4cc8437d176cac20fb09ff65100d2f9d61b3a48, 2026-11-02T11:48:43Z.
  • New commits read: 1 — 354e1fce "test(proxy): name the per-family split floor in the ccbody fixture comment".
  • Read in full: 4 reviews, 3 comments, 0 inline comments (from the three files; the inline file is empty).
  • New items since my last review:
    • Reviewer 2's round-3 review (2026-11-02T11:49:07Z) — read in full. Its verification of the four ApplyForm call sites matches what I found in round 3.
    • The author's comment (2026-11-02T11:50:29Z) — read in full. Both claims checked: the ccbody comment fix is in the diff, and the PR body line is updated on the server.
    • Commit 354e1fce — the full diff is one comment line in proxy/ccbody_test.go:26. I read the file around it. The fixture uses claude-sonnet-5 and a ~6.7 KB stable half, so it clears the 853 o200k Sonnet floor and the test still holds. No code change, no behavior change.

I did not run builds or tests. Live tests are not approved, and Go is not installed on this machine. I read the code only.

- One list of cache tuning keys (CacheForm.tuningValues) feeds the write loop
  and the cache_reset check, so a typo cannot report success.
- Form.validate returns an error that names the typo and the valid keys.
  The settings handler returns it as a 400.

Assisted-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Fixed in the new head.

  • One key list. CacheForm.tuningValues() holds the 7 tuning keys. The write loop and the cache_reset check both read it.
  • Typo fails. Form.validate rejects a name outside the list. The error names the typo and lists the valid keys. The settings handler already returns an ApplyForm error as a 400.
  • Tests. TestApplyFormRejectsAnUnknownCacheResetName (config). The control test now also PUTs a typo name and expects a 400 that names the key.

-race: ./config/... and the full ./proxy/... pass. gofmt -l and go vet are clean.

@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.316 offload-review skill, @amiddavid's session resumed 1 of 2 5 of 5 0b5773f16454 approve

Verdict: approve

Findings

None. The fix is correct and closes the last open review item.

Earlier findings, and their state

  • The cache_reset typo was silently ignored (reviewer 2, round 3; I agreed in round 4) — fixed in 0b5773f1. Form.validate now rejects a name outside the seven-key list, with an error that names the typo and lists the valid keys (config/form.go:601-611). The settings handler returns an ApplyForm error as a 400, so the typo is visible to the caller.
  • All other items from rounds 1-4 are fixed and verified in those rounds. Nothing regressed.

What I checked

  • Last review: round 4, 354e1fce3f81bf019fe12ba4c314e4e982474e38, 2026-11-02T11:51:38Z.
  • New commits read: 1 — 0b5773f1 "fix(config): reject an unknown name in cache_reset (#798)".
  • Read in full: 6 reviews, 4 comments, 0 inline comments (from the three files; the inline file is empty).
  • New items since my last review:
    • Reviewer 2's round-4 review (2026-11-02T11:51:33Z) — read in full. It approved the comment-only commit and kept the cache_reset typo and the human yes as the open items.
    • The author's comment (2026-11-02T12:03:40Z) — read in full. All three claims checked against the code, below.
    • Commit 0b5773f1 — full diff plus the code around each hunk.

On the new commit:

  • One key list, two readers. CacheForm.tuningValues() (config/form.go:137-147) holds the seven keys and the stated values. The ApplyForm write loop and the cache_reset check both read it, so the two can no longer drift — the exact structure I would have asked for.
  • The write path is unchanged. The loop body is byte-for-byte the old switch over the same map, now built by the method. No value, key, or precedence moves.
  • The validation is placed correctly. Form.validate runs before ApplyForm writes anything, and ctlUpdateMe maps an ApplyForm error to a 400. The check sits before the f.Cache != nil block, so it also guards a form that names a reset without a cache object — stricter, never looser.
  • sort and strings were already imported in config/form.go, so the new code compiles with no import change.
  • Tests match the behavior. TestApplyFormRejectsAnUnknownCacheResetName checks the error names both the typo and a valid key. The control test PUTs a typo through /api/me and expects a 400 that names the key — the handler path, not just the library path.
  • Nothing user-visible changes. cache_reset ships in this same PR and no UI sends it, so turning a silent no-op into a 400 is not a behavior change on any existing client.

The one thing still open before merge is the human developer's yes on the four behavior changes, which the PR body asks for at the top.

I did not run builds or tests. Live tests are not approved, and Go is not installed on this machine. I read the code only.

@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.316 offload-review skill, @amiddavid's session resumed 2 of 2 5 of 5 0b5773f16454 approve

Verdict: approve

Findings

None. The new commit closes my last open item, and it is correct.

Status of earlier items

My round-4 non-blocking items:

  1. A typo in cache_reset is silently ignored — fixed in 0b5773f1. Form.validate now rejects a name outside the seven tuning keys, and the error names the typo and lists the valid keys (config/form.go:601-611). The settings handler returns that error as a 400 (proxy/control.go:1297-1301). Verified below.
  2. The four behavior changes need the human developer's yes — still pending. The PR body still heads the list with "need a human developer's yes".

Reviewer 1's round-4 review raised nothing new. Its one non-blocking item was the same cache_reset typo; both of us flagged it, and this commit fixes it.

The new commit (0b5773f)

I read the full diff and the code around each change. What I verified:

  1. One key list, no drift. CacheForm.tuningValues() holds the same seven keys with the same values the write loop used to build inline (config/form.go:138-148). The write loop (config/form.go:427) and the new validation both read it, so a key cannot be writable but not resettable, or the reverse.
  2. Validation runs before any write. ApplyForm calls f.validate() first (config/form.go:394-397), so a typo cannot delete or keep anything. The check works when f.Cache is nil: it runs on a fresh &CacheForm{}, not on f.Cache.
  3. The 400 is real. control.go:1297-1301 returns an ApplyForm error as a 400 with the error text. TestApplyFormRejectsAnUnknownCacheResetName checks the error names the typo and a valid key; the control test PUTs a typo and asserts the 400 and the message (proxy/control_test.go:646-654).
  4. No internal caller can trip the check. Only the JSON request body sets Form.CacheReset. The other three ApplyForm call sites (keepalivectl.go:301, toolfilterctl.go:213, adaptctl.go:153) build forms from ParseForm, which never sets it. I grepped the repo: no non-test code sets CacheReset besides the decode.
  5. No new behavior change against main. cache_reset itself is new in this PR, so rejecting unknown names defines the new field. It fails safe: the save is refused with a clear message, and the stored document keeps its keys. No CLAUDE.md disclosure is required, and the PR body's item 3 already describes the field.

Non-blocking

  • The four behavior changes still need the human developer's yes before merge. The PR asks for it. Merge should not happen without it.
  • Optional: PR body item 3 could say that an unknown cache_reset name is a 400. Not required, because the field is new in this PR.

What I checked

  • Last review: round 4, 354e1fc, 2026-11-02T11:51:33Z.
  • New commits read: 1 (0b5773f "fix(config): reject an unknown name in cache_reset (#798)").
  • Read in full: 6 reviews, 4 comments, 0 inline comments (from the three files; the inline file is empty).
  • New items since my last review:
    • Reviewer 1's round-4 review (2026-11-02T11:51:38Z) — read in full. It approved 354e1fce and agreed with my cache_reset typo item. Nothing new to check beyond that.
    • Commit 0b5773f — full diff plus the code around each hunk: config/form.go (tuningValues, the write loop, validate), config/headgate_test.go, proxy/control_test.go, proxy/control.go:1297-1301.
    • The author's reply comment (2026-11-02T12:03:40Z) — read in full. All four claims checked against the code, as listed under "The new commit".
  • Every CacheReset reference in the repo, to prove only the JSON decode sets it.
  • Form.normalize and Form.validate, to prove validation runs before any write and nothing strips CacheReset.
  • The current PR body, read back from the server: the four behavior changes are intact, item 3 names the field, and the header still asks for the human yes.

I did not run builds or tests. Live tests are not approved for this review, and Go is not installed on this machine. I read the code only, as instructed.

@amiddavid
amiddavid merged commit 86e906f into main Nov 2, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 2, 2026
@amiddavid
amiddavid deleted the feat/token-estimate branch November 2, 2026 17:20
amiddavid added a commit that referenced this pull request Nov 2, 2026
…0.2.9) (#863)

Claude Code plugin 0.6.4 -> 0.6.5:
- #850: 12 display-only skills get disable-model-invocation: true.
- #738: an optional beep when Claude finishes or needs input.
- #848: settings.py still writes head_ttl_min_tokens, so an older proxy loads its config.
- #859: the band and cg.py show "finished" for an agent that ended with a terminal tool call.

Codex plugin 0.2.8 -> 0.2.9:
- #850: 9 display-only skills get allow_implicit_invocation: false.
- #852: the session skill's front matter is valid YAML, so Codex loads it.

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.

refactor: the bytes/4 token estimate has 5 separate copies with different rounding

1 participant