Skip to content

Money: book the gateway's actual cost; catalog models priced in the broker; budget stop says so - #1903

Merged
abhishek255 merged 3 commits into
mainlinefrom
fix/broker-price-catalog-models
Dec 6, 2026
Merged

abhishek255 merged 3 commits into
mainlinefrom
fix/broker-price-catalog-models

Conversation

@abhishek255

@abhishek255 abhishek255 commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

What was wrong

On beta, a task that used Amazon Ergo 1.0 was over-booked. The gateway ledger priced four Ergo calls at the real rates ($1.10 in, $3.30 out, $0.033 cache read, $1.375 cache write per 1M tokens), $0.0754 in total. The broker booked the same usage at $1.195: its price table had no Ergo row, so the booking fell to the Opus-rate fallback ($15 / $75 / $1.50 / $18.75) and was stored with source unknown. The task header then showed $1.78 against a $1.26 limit while the true spend was $0.659. Since #1896 the model catalog discovers and prices new models in the gateway, so every newly offered model would have hit the same fallback.

What changes

  1. One source of price truth. A session's final usage report is now booked at the gateway's own actual cost for that run and model. The broker reads the gateway's run-charges record (the receipts it already reads for lost runs, now also summed per model) and books the figure as it is (source provider-reported), less what the run's checkpoints already booked for that model, never below zero. It is used only when the gateway's record is complete, starts inside its index, and every receipt of the model is final. Otherwise the booking prices as before. The cautious fallback now applies only when there is no gateway figure, no quote and no table row, and it logs a warning (broker.usage_priced_at_fallback).
  2. Catalog prices for estimates. The model runtime's price list (listPricesPerMillion, which the broker's price table, caps and holds read) gets a small row table for models Pi's catalog lacks. It holds Ergo at the gateway's own rates. A new test holds every offered model priced in the broker and every extra row equal to the gateway's price for the same id (computed through the gateway's price source from the AWS rates).
  3. Correction of the bad booking. scripts/correct-unknown-source-bookings.ts is a one-off for the controller to run with approval. Dry run by default (only Get and Query); --apply writes. It takes the gateway's run-charges answers as a JSON file, finds unknown entries whose model has a price now, and sets each to the gateway's figure for the model (less the run's other entries on it). The entry, the task total and the company day's spend move by the difference; the day's admission load is left as it is. Every write is conditioned on the entry still being unknown at the amount read, so it is idempotent. Nothing here calls AWS.
  4. Stop wording. A build or review run that a spending limit stopped now says so ("Stopped: this task reached its own spending limit ... raise it on Spending limits; then choose Continue to resume.") instead of "The build step failed." The typed stop is kept on the blocked workflow, and the Slack view of a blocked coding step shows the stop's words.

Tests

tests/unit/broker-gateway-actual-booking.test.ts: a booking with a gateway-actual cost uses it; checkpoints plus final; an unknown-price model with no actual still books the fallback and logs it; offered-model parity with the gateway price; the stop wording; the task header equals the ledger sum for a mixed GLM + Ergo task; the correction script plans, skips what it cannot be sure of, applies once and does nothing the second time.

Gates run: typecheck:all (heap 10240), eslint on the changed files, complexity:check (no baseline raised), every test file importing a changed source, tests/contract, tests/journeys.

🤖 Generated with Claude Code


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

m2 and others added 3 commits December 5, 2026 17:06
…roker; budget stop says so

A final usage report is booked at the gateway's own actual cost for the run and model (its run-charges receipts), less what the run's checkpoints booked. The cautious fallback stays only where there is no gateway figure, quote or table row, and logs a warning. Models Pi's catalog lacks (Ergo) get rows equal to the gateway's price, with a parity test. A one-off dry-run-by-default script corrects bookings made at the fallback. A run a spending limit stopped says so instead of 'The build step failed'.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…rection script, company-scoped fallback warning, convergence and stop-wording tests

- scripts/correct-unknown-source-bookings.ts: --expect-account is required and checked with STS GetCallerIdentity before any read or write; the cost-entry once row update is conditioned on the row existing; functions split to hold the complexity baseline.
- hosted-modules.ts: the fallback warning goes through companyLog (one reviewed console sink in company-log-sites.json), fixing the company-log ratchet.
- Tests: checkpoint-high, retried final, two models in one run, account guard, and the typed stop reaching the blocked task's words through recordBuilt.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ure back to mainline), grouped and day-exact corrections, no STS SDK client

- hosted-modules: the meter's fallback warning goes through an optional `log` the
  hosted modules pass from the broker root; no console call, so the company-log-sites
  fixture is identical to origin/mainline (the pre-review raise is removed).
- correction script: several unknown entries of one run and model (checkpoints and a
  final) are corrected together, split by what each held, in one transaction; each
  booking day comes from the entry's expiry (the ledger's booking day, not the
  report's); the company index row update requires the row (never creates one; the
  test seeded the wrong key and hid it); never deletes (tested).
- the STS guard reads the account with the operator's AWS CLI, not an SDK client
  (the port guard allows SDK clients only for the four adapter services).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@abhishek255
abhishek255 added this pull request to the merge queue Dec 6, 2026
Merged via the queue into mainline with commit d6499bd Dec 6, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants