Skip to content

Fix: Price rows booked at $0 before the price map loaded - #1002

Merged
amiddavid merged 5 commits into
mainfrom
fix/920-unpriced-startup-rows
Nov 10, 2026
Merged

amiddavid merged 5 commits into
mainfrom
fix/920-unpriced-startup-rows

Conversation

@boazdavid

@boazdavid boazdavid commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The price map loads in the background. Requests in the first seconds after start are stored token_accounting=partial at cost $0 (acc_fallback reason=unpriced), so total cost under-counts the bill. Refs #920.

Change

  • The recorder remembers rows it wrote partial, with billed tokens and no cost (at most 4096 queued).
  • repriceLoop (dash/reprice.go, every 15 s) prices them from their own tokens once Prices.Price knows the model. It updates cost_usd, baseline_cost_usd, cache_saved_usd, billed_token_factor and token_accounting=complete, and the tenant_spend rollup in the same transaction.
  • No request is held, so no latency is added. Holding would stall requests if the price download is slow or fails.
  • A repriced row books no saving: its figure was unpriced, so the baseline equals the cost.
  • A bypassed request is written missing and becomes partial only when the count worker fills in its token count, so the queue and the update guard take both labels.
  • A request whose compaction calls could not be priced (Event.CGCostUnpriced, set at capture, not stored) is not repriced. It stays partial at $0, which readers take for unknown. Repricing it would mark the row complete while cg_llm_cost_usd was still an unknown $0.

Not fixed

  • A request that made a compaction call before the price map loaded stays unpriced, including its provider cost. Closing this needs the compaction token counts stored on the row (a schema change).
  • Rows 9 and 20 of the original run (partial at $0, not startup rows, one after a 400 s pause) are still unexplained. The run-B database and log are gone. This PR does not close Dashboard: the first request of a session books cost $0 (token_accounting=partial), so total cost under-counts the bill #920 for that reason.
  • Rows already stored as partial at $0 in older databases stay as written.
  • A row repriced after a rate change gets the rate at repricing time, not at request time.

Decision for the owner

Repricing changes stored history: cost_usd goes from 0 to a real value, so monthly spend goes up. This needs a human yes before merge.

Tests

  • TestRecorderRepricesRowsBookedBeforeThePriceMapLoaded (written first; failed to compile until the options existed): partial at $0 before the load, priced after, baseline and tenant_spend follow, rows with no tokens and rows from before the start are untouched.
  • go test ./dash ./proxy passes. go vet and gofmt -l are clean.
  • go test ./cmd/context-guru-proxy has 2 failures (TestPreflightReadsKeyEnvFromConfigNotComments, TestPreflightResolvesToolsOnTheServicePATH, install.sh: in_service_path: command not found). The agent reports they fail the same way without this change; I did not confirm it.
  • A/B rerun and two rounds of review: see the comments below.

Assisted-By: Claude (Anthropic AI) [email protected]

The price map loads in the background, so requests in the first seconds
after start were stored partial at $0 (acc_fallback reason=unpriced) and
under-counted total cost. The recorder now remembers the rows it wrote
partial with billed tokens and no cost, and prices them from their own
tokens once the model has a price. The monthly spend rollup follows.
No request is held, so no latency is added.

Refs #920

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: DAVID BOAZ <[email protected]>
@boazdavid

Copy link
Copy Markdown
Collaborator Author

A/B result: the fix repairs the startup race; rows 9 and 20 did not reproduce

I rebuilt the A/B harness (the old one was lost) and ran both variants in real time, 14 minutes each, with pauses of 330 to 400 s. The proxy fetches the real LiteLLM price map through a proxy that delays the fetch by 4 s, so the first requests hit the startup race.

A: main (b49cbeb) B: this PR
Requests (3 sessions) 42 42
Rows stored partial at $0 3 0
Dash total cost $0.5617 $0.8113
Fake upstream's true bill $0.8091 $0.8113
  • A reproduces the bug. The first turn of each session was booked at $0, and each logged acc_fallback reason=unpriced within the same second. The dash total is about $0.25 under the true bill.
  • B repairs it. All 3 rows were repriced after the map loaded. The dash total equals the fake's true bill for that run ($0.8113). The two variants ran against separate fake upstreams in parallel, so their true bills differ slightly ($0.8091 vs $0.8113). I did not look into why.
  • Rows 9 and 20 did not reproduce. In neither variant did a row after startup book partial at $0, including the rows after the long pauses. This is a null result. It does not explain them. This PR does not close Dashboard: the first request of a session books cost $0 (token_accounting=partial), so total cost under-counts the bill #920 for that reason.

Limits

  • The upstream is a fake with a simple prefix-cache model, not the real API.
  • One run per variant. Not repeated.
  • Only the startup race was exercised. A model id that the price chain does not match was not tried.

Harness: fake.py (upstream plus ground-truth log), delayproxy.py, driver.py, run.sh, analyze.sh, in /tmp/ab920 on the author's machine. Rerun: ./run.sh A 1 4 & ./run.sh B 1 4 & wait.

Assisted-By: Claude (Anthropic AI) [email protected]

@boazdavid boazdavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @boazdavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 offload-review skill, @boazdavid's session fresh 2 of 2 1 of 2 67340e3ac59e blocking

Verdict: blocking

Findings

  1. dash/reprice.go:101-105 — a repriced row is marked complete while its cg_llm_cost_usd stays an unknown $0

    • What fails: a request with compaction calls, written before the price map loaded, has CostUSD = 0 and CGLLMCostUSD = 0 (proxy/dashcapture.go:782-791 prices the cg half from the same unloaded map and leaves it 0 when cgPriced is false). The reprice sets cost_usd and flips token_accounting to complete, but never prices cg_llm_cost_usd, and the cg token counts are not stored on the row, so no later pass can recover it. The schema's own rule (dash/schema.go:55-57) says a 0 cost column with token_accounting <> 'complete' must read as unknown, not as free. After the reprice the row reads complete, so cg_llm_cost_usd = 0 reads as "context-guru spent nothing on this request". metrics_export.go NetSavedUSD subtracts CGLLMCostUSD, and tenant_spend/cg_tenant_cg_llm_cost_usd under-count the same window the PR fixes. The unknown marker is removed while part of the cost is still unknown.
    • Proof: proxy/dashcapture.go:742-743 sets priced = false when the map has not loaded; proxy/dashcapture.go:782-791 then skips e.CGLLMCostUSD. dash/reprice.go:26-28 copies only the request's own token tiers, so priceCost on the copy cannot compute a cg figure. dash/reprice.go:101-105 updates cost_usd, baseline_cost_usd, cache_saved_usd, billed_token_factor, token_accounting — not cg_llm_cost_usd. The insert schema (dash/store.go:580-601) stores no cg token counts, so the figure is unrecoverable after the write.
    • Fix: do one of these. (a) Carry the cg model and cg token tiers on the copy (the capture site has them at write time) and price cg_llm_cost_usd in the same UPDATE. (b) Keep a marker: leave a flag or a distinct accounting value on rows whose cg half is unpriced, so readers can render it as unknown. Name the choice in the PR body either way; today it is in neither "Change" nor "Not fixed".
  2. dash/reprice.go:22 — a bypassed request counted late is never repriced, so it stays partial at $0 forever

    • What fails: a bypassed request has TokensBefore = 0 at write time, so priceCost labels it AccountingMissing when the price is unknown (dash/event.go:887-894). noteUnpriced requires AccountingPartial, so the row is never queued. The count worker then fills tokens_before and flips the row to partial (dash/store.go:1165-1171). The row now has billed tokens, a model, and cost $0 — exactly the case the PR says it fixes ("rows this process wrote with billed tokens and no price") — but it is no longer in unpriced and nothing re-examines it. It stays $0 for the life of the database.
    • Proof: dash/event.go:887-894 chooses AccountingMissing when TokensBefore <= 0. dash/reprice.go:22 returns early on e.TokenAccounting != AccountingPartial. dash/store.go:1168 sets token_accounting = 'partial' after the write, and noteUnpriced runs only once, at write time (dash/capture.go:553).
    • Fix: also treat a late-counted bypass row as unpriced. Either queue a row in countLoop/setBypassTokens when it flips to partial at $0 with billed tokens, or make the reprice pass find such rows in the database. If you choose to leave it out, name it under "Not fixed" in the PR body.

Non-blocking

  • dash/reprice.go:33-35 — the maxUnpriced eviction (drop the oldest at 4096) has no test. The main pass is tested; the bound is not.
  • dash/reprice.go:109 — res.RowsAffected() error is discarded. On error n reads 0, the row is dropped from keep, and it is never retried, so it stays $0 with no log line. Rare, but a silent drop.
  • dash/reprice.go:82-85 — re-appending keep in front of r.unpriced can push the list past maxUnpriced; the cap is trimmed only one row per new write. A soft overrun, bounded by one pass's keeps.
  • dash/capture.go:489 — the comment "Nothing else writes to the database" is now stale: repriceLoop writes too, as countLoop and the migrations already did.
  • Rows waiting in unpriced at Close are dropped. They become "rows from a previous process", which the PR body names as not fixed, so this stays inside the stated scope.

What I checked

  • The full diff of 67340e3 against b49cbeb, and the code around each change: dash/capture.go, dash/reprice.go, dash/reprice_test.go, cmd/context-guru-proxy/main.go, docs/data-dependence.md.
  • The write-time pricing path: dash/event.go Price/priceCost, dash/accountant_price.go PriceMode, proxy/dashcapture.go finish (usage, pricer, cg cost, rejected requests).
  • The store: insertBatch and its tenant_spend upsert, monthKey, setBypassTokens, the requests schema (id INTEGER PRIMARY KEY AUTOINCREMENT, so no id reuse across the janitor's deletes), WAL and busy_timeout in the DSN.
  • Concurrency: unpricedMu swap in repricePass against noteUnpriced on the writer goroutine; wg/done shutdown of repriceLoop; modelinfo.Pricer/Chain.Price and litellm.Price are in-memory lookups, so the pass never blocks on network.
  • The guard in applyReprice (token_accounting = 'partial' AND cost_usd = 0): no double rollup, no overwrite of a row priced another way, no effect on rows from another process.
  • Data dependence: the unpriced copy holds only ids, timestamps, tenant, model, and token counts — metadata only. docs/data-dependence.md has the matching row.
  • The PR body: it names the behavior change (stored history and monthly spend go up) and asks the owner, as CLAUDE.md requires. Both findings above are cases the body does not name.
  • Read-time consumers of token_accounting (spendexplain.go, adaptcompaction.go, adapttools.go, kvcache.go): a repriced row now counts as complete for them, which is the intended direction.
  • The test's arithmetic against Price.CostWithCacheWrite1h, and its assertions for the no-token row and the pre-process row.
  • Live tests were not run (not approved); this is a code read only.

@boazdavid boazdavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @boazdavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 offload-review skill, @boazdavid's session fresh 1 of 2 1 of 2 67340e3ac59e blocking

Verdict: blocking

Findings

  1. dash/reprice.go:22 — bypassed requests keep the #920 defect: the reprice never picks them up
    • What fails: a request that runs in bypass mode while the price map has not loaded is written with token_accounting = 'missing', not 'partial'. It has billed tokens and cost_usd = 0. noteUnpriced runs at write time and requires AccountingPartial, so it skips the row. The count worker flips the label to 'partial' only later (setBypassTokens, dash/store.go:1165). By then noteUnpriced has already run, so the row never enters the queue. It stays at $0 forever. This is the exact defect the PR says it fixes: "Rows this process wrote with billed tokens and no price are priced once Prices knows the model."
    • Proof: the write-time label comes from priceCost (dash/event.go:887-894): no price and TokensBefore == 0 gives AccountingMissing. A bypassed request has TokensBefore == 0 at write time, because Pipeline.Run returns early on bypass and leaves the count at zero (components/pipeline.go:82-90), and the count is filled off-path (apply/apply.go:819 sets BypassCount; dash/capture.go enqueueCount). The filter at dash/reprice.go:22 (e.TokenAccounting != AccountingPartial) then excludes the row. The store comment confirms the sequence: "Priced with the count still unknown, such a row is labelled 'missing'; with a count it is 'partial'" (dash/store.go:1162-1164).
    • Fix: also enqueue rows with AccountingMissing when they have billed tokens and cost_usd = 0 (the reprice's own WHERE token_accounting = 'partial' guard must then accept both labels), or note the row when setBypassTokens flips it to 'partial'. Add a test with a bypassed event that has BypassCount and a late price.

Non-blocking

  • The reprice does not recompute cg_llm_cost_usd for the same rows. When the price map is late, the cheap-model call cost also stays 0 (proxy/dashcapture.go:782-792 skips it when not priced), and tenant_spend misses that side too. The PR targets provider-billed cost, so this is a known limit. Say it in the PR or the code comment if it stays.
  • No test covers maxUnpriced (the drop-oldest bound) or the RowsAffected() == 0 path in applyReprice (a row changed or deleted between note and pass). Both paths are simple, but they are new behavior with no test.
  • Process check, per CLAUDE.md's behavior-change rule: rows that read "unknown cost" now show a priced cost, and tenant_spend — the number the spend cap reads — now counts them. Name this change at the top of the PR (who it affects, old and new behavior), and have the human confirm it. I did not read the PR body in round 1, so I cannot verify it is there.

What I checked

  • The full diff: cmd/context-guru-proxy/main.go, dash/capture.go, dash/reprice.go, dash/reprice_test.go, docs/data-dependence.md.
  • The pricing path end to end: proxy/dashcapture.go finish and PriceMode(price, usageOK && priced), dash/accountant_price.go PriceMode/accOverride, dash/event.go Price/priceCost, internal/modelinfo Price.Zero/CostWithCacheWrite1h/Pricer/Chain.Price, and cmd/context-guru-proxy/main.go modelWindows/priceResolver. I confirmed that a partial row with billed tokens can only be partial because no link could price the model (usage is zero unless usageOK, and rejected requests book no saving), so forcing accountingComplete = true in the reprice is right for the rows it touches.
  • Double-count risk on tenant_spend: the write-time insert adds CostUSD + CGLLMCostUSD (0 for these rows), and applyReprice adds the repriced CostUSD once, in the same transaction as the row update, guarded by token_accounting = 'partial' AND cost_usd = 0. Ids are AUTOINCREMENT, so a reused id cannot hit another row. No double count found.
  • Savings side: a repriced row gets baseline_cost_usd = cost_usd and books no saving. This is correct — the accountant result is not stored, so the saving cannot be re-derived. The row's savings read as zero, not as unknown; the cost side is honest.
  • Races: noteUnpriced (writer goroutine) and repricePass share unpriced under unpricedMu; DB work runs outside the lock; repriceLoop is counted in wg before NewRecorder returns, so Close covers it. setBypassTokens and applyReprice cannot corrupt each other's label flips (the CASE guard in setBypassTokens only fires on 'missing').
  • Fail-open: an applyReprice error logs a warning and keeps the row queued; no request path is touched; the copy kept in unpriced carries counts and ids only, no content. The data-dependence row is updated and stays at the metadata level.
  • The test itself: I traced the arithmetic (CostWithCacheWrite1h with CacheWrite1h = 0), the late-loader sequencing, and the three control rows (noTokens, hist). The assertions match the code. Live tests were not run; Go is not installed here.

…ion call unknown

Review of #1002, round 1.

- A request run in bypass mode before the price map loaded is written
  "missing" and becomes "partial" only when the count worker fills in its
  token count, after the reprice queue was fed. It never entered the queue
  and stayed $0. The queue and the update guard now take "missing" too.
- A row whose compaction calls could not be priced (Event.CGCostUnpriced,
  set at capture) is no longer repriced. Repricing it marked the row
  complete while cg_llm_cost_usd was still an unknown $0, which readers
  take for "context-guru spent nothing". It stays partial at $0, which
  they take for unknown.
- A RowsAffected error is returned, so the row is kept and retried.
- Rows put back by a pass that found no price can no longer take the
  queue past maxUnpriced.
- The stale "nothing else writes" comment is corrected.

Refs #920

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: DAVID BOAZ <[email protected]>
@boazdavid

Copy link
Copy Markdown
Collaborator Author

Replies to the round 1 findings

Commit 2fe288d fixes both blocking findings. I checked each claim in the code before I changed it.

Finding 1 (both reviewers): a bypassed row is never repriced. Fixed.

  • A bypassed request is written missing. The count worker makes it partial later. noteUnpriced ran before that, so the row was never queued.
  • noteUnpriced now queues missing rows as well. The guard in applyReprice takes partial or missing.
  • New test: TestRecorderRepricesABypassedRowBookedBeforeThePriceMapLoaded. It failed before the change (timeout, the row stayed at $0) and passes now.

Finding 2 (reviewer 2; non-blocking for reviewer 1): a repriced row hides an unknown compaction cost. Fixed with option (b), a marker. No schema change.

  • The capture site now sets Event.CGCostUnpriced when compaction calls could not be priced. It is not stored.
  • noteUnpriced skips such a row. It stays partial at $0, which readers already take for unknown.
  • Consequence: a request that made a compaction call before the price map loaded is not repriced. Its provider cost stays at $0, as before this PR. This is a known gap. Option (a) would close it: store the compaction token counts and price both halves.
  • New test: TestRecorderLeavesARowWithAnUnpricedCompactionCallUnknown. It failed before the change (row was complete) and passes now.

Non-blocking points

  • The maxUnpriced bound had no test. Added TestUnpricedQueueIsBounded. It exposed a real overrun: after a pass found no price, the queue held 4116 rows. The queue is now trimmed to the cap, oldest first.
  • The RowsAffected() error was discarded. It is now returned, so the row is kept and retried.
  • The stale comment at dash/capture.go:488 is corrected.
  • The PR body already names the spend increase. I did not add anything on the spend cap. tenant_spend is the figure the cap reads, so the owner decision covers it.

Checks: go test ./dash ./proxy passes. go vet and gofmt -l are clean. No live run.

@boazdavid boazdavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @boazdavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 offload-review skill, @boazdavid's session resumed 2 of 2 2 of 2 2fe288dddff4 approve

Verdict: approve

Findings

None.

Round 1 findings, re-checked

  1. cg_llm_cost_usd read as free under a complete label (my finding 1) — fixed. The capture site now sets Event.CGCostUnpriced when compaction calls could not be priced (proxy/dashcapture.go:789-793). noteUnpriced skips such a row (dash/reprice.go:27), so it stays partial at $0, which readers take for unknown. That is my option (b), with no schema change. The flag is json:"-" and absent from the insert, so nothing is stored and the data-dependence row stays true. Verified: the flag is set after PriceMode (proxy/dashcapture.go:778), on a fresh event per request, so no stale carry-over. New test TestRecorderLeavesARowWithAnUnpricedCompactionCallUnknown covers it.
  2. A bypassed row counted late was never repriced (my finding 2; reviewer 1's finding 1) — fixed. noteUnpriced now queues missing rows too (dash/reprice.go:26), and the update guard takes both labels (dash/reprice.go:111-113). I checked both orderings against setBypassTokens (dash/store.go:1165-1171): if the reprice completes the row first, the worker's CASE WHEN token_accounting = 'missing' leaves complete alone and only fills tokens_before; if the worker runs first, the row is partial and still matches the guard. A missing row whose count never arrives is also repriced, which matches write-time behavior (a known price completes such a row with tokens_before = 0 too). New test TestRecorderRepricesABypassedRowBookedBeforeThePriceMapLoaded covers it.
  3. Non-blocking points — all addressed. TestUnpricedQueueIsBounded covers the cap and found a real overrun (4116 rows after a no-price pass); the re-queue now trims to the cap, oldest first (dash/reprice.go:90-92). The RowsAffected error is returned, so the row is retried (dash/reprice.go:117-120). The stale writer comment is corrected (dash/capture.go:487-488).

Non-blocking

  • The fix for finding 1 leaves a named gap: a request that made compaction calls before the price map loaded is not repriced at all, so its provider cost also stays $0. The author named this in the reply. The row reads as unknown, not as free, so the failure direction is safe. Option (a) from my round 1 (store the cg model and token tiers, price both halves) closes it; worth a follow-up issue.
  • The A/B run in the comments exercised the startup race only. The bypassed and unpriced-cg paths are covered by unit tests, not the live run.
  • The author's A/B report says rows 9 and 20 of the original run did not reproduce, so this PR does not close #920. Stated plainly in both the PR body and the comment. Nothing to check further.

What I checked

  • Last review: round 1, 67340e3, 2026-11-10T09:16:03Z
  • New commits read: 1 (2fe288d "fix(dash): Reprice bypassed rows; leave rows with an unpriced compaction call unknown")
  • Read in full: 2 reviews, 2 comments, 0 inline comments (from the three files)
  • New items since my last review: the author's reply comment (2026-11-10T09:26:41Z) — I checked each claim against the code; commit 2fe288d — full diff and the changed files around each change. The A/B comment (09:07:12Z) predates my round-1 review but was unread then; I read it in full now.
  • The full diff of 2fe288d: dash/capture.go, dash/event.go, dash/reprice.go, dash/reprice_test.go, proxy/dashcapture.go.
  • The final state of dash/reprice.go in full: the queue gate, the copy, the pass, the cap trim, and the applyReprice transaction with the two-label guard and the checked RowsAffected.
  • The CGCostUnpriced flag: set only inside the cg-calls block at capture, never stored, never read except by noteUnpriced. No other event source sets it, and pings carry no cg calls.
  • The three new tests: traced the setup and assertions of each against the code paths they exercise, including the direct queue manipulation in TestUnpricedQueueIsBounded (safe: the reprice ticker is one hour, so no concurrent pass).
  • Both orderings of setBypassTokens against applyReprice, as described above.
  • Reviewer 1's round-1 review: their finding 1 is my finding 2, fixed as above; their non-blocking points (cg cost, cap and RowsAffected tests, the process check) are all addressed — the PR body names the behavior change and the owner decision, which I verified in round 1.
  • Live tests were not run (not approved); this is a code read only.

@boazdavid boazdavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @boazdavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 offload-review skill, @boazdavid's session resumed 1 of 2 2 of 2 2fe288dddff4 approve

Verdict: approve

Findings

None.

Earlier findings

  1. Mine, round 1 — bypassed requests never entered the reprice queue. Fixed in 2fe288d. noteUnpriced now queues missing rows too (dash/reprice.go:26), and applyReprice's guard takes both labels (dash/reprice.go:111-113). I traced the ordering: the row is queued at write time as missing, the count worker may flip it to partial before or after a pass, and both orders land right — setBypassTokens's CASE only fires on missing, and the reprice's IN ('partial','missing') matches either. The new test TestRecorderRepricesABypassedRowBookedBeforeThePriceMapLoaded covers the sequence.
  2. Reviewer 2, round 1, finding 1 — a repriced row hid an unknown cg_llm_cost_usd. Fixed with their option (b). I checked it myself: proxy/dashcapture.go sets Event.CGCostUnpriced when compaction tokens exist and the cg model has no price, noteUnpriced skips such a row (dash/reprice.go:27), and it stays partial at $0, which readers take for unknown. The consequence is named by the author: such a row is not repriced at all, so its provider cost stays unknown. That is the conservative direction, and option (a) remains open for later. I accept it.
  3. Reviewer 2, round 1, finding 2 was the same bypass defect as my finding 1. Fixed as above.
  4. My non-blocking points. All addressed: TestUnpricedQueueIsBounded covers the maxUnpriced bound and exposed a real overrun (a pass that found no price could re-queue past the cap), now trimmed oldest-first (dash/reprice.go:90-92). The RowsAffected error is returned and the row retried (dash/reprice.go:117-120). The stale "nothing else writes" comment is corrected. My process point is satisfied: the PR body names the spend increase under "Decision for the owner" and asks for the human yes, as CLAUDE.md requires. My cg_llm_cost_usd note became reviewer 2's finding, fixed as above.

Non-blocking

  • The PR body's "Change" list is now behind the code: it does not name the bypassed-row fix or the CGCostUnpriced carve-out. The reply comment documents both. Update the body so a reader who sees only the description gets the full behavior.
  • The known gap stands, named by the author: a request whose compaction call could not be priced is not repriced, so its provider cost also stays unknown. Option (a) — store the cg token tiers and price both halves — would close it.
  • I did not run the tests. Go is not installed here and live tests are not approved. The author reports go test ./dash ./proxy, go vet and gofmt -l clean.

What I checked

  • Last review: round 1, 67340e3, 2026-11-10T09:17:03Z.
  • New commits read: 1 — 2fe288d "fix(dash): Reprice bypassed rows; leave rows with an unpriced compaction call unknown".
  • Read in full: 2 reviews, 2 comments, 0 inline comments (from the three files; the inline list is empty).
  • New items since my last review: the author's reply comment at 2026-11-10T09:26:41Z (checked every claim in the code — all hold), and commit 2fe288d (reviewed below). The A/B comment at 09:07:12Z predates my round-1 review; I read it in full now: it measures the startup race repaired and reports rows 9 and 20 as not reproduced, a null result the PR body already carries under "Not fixed".
  • The new commit's diff in full: dash/capture.go (comment), dash/event.go (CGCostUnpriced, not stored, json:"-"), dash/reprice.go (queue both labels, cap trim, error return, guard IN (?, ?)), dash/reprice_test.go (three new tests), proxy/dashcapture.go (the else that sets the marker).
  • The new missing acceptance for harm: a missing row with billed tokens is missing only because no price link answered (usage is zero unless usageOK), so repricing it is the write-time arithmetic. setBypassTokens and applyReprice cannot corrupt each other's label in either order. tokens_before is filled by the count worker regardless of the label.
  • The CGCostUnpriced gate for holes: it is set only when compaction tokens exist and the cg half has no price; a row with a priced main model is complete at write and never queued; a row with a priced cg half and an unpriced main model is queued and repriced with both halves known; a call with no tokens books a true $0.
  • The new tests' logic and arithmetic, including the hardcoded id 1 (first insert into a fresh AUTOINCREMENT database) and the direct repricePass call with a 1-hour ticker that cannot fire during the test.
  • The final state of dash/reprice.go, dash/capture.go:485-560, dash/event.go:288-296, proxy/dashcapture.go:782-794, and the PR title and body.

@boazdavid
boazdavid marked this pull request as ready for review November 10, 2026 09:51
Bring the PR up to date with main; no conflicts, no hand resolution.

Assisted-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
One conflict in docs/data-dependence.md: both sides edited the Dashboard database row. Kept main's text and added the #920 sentence.

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

Copy link
Copy Markdown
Collaborator

Merge of main

Tests on the merged tree (shared box, -race)

  • ./dash/...: pass (run in two halves). One half failed once on TestCrossCheckCoversOnlyStoredRows. That test does not use the recorder. It passed alone 9 times and in a rerun of the same half. A flake.
  • ./proxy/...: pass.
  • ./cmd/context-guru-proxy/...: pass.

CI, CodeQL and Docs: green on 36a50042.

Main moved again after this (#720, #483). merge-tree shows no conflict with it.

Bring in #720; no conflict, no hand resolution.

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

Copy link
Copy Markdown
Collaborator

Merge of main (#720)

  • Head 1b8a1793. Merged origin/main (includes feat(sweep): the warm path, an economic gate on a held answer (#491) #720). No conflict. Remerge diff: 0 lines.
  • Semantic check: go vet ./... is clean. SweepFalseExpandsWarm and its column go through the insert and select lists in dash/store.go and dash/query.go. The reprice code touches neither. It updates only cost columns.
  • Tests (box, -race): ./dash/... pass in two halves. ./proxy/... pass in two halves (the whole package now passes 9.5 minutes, so one call timed out).
  • CI, CodeQL, Docs: green.

@amiddavid
amiddavid merged commit 87b29db into main Nov 10, 2026
9 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 10, 2026
amiddavid pushed a commit that referenced this pull request Nov 16, 2026
…tartup (#1172)

The reprice pass (#1002) also prices a row's compaction call. A row
written in the first seconds after a start, before the price map
loads, for a request that also made compaction calls, stayed partial
at $0 for good: neither cost_usd nor cg_llm_cost_usd was priced.

Behavior change: those dashboard rows. Old: partial at $0 for good.
New: once the map loads, the reprice pass prices both halves, marks
the row complete, and adds both halves to tenant_spend. Turn it off:
no separate switch; Options.Prices = nil turns off the whole reprice
pass, as before.
Owner's yes, 2026-11-16, in the integrator session: "yes" (to the
behavior changes of #1150, #1173, #1165, #1139, #1172 and #1140).

Data dependence: unchanged (metadata only). Row:
docs/data-dependence/features/dashboard-database.md.

Reviews: 2 offload review rounds (Claude backend). Round 2: both
approve at df9c251, which is the PR head. CI passed on a fresh merge
with main after #1150 and #1165 (the eval box was down; owner: merge
on CI and reviews until it is back).

Signed-off-by: DAVID BOAZ <[email protected]>
Assisted-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Dashboard: the first request of a session books cost $0 (token_accounting=partial), so total cost under-counts the bill

2 participants