Repository navigation
fix(modelinfo): index a qualified price entry by its own bare tail - #334
Conversation
Table.lookup never derived a bare-id index for a qualified entry (one whose match contains "/" or "."), unlike LiteLLM.fetch, which does this for the public price map. So a request whose model id omitted the provider prefix an operator priced it under fell past that specific entry to whichever wildcard family entry happened to prefix-match, silently, with ok=true and token_accounting=complete. On the live price list this overcharged every bare claude-sonnet-5 request 1.5x ($970.85 on the snapshot corpus, closes #324) and underpriced bare gpt-5.6-sol by falling through to the public map instead of its own explicit azure/gpt-5.6-sol entry. Fix: derive each qualified, non-family entry's bare tail once at parse time and consult it between the exact-match pass and the family/containment pass, so a bare id resolves to the specific entry it is the tail of before any wildcard is tried. An explicit bare entry the operator wrote on purpose still wins outright (it is already an exact match). A tail that two differently-priced qualified entries would both claim is ambiguous and is deliberately left unindexed rather than guessing: it falls through to the family/ public-map passes, logged once at load time. Independently replayed against the 2026-09-28 snapshot corpus (264,163 requests): reproduces the $970.85 overcharge and 1.4988 (=2.28/1.52) ratio exactly, and the ~$12.22 gpt-5.6-sol underprice. Signed-off-by: Osher-Elhadad <[email protected]>
OsherElhadad
left a comment
There was a problem hiding this comment.
Independent review (REV) — PR #334 (fix(modelinfo): index a qualified price entry by its own bare tail)
Reproduced everything below myself: own worktree, own SQL against the read-only snapshot, own
from-scratch test cases (not reused from the PR or from FIX-price's report), sudo cat of the
live /etc/context-guru/prices.yaml for verification only (never written). No spend, no
systemctl action, no writes to the snapshot or the control DB.
The precedence chain — correct, and I attacked it rather than read it
Traced lookup: (1) exact match against every entry's match (e.match==full||e.match==tail) —
this can only ever hit a literal bare entry or a full qualified id, never a qualified entry's
bare tail (since a qualified entry's match always contains / or . by definition, so it can
never equal a bare tail string); (2) the new bareTail map; (3) family/containment, one pass,
longest-match-first (unchanged). Confirmed deriveBareTails skips any tail already claimed by a
literal entry (so an intentional bare entry can never be shadowed by a derived one) — the
literal[e.match] check runs before the tail is ever considered.
I wrote 3 additional adversarial tests beyond the author's own 6, none reused:
- Three-way ambiguity (not just two providers) — still falls through to the family rate
correctly. PASS. - Pathological match strings (
"aws/","/"— trailing/bare slash) —deriveBareTails
does not panic (wrapped in arecover()to be sure) and a real sibling entry still resolves
correctly. PASS. - Ambiguous tail with no family fallback at all — reports
ok=falserather than silently
resolving to either provider's rate. PASS.
Regression test: verified it genuinely fails on pre-fix code, not just asserted
Checked out main's table.go with the PR's new table_test.go on top (own git surgery, not
trusting the PR body's claim): TestBareIDResolvesToQualifiedEntryNotFamily324 fails on main
exactly as described (bare claude-sonnet-5: in = $2.28/MTok, want $1.52 ... got the family rate).
The other 4 new tests happen to also pass on pre-fix code, which is expected — they exercise
precedence rules the old 2-pass lookup already handled correctly by construction (explicit-bare,
family-fallback, unknown-id), not the #324 regression itself. Restored the fix branch afterward.
go test -race ./internal/... — ran myself, all packages pass (adjudicate, cheapmodel, coref,
extract, logging, modelinfo, redact, skills, tokens).
slog.Warn reachability — confirmed, not assumed
No slog.SetDefault anywhere in this repo, so the ambiguity warning goes through Go's default
handler → os.Stderr, the same mechanism cmd/context-guru-proxy/main.go already uses for
every other operator-facing startup warning (e.g. "no --manager-email set", "no email path
configured"). Under systemd that's the journal, reachable via install.sh status. I saw it fire
literally, in test output: WARN model price list: bare id is ambiguous.... Not a black hole.
Malformed-file fail-closed behavior — untouched, verified by reading, not just trusting the diff
deriveBareTails is called only as the last line of ParseTable, after every existing
validation (negative rate, zero rate, no match, unknown YAML key via KnownFields(true))
already returns early on error. A malformed file never reaches it. Combined with the
panic-safety test above, I'm satisfied this doesn't introduce a new way for a bad file to load
"successfully."
Independent re-derivation of $970.85 / 1.4988 / $12.22 — third method, matches to the cent
Neither reusing M-meas's SQL nor FIX-price's Python port: straight SQL against requests' raw
token columns (fresh_input, cache_read, cache_write, output_tokens) and the live
prices.yaml rates (aws/claude-sonnet-5: $1.52/$7.60; family claude-sonnet*: $2.28/$11.40;
azure/gpt-5.6-sol: $5.00/$30.00), applying the documented cache fracs directly:
SELECT COUNT(*), SUM(cost_usd),
SUM((fresh_input + cache_read*0.1 + cache_write*1.25)*2.28e-6 + output_tokens*11.40e-6),
SUM((fresh_input + cache_read*0.1 + cache_write*1.25)*1.52e-6 + output_tokens*7.60e-6)
FROM requests WHERE model='claude-sonnet-5' AND token_accounting='complete';
-- n=46028, recorded=$2917.2661, family-rate-recompute=$2919.6181, aws-rate-recompute=$1946.4121$1946.4121 matches the PR's after-fix figure exactly. $2917.2661 − $1946.4121 = $970.8540
— matches $970.85 exactly. Same for gpt-5.6-sol (own query, azure rate, cache_write frac=1.0
since neither "gpt" nor "azure" contains "claude"/"anthropic"): recorded $41.0383, correct-rate
$53.2572, underprice $12.2189 ≈ $12.22, exact match. Three independent derivations (M-meas's
original, FIX-price's Python port, and this SQL recompute) now agree to the cent.
One small, non-blocking thing I chased down while I was in there: the PR states "ratio 1.4988
(== 2.28/1.52 exactly)" — but 2.28/1.52 is exactly 1.5, not 1.4988. The observed ratio really
is 1.4988 (recorded/after-fix), but it isn't literally the clean rate ratio: my own
"family-rate-recompute" ($2919.62, using today's $2.28 rate on the raw tokens) doesn't quite match
recorded ($2917.27) either — a ~0.08%/$2.35 gap. Since input/output/cache-read/cache-write all
scale by exactly 1.5x between these two specific entries (verified: both contain "claude" so both
get the same 1.25x cache-write premium, and neither states an explicit cache override), the
aggregate ratio should be exactly 1.5 if every one of the 46,028 rows was priced at today's exact
family rate the whole time. The small gap says a few of the 41.4 days' worth of rows were probably
priced under a slightly different (historical) rate before prices.yaml was last edited — not a
code defect, doesn't change the $970.85 conclusion (which matches recorded exactly, the only
correct baseline), and not something this PR needs to account for. Flagging only so "1.4988 ==
2.28/1.52 exactly" in the PR body gets corrected to something like "≈2.28/1.52" — a reader who
divides those two numbers will get 1.5 and wonder if they misread something.
The self-reported $1,047.97-vs-$958.63 discrepancy — confirmed sound
I didn't need to reproduce FIX-price's mistake to confirm the fix: my SQL above computes the
after-fix cost by re-rating the raw tokens once and comparing directly against recorded cost_usd
(the correct baseline) for each bucket separately, exactly the corrected method they describe
arriving at. Landing on $970.85 and $12.22 independently, via a third method that never took the
wrong turn (replay-vs-replay) in the first place, is itself the confirmation that recorded-vs-
single-replay is the right comparison and their diagnosis (double-counted reimplementation noise
from comparing two replays instead of one replay against ground truth) is consistent with getting
a clean, exact-cent match by avoiding exactly that mistake.
Verdict
Passes. Precedence is correct and matches its own documentation; the ambiguity decision is
implemented as described and is genuinely observable (not a silent log); deriveBareTails cannot
panic or bypass fail-closed loading on a malformed file; the regression test is real (verified
failing on main, not just asserted); the headline dollar figures are independently reproduced to
the cent via a third, from-scratch method. One text-only nit (the "1.4988 == 2.28/1.52 exactly"
line) — not blocking, just worth a one-word edit ("≈" for "==").
|
Thanks for the independent re-derivation and the catch. Fixed the PR body: "1.4988 (== 2.28/1.52 exactly)" -> "≈ 2.28/1.52, not exactly" with a note. Also fixed my own attribution error while I was in there -- I'd originally called the $2.35 gap "float-reimplementation noise" in my report, which doesn't hold up dimensionally (float64 summation error over 46,028 rows is nowhere near $2.35). Your explanation (the price file was probably edited at least once during the 41.4-day window, since the ratio should be exactly 1.5 if every row had been priced at today's exact rate the whole time) is the right one and I've corrected the report to credit it. Doesn't change $970.85/$12.22/the fix itself -- three independent derivations (M-meas, mine, yours) still agree to the cent on those. |
Resolve the table_test.go conflict (both sides appended tests; keep both). Review fixes: - Use the bare-tail index only for a request with no provider prefix, so vertex/claude-sonnet-5 no longer takes aws/claude-sonnet-5's rate. - Treat a shared tail as ambiguous only when the providers' prices differ, as the comment already said. - Rename the misnamed family-fallback test; add an inline #324 acceptance test, a vertex-prefix test and a same-rate test. - Update ratefill_before.json: bare claude-sonnet-5 now resolves to aws/claude-sonnet-5 (it was recorded as unpriced, which is the #324 bug). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | cb4c48e8 |
blocking |
Verdict: blocking
Findings
- internal/modelinfo/table.go:212 — the ambiguity rule compares only price, but the derived tail also serves window and compaction point
- What fails: the operator lists one model under two providers at the same rate with different
metadata, e.g.aws/claude-sonnet-5(in 1.52,window: 200000) and
vertex/claude-sonnet-5(in 1.52,window: 1000000). The prices are equal, so
deriveBareTailsdoes not mark the tail ambiguous and indexes it. A bare request
claude-sonnet-5takes whichever claiming entry sorts first — herevertex/..., the
longer match.Windowthen returns 1000000 andWindowExactreports it as exact. If the
bare traffic is the aws deployment, every window-scaled trigger (a summarizer's
min_request_frac, the warm sweep's turns-left estimate) runs against a 5x-too-high
window, confidently and marked exact. The same holds forcompaction_point, which sizes
the sweep. The rule's own comment, "two providers at one rate are not a guess", is true
for the rate and false for the metadata the entry also carries. - Proof:
lookupis shared. The new pass (table.go:277-281) returns thebareTailentry,
andWindow(table.go:328),WindowExact(table.go:313) andCompactionPoint
(table.go:320) all callt.lookup.deriveBareTailsmarks a tail ambiguous only when
prev.price != e.price(table.go:212);windowandcompactionPointare never
compared. No new test exercisesWindoworCompactionPointthrough a bare-tail hit —
all eight new tests checkPriceonly. - Fix: treat a tail as ambiguous also when the claiming entries differ in
windowor
compactionPoint, not only in price. Add a test: two same-price entries with different
windows; the bare id must not report one provider's window as exact.
- What fails: the operator lists one model under two providers at the same rate with different
Non-blocking
internal/modelinfo/testdata/ratefill_before.json— the fixture's stated contract is now
stale.ratefilltest.gosays the values were "made on origin/main c2a06dd, before any
code changed", andCheck's failure text says "before the refactor it was". This PR edits
4 rows, so the file no longer holds those "before" values. Say in the fixture or its
comment that rows for bareclaude-sonnet-5were re-baselined by #334.- The PR body says "six new cases" and lists five; the diff adds eight test functions. Doc
drift only. deriveBareTails(table.go:211): an entry whosematchstring repeats an earlier one
bypasses the ambiguity check (prev.match != e.match) and overwrites the indexed tail, so
a duplicated match at two rates can priceaws/xand barexdifferently. Garbage input;
ParseTablecould reject duplicate matches instead.
What I checked
- Full diff of
internal/modelinfo/table.go,table_test.go,testdata/ratefill_before.json,
and the code around each change:Normalize/stripVariant,ParseTable,lookup,
Price.Resolved,Chain. - The new precedence is sound. For a bare request, pass 2 fires only on exact tail equality,
and every pass-3 competitor for that id (a family prefix of it, or a qualified entry
contained in it) is strictly shorter than the qualified entry's full match. Pass 1 still
wins for an explicit bare entry and for a family whose stripped match equals the id. - The ambiguity detection is sound for prices: the first claimer is never replaced, so any
later entry at a different price flags the tail, and if none differs, all are equal.
Finding 1 is the one hole: metadata other than price is not compared. - The
full == tailguard is correct: a prefixed request (vertex/claude-sonnet-5) never
takes another provider's tail. Verified againstTestOtherProvidersPrefixDoesNotTakeAQualifiedTail. - The LiteLLM reference in the comment is accurate (
litellm.go:206-207, 230-232does
first-wins tail indexing). This PR deliberately deviates (refuse-and-log) for ambiguity;
the deviation is documented and tested. - The shipped
deploy/service/prices.example.yaml: no two qualified entries share a bare
tail, so no ambiguity warning fires on it;aws/claude-sonnet-5($1.52) and
azure/gpt-5.6-sol($5.00) are the only tails the new pass adds, matching the two
regression-test claims. Thegoogle/gemmatail also becomes reachable bare — intended,
same rule. - The 4 changed fixture rows: re-derived the arithmetic (in 3.0/MTok, out 15, cache read
0.1x/0.2x/0.3x per doc frac, cache write 1.25x/1.5x, 1h 2x). All values match the
aws/claude-sonnet-5 entry in the test table. All other rows are unchanged by the new pass,
as expected. - The PR names the behavior change at the top (who it affects, old and new behavior, the
#323cost_usdinteraction). It prices only from the operator's own file; no new data
dependence, sodocs/data-dependence.mdneeds no row. - Live tests were not run (not approved); Go is not on this machine.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | cb4c48e8cd57 |
blocking |
Verdict: blocking
Findings
-
deploy/harbor/kv_ttl_cost_model.py:615 — the guarded Python port of
Tabledid not get the bare-tail pass, so the two implementations of one money question now disagree.- What fails: the drift test's own header (kv_ttl_cost_drift_test.go:5-11) says
kv_ttl_cost_model.pyis a port ofmodelinfo.Table, the test is the guard, and Go is right when they disagree. This PR changes the Go side only. After it, a bare id that is the tail of a qualified entry prices differently in each: Go returnsaws/claude-sonnet-5's $1.52 forclaude-sonnet-5; Python's_lookup(lines 623-632) has no bare-tail pass, so it returns the family rate orknown=False. The harbor analyses price real corpus rows this way:kv_ttl_predictor_arms.py:503andkv_ttl_keepalive_policy.py:818load the operator file intoPriceBookand callfor_model(r.model)per request, and the PR body itself counts 46,028 bareclaude-sonnet-5rows in the corpus. So #324 survives in every Python-side dollar figure — the predictor arms and the keepalive policy still see the 1.5x overcharge this PR fixes in Go. - Proof:
kv_ttl_cost_model.py:623-632— pass 1 matchesmatch == full or match == tail(the entry's own id, not a derived tail), then families and containment. No step derives a qualified entry's bare tail. The parity guardkv_ttl_price_parity_test.go:36-41queries no bare tail of a qualified entry (claude-sonnet-5andgpt-5.5are queried only with their prefixes), so it stays green and hides the divergence. - Fix: port
deriveBareTailsand thefull == tailpass into_lookup(same rules: skip family and bare entries, skip a tail a literal entry claims, drop an ambiguous tail with a warning). Add a bare-tail id, e.g.claude-sonnet-5, to the parity test'sidsso the guard covers the new pass.
- What fails: the drift test's own header (kv_ttl_cost_drift_test.go:5-11) says
-
internal/modelinfo/table.go:212 — the ambiguity guard compares
Priceonly, sowindowandcompaction_pointare guessed silently.- What fails: two qualified entries share a bare tail at the SAME price but state different
windoworcompaction_point.prev.price != e.priceis false, so the tail is indexed to whichever entry sorts first, andTable.Window/WindowExact/CompactionPoint(lines 313-334) resolve the bare id to that entry.WindowExactreports the window authoritative, so it overrides the public map with confidence. - Proof:
tableEntry(table.go:39-49) carrieswindowandcompactionPointoutsidePrice; the comparison at line 212 cannot see them. Example: an operator listsaws/x(window 200000) andvertex/x(window 1000000) at one rate. A barexrequest gets 200000 as EXACT. Fraction triggers and the warm sweep's turns-left estimate then run on the other provider's window, with no log line. That is the same silent guessing the guard exists to stop — its own comment (table.go:187-191) says a bare request for an ambiguous tail "cannot be resolved without guessing which provider it meant", and window is part of what the entry means. - Fix: treat a tail as ambiguous when the claiming entries differ in
price,windoworcompactionPoint— compare the whole entry exceptmatch. Or keepWindow/CompactionPointon the old passes and let the bare-tail index servePriceonly.
- What fails: two qualified entries share a bare tail at the SAME price but state different
Non-blocking
deploy/service/prices.example.yaml:85-90is now stale. It says the families catch the bare aliases because the missing prefix is not normalised. After this PR the specific entries catch them first. The file documents every other matching rule, so it should also state the new one: a qualified entry answers its own bare tail, and a tail two providers price differently is dropped with a load-time warning.- Pre-existing, not changed by this PR: a family entry
x*still exact-matches a barexin pass 1, because its trimmedmatchequals the request's tail (table.go:267-271). So a specificaws/xcannot win the bare id when a familyx*exists. Theliteralskip inderiveBareTailsis consistent with that, but it leaves one corner of #324's shape open. Worth an issue of its own. - The PR text says "six new cases"; the diff adds eight test functions. The merge commit 4a2e599 names the extra three.
ratefill_before.json: four rows were regenerated after the fix. The provenance comment inratefill_test.go:11-12("fixture made on origin/main c2a06dd... before any code changed") now holds for only part of the file.
What I checked
- The full diff (3 files) and every commit: 173c5a0, merge 4a2e599, merge cb4c48e.
deriveBareTailsby hand: ambiguity with two and three same-tail entries, in both price orders; same-price tails; duplicate match strings; prefix and bare entries skipped; a tail claimed by a literal entry skipped. The ambiguity decision is sound for prices.lookupprecedence: the exact pass, thefull == tailgate (variant-suffixed ids likeclaude-sonnet-5[1m]and decorated ids likevertex/claude-sonnet-5behave correctly), the family/containment pass.Normalize(modelinfo.go:208) read in full.- All eight new tests re-derived by hand against the example file and the inline tables. Each asserts what it claims. The example file really carries
aws/claude-sonnet-5at $1.52 (line 54),azure/gpt-5.6-solat $5.00 (line 71) andclaude-sonnet*at $2.28 (line 92). - The four changed
ratefill_before.jsonrows re-derived by hand: the plain, readfrac, writefrac and bothfracs arithmetic foraws/claude-sonnet-5at 3/15 all match. - Every other test that builds a
Table(internal/modelinfo, kvcache, dash, keepalive, proxy, proxyapp, components/offload, deploy/harbor) checked for bare-id queries whose answer would change. None queries a bare tail of a qualified entry — which is exactly why finding 1 stays hidden. - The example file's behavior change enumerated model by model: only bare
claude-sonnet-5($2.28 to $1.52) and the no-family tails (gpt-5.6-sol,gemini-3-*,gemma) change; every other bare alias lands on a rate identical to its family's. - The chain wiring (cmd/context-guru-proxy/main.go:1480-1536) and
LiteLLM.fetch(litellm.go:200-232), which the PR claims to mirror. The claim is accurate. - The PR body names the behavior change at the top, as CLAUDE.md requires. Data dependence is unchanged: the feature reads the operator's config file only, so no
docs/data-dependence.mdrow moves. - I did not run Go builds or tests; live tests are not approved and Go is not on this machine.
|
Integrator note after GLM round 1 at cb4c48e. Both reviewers block. Please fix these, then run round 2 (offload-review):
Also needed in the PR text:
|
…ion point differ deriveBareTails compared only price, but Window, WindowExact and CompactionPoint read the same entry. Two providers at one rate with different windows made the bare id report one provider's window as exact. ParseTable now rejects a repeated match, which bypassed the ambiguity check. Note in ratefill_test.go that the claude-sonnet-5 rows were re-baselined. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
kv_ttl_cost_model.py is a port of modelinfo.Table and had no bare-tail pass, so the harbor analyses still priced a bare claude-sonnet-5 at the family rate. Add the pass and the ambiguity rule, put a bare tail in the parity test, and update the stale note in prices.example.yaml. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
|
Round 1 findings are fixed in f9a6025 and the commit after it. Reviewer 1, finding 1, and reviewer 2, finding 2 (same defect):
Reviewer 2, finding 1:
Non-blocking items:
|
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | fresh | 2 of 2 | 2 of 2 | 1f0a5bd30fb0 |
blocking |
Verdict: blocking
Findings
-
deploy/harbor/kv_ttl_cost_model.py:644-674 — the Python port of the new ambiguity rule compares rates only, so Go and Python price the same bare id differently again.
- What fails: an operator lists one model under two providers at the same rate but with different
windoworcompaction_point, plus a family fallback. Example:aws/claude-sonnet-5(in 1.52, window 200000),vertex/claude-sonnet-5(in 1.52, window 1000000),claude-sonnet*(in 2.28). Go now drops the tail as ambiguous (table.go:223compares price, window and compaction point), so a bareclaude-sonnet-5falls through to the family and prices at $2.28. Python's_derive_bare_tailscomparesrates()only, indexes the tail, and prices the bare id at $1.52.from_operator_file(lines 534-561) never reads thewindoworcompaction_pointkeys, so the Python side cannot see the difference. The harbor analyses (kv_ttl_predictor_arms.py:503,kv_ttl_keepalive_policy.py:818) then quote a different dollar figure than the proxy for the same rows — the exact divergence that round-1 finding 1 closed. - Proof: Go
deriveBareTails(table.go:221-227) marks the tail ambiguous andlookuppass 3 (table.go:293-296) returns the family entry. Python_derive_bare_tails(kv_ttl_cost_model.py:663-668) checksrates(prev[1]) != rates(price);rates()(line 650-652) touches price fields only, andModelPricinghas no window field. The parity guardkv_ttl_price_parity_test.godoes not cover the shape: its YAML (lines 25-35) has one qualified entry per tail, so the two-entries-one-tail case never reaches the test. - Fix: read
windowandcompaction_pointinfrom_operator_file, carry them with the entry, and include them in the ambiguity comparison. Add a same-rate different-window pair to the parity test YAML, and query its bare tail, so the guard covers the rule.
- What fails: an operator lists one model under two providers at the same rate but with different
-
PR text — the sections the integrator asked for on 2026-11-11 are still missing.
- What fails: the integrator note (issue comment, 09:43:25Z) says the PR text needs a Behavior change section (who it affects, old and new behavior, how to turn it off, the owner's yes) and a Data dependence section. Neither is in the PR body at head
1f0a5bd3. The Tests section still says "six new cases" and lists five; the branch now adds twelve test functions intable_test.go. The author said at 10:03 that the count edit "still needs an edit", and no later change did it. - Proof: PR body fetched on 2026-11-11 — no "Behavior change" heading, no "Data dependence" heading, "six new cases" present.
git diff fd6f3865..HEAD -- internal/modelinfo/table_test.goadds twelvefunc Test...functions. - Fix: add both sections and correct the count before merge. CLAUDE.md makes the named behavior change a merge gate, and this PR moves
cost_usditself.
- What fails: the integrator note (issue comment, 09:43:25Z) says the PR text needs a Behavior change section (who it affects, old and new behavior, how to turn it off, the owner's yes) and a Data dependence section. Neither is in the PR body at head
Non-blocking
- Python
from_operator_fileaccepts a duplicatedmatchthat Go'sParseTablenow rejects (table.go:129-132). In_derive_bare_tailstheprev[0] != matchbranch is therefore reachable in Python, and a later duplicate overwrites the indexed tail (kv_ttl_cost_model.py:664-668). Garbage input only; Go refuses the file at startup, so the operator must fix it before the proxy runs. Porting the duplicate rejection would close it. - The Go
slog.Warn(table.go:237) and the Pythonwarnings.warnstill say "different rates", but the rule now also covers window and compaction point. Message drift only.
What I checked
- Last review: round 1, cb4c48e, 2026-11-11T09:42:33Z
- New commits read: 2 — f9a6025 "fix(modelinfo): Treat a bare tail as ambiguous when window or compaction point differ", 1f0a5bd "fix(harbor): Port the bare-tail pass to the Python price reader"
- Read in full: 3 reviews, 3 comments, 0 inline comments (from the three files)
- New items since my last review:
- Integrator note by amiddavid, 09:43:25Z. Checked each request. Items 1 and 3 are done (verified in code). Item 2 is done in code but incomplete in the port — finding 1. The PR-text requests are not done — finding 2.
- Author comment by boazdavid, 10:03:10Z. Verified each claim: the Go ambiguity fix, the Python pass, the parity ids, the example-yaml note, the ratefill comment, the duplicate rejection. All true except the port is narrower than the Go rule (finding 1). The author's own "PR body count still needs an edit" is still open — finding 2.
- Commits f9a6025 and 1f0a5bd. Reviewed below.
- Earlier findings:
- Reviewer 1 finding 1 and my round-1 finding 2 (ambiguity compares price only): fixed.
table.go:223now comparesprice,windowandcompactionPoint. Three new tests cover different window, different compaction point, and same window kept.ParseTablerejects a repeated match, which closes the duplicate-match bypass. The first-claimer logic stays sound:ParseTablenow guarantees unique matches, soprev.match != e.matchis always true on a second claimer, and any difference marks the tail. - My round-1 finding 1 (Python port missing the pass): fixed in pass, not in rule — the bare-tail pass and the
full == tailgate are in_lookup,claude-sonnet-5andvertex/claude-sonnet-5are in the parity ids, and all harbor entry points usefrom_operator_file. But the ambiguity comparison is price-only — finding 1. - OsherElhadad's review (2026-09-28): its nit ("1.4988 == 2.28/1.52 exactly") is fixed in the PR body ("≈ 2.28 / 1.52, not exactly", with the confirmed rate-step note). Nothing else in it asks for change.
- Round-1 non-blocking items:
prices.example.yamlnote updated and accurate;ratefill_test.gocomment states the re-baseline; the familyx*exact-match corner stays open by the author's choice — accepted, it predates this PR and deserves its own issue; the "six new cases" count is still wrong — finding 2.
- Reviewer 1 finding 1 and my round-1 finding 2 (ambiguity compares price only): fixed.
- The new Go tests re-derived by hand against
lookupandderiveBareTails: each asserts what it claims, including the negative assertions (ok=false,exact=false) and the positive aws-prefixed control. - The ratefill fixture: the new rule does not move it. Its table has one qualified entry per tail, so the window comparison never fires; no re-baseline was needed, and none was made.
- The parity test re-derived by hand for each new id: bare
claude-sonnet-5takesaws/claude-sonnet-5in both implementations;vertex/claude-sonnet-5matches nothing in either;aws/claude-sonnet-5-5still takes the containment hit. The author's "passes with PyYAML on Python 3.12" is consistent with the code; I could not run it, Go and the test harness are not on this machine. Priceis comparable (modelinfo.go:65-76, float64 fields only), so the!=at table.go:223 compiles and compares every field.- No code was changed, committed or pushed. The only file written is
.review.md.
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | fresh | 1 of 2 | 2 of 2 | 1f0a5bd30fb0 |
blocking |
Verdict: blocking
Findings
-
deploy/harbor/kv_ttl_cost_model.py:619 — the Python lookup does not strip the
[...]variant suffix, so the new bare-tail pass misses a variant-suffixed bare id that Go resolves- What fails: query
claude-sonnet-5[1m]againstdeploy/service/prices.example.yaml. Go'sNormalize(modelinfo.go:208-229) strips the trailing[1m], solookuppass 2 returnsaws/claude-sonnet-5at $1.52. Python's_lookupsetsfull = (model or "").strip().lower()and strips nothing; the bare-tail map key isclaude-sonnet-5, soclaude-sonnet-5[1m]misses, pass 3 returns familyclaude-sonnet*at $2.28. The harbor analyses keep the exact 1.5x overcharge this PR fixes in Go, for[1m]traffic. Before this PR both engines said $2.28; the port made them diverge. - Proof: modelinfo.go:208-229 vs kv_ttl_cost_model.py:619-620. No variant strip exists anywhere in the Python file. The parity test ids include
claude-sonnet-5but noclaude-sonnet-5[1m]. With that id added to the current fixture, Go answers known at in=3.0 (theaws/claude-sonnet-5entry) and Python answersknown=False(no family covers sonnet-5 in that table) — the parity test fails. - Fix: strip one trailing bracketed group in
_lookupbefore the passes, asstripVariantdoes. Addclaude-sonnet-5[1m]to the parity test ids.
- What fails: query
-
deploy/harbor/kv_ttl_cost_model.py:644 — the ported ambiguity rule is the rule before f9a6025, not the Go rule this PR ships
- What fails: an operator file with
aws/x(in 1.0,window: 200000),vertex/x(in 1.0,window: 1000000) and familyx*(in 3.0). Go (table.go:223) marks the tail ambiguous, because the windows differ, and drops it; barexprices at the family rate, 3.0. Python compares rates only (rates()at line 650), becausefrom_operator_file(lines 534-561) never readswindoworcompaction_point— the keys are silently ignored. Python indexes the tail; barexprices at 1.0. The two engines disagree on a money figure. The duplicate-match rejection (table.go:129-132) was also not ported: Python accepts a repeated match, and theprev[0] != matchbypass at line 664 then indexes the LAST duplicate while_lookup's exact pass returns the FIRST, soaws/xand barexprice from different entries — and the same file fails to load in Go outright. - Proof: the traces above, read off the code. The parity fixture has no same-tail pair and no duplicate entry, so
TestPythonPriceReaderMatchesGoTablestays green and hides both divergences. - Fix: track
window/compaction_pointper entry infrom_operator_fileand compare them in_derive_bare_tails; reject a repeated match at load, asParseTabledoes. Add a same-price different-window pair plus a family entry, and a duplicate entry, to the parity fixture.
- What fails: an operator file with
-
PR text — the body still lacks what the integrator asked for and what CLAUDE.md requires before merge
- What fails: no Behavior change section and no Data dependence section, both requested in the integrator note of 2026-11-11. The new duplicate-match rejection is itself a behavior change — old: a file with a repeated match loaded and priced; new:
ParseTablereturns an error — and it is named nowhere in the PR body. The Tests section still says "six new cases" and lists five; the diff adds twelve test functions. The author's reply of 2026-11-11 says the count edit is still pending. - Proof: the PR body as of head
1f0a5bd3(saved and read in full this round).git diff fd6f3865..HEAD -- internal/modelinfo/table_test.go | grep -c "^+func Test"returns 12. - Fix: add the two sections. Name the duplicate rejection: who it affects (an operator whose file repeats a match), old and new behavior, and how to avoid it (remove the duplicate). For the bare-tail change, say how to turn it off (write a literal bare entry, which wins pass 1). Correct the test count.
- What fails: no Behavior change section and no Data dependence section, both requested in the integrator note of 2026-11-11. The new duplicate-match rejection is itself a behavior change — old: a file with a repeated match loaded and priced; new:
Non-blocking
deploy/service/prices.example.yaml:90says "or give different windows". The rule also drops a tail whose entries differ incompaction_point. One word missing.- Go's
Pricecomparison stays stricter than Python's in one corner: one entry statescache_writeexplicitly, the other leaves it blank, and a file-levelcache_write_fracmakes the effective rates equal. Go seesCacheWrite1.4 vs 0 and drops the tail; Python compares the computedwrite_5mand keeps it. Same direction as finding 2; settle it when the two rules are unified. - The missing variant strip also breaks Python pass 1 for literal entries: query
gemini-2.5-pro[1m]returns Go's literalgemini-2.5-proentry ($1.25) and Python'sgemini-2.5*family ($0.30). Pre-existing before this PR; the fix for finding 1 fixes this too. - The family
x*corner (a family entry exact-matches a barexin pass 1, so a specificaws/xcannot win the bare id): the author declined with the reason that it is older than this PR and needs its own issue. The reason is right; reviewer 2 asked for the same issue.
What I checked
- Last review: round 1, cb4c48e, 2026-11-11T09:40:17Z.
- New commits read: 2 — f9a6025 (window and compaction point join the ambiguity rule;
ParseTablerejects a repeated match), 1f0a5bd (the bare-tail pass ported to the Python price reader). - Read in full: 3 reviews, 3 comments, 0 inline comments (the inline file is empty). Also the PR body in full.
- New items since my last review, and what I did about each:
- Reviewer 2 round-1 review (09:42:33Z). Read in full. Its finding 1 (the Python port) is the item behind my findings 1 and 2; its finding 2 matched my round-1 finding 1.
- Integrator note (09:43:25Z). Items 1 and 2 are done in code but incompletely (findings 1 and 2). The PR-text items are not done (finding 3).
- Author reply by boazdavid (10:03:10Z). Each claim checked against the diff: the Go ambiguity fix, the three new tests, the Python pass, the parity ids, the example-yaml note, the ratefill comment, the duplicate rejection — all present as stated, except the port is unfaithful (findings 1 and 2) and the PR body is unchanged (finding 3).
- Earlier findings: my round-1 finding 1 (window and compaction point not compared) is fixed — table.go:223 compares all three, and
TestSameRateDifferentWindowTailIsAmbiguous,TestSameRateDifferentCompactionPointTailIsAmbiguousandTestSameRateAndWindowTailKeepsItsWindowcover it. My non-blocking items: the ratefill provenance comment is fixed (ratefill_test.go:11-13); the PR-body count is not (finding 3); the duplicate-match bypass is fixed in Go only (finding 2). deriveBareTailsre-traced by hand with two and three same-tail entries, in both sort orders: the first claimer is never replaced, each later entry is compared against it, so the extended comparison is sound. An entry with a window and one without also count as different, which is the conservative direction.ParseTable's duplicate check: it runs on the lowercased match before the*is trimmed, soAWS/xafteraws/xis caught (tested), and a familyx*beside an exactxstays two distinct entries, as before.kv_ttl_cost_model.pyread in full around the change:ModelPricing,from_operator_file,_lookup,_derive_bare_tails,hit's read-rate fill from the queried model (matches Go'sPrice.Resolved). Therates()masking of the entry id and the derived read rate is right for what it compares; the gap is what it does not compare (finding 2).- The parity fixture traced by hand for every id in the list, Go side against Python side. All agree on the current fixture; the ids that would disagree (
claude-sonnet-5[1m], a same-tail pair with different windows, a duplicate) are not in it. - The PR names the bare-tail behavior change in the Summary (who, old, new, the corpus counts) but not how to turn it off, and does not use the section names the integrator asked for (finding 3).
- Live tests were not run; live tests are not approved and Go is not on this machine.
…he Python reader Compare window and compaction_point in the Python bare-tail rule, strip a trailing [variant] suffix in _lookup, and reject a repeated match at load, as modelinfo does. Add the cases to the parity test and say compaction point in the warning and the example file. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | resumed | 2 of 2 | 3 of 3 | a0c1269dcf2d |
blocking |
Verdict: blocking
Findings
-
deploy/harbor/kv_ttl_cost_model.py:541-567 — the new duplicate check and the
metamap disagree about the key, so a family-plus-specific pair either fails to load or gets the wrong window in the ambiguity rule.- What fails: the check
if match in metaruns on the match BEFORE the*is trimmed, butmetais keyed by the match AFTER the trim. Two consequences for a file that carries bothaws/x*(a family) andaws/x(a specific), which Go'sParseTableaccepts because itsseenmap keys the untrimmed match (table.go:121-134):- Family first, specific second: the specific entry's untrimmed
aws/xis already ametakey (the family set it), so Python raises"'aws/x' appears more than once"and refuses a file the proxy runs on. - Specific first, family second: no raise, but
meta["aws/x"]is overwritten with the family's(window, compaction_point). The ambiguity comparison then uses the family's metadata for the specific entry. Example:aws/x(in 1.0, window 100000),aws/x*(in 2.0, no window),vertex/x(in 1.0, no window). Go marks the tail ambiguous (windows 100000 vs 0) and prices barexat the family rate, 2.0. Python compares (0,0) vs (0,0), indexes the tail, and prices barexat 1.0.
- Family first, specific second: the specific entry's untrimmed
- Proof: kv_ttl_cost_model.py:541-544 (check before trim) vs 567 (
meta[match]after trim);rates()at 660-664 readsmeta.get(match, (0,0)). Go'sseencheck (table.go:129-132) uses the untrimmed match, soaws/xandaws/x*never collide there, and Go'stableEntrycarries window per entry, so no overwrite is possible. The newTestPythonPriceReaderRejectsADuplicateMatchLikeGouses two identicalaws/xentries, and the parity fixture has no family-plus-specific pair, so neither test catches it. - Fix: key the duplicate check on the untrimmed match, as Go does — a separate
seenset. Carry(window, compaction_point)per entry, not in a dict keyed by the trimmed match — for example extend the entries tuple. Add the family-plus-specific pair to the parity fixture.
- What fails: the check
-
PR text — the body is unchanged since round 2 and still lacks what the integrator asked for and what CLAUDE.md requires before merge.
- What fails: no Behavior change section and no Data dependence section, both requested in the integrator note of 2026-11-11 09:43:25Z. The Tests section still says "six new cases" and lists five; the diff adds twelve test functions in
table_test.go. The duplicate-match rejection thatf9a60259added toParseTableis itself a behavior change — old: a file with a repeated match loaded and priced; new:ParseTablereturns an error and the proxy does not start — and it is named nowhere in the PR body. I agree with reviewer 1, round-2 finding 3, and checked it myself: the body saved this round is byte-for-byte the round-2 body. - Proof: PR body fetched at head
a0c1269d(saved and read in full). No "Behavior change" heading, no "Data dependence" heading, "six new cases" at the Tests section. - Fix: add both sections before merge. Name the bare-tail change (who, old, new, how to turn it off: write a literal bare entry, which wins pass 1) and the duplicate rejection (who, old, new, how to avoid it: remove the duplicate). Correct the count. CLAUDE.md makes the named behavior change and the owner's yes a merge gate.
- What fails: no Behavior change section and no Data dependence section, both requested in the integrator note of 2026-11-11 09:43:25Z. The Tests section still says "six new cases" and lists five; the diff adds twelve test functions in
Non-blocking
rstrip("*")in Python (kv_ttl_cost_model.py:544) strips all trailing*characters; Go'sTrimSuffixstrips one. An id ending in**trims differently. Garbage input only.- The
rates()masking still compares a slightly different field set than Go'sPrice !=(one entry statescache_write, the other leaves it blank under a file-level frac): Go is stricter and can drop a tail Python keeps. Pre-existing port design, same direction as before; not introduced by this commit.
What I checked
- Last review: round 2, 1f0a5bd, 2026-11-11T10:08:09Z
- New commits read: 1 — a0c1269 "fix(harbor): Match the Go ambiguity, variant and duplicate rules in the Python reader"
- Read in full: 5 reviews, 3 comments, 0 inline comments (from the three files). Also the PR body in full.
- New items since my last review:
- Reviewer 1's round-2 review (10:11:37Z). Read in full. Its finding 1 (variant strip missing in Python) was new to me — I verified it against
modelinfo.go:208-229and the pre-commit Python, and it was correct. Its finding 2 matched my round-2 finding 1 plus the duplicate port. Its finding 3 matched my round-2 finding 2. - Commit a0c1269. Reviewed below.
- No new issue comments; the comment list still ends at 10:03:10Z.
- Reviewer 1's round-2 review (10:11:37Z). Read in full. Its finding 1 (variant strip missing in Python) was new to me — I verified it against
- Earlier findings:
- My round-2 finding 1 (Python ambiguity compares rates only): fixed.
from_operator_filenow readswindowandcompaction_pointintometa,rates()includes them, and the parity fixture gains theaws/ambig-model/vertex/ambig-modelpair with theambig*family — exactly the shape I asked for. The port is faithful except for themetakeying — finding 1. - My round-2 finding 2 (PR text): not fixed — finding 2.
- My round-2 non-blocking (duplicate rejection not ported): fixed in intent, defective in the keying — the rejection exists and has a parity test, but the check and the
metamap disagree about the key — finding 1. - My round-2 non-blocking (warning text says "different rates"): fixed on both sides;
prices.example.yamlnow says "windows or compaction points". - Reviewer 1's round-2 finding 1 (variant strip): fixed. The Python strip (kv_ttl_cost_model.py:627-628) matches Go's
stripVariantexactly, including the corner cases:rfind("[") > 0mirrorsi <= 0(no opener, or the whole id is the group), and only one group is stripped. The strip runs before the tail is computed, as inNormalize. The parity ids gainclaude-sonnet-5[1m]andgemini-3-flash-preview[1m]. - Reviewer 1's round-2 finding 2: fixed, same as my round-2 finding 1, with finding 1's defect.
- Reviewer 1's round-2 finding 3: not fixed — finding 2.
- Reviewer 1's round-2 non-blocking items: the example-yaml wording is fixed; the
cache_writeexplicit-vs-blank corner is unchanged (my non-blocking above); the familyx*corner stays declined with the reason "older than this PR, needs its own issue" — I checked the reason and accept it.
- My round-2 finding 1 (Python ambiguity compares rates only): fixed.
- The new commit's Go side: only the
slog.Warnmessage text changed. Re-readderiveBareTailsandParseTablein full around it; no behavior change. - The parity fixture traced by hand for every id, Go side against Python side at head
a0c1269d: bareambig-model→ tail dropped (windows differ), familyambig*3.0 in both;aws/ambig-model→ 1.0 in both;claude-sonnet-5[1m]→ strip → bare-tail →aws/claude-sonnet-53.0 in both;gemini-3-flash-preview[1m]→ strip →gemini*2.0 in both. All agree. Mappingis imported (kv_ttl_cost_model.py:246), so the new_derive_bare_tailssignature resolves.- The shipped
prices.example.yamlhas no family-plus-specific pair sharing a trimmed key (allaws/*andazure/*entries are exact; the families are bareclaude-*), so finding 1 does not fire on the shipped file — it fires on a legal file shape Go accepts. - I did not run Go or Python tests; live tests are not approved and Go is not on this machine.
- No code was changed, committed or pushed. The only file written is
.review.md.
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | resumed | 1 of 2 | 3 of 3 | a0c1269dcf2d |
blocking |
Verdict: blocking
Findings
-
deploy/harbor/kv_ttl_cost_model.py:567 —
metais keyed by the trimmed match, so a family sibling overwrites the exact entry's window and compaction point, and Python drops or keeps a tail Go decides the other way- What fails: the duplicate check at line 541 runs on the match WITH its
*, soaws/claude-sonnet-5andaws/claude-sonnet-5*are two legal entries in both engines — a natural file shape: the exact rate for the id, the family default for its siblings. Butmeta[match]at line 567 is written AFTERrstrip("*"), so both entries write the same key and the later one wins. File order then decides which entry's(window, compaction_point)the ambiguity rule sees. Example:aws/claude-sonnet-5(in 1.52, window 200000), thenaws/claude-sonnet-5*(in 1.52, no window), thenvertex/claude-sonnet-5(in 1.52, window 200000). Go: both claimants carry window 200000 and one price, the tail is indexed, bareclaude-sonnet-5prices at 1.52. Python: the family sibling has overwrittenmeta["aws/claude-sonnet-5"]to (0, 0), the comparison sees (0, 0) against (200000, 0), the tail is dropped with a warning, and the bare id falls through to a family rate or unknown. The reverse order of the two aws entries hides the bug — it is order-dependent and silent. - Proof: lines 541-544 and 567 of kv_ttl_cost_model.py, read against table.go, where each
tableEntrycarries its ownwindowandcompactionPoint(table.go:169-170) so no collision is possible. The parity fixture has no exact entry paired with its own family sibling plus a second provider, soTestPythonPriceReaderMatchesGoTablestays green. - Fix: key
metaby the untrimmed match (unique by the new duplicate check), or carry(window, compaction_point)in the entry tuple as Go'stableEntrydoes. Add the shape to the parity fixture: an exact entry, its own family sibling, and a second provider on the same tail.
- What fails: the duplicate check at line 541 runs on the match WITH its
-
PR text — round-2 finding 3 is still not fixed: the body is unchanged
- What fails: no Behavior change section and no Data dependence section, both requested by the integrator on 2026-11-11 and required by CLAUDE.md before merge. The duplicate-match rejection is a behavior change — old: a file with a repeated match loaded and priced; new:
ParseTableandfrom_operator_fileboth refuse it — and it is named nowhere in the PR body. The Tests section still says "six new cases"; the branch adds twelve test functions intable_test.goand one inkv_ttl_price_parity_test.go. The author said on 2026-11-11 that the count edit was still pending; no later change did it. - Proof: the PR body fetched this round at head
a0c1269dand read in full — "six new cases" at line 111, no "Behavior change" or "Data dependence" heading anywhere.git diff fd6f3865..HEAD -- internal/modelinfo/table_test.go | grep -c "^+func Test"returns 12. - Fix: add the two sections. Name the duplicate rejection (who: an operator whose file repeats a match; old: loads and prices; new: load error; avoidance: remove the duplicate). Say how to turn the bare-tail change off (write a literal bare entry, which wins pass 1). Correct the count.
- What fails: no Behavior change section and no Data dependence section, both requested by the integrator on 2026-11-11 and required by CLAUDE.md before merge. The duplicate-match rejection is a behavior change — old: a file with a repeated match loaded and priced; new:
Non-blocking
from_operator_filereadswindowandcompaction_pointbut skips Go's validation of them: Go refuses a negative window or acompaction_pointabove the window (table.go:135-140); Python accepts the file and uses the values in the ambiguity comparison. The new duplicate test's own comment says the analyses must not price from a file the proxy would not start on. No wrong money figure directly — the values feed only the drop/keep decision.- The cache-write strictness corner from my round-2 note is still open: one entry states
cache_writeexplicitly, the other leaves it blank, a file-levelcache_write_fracmakes the effective rates equal. Go compares the statedCacheWrite(1.4 against 0) and drops the tail; Python compares the computedwrite_5mand keeps it. Unchanged by this commit.
What I checked
- Last review: round 2, 1f0a5bd, 2026-11-11T10:11:37Z.
- New commits read: 1 — a0c1269 "fix(harbor): Match the Go ambiguity, variant and duplicate rules in the Python reader".
- Read in full: 5 reviews, 3 comments, 0 inline comments (the inline file is empty). Also the PR body in full, re-fetched this round.
- New items since my last review: only commit a0c1269. No review, comment or inline comment was posted after 10:11:37Z. Reviewer 2's round-2 review (10:08:09Z) predates my round-2; I read it in full this round anyway. I agree with its finding 1 (the Python ambiguity rule compared rates only) — fixed by this commit, with the collision in my finding 1 left. I agree with its finding 2 (the PR text) — my finding 2. Its two non-blocking items (duplicate rejection not ported; warning text drift) are both fixed.
- Earlier findings:
- My round-2 finding 1 (variant suffix not stripped in Python): fixed.
_lookupnow strips one trailing bracketed group before the passes. Traced againststripVariantedge cases: no opener, an id that is only the group, an unterminated bracket, two stacked groups — all match Go. The parity ids addclaude-sonnet-5[1m]andgemini-3-flash-preview[1m]; traced on both engines, they agree. - My round-2 finding 2 (the ported ambiguity rule was the pre-f9a60259 rule; no duplicate rejection): fixed except the collision. Window and compaction point are now read and compared, a repeated match is refused at load in both engines, the parity fixture has the same-rate different-window pair with a family fallback, and
TestPythonPriceReaderRejectsADuplicateMatchLikeGocovers the duplicate on both sides. The remaining hole is finding 1. - My round-2 finding 3 (PR text): not fixed — finding 2.
- My round-2 non-blocking items: the example-yaml wording is fixed ("windows or compaction points"); the Go and Python warnings now say "differ in rate, window or compaction point"; the family
x*corner stays deferred to its own issue by the author's choice — accepted, it predates this PR.
- My round-2 finding 1 (variant suffix not stripped in Python): fixed.
- The new parity fixture traced id by id on both engines:
ambig-modelis dropped as ambiguous in both and takes theambig*family at 3/15;aws/ambig-modelis an exact hit in both; every pre-existing id still agrees. - The Python duplicate check catches a case-different repeat (
AWS/xafteraws/x), because the check runs on the lowercased match, as Go's does.Mappingis imported andfrom __future__ import annotationsis present, so the new annotation cannot fail at import. - The
metacollision traced in both directions: family sibling later in the file corrupts the exact entry's values (Go keeps, Python drops); a family sibling carrying the other provider's window can make Python keep a tail Go drops. Both orders read off lines 541-567 and the sort at line 570. - Live tests were not run; live tests are not approved and Go is not on this machine.
…ke Go A family sibling (aws/x*) shared its trimmed match with the exact entry and overwrote its window. Keep the map to exact entries, check duplicates on the match as written, and refuse a negative window or a compaction point above it. Add an exact entry with its family sibling and a second provider to the parity fixture. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
|
Round 3 findings are fixed in baceab0, and the PR body is now updated.
Still open: the owner's yes in Behavior change, and the explicit-versus-blank |
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | resumed | 1 of 2 | 4 of 4 | baceab0429a3 |
approve |
Verdict: approve
Findings
None.
Non-blocking
- The explicit-versus-blank
cache_writecorner is still open, and the author says so: one entry statescache_write, the other leaves it blank, a file-levelcache_write_fracmakes the effective rates equal. Go compares the statedCacheWrite(1.4 against 0) and drops the tail; Python compares the computedwrite_5mand keeps it. Both engines stay deterministic and the input is contrived. Worth a follow-up issue, not a change in this PR. - The PR body's Owner's yes line says pending. CLAUDE.md makes the owner's yes a merge gate. Do not merge until it is recorded.
What I checked
- Last review: round 3, a0c1269, 2026-11-11T10:22:19Z.
- New commits read: 1 — baceab0 "fix(harbor): Key the window map by the exact entry and validate it like Go".
- Read in full: 6 reviews, 4 comments, 0 inline comments (the inline file is empty). Also the PR body in full, re-fetched this round.
- New items since my last review, and what I did about each:
- Reviewer 2's round-3 review (10:21:12Z, one minute before my round-3; read in full this round). Its finding 1 is my round-3 finding 1 plus one more consequence I had missed: with the family sibling FIRST, the old code's duplicate check keyed on the untrimmed match against
metakeys keyed on the trimmed match, so a legal exact+family pair was refused outright. I checked that consequence against the round-3 code — it is correct. Its finding 2 is my round-3 finding 2. Its non-blockingrstrip("*")point (Go trims one*, the old Python trimmed all) is correct. - Author comment by boazdavid (10:23:38Z). Each claim checked against the diff: all true.
- Commit baceab0. Reviewed below.
- The PR body update. Verified in full — see my round-3 finding 2.
- Reviewer 2's round-3 review (10:21:12Z, one minute before my round-3; read in full this round). Its finding 1 is my round-3 finding 1 plus one more consequence I had missed: with the family sibling FIRST, the old code's duplicate check keyed on the untrimmed match against
- Earlier findings:
- My round-3 finding 1 (
metakeyed by the trimmed match; family sibling overwrites the exact entry's window; false duplicate refusal in the family-first order): fixed. The duplicate check now uses a separateseenset keyed on the match as written,*included, exactly as Go'sseenmap keys it (kv_ttl_cost_model.py:537, 542-544 vs table.go:121-134), so an exact entry and its family sibling never collide in either order.metais written only for non-prefix entries (line 575-576); a non-prefix match is stored as written andseenguarantees the written form is unique, sometakeys are unique and no overwrite is possible in any file order. The parity fixture now carries the exact shape I asked for:aws/famsib-model(window 200000),aws/famsib-model*(a different rate, no window),vertex/famsib-model(window 200000), queried bare, prefixed and as a sibling. - My round-3 finding 2 (PR text): fixed. The body now has a Behavior change section (who it affects, old, new, the corpus numbers, the duplicate-match rejection named with its old and new behavior and how to avoid it, how to turn the bare-tail change off — write a literal bare entry), a Data dependence section (none; no
docs/data-dependence.mdrow needed), and the corrected count: "twelve new test functions", which matchesgit diff fd6f3865..HEAD -- internal/modelinfo/table_test.go | grep -c "^+func Test"= 12, and the parity file's second test is named in prose. The author's note that the earlier body edit failed on a GitHub API error explains why round 3 saw the old body. - My round-3 non-blocking items: the window/compaction validation gap is fixed — Python now refuses a negative window or compaction point and a compaction point above the window, with the same conditions as table.go:135-140 (
window > 0 and compaction > window, negative check), placed after the trim as in Go. Thecache_writecorner stays open, acknowledged by the author. The familyx*corner stays deferred to its own issue — accepted, it predates this PR.
- My round-3 finding 1 (
- The new fixture traced id by id on both engines: bare
famsib-model— both engines index the tail (prices equal, windows equal at 200000 becausemetanow holds the exact entry's window, not the family's) and price it at the vertex entry's 1/5;aws/famsib-model— exact hit at 1/5 in both;aws/famsib-model-2— the family's 2/9 in both. If the round-3 bug were still present, the family would have zeroedmeta["aws/famsib-model"], the tail would drop, and the bare id would answer unknown in Python against 1/5 in Go — the fixture catches the bug it was built for. - The one-
*trim (line 546,match[:-1] if prefix else match) matches Go'sTrimSuffix:aws/x**keeps one*in the trimmed match in both engines. Reviewer 2's round-3 non-blocking is closed. - The check order in
from_operator_file(empty match, duplicate, trim, window/compaction validation, rate validation) matchesParseTable's order, so the two readers refuse the same files for the same first reason. deploy/harbor/kv_ttl_cost_model.pyread in full around the change; no other behavior moved. The Go side of the PR is unchanged since round 3 except the warning text already reviewed then.- Live tests were not run; live tests are not approved and Go is not on this machine. The author reports the parity test passes with PyYAML on Python 3.12; the traces above are consistent with that.
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | resumed | 2 of 2 | 4 of 4 | baceab0429a3 |
approve |
Verdict: approve
Findings
None.
Non-blocking
- The merge gate is still open: the owner's yes. The Behavior change section ends with "Owner's yes. Needed before merge: pending", and the author's reply of 10:23:38Z names it as still open. CLAUDE.md says an agent never decides this. Do not merge before the owner says yes in the PR. This is the one remaining item, and it is not a code defect.
- The explicit-versus-blank
cache_writecorner is still open, by the author's choice: one entry statescache_write, the other leaves it blank under a file-levelcache_write_fracthat makes the effective rates equal. Go compares the stated value (against 0) and drops the tail; Python compares the computedwrite_5mand keeps it. Pre-existing port design, contrived file shape, both reviewers have held it non-blocking since round 2. - Pre-existing, unchanged by this PR: Python ignores an unknown YAML key that Go's
KnownFields(true)rejects, so a typo'd key (windo:) makes Go refuse the file and Python load it with window 0. Alsoint(m.get("window") or 0)truncates a fractional window where Go's decode errors. Garbage input both.
What I checked
- Last review: round 3, a0c1269, 2026-11-11T10:21:12Z
- New commits read: 1 — baceab0 "fix(harbor): Key the window map by the exact entry and validate it like Go"
- Read in full: 6 reviews, 4 comments, 0 inline comments (from the three files). Also the PR body in full, re-fetched this round.
- New items since my last review:
- Reviewer 1's round-3 review (10:22:19Z). Read in full. Its finding 1 (the
metakeying) is the same defect as my round-3 finding 1; its finding 2 (PR text) is the same as my round-3 finding 2. Both are fixed by this commit — verified independently below. Its non-blocking item (Python skipped Go's window/compaction validation) is also fixed by this commit. - Author comment by boazdavid (10:23:38Z). Each claim checked against the diff: the
seenset on the written match,metafor exact entries only, the window and compaction validation, the single-*trim, the new parity fixture, and the PR-body sections. All true. Its "still open" list matches mine. - Commit baceab0. Reviewed below.
- The PR body, re-fetched and read in full: it now has a Behavior change section (who, old, new, the duplicate-match rejection named, how to turn it off, owner's yes pending), a Data dependence section (none), and the corrected count ("twelve new test functions", plus the parity test described). The round-3 finding is closed. The author says the earlier body edit had failed on a GitHub API error, which explains why round 3 saw the old body.
- Reviewer 1's round-3 review (10:22:19Z). Read in full. Its finding 1 (the
- Earlier findings:
- My round-3 finding 1 (
metakeyed by the trimmed match; duplicate check on the untrimmed match): fixed. The duplicate check now uses a separateseenset keyed by the match as written,*included — exactly Go'sseenmap (kv_ttl_cost_model.py:537-544 vs table.go:121-134).metais written only by non-prefix entries (line 575-576); an exact entry's written match equals its trimmed match and theseencheck makes it unique, so no collision is possible and file order no longer matters. The parity fixture gains the shape both reviewers asked for:aws/famsib-model(exact, window 200000),aws/famsib-model*(family),vertex/famsib-model(second provider), withfamsib-model,aws/famsib-modelandaws/famsib-model-2in the query list. - My round-3 finding 2 (PR text): fixed, except the owner's yes, which is a human step, named as pending in the body itself.
- My round-3 non-blocking (
rstrip("*")strips all stars): fixed —match[:-1] if prefix else matchstrips exactly one, as Go'sTrimSuffix(kv_ttl_cost_model.py:546). - My round-3 non-blocking (the
cache_writecorner): still open, non-blocking, acknowledged by the author. - Reviewer 1's round-3 findings 1 and 2: same as mine, both fixed. Its non-blocking window-validation item: fixed — negative window or compaction point, and a compaction point above the window, are now refused (kv_ttl_cost_model.py:547-552), matching table.go:135-140.
- The family
x*exact-match corner: still declined with the reason "older than this PR, needs its own issue". I checked the reason again and accept it.
- My round-3 finding 1 (
- The new fixture traced by hand on both engines, in all four doc variants (plain, readfrac, writefrac, both): the two
famsib-modelclaimants carry one price and one window in both engines, the tail is indexed, barefamsib-modelprices at 1.0 in both;aws/famsib-modelis an exact hit at 1.0;aws/famsib-model-2takes the exact entry by containment (longest-first stable sort, exact before family at equal length) at 1.0 in both. Theread_derivedmasking and the per-familycache_write_frac_forbehave identically for both claimants, so the rates comparison agrees in every variant. - The
seencheck traced on the corner cases:aws/xtwice rejected;AWS/xafteraws/xrejected (lowercased, as Go);aws/xbesideaws/x*accepted, withmetaholding only the exact entry's values in both file orders. - The validation order and messages match Go's set of rejections; the message text uses the lowered match where Go uses the written one. Cosmetic only.
- I did not run Go or Python tests; live tests are not approved and Go is not on this machine.
- No code was changed, committed or pushed. The only file written is
.review.md.
|
Integrator note: the owner approved the behavior change on 2026-11-11 ("approve behavior change"): a bare model id now takes the price of the operator's qualified entry for it. Please put that in the Behavior change section, with how to turn it off. I see the 4 fix commits up to baceab0. When you are done, please run offload-review round 2 on the final head and message the integrator session. |
- prices.example.yaml: wrap the bare-alias note to the file's line width. - ratefilltest.go: say that #334 re-made the four sonnet-5 fixture rows. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
|
Integrator note on the approval at 42ed07d:
|
Behavior change (owner approved, David Amid, 2026-11-11):
aws/claude-sonnet-5, while requests send the bare id.claude-sonnet-5billed 1.5x too high) or to the public map (baregpt-5.6-solpriced too low).Second behavior change (owner approved, David Amid, 2026-11-11):
MODEL_PRICESfile lists the samematchtwice.ParseTablerefuses the file ("<match>" appears more than once). The proxy treats a bad price list as fatal, so it does not start.Data dependence: none. The change uses only model ids and prices.
docs/data-dependence.mddoes not change.Changed since round 1 (review at cb4c48e):
kv_ttl_cost_model.py) has the same bare-tail pass, variant strip, and duplicate and window checks.ParseTablerejects a repeatedmatch.[1m]variants, same-rate/different-window pair, duplicate-match test.prices.example.yaml,ratefill_test.goandratefilltest.gonow describe the new rule and the four re-made fixture rows.table_test.go, plus the harbor parity cases.Summary
Closes #324.
Table.lookupnever derived a bare-id index for a qualified entry (one whosematchcontains/or., e.g.aws/claude-sonnet-5) — unlikemodelinfo.LiteLLM.fetch, which does exactly this for the public price map(
m[full]=w; if _,ok:=m[tail]; !ok { m[tail]=w }). So a request whosemodelfield omitted the provider prefix the operator priced it under fell straight
past that specific entry to whichever wildcard family entry happened to
prefix-match — silently,
ok=true,token_accounting='complete'.On the live price list this overcharges every bare
claude-sonnet-5request1.5x, and separately underprices bare
gpt-5.6-solby falling through Tableentirely (no family entry exists for it) to the public LiteLLM map instead of
the operator's own
azure/gpt-5.6-solentry — same root cause, oppositedirection.
Fix and precedence
Each qualified, non-family (
matchwithout a trailing*) entry's bare tail(the part after its last
/) is derived once at parse time and consultedbetween the exact-match pass and the family/containment pass:
prefix*and containment, competing in one pass ordered by match length (unchanged)Table)An explicit bare entry the operator wrote on purpose always wins over a
derived tail — it's already an exact match in pass 1, so the new pass never
even runs for it.
Ambiguity. If two qualified entries under different providers would
derive the same bare tail at different rates (e.g.
aws/claude-sonnet-5and
vertex/claude-sonnet-5disagreeing), that tail is genuinely ambiguous —resolving it either way means guessing which provider a bare request meant,
which is the exact mechanism that produced #324. I chose refuse and log
over first-wins/last-wins: the tail is left unindexed, falls through to the
family/public-map passes (same as if neither qualified entry existed), and a
slog.Warnnames every ambiguous tail once at load time. First-wins is whatprices.example.yaml's comments already show operators working around byhand for the opposite problem (a family default not covering a specific
member) — repeating that pattern silently for provider ambiguity felt like
reintroducing this same bug in a new shape.
Interaction with #323
#323 proposes redeploying at
mainand states a falsification check of"
cost_usdunchanged, only the counterfactual moves." This PR breaks thatcheck — it moves
cost_usditself, not just the baseline counterfactual.If both land in the same release: recorded spend goes down on this corpus
(the sonnet-5 correction outweighs the gpt-5.6-sol one), and that is the
correct, expected effect of fixing a real overcharge — don't read the
combined deploy as a regression because
cost_usdmoved. (M-meas flaggedthis same interaction on #323 already.)
Verification
Independently re-derived against the 2026-09-28 00:15 UTC read-only snapshot
(
snap/cg.db, 264,163 requests), from a from-scratch Python port of theactual fixed
Table.lookup/deriveBareTails(not a reuse of anyone else'sworkaround script):
(Correction, caught by REV's independent review: 2.28/1.52 is exactly 1.5, not
1.4988 — the observed ratio is real but not literally the clean rate ratio.
Re-rating the raw tokens at today's exact $2.28 family rate for all 46,028 rows
gives $2919.62, not quite
recorded's $2917.27 — a ~0.08%/$2.35 gap. Since everycost component scales by exactly 1.5x between these two entries, the aggregate
ratio should be exactly 1.5 if every row had been priced at today's exact rate
for the whole 41.4-day window; the small gap most likely means
prices.yamlwasedited at least once during that window. Doesn't change the $970.85 conclusion,
which is recorded cost_usd vs. the after-fix replay — the correct comparison —
not two rates divided by each other.)
Update: REV's hypothesis above is now CONFIRMED by direct measurement, not
left as a leading guess — see finding P2-13 in PHASE2.md. A per-week implied rate
on the bare
claude-sonnet-5bucket (1e6 × Σcost_usd / Σ(fresh + read×0.1 + write×1.25 + 5×output)) shows a clean step change: the first week(2026-08-17, 347 rows) bills at 2.11849; every week after (30,357+ rows) bills
at exactly 2.28000.
prices.yamlreally was edited once, in the corpus'sfirst few days. Magnitude checks out: 347/46,028 rows (0.754%) at a rate 7.1%
lower predicts ~0.054% aggregate reduction against the observed 0.080% — same
order, the remainder plausibly row-size weighting. $970.85 is unaffected and
still agrees to the cent across all three independent derivations (M-meas,
this PR, REV). Also worth knowing for anyone doing a per-week or time-series
read of this corpus: 2026-08-17 to 08-19 is a deployment bootstrap window with
its own behavior (this rate step, and separately #329's saved_usd=0 defect,
both land there) — exclude it or report with/without it rather than reading a
step or trend across those three days as steady-state.
No ambiguous tails exist in the current live
prices.yaml(checked againstthe real
TableviaLoadTable, not just the Python replay) — the ambiguitypath is exercised only by
TestAmbiguousBareTailFallsThroughInsteadOfGuessing.Behavior change
Who it affects. An operator whose price file has a qualified entry (
matchwith a/or a., such asaws/claude-sonnet-5), and a client that sends the model idwithout the provider prefix.
Old. The bare id fell past the qualified entry to a family rate, or to the public
LiteLLM map.
New. The bare id takes the qualified entry's price. Window and compaction point follow
the same entry. If two qualified entries share the tail and differ in price, window or
compaction point, the tail is not indexed, a load-time warning names it, and the old
fall-through applies.
On the live list this lowers the price of bare
claude-sonnet-5from $2.28 to $1.52 (46,028rows, $970.85) and raises bare
gpt-5.6-solby $12.22. It movescost_usditself (see#323 above).
A second change:
ParseTablenow refuses a price file that repeats amatch. Before, thefile loaded and the first entry won. The Python reader refuses it too. Remove the duplicate
entry to fix the error.
How to turn it off. Write a literal bare entry for the id (for example
claude-sonnet-5).An exact bare entry wins before the new pass runs. To keep the old fall-through for a
whole tail, remove the qualified entry.
Owner's yes. Given by David Amid, 2026-11-11.
Data dependence
None. The change reads only the operator's price file and model ids. No new data source,
so
docs/data-dependence.mdneeds no row.Tests
internal/modelinfo/table_test.go— twelve new test functions: the #324 regression(fails on pre-fix code), an explicit bare entry beating a qualified tail, an
ambiguous tail falling through, a bare id with only a family entry, a bare id with
neither a qualified nor a family entry reporting unknown, a prefixed id not taking
another provider's tail, a same-rate tail, same-rate tails that differ in window or
in compaction point (ambiguous), a same-window tail keeping its window, and a repeated
matchbeing rejected.deploy/harbor/kv_ttl_price_parity_test.go— the Python price reader now has the samebare-tail pass. The parity test queries a bare tail, a
[1m]variant of it, and asame-rate/different-window pair, and a second test checks that both readers refuse a
repeated
match.gofmt -landgo vet ./internal/modelinfo/...are both clean.Not touched
/etc/context-guru/prices.yaml(live config, read-only viasudo catforverification), the deployed service,
cg-control.db. No merge, no deploy.