Repository navigation
Money: book the gateway's actual cost; catalog models priced in the broker; budget stop says so - #1903
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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).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).scripts/correct-unknown-source-bookings.tsis a one-off for the controller to run with approval. Dry run by default (only Get and Query);--applywrites. It takes the gateway's run-charges answers as a JSON file, findsunknownentries 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 beingunknownat the amount read, so it is idempotent. Nothing here calls AWS.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-botwith what you need.