Repository navigation
feat(sweep): cut below a provider's price-tier line when it pays - #1455
Conversation
Below the sweet spot the sweep never cut. A request just above a price-tier line (OpenAI GPT-5.4+ at 272K, Haiku 5.5 at 100K) paid the high rates for many turns. With tier_target: true (off by default, needs sweep v3) a request above a line may be cut to line minus a margin. The cut must reach the goal and pass the warm gate with tier rates, counted for the turns until the prompt grows back to the line. Lines and rates come from Price.Tiers via Price.At. Fixes #1329 Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Owner decision (David Amid, 2026-11-26)
|
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 4 | c18ddf4452cc |
blocking |
Verdict: blocking
Findings
- components/offload/extract_sweep_v3.go:694 — no test covers the tier target on the judge or hybrid selector, only on
selector: rule- What fails: with
selector: judge(the default) orhybrid,tier_target: trueand a prompt above a line but below the sweet spot, the code now walks past the sweet-spot return and reaches the judge-ask block (extract_sweep_v3.go:770-780). The judge question is now asked below the sweet spot, and the held answer is later applied through the tier gate. Before this PR,not_in_sweet_spotreturned first and no question was ever asked there. All six new tests inextract_sweep_tier_test.gousev3Rule(selector: rule). A defect in the judge path of the default config would ship untested. - Proof:
v3Stepassignstierat line 694 and falls through; the rule branch at line 735 is the only selector path the tests take.apply(true)(held answer, line 767) and the hybrid rules-only branch (line 771) have no tier test.grep -n selector extract_sweep_tier_test.gofinds onlyv3Rule. - Fix: add one judge-selector (or hybrid) test: above the line, below the sweet spot,
tier_target: true— assert the question is asked, the answer is applied, and the cut reaches below the goal. Add one test that a held answer is not applied when the apply-time prompt falls back below every line.
- What fails: with
Non-blocking
- extract_sweep_v3.go:884 —
tier_line_not_reachedmislabels two unrelated refusals. The check!measuredalso fires when the recheck left no valid drop (no_valid_drop,no_drop_proposed) or the billed size is unknown (no_billed_size). The outcome is the same (refuse, fail-safe), only the logged reason is wrong. Split the!measuredcase out, or letinnerrun first. - components/ratesof.go:7 —
components.RatesOfnames aninternal/type in an exported signature.modelinfo.Priceis not importable outside this module, so the sidecar plugin and Cortex cannot callRatesOfeven thoughcomponentsis one of the four public API packages (CLAUDE.md, hard boundaries). Within the module everything works. Consider movingRatesOftolifecycle, which already exportsmodelinfo.Pricersignatures. - components/component.go:1028,1045 —
TokenRates.At/LineBelowre-implementmodelinfo.Price.At's line selection. Two copies of "the highest line below the prompt size wins" must now stay in sync, or the sweep's gate and the bill disagree.Price.Atcannot be reused onTokenRatesdirectly, so at least keep the pinning tests (TestTierRatesCarryTheLines,TestRatesCarryTheTiers) over both. - Margin vs the growth wait. After a tier cut, the thread waits
minDropFrac x Cof growth (default 0.15 x C) before any new cut (extract_sweep_v3.go:678-681). At C = 1M that is 150k, far more than the 4-10% margin (11k-27k at 272k). The prompt can sit above the line, paying the high rates, for many turns before a re-cut. Each cut still pays back on its own (the gate's saving counts only the turns below the line), so this is a coverage limit of the feature, not a wrong result. Worth an answer under the PR's open question 1.
What I checked
- Full diff base
3ef26ffd..headc18ddf44, and the code around each hunk:v3Step,v3Gate,v3Apply,warmGate,warmEconIn,agentRates,warmGateRates,warmRatios,noteBilledGrowth,warmTurnsLeftAfter. - Tier plan math:
tierGoal,tierMargin(4-10% clamp, 8 turns),tierEcon(saving, rewrite, turns cap at the line). Verified the goal andafteruse the same content ratio as the gate'sdBilled, and thattierEconruns only afterv3Gate's goal check passed, soreadBis always the lower-tier rate there. - Rate wiring:
components.RatesOfresolves tiers throughPrice.At(line+1); both production price sources applyWithTiers(internal/modelinfo/table.go:347,litellm.go:233), solifecycle.SelfRatescarries lines in production, not only in tests. - Off-by-default and isolation:
tier_targetis not in the v3 switch-on list (parseSweepV3), so it does not switch v3 on; every non-v3warmApplyis built without a tier (extract_sweep_warm.go:922,extract_sweep_v3.go:621);tierGoalreturns nil withwarm_gate_price_modelset, matching the rates the gate would use. - Fail open: no new panic path (
withRatescopies a lock-freeCtx); the warm step's recover still forwards the request unchanged. - No other consumer of
SelfRatesreads the newTiersfield, and no positionalTokenRates{...}literal breaks. - Docs:
advanced-offload.mdsection, thetier_targetfield hint, and the data-dependence row match the code; the generated page diff matches the row edit. Data dependence is metadata only, as the PR states. - PR body: names the behavior change at the top, default off, owner decision dated 2026-11-26. CI green (lint-build, purego, trivy);
go.modunchanged; no binaries.
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.332 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 4 | c18ddf4452cc |
blocking |
Verdict: blocking
Findings
- components/offload/extract_sweep.go:818 — the sweep's own question cost ignores the tier rates
- What fails: with
tier_targeton, a judge or hybrid sweep asks its question on prompts above a price line (272K–600K on GPT-5.4+, 100K–140K on Haiku 5.5).recordLeg(line 842) prices that call withratesPricing(c.SelfRates), andratesPricing(extract_llm.go:656) copies only the four base rates and drops the newTiers. The bookedCostUSD,metrics.RecordExtractionSpendand thecost_usdlog row (line 1272) come out 2x too low on GPT and 5x too low on Haiku. The request-level accountant prices the same traffic withPrice.At(dash/event.go:1017, proxy/metricsink.go:39), so the two ledgers disagree — the same defect class the comment above this code says #176 fixed ("two recorded totals disagreeing ... is worse than either alone"). - Proof:
ratesPricingbuildscheapmodel.Pricingfromr.Input/Output/CacheRead/CacheWriteonly;TokenRates.Tiersis never read. The question reads the stashed body, sousage.CacheReadis ~P, above the line.Price.At(internal/modelinfo/pricetier.go:34) is what the provider bills there. - Partly pre-existing: sweet-spot questions above a line were already under-priced. This PR opens the below-sweet-spot band, where every new question sits above the line, and it is the PR that puts the tiers on
SelfRatesin the first place. - Fix: in
recordLeg, resolve the tier before pricing:rates := c.SelfRates.At(usage.Fresh + usage.CacheRead + usage.CacheWrite), thenratesPricing(rates). Or make a tier-awareCost. If the owner prefers, file it as its own issue — but then say so in the PR.
- What fails: with
Non-blocking
components/component.go:1017—MaxRateTiers = 3redefinesmodelinfo.MaxTierswith a comment "It matches modelinfo.MaxTiers". That is a keep-in-sync constant.componentsalready importsmodelinfo(ratesof.go), so writeconst MaxRateTiers = modelinfo.MaxTiers.components/component.go:1026—TokenRates.AtandLineBelowduplicatemodelinfo.Price.At's tier-selection loop (the same "highest line below" rule in two packages).RatesOfalready delegates rate resolution toPrice.At; the selection rule could be shared too.components/ratesof.go:8—RatesOfis exported and its signature namesmodelinfo.Price, an internal type. A module outside this one cannot name that type, so it cannot call the function. In-module callers (lifecycle) are the only users.components/component.go:1060—TokenRates.CostignoresTiers. Any caller pricing a large prompt from aTokenRatesunder-reports (finding 1 is one instance;summarize_async.go:586prices deferred calls the same way). Worth one decision for all callers.- No test covers the
warm_gate_price_modelguard intierGoal(extract_sweep_tier.go:59), and none coverstier_target: truewith v3 off ("does nothing without v3"). extract_sweep_v3.go:884— with a tier plan set, a refusal for no valid drops or no billed size is labelledtier_line_not_reached. The finer cause (no_valid_drop,no_billed_size) is lost from the reason ledger.- Design tension, adjacent to the PR's open question 1: after a tier cut, the growth wait demands
minDropFrac x Cof growth before the next cut (extract_sweep_v3.go:669). On a 1M window that is 150K, while the margin buys only 10.9K–27.2K below the line. The thread can sit above the line, paying the high rates, for ~120K of growth while the sweep answerswaiting_for_growth. The payback gate itself would allow a re-cut much sooner.
What I checked
- Read the full diff (14 files) and the code around each change:
TokenRates.At/LineBelow/RatesOfagainstmodelinfo.Price.AtandWithTiers;tierGoal,tierMargin,tierEcon; thev3Stepsweet-spot branch; the rule-select early refusal; thev3Gatetier check and its order againstwarmGate; thewarmGatetier-econ hook; the config plumbing (tier_targetdoes not switch v3 on,parseSweepV3reads it only past theongate). - Checked the gate order for fail-safe behaviour:
tier_line_not_reachedruns beforewarmGate, sotierEcononly sees cuts that reach the goal; a cut whose valid drops are not all found in the request drivesturnsto 0 and refuses. Errors in the tier code only refuse a cut; the request goes out unchanged. The marker and the stash are the unchanged cut path. - Checked the saving arithmetic:
P x readA - after x readB=D x readA + after x (readA - readB), counted only for the turns until the prompt grows back to the line. The constant-size approximation under-counts the saving (growth above the line would bill at the high rate), so it errs towards refusal. - Checked
agentRateson tier-resolved rates: a stated tier rate passes throughCacheReadForunchanged; a blank one falls back to the model's multiplier, the same rule as the base card. - Checked the new tests: each rig test resets the v3 ledger (
newV3Rig→resetWarmForTest→resetV3ForTest), so thelen(v.Recent) != 1assertions are safe; the paced refusal counters line up withwarm_every_n3 over thetierRunrequest sequence; the Haiku rig at 110K is below its sweet spot (0.70 x 200K), so it does exercise the tier path. - Checked the units:
P,growthFromand the margin are all billed tokens;RatioContent/RatioFullare used the same way aswarmEcon. - Checked the docs: the
advanced-offload.mdsection matches the code; the data-dependence row file and the generated page carry the same sentence; the row says the dependence does not change, which matches what the code reads (token counts, prices, growth). - Checked the PR body: the behavior change is named at the top, with the off switch, the default (off) and the owner decision date; test notes name the machine.
- No builds or tests were run (not approved). Code reading only.
… wait on a tier cut - TokenRates.Cost and the sweep's recordLeg price a call at the tier rates of its own prompt size. Before, the question's cost was 2x or 5x low above a line. - A tier cut is not held by the growth wait; the tier gates decide. - tier_line_not_reached no longer hides no_valid_drop, no_drop_proposed or no_billed_size. - MaxRateTiers = modelinfo.MaxTiers. RatesOf moves to lifecycle. A test pins TokenRates.At to Price.At on a grid. - Tests: judge selector, held answer below every line, v3 off, gate price model, growth wait, card cost. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Replies to round 1 (both reviewers blocked)Fixed in Reviewer 1, finding 1: the question cost ignored the tiers. Fixed. Reviewer 2, finding 1: no judge or hybrid test. Fixed:
Non-blocking notes: all done.
Owner decision: Tests (macOS, Go 1.27.4):
Local tests: waived (owner rule) |
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 4 | 93cf004c2236 |
approve |
Verdict: approve
Findings
None. The round-2 commit fixes both round-1 findings correctly, and I found no new defect in it.
Round-1 findings, checked
- Mine, finding 1 (question cost ignored the tiers): fixed.
recordLegnow prices each leg withratesPricing(card.At(fresh + cacheWrite + cacheRead))(extract_sweep.go:846-852), which is the fix I proposed.TokenRates.Costis also tier-aware now (component.go:1058-1062), which fixessummarize_async's deferred calls the same way.TestTierCardPricesACallAtItsPromptSizepins the arithmetic, including the equality between the card and the sweep-leg pricing. The change is a second behavior change, not behindtier_target, and the PR body names it at the top with its off switch (flat: true).extract_llm's per-candidate calls stay below tier, named under "Not covered" — accepted: their prompts carry one tool output. - Reviewer 2, finding 1 (no judge or hybrid tier test): fixed. I checked both new tests myself.
TestTierJudgeSelectorAsksThenCutsBelowTheGoalwalks the real path: question asked below the sweet spot, answer held, then applied through the tier gate, cut below the goal, judge drops counted.TestTierHeldAnswerIsNotAppliedBelowEveryLinechecks the apply-time prompt below every line leaves the answer unapplied. - Non-blocking notes, mine and reviewer 2's: all addressed.
MaxRateTiers = modelinfo.MaxTiers(components/ratesof.go).RatesOfmoved tolifecycle; no exported signature incomponentsnames an internal type any more, and no caller of the oldcomponents.RatesOfremains.TestRatesAtMatchesPriceAtpinsTokenRates.AttoPrice.Aton a grid over both lines.tier_line_not_reachednow fires only for a measured cut that misses the goal;no_valid_drop,no_drop_proposedandno_billed_sizecome throughinneragain. Guard tests added forwarm_gate_price_modeland v3 off. The growth wait no longer holds a request above a line below the sweet spot.
The growth-wait bypass (new behavior, checked)
v3Stepsetswaiting = falsewhen a tier plan exists (extract_sweep_v3.go:694-701). The bypass is inside the below-sweet-spot branch only; a request in the sweet spot keeps the wait. After a tier cut the prompt sits below the line,tierGoalreturns nil, and the sweep refuses withnot_in_sweet_spot— so the bypass cannot make the sweep cut every turn. A re-cut needs the prompt above the line again, and the payback gate prices the rewrite. Fail open is unchanged.- Documented in
advanced-offload.md("No growth wait") and named in the PR body as the third behavior change, behindtier_target.TestTierCutIsNotHeldByTheGrowthWaitcovers it, and the author reports the mutation (removing the bypass) fails a test.
Non-blocking
components/component.go:1016— the comment "MaxRateTiers is how many tiers TokenRates holds. It matches modelinfo.MaxTiers." was left behind when the const moved toratesof.go. It now floats abovetype RateTierand documents the wrong thing. Delete it (the const has its own comment).- The PR body's "Rates" bullet still says the tiers are "built by
components.RatesOf". The function moved tolifecycle. Worth one edit so a reader finds it. tierRatesinextract_sweep_tier_test.gocopieslifecycle.RatesOfinline. The comment says offload cannot import lifecycle; that is right (lifecycleimportscomponents/offload, so a test in packageoffloadwould cycle). A drift between the copy and the real one would weaken the tier tests silently;TestRatesAtMatchesPriceAtcovers the selection rule but not this conversion. Acceptable as is.
What I checked
- Last review: round 1,
c18ddf4452cce4547c1443654f01c347d8e6d4f9, 2026-11-26T11:31:04Z. - New commits read: 1 —
93cf004c"fix(sweep): price a question at its tier, judge-path tests, no growth wait on a tier cut". - Read in full: 2 reviews, 2 comments, 0 inline comments (from the three saved files).
- New items since my last review: the author's reply comment (2026-11-26T11:36:49Z, fixes and owner decision) and commit
93cf004c. Both handled above. The owner-decision comment (11:18) predates my round 1 and matches the PR body. - Read the full round-2 diff and the code around each hunk:
TokenRates.Cost's newAt(checked every caller repo-wide: onlysummarize_asyncpasses a real prompt size; dash'sPrice.Costandcheapmodel.Pricing.Costare different types and unchanged);recordLeg's per-leg resolution (thepricingfallback is used only when the card is zero); thewaiting = falsebypass and its reach; thev3Gatemeasuredfix (verifiedwarmGatestill returns the finer reasons beforetierEconcan run). - Checked the new tests' mechanics: the judge test's ask cadence over
warm_every_n3, the held-answer test's refusal path, the without-v3 test's directe.v3assertion (the rig config isv3Basewithout a v3-switching setting), and the card-cost test's argument order againstCost(fresh, output, cacheWrite, cacheRead). - Checked the PR body: both new behavior changes are named at the top with off switches; "Not covered" names the
extract_llmgap and therecordLegindirection honestly. - No builds or tests were run (not approved). Code reading only.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 4 | 93cf004c2236 |
blocking |
Verdict: blocking
Findings
- dash/event.go:998 —
PriceCGstill prices the compaction calls flat, so the dash row and the sweep's booked spend now disagree above a line- What fails: this commit makes
recordLeg(extract_sweep.go:846-851) andsummarize_async(summarize_async.go:586, through the new tier-awareTokenRates.Cost) book a compaction call at the tier rates of its prompt size. The dash row prices the SAME call at the base rates:PriceCGcallsp.Cost(e.CGFresh, e.CGCacheRead, e.CGCacheWrite, e.CGOutput)on apthat never went throughp.At. Above a line,cg_llm_cost_usd(dash, Prometheuscg_tenant_cg_llm_cost_usd) reads 2x low on GPT-5.4+ and 5x low on Haiku 5.5 while the component'sRecordExtractionSpend,ModelCall.CostUSDandcost_usdlogs are right. Before this PR both sides were flat and agreed; now they disagree. - Proof:
priceCostin the same file appliesp = p.At(modelinfo.PromptTokens(...))for the request's own cost (dash/event.go:1017);PriceCG, which the capture site and the reprice pass both call (dashcapture.go:872), does not. The comment aboverecordLeg(extract_sweep.go:806-809) says the component prices "from the same rates the request-level figure uses, so the two agree rather than being two independent guesses" — above a line that claim is now false. This is the #176 defect class the fix itself cites: "Two recorded totals disagreeing ... is worse than either alone." - Fix: in
PriceCG, resolve the tier before pricing, aspriceCostdoes:p = p.At(modelinfo.PromptTokens(e.CGFresh, e.CGCacheRead, e.CGCacheWrite)). The PR body's second behavior change then holds for both ledgers.
- What fails: this commit makes
Non-blocking
- PR body, "What changed → Rates" still says the tiers are "built by
components.RatesOf". That function moved tolifecyclein this commit. Update the line. - "Decided" records only the
tier_targetdefault. The second behavior change (TokenRates.Cost, not behind any sweep switch) has no recorded owner yes in the PR. The author is the owner, so add one line naming the decision and the date. extract_econ.go:269,294(callCost,analyticBaseline) still estimate a judge call at flat rates. It is a gate estimate, not booked spend, and the "Not covered" section already names the per-candidate class. Fine to leave, worth one line there.- The test helper
tierRates(extract_sweep_tier_test.go:22) copies theRatesOfconversion. The comment is right thatoffloadcannot importlifecycle(lifecycle/prepare.goimportscomponents/offload), so the copy is forced. Test-only.
Earlier findings
- Mine, round 1, finding 1 (no judge or hybrid test): fixed.
TestTierJudgeSelectorAsksThenCutsBelowTheGoalcovers the question below the sweet spot, the apply through the tier gate, and the goal;TestTierHeldAnswerIsNotAppliedBelowEveryLinecovers the prompt falling back below every line. Both assert what I asked for. - Reviewer 1, round 1, finding 1 (question cost ignored the tiers): fixed in the component, incomplete on the dash side.
TokenRates.Costnow appliesAt(fresh + cacheWrite + cacheRead),recordLegresolves the card per leg,summarize_asyncis covered throughCost, andTestTierCardPricesACallAtItsPromptSizepins the arithmetic. My finding 1 above is the remaining half: the dash row for the same calls. - My round-1 non-blocking notes: all addressed.
tier_line_not_reachednow fires only for a measured cut (extract_sweep_v3.go:885); I re-checked thatinneralways refuses when!measured, so no tier cut slips through unmeasured.RatesOfmoved tolifecycle, so no exported signature incomponentsnames an internal type.TestRatesAtMatchesPriceAtpinsTokenRates.AttoPrice.Aton a grid with the lines and both sides. The growth wait no longer holds a tier cut. - Reviewer 1's non-blocking notes: all addressed (
MaxRateTiers = modelinfo.MaxTiers, the same pinning test,RatesOfmove, themeasuredlabel, the two guard tests, the growth wait).
What I checked
- Last review: round 1,
c18ddf4452cce4547c1443654f01c347d8e6d4f9, 2026-11-26T11:29:26Z - New commits read: 1 (
93cf004"fix(sweep): price a question at its tier, judge-path tests, no growth wait on a tier cut") - Read in full: 2 reviews, 2 comments, 0 inline comments (from the three saved files)
- New items since my last review: reviewer 1's round-1 review (read in full, its finding cross-checked above); the owner-decision comment (tier_target defaults off, David Amid 2026-11-26); the author's replies comment (each reply checked against the code); the fix commit (reviewed below).
- The growth-wait bypass (
extract_sweep_v3.go:694-699):waiting = falseonly below the sweet spot with a live tier plan; the sweet-spot path keeps the wait, as the docs say. The margin and the payback gate replace the wait as anti-thrash: after a tier cut the prompt sits below the line,tierGoalreturns nil there, and a re-cut needs the prompt above the line again plus a paying gate. Behavior change named in the body, behindtier_target, test attached. - The
Costchange's blast radius: everyTokenRates.Costandcheapmodel.Pricing.Costcaller in the repo enumerated (extract_sweep.go:851,extract_llm.go:1364,summarize_async.go:586,extract_econ.go:269,294,proxy/proxy.go:2748,dash/event.go:998). Onlysummarize_async.go:586calls the tier-awareTokenRates.Cost; the sweep leg resolvescard.Atper leg before the flatcheapmodelcost, andAtof an already-resolved card is a no-op (itsTiersare empty), so nothing double-applies.extract_llm's per-candidate calls stay flat, as "Not covered" says. - The second behavior change is named at the top of the PR body with its off switch (
flat: trueon the price-file entry). - The new tests' logic and arithmetic: judge path (ask at 300K above the line, apply,
JudgeDrops > 0, goal reached), held answer below every line, v3 off (tier_targetis not in the v3 switch-on list), gate price model guard, growth-wait bypass, and theCostnumbers inTestTierCardPricesACallAtItsPromptSize(300K read at 2x 0.5e-6 plus 1000 output at 1.5x 30e-6). lifecycle.RatesOfmoved verbatim; no reference tocomponents.RatesOfremains;MaxRateTiers = modelinfo.MaxTierscompiles as an untyped constant.- CI green on the new head (lint-build, purego, trivy, DCO). No builds or tests were run by me (not approved). Code reading only.
PriceCG priced the compaction calls flat, so above a price-tier line the cg_llm_cost_usd row disagreed with the component's booked spend. It now resolves the tier as priceCost does. Also drops a stale comment. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Replies to round 2Fixed in Reviewer 2, finding 1: Non-blocking notes, both reviewers:
Tests (macOS, Go 1.27.4): build and vet are clean. Plain Local tests: waived (owner rule) |
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 3 of 4 | e27765bdc |
approve |
Verdict: approve
Findings
None. The round-3 commit fixes my round-2 finding exactly as proposed, and I found no new defect in it.
Earlier findings
- Mine, round 2, finding 1 (
PriceCGpriced the compaction calls flat): fixed.dash/event.go:998-999now resolves the tier before pricing:p = p.At(modelinfo.PromptTokens(e.CGFresh, e.CGCacheRead, e.CGCacheWrite)), the same patternpriceCostuses ten lines below, placed after the!okguard. The capture site and the reprice pass both go throughPriceCG, so both get the fix. - My round-2 non-blocking notes: all addressed. The "Rates" bullet now names
lifecycle.RatesOf(body line 34). "Decided" records theTokenRates.Costdecision with the owner and the date (line 72). "Not covered" listsextract_econ.go'scallCostandanalyticBaseline(line 63). ThetierRatestest copy stays, forced by the import cycle — accepted. - Reviewer 1's round-2 review (approve): its three non-blocking notes are handled. The orphan
MaxRateTierscomment incomponents/component.gois deleted by this commit; the stale "Rates" bullet is fixed in the body; thetierRatescopy is accepted by both reviewers. Nothing to add. - Reviewer 1's round-1 finding and my round-1 finding: fixed in round 2 and unchanged since. I re-read the round-2 fix areas (
recordLeg,TokenRates.Cost, the judge tests) in this head; they are as reviewed.
What I checked
- Last review: round 2,
93cf004c22363d1b9c03107c01f9aeb2b15bd23f, 2026-11-26T11:42:37Z - New commits read: 1 (
e27765b"fix(dash): price the compaction calls at the tier of their prompt size") - Read in full: 4 reviews, 3 comments, 0 inline comments (from the three saved files)
- New items since my last review: reviewer 1's round-2 review (approve, 11:40:40Z — read in full, its notes cross-checked above); the author's replies-to-round-2 comment (11:46:49Z — each reply checked against the code and the body); commit
e27765b(reviewed below). - The
PriceCGfix:modelinfo.PromptTokens(fresh, cacheRead, cacheWrite)argument order matches its signature; output tokens stay out of the prompt size, asmodelinfodefines;Atof the resolved card leavesCoston the tier rates.compactepisode.goand the tenant rollup (cg_tenant_cg_llm_cost_usd) readCGLLMCostUSDand now agree with the component's booked spend. - The new test
TestPriceCGPricesAtTheTierOfTheCallsPrompt: prompt = 1000 + 299,000 = 300,000 > 272,000, so the gpt-5.6 tier applies. Both sides compute 1000 x 10e-6 + 299,000 x 1e-6 + 500 x 45e-6 = $0.3315; the flat price is $0.1695, and the assertion> 1.9x flatholds. The argument order matches bothCostsignatures (TokenRates.Cost(fresh, output, cacheWrite, cacheRead),Price.Cost(fresh, cacheRead, cacheWrite, output)). Dropping theAtmakes the equality fail, so the mutation claim holds.dashimportinglifecycleis a host importing a library — allowed. components/component.go: only the orphan comment is removed; the const keeps its own comment inratesof.go.- The PR body: the dash row is named inside the second behavior-change block with its test; "Decided" now records the
Costdecision; the two "Not covered" sections name every flat-rate remainder honestly. - CI on head
e27765b: trivy and DCO pass; build, analyze, lint-build and purego were still pending when I checked. The integrator needs them green before merge. No builds or tests were run by me (not approved). Code reading only.
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.332 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 3 of 4 | e27765bdcc8c |
approve |
Verdict: approve
Findings
None. The round-3 commit fixes reviewer 2's round-2 finding correctly, and I found no new defect in it.
Round-2 findings, checked
- Reviewer 2, finding 1 (
PriceCGpriced the compaction calls flat): fixed. I checked the fix myself.PriceCGnow resolves the tier before pricing (dash/event.go:998-999):p = p.At(modelinfo.PromptTokens(e.CGFresh, e.CGCacheRead, e.CGCacheWrite)), the same patternpriceCostuses for the request's own cost (dash/event.go:1017). I checked the argument order ofPromptTokens(fresh, cacheRead, cacheWrite)and ofPrice.Cost(fresh, cacheRead, cacheWrite, output)against the call — both match. A flat price is unchanged (Atis a no-op without tiers). Both PriceCG call sites (capture and reprice) go through the one function. - The new test, checked by hand.
TestPriceCGPricesAtTheTierOfTheCallsPrompt: a 300K gpt-5.6 prompt (1000 fresh + 299K cache read) above the 272K line. The dash row andlifecycle.RatesOf(p).Cost(...)must agree, and both must sit near 2x the flat price. I computed them: tier cost 1000 x 1e-5 + 299,000 x 1e-6 + 500 x 45e-6 = $0.3315; flat $0.1695; ratio 1.955, above the test's 1.9 floor. The two paths run the same resolved rates, so the equality holds exactly. The test's import oflifecycleintodashis test-only and acyclic (lifecycledoes not importdash). - My round-2 non-blocking notes: fixed. The orphaned
MaxRateTierscomment abovetype RateTieris deleted (component.go). The PR body's "Rates" bullet now nameslifecycle.RatesOf. ThetierRatestest copy stays, with the import-cycle note — acceptable. - Reviewer 2's round-2 non-blocking notes: fixed. "Decided" now records the
TokenRates.Costdecision (owner, 2026-11-26). "Not covered (more)" listsextract_econ.go'scallCostandanalyticBaselineas flat gate estimates. The dash row is named inside the second behavior-change block, with its test.
What I checked
- Last review: round 2,
93cf004c22363d1b9c03107c01f9aeb2b15bd23f, 2026-11-26T11:40:40Z. - New commits read: 1 —
e27765bd"fix(dash): price the compaction calls at the tier of their prompt size". - Read in full: 4 reviews, 3 comments, 0 inline comments (from the three saved files).
- New items since my last review: reviewer 2's round-2 review (11:42:37Z, its finding cross-checked above), the author's replies comment (11:46:49Z, each reply checked against the code), and commit
e27765bd. All handled. - Read the full round-3 diff (3 files) and the code around each hunk:
PriceCGand its guard for a request with no compaction tokens, thepselection whenpricesis nil or the CG model differs, and the stale-comment deletion incomponents/component.go. - Checked the PR body: the dash row is part of the named second behavior change, with the off switch (
flat: true); "Decided" records both owner decisions; "Not covered" names the remaining flat-rate estimates honestly. - Confirmed the tier-aware pricing is now complete where it matters:
priceCost,PriceCG,adapttools,toolsuggest,cachestate,keepaliveandaccountant_pricein dash all resolveAtbeforeCost; the component side resolves per leg;extract_econ's gate estimates stay flat and are listed. - No builds or tests were run (not approved). Code reading only.
Signed-off-by: DAVID AMID <[email protected]>
Merged main (with #1193)
Local tests: waived (owner rule) |
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 4 of 4 | 7212131e6a69 |
approve |
Verdict: approve
Findings
None. The only new commit is a merge of origin/main (#1193 and others). The merge is correct, and the two code paths work together.
The merge, checked
- Conflicts: only the data-dependence docs, resolved right. The combined diff of the merge shows the two conflicted files (
docs/data-dependence.mdand theextract_llm_sweeprow file). The resolution takes main's #1193 text (the warm-only copy for a thread the keep-alive cannot ping, the 300-second bound, the new "off" column wording) with thetier_targetsentence added back in its place. I read the merged row in both files: they carry the same text, so the page matches the row. - The tier code survived the merge intact. Verified in the merged head: the sweet-spot branch with the tier plan and the growth-wait bypass (
extract_sweep_v3.go:694-701), themeasuredfix (:888), thetierEconhook inwarmGate(extract_sweep_warm.go:796),tierGoal, the tier-awareTokenRates.Cost(component.go:1062), andPriceCG'sAtresolution (dash/event.go:999). - The two features work together (the round-4 question). #1193 changes
registerWarm's guard fromCanKeepAlive()tokeepsCopy(c)(e.warm || pingable), so with warm on, a thread the keep-alive cannot ping (IBM Bob's route) now registers a warm-only copy and can be asked. The tier path reachesregisterWarmthrough the same v3Step hybrid branch, so a tier question on such a route asks after the forward, from that copy — which is #1193's design and the tier feature's design together, not a conflict. The copy is dropped when the question ends (dropWarmOnly), and the question's Ctx copy carriesSelfRateswith tiers (extract_sweep_ping.go:314), so the per-leg tier pricing applies there too. - One convention note, not a defect.
tierEconprices the per-turn saving at the cache-read rate, aswarmEconalways has. On a route with no prompt caching (Bob's, cache strategy none) the true per-turn cost is the fresh rate, so both gates under-count the saving there and refuse more. Same direction as today's warm gate, conservative. Nothing to change in this PR. - Main's new pricing code is tier-aware. The files the merge brought in (
dash/accountant_price.go,proxy/accountant_wire.go,dash/cachestate.go'sNextRequestUSD) all resolvePrice.Atbefore costing;NextRequestUSDgained thenextInparameter from #1454 and its test moved with it. - CI is green on the merged head (lint-build, purego, trivy, build, analyze, CodeQL all pass).
Earlier findings
- All findings from rounds 1 to 3, both reviewers, are fixed and unchanged by the merge (verified per point 2 above).
What I checked
- Last review: round 3,
e27765bdcc8c0d939b3018582f80e8a316768b56, 2026-11-26T11:48:46Z. - New commits read: 1 —
7212131e"merge origin/main into feat/sweep-tier-line" (a merge of maine2d4177e, which carries #1193, #1454, #1456, #1458 and more). - Read in full: 6 reviews, 4 comments, 0 inline comments (from the three saved files).
- New items since my last review: reviewer 2's round-3 review (approve, 11:48:43Z — read in full, nothing to add); the author's merge comment (13:12:04Z — its claims checked: conflicts only in the docs, code merged clean, tests re-run); the merge commit itself. All handled above.
- Read the merge's combined diff (
git show --cc) in full: only the two data-dependence files needed a hand resolution. Read the merge's diff against my round-3 head for every code file it touched, and the code around the interaction points (registerWarm,keepsCopy,runWarmQuestion,dropWarmOnly,warmPending, the v3Step hybrid branch). - Checked the PR's merge-base claim: base moved from
3ef26ffdtoe2d4177e(main), so the PR now contains only its own changes on top of main. - No builds or tests were run by me (not approved). Code reading only. The author reports build, vet, plain tests and
-race -run 'TestTier|TestRates|Warm'clean on the merged head, macOS, Go 1.27.4.
From my side the PR is ready for the integrator at head 7212131e.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 4 of 4 | 7212131e6a69 |
approve |
Verdict: approve
Findings
None. The only new commit is a merge of origin/main. The merge keeps every change of this PR byte-identical, resolves the one conflict correctly, and the two code paths work together.
What the merge brings and how it fits
- #1193 (warm question without a ping) is the one main change that touches this PR's area. It rewrites
registerWarm(extract_sweep_warm.go:1122-1127) to keep a warm-only conversation copy for threads the keep-alive cannot ping, and changes theCanKeepAlivecontract comment incomponents/component.go. Interaction with the tier target: the judge-ask call atextract_sweep_v3.go:780now also registers on unpingable threads. That widens WHERE a question can happen (main's reviewed behavior change, #1191), and changes nothing about WHEN: the sweet-spot and tier gates still decide, unchanged. Fail open is unchanged. - Main's parallel dash tier work (#1454:
pricetier_callers_test.go,cachestate.go,nextinput; #1458; #1456) is complementary. Main did not touchdash/event.go, so this PR'sPriceCGfix stands as reviewed, and main's tests pin the same tier semantics (Price.Atat the prompt size) this PR relies on. - The remaining main commits (#1450, #1414, #1296, #1453, #1452) touch the accountant version, the OpenCode installer, lock gaps and test timing — no contact with this PR's code.
Earlier findings
- All findings from rounds 1 to 3, both reviewers, are fixed and stay fixed: every PR-owned file is byte-identical across the merge (verified, see below), and the PR's hunks inside the three merge-co-touched files are intact (
TokenRates.Cost'sAtatcomponents/component.go:1062,recordLeg'scard.Atatextract_sweep.go:849).
What I checked
- Last review: round 3,
e27765bdcc8c0d939b3018582f80e8a316768b56, 2026-11-26T11:48:43Z - New commits read: 1 on the PR branch (
7212131e"merge origin/main into feat/sweep-tier-line"), bringing 9 main commits:e2d4177e#1193 warm copy without a ping,ec82ede3#1458,5dcb70fa#1450 accountant bump,f174d823#1454 NextRequestUSD,8dee073a#1456 accountant on every request,c4a6dd86#1414 and25580ca3#1296 OpenCode installer,bf68543d#1453 lock gaps,e0ad5c51#1452 picker test. - Read in full: 5 reviews, 4 comments, 0 inline comments (from the three saved files)
- New items since my last review: reviewer 1's round-3 review (approve, 11:48:46Z — read in full, nothing to add); the author's merge comment (13:12:04Z — each claim checked below); the merge commit
7212131e. - The merge keeps this PR intact:
git diff e27765bd..HEADover the PR-owned paths (extract_sweep_tier.go,extract_sweep_tier_test.go,extract_sweep_v3.go,extract_sweep_v3_test.go,components/ratesof.go,lifecycle/,dash/event.go,dash/pricecg_tier_test.go,docs/components/advanced-offload.md) is empty. The tier markers are all present in the merged head:tierGoal,tierEcon,waiting = false(extract_sweep_v3.go:697), themeasuredgoal check (:888), andPriceCG'sp.At(dash/event.go:999). - The conflict resolution is correct: the author says only the data-dependence docs conflicted. The merged
extract_llm_sweeprow carries both #1193's warm-only-copy text and thetier_targetsentence, and the generateddocs/data-dependence.mdmatches the row file exactly — I compared thewhereandoffcolumns of the table row against the row file's fields, character for character. No hand edit of the generated page. - The two code paths work together:
registerWarm's new condition (c.PrefixAsk == nil || !e.keepsCopy(c)) and the tier judge path compose — registration widens, gates unchanged. The test helpers this PR's tests use (pingAsker,warmRig.forward) are unchanged by the merge, so the tier tests compile and run against the merged machinery; purego CI on the merge head runs thecomponentstests and is green. - CI on head
7212131e: all jobs pass (build, lint-build, purego, analyze, trivy, DCO, CodeQL). No builds or tests were run by me (not approved). Code reading only.
…1462) refactor(dash): price the dashboard's savings with accountant.Figure The dollar math leaves dash. AccountantFigure now calls accountant.Figure with the host pricer (modelinfo.Price.RateAt, the rule the metrics sink uses) and only maps the USDFigure to the dashboard's rows and columns. accPrices, reRateUSD, bookReRate, tierUSD and the effect pricing are removed. - UnownedMarkUSD goes to the tailbreakpoint row, as before. - UnownedReRateUSD goes to the ended_change row, as before. - The held floor reads ByComponentSaved and ByComponentSavedAsRead (accwire.HeldFloorUSD). - The re-rate goes to the operations that moved the size (#120). - A test checks the dashboard figure equals the llm_savings_* counters. Fixes #1440 refactor(dash): review round 1 notes for the figure mapping - Move HeldFloorUSD from accwire to accrec (shared glue rule). - hostPricer refuses a model it does not hold (rate 0, estimated). - Skip a zero-token op in the mapping, as before. - Fix two stale names in comments. - Test an InBaseline rescue and the pricer refusal. fix(dash): keep a zero-token key of a component that acted A component that acted can have counted ops of 0 tokens (the byte ratio truncates). The zero-token skip removed its key, and accOverride then dropped the whole request's saving. The skip now applies only to a name with no row. - Test: an acted row with a zero-token op plus a real figure still prices. - docs/design.md: name HeldFloorUSD in the accrec row. Behavior change (the dashboard savings figures come only from accountant.Figure; figures move where the library rule differs from the old dash copy) approved by the owner in the integrator session: "1462 yes". Merged tree with #1461/#1455 built, vetted and tested before the merge; proxy-boundary check passed. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
Behavior change (a human must say yes)
tier_targetin theextract_llm_sweepconfig. Default: off. It needs sweep v3 and does not switch v3 on. A flat price has no line, so nothing changes for it.Second behavior change (NOT behind
tier_target)tier_targetoff.TokenRates.Costused the base rates for every prompt size. The booked spend of a sweep question, asummarize_asyncdeferred call and any other caller was 2x (Haiku 5.5: 5x) too low above a line.TokenRates.Costprices a call at the tier rates of its own prompt size.CostUSD,RecordExtractionSpendand thecost_usdlogs rise above a line. They now match the provider's bill.PriceCGrow (cg_llm_cost_usd) prices the compaction calls at the tier of their prompt size, so it agrees with the component's booked spend. Test:TestPriceCGPricesAtTheTierOfTheCallsPrompt.flat: trueon the price-file entry removes the tiers.Summary
Fixes #1329. The sweep now has a price-tier target. Local tests: waived (owner rule).
What changed
line - margin. The line comes fromPrice.TiersthroughPrice.At. No constant.tier_line_not_reached, and today's target stands (no cut).tier_target): a request above a line and below the sweet spot is no longer held by themin_drop_frac x Cwait (150K at C = 1M). The tier gates decide when the next cut may happen. In the sweet spot the wait stays. Test:TestTierCutIsNotHeldByTheGrowthWait.components.TokenRatesgetsTiers(absolute rates, built bylifecycle.RatesOffromPrice.At).lifecycle.SelfRatesuses it.Price.Atonly for its own decision.How it was tested
macOS, Go 1.27.4.
go build ./...,go vet ./...: clean.go testoncomponents/...,apply/...,lifecycle/...,config/...,internal/...: pass.CGO_ENABLED=1 go test -race -run 'TestTier|TestRatesCarry'oncomponents/offloadandlifecycle: pass.tier_target: false: unchanged.TestTierKeepsTodaysTargetWhenTheCutDoesNotPayfails.TestTierRefusesACutThatEndsInsideTheMarginfails.Not covered
extract_llm's per-candidate calls still price below tier. Their prompts carry one tool output, so they rarely cross a line.recordLeg.TestTierCardPricesACallAtItsPromptSizecovers the call it makes.TestTierJudgeSelectorAsksThenCutsBelowTheGoal,TestTierHeldAnswerIsNotAppliedBelowEveryLine), v3 off, and the gate price model.Not covered (more)
extract_econ.gocallCostandanalyticBaseline(flat gate estimates) still price below tier.Data dependence
Metadata only. Token counts, tier lines, rates and growth per turn. No customer text. The feature's data dependence does not change at any storage level (off, metadata only, everything). The row note for
extract_llm_sweepis updated anddocs/data-dependence.mdis regenerated.Decided
tier_target: off. Owner decision, 2026-11-26.TokenRates.Costpriced at the prompt's tier for every caller (owner, 2026-11-26, together with the tier feature). The merge yes is still with the integrator.Open questions
Local tests: waived (owner rule)