Skip to content

Check supervisor resumes before the balance lookup; fix cost fallbacks - #312

Draft
MaxGhenis wants to merge 3 commits into
mainfrom
lane/supervisor-resume-and-cost-fallbacks
Draft

MaxGhenis wants to merge 3 commits into
mainfrom
lane/supervisor-resume-and-cost-fallbacks

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #305 and #129.

What changes

  • Resume check before the balance lookup (Supervisor balance call before resume validation; cost fallbacks with incomplete usage #305). Supervisor.__init__ no longer calls the OpenRouter /credits endpoint. run() reads the baseline after _validate_resume and the provenance write, so a refused resume never calls OpenRouter's /credits endpoint. (Importing LiteLLM can still fetch its cost map, as it does on main.) _spent() only reads the credits fields when a baseline exists, so moving the setup is safe.
  • Zero completion tokens (Supervisor balance call before resume validation; cost fallbacks with incomplete usage #305). eval_no_tools used completion_tokens or output_tokens, which turned a reported 0 into missing and skipped cost reconstruction for the prompt side. It now keeps 0 and prices the count it records. A zero-output response gets a reconstructed input cost even when the provider also reports a charge, the same precedence every other response already follows (reconstructed cost first, provider cost only when reconstruction is impossible).
  • One override pricing function (Supervisor balance call before resume validation; cost fallbacks with incomplete usage #305). gpt_responses_cache_rates, bounded_cache_tokens, override_token_cost and override_cost_for_usage move to config.py, and eval_no_tools reconstruction calls them. analysis.model_cost_latency keeps main's aggregate expression (prompt * input / 1e6 + completion * output / 1e6) unless a model has cache tokens priced at a rate other than its input rate. Only then does it cap cache reads and writes per row and price the summed classes at the override's cache rates.
  • Budget meter for override-priced models (Supervisor budget meter ignores PRICE_OVERRIDES_PER_1M #129). _spent_from_disk estimates spend from PRICE_OVERRIDES_PER_1M for calls with recorded tokens and no recorded cost, so --budget-usd now binds for override-priced models instead of reading $0. Recorded costs, genuine zeros included, take precedence per ledger call and per CSV row, so one recorded cost no longer hides other calls' usage. A scenario's spend ledger, when it yields any cost, covers that scenario, and its CSV is skipped so the same usage is never counted twice. An unpriced CSV row is estimated only when it shows live calls and no cache replays (live_calls > 0, cache_hit_calls == 0). Rows that mix the two rely on the ledger.

Impact on published numbers

model_cost_latency feeds the dashboard export's costUsd. I ran main's and this head's model_cost_latency on the frozen US snapshot (paper/snapshot/20260501/runs/us_full_run_20260612_policyengine_4_16_1_populace/predictions.csv.gz), once with every column and once without the cache columns. Every model's costUsd, costPerHousehold and latency fields are identical, bit for bit. Three override-priced models there have no recorded cost: claude-fable-5 (no recorded usage, so no cost either way), gemini-3.6-flash (no cache tokens) and grok-build-0.1 (132,096 cache reads, but its override has no separate cache rate). All three take main's aggregate branch.

The fix commit that reworked the budget meter touched only supervisor.py and tests, not the export path, so this comparison still applies.

Existing rows change on re-export only for a model with no recorded total_cost_usd whose cache tokens price at a rate other than its input rate, including GPT models whose cache rates are implicit.

Future runs record cost differently in two cases, for any model with a known price:

  • A zero-output response with no provider charge now records its reconstructed input cost instead of no cost. The DeepSeek test fixture (100 prompt tokens) goes from missing to $0.0000435.
  • When the provider also reports a charge, the reconstruction becomes total_cost_usd and the charge stays in provider_reported_cost_usd.

Both apply to cache replays processed after this change as well as to live calls, and both feed costUsd and costPerHousehold, even for models with a single input rate. Under the PR guide this is a bug fix that moves model aggregates, so it states the impact here rather than asking for approval.

Overlap

#300 (held) edits four of the same files (config.py, eval_no_tools.py, supervisor.py and tests/test_eval_no_tools.py), for OpenRouter routing rather than cost. Whichever merges second may need a rebase.

Tests

  • test_supervisor: test_refused_openrouter_resume_never_requests_credits; test_budget_governor_prices_unrecorded_cost_with_override (ledger and CSV arms, both with known live provenance); test_spend_override_preserves_recorded_csv_cost (a recorded $0 or $0.70 row beside an unpriced row, in one CSV and across two); test_spend_override_prices_only_unrecorded_ledger_calls; test_spend_override_requires_live_only_csv_provenance (zero, blank, missing and mixed provenance). Existing baseline tests now call run() before they check the baseline.
  • test_eval_no_tools: test_zero_completion_tokens_still_reconstructs_input_cost expects the reconstructed input cost with and without a provider charge.
  • test_cost_latency: test_price_override_uses_cache_read_and_write_rates; test_price_override_at_input_rate_matches_aggregate_cost (exact equality with main's expression for gemini-3.6-flash and grok-build-0.1, with the second row at six and at four completion tokens, which between them catch both a per-row sum and override_token_cost on the totals); test_price_override_bounds_cache_counts_per_row.
  • test_anthropic_thinking_tokens: completion tokens equal the batch's; test_a_response_with_no_output_tokens_records_zero_completion.

The patch and its fix commits came from read-only Codex lanes that could not run pytest. CI runs the tests (-m "not slow"). ruff check and ruff format --check pass on the changed files.

🤖 Generated with Claude Code

- The supervisor reads the OpenRouter balance only after resume
  validation, so a refused resume makes no request (#305).
- A response with prompt tokens, zero completion tokens and no provider
  cost now records 0 completion tokens and gets a reconstructed cost
  (#305).
- The analysis cost fallback prices cache reads and writes at the
  override's own rates, through the same function as reconstruction
  (#305).
- The supervisor's spend meter falls back to PRICE_OVERRIDES_PER_1M for a
  model with recorded tokens and no recorded cost, so --budget-usd binds
  for override-priced models (#129).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
policybench-site Ready Ready Preview Dec 3, 2026 5:27am UTC

Request Review

The leaderboard's price-override fallback goes back to main's aggregate
expression (prompt * input / 1e6 + completion * output / 1e6) unless the
model has cache tokens priced at a rate other than the input rate. Only
then does it cap cache reads and writes per row and price the summed
classes with per_request=False. The frozen 20260501 snapshot values
reproduce exactly again.

Usage extraction prices the same completion count it records. A response
that reports zero completion tokens now gets a reconstructed input cost
even when the provider also reports a charge, the same precedence every
other response already follows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Round 1 found two ways the budget governor's disk fallback could
misstate spend.

One recorded cost anywhere in a model's files suppressed the price
override estimate for every other call, so an unpriced live call beside
a $0 cache replay metered $0. _spent_from_disk now applies recorded-cost
precedence per ledger call and per CSV row, genuine zeros included. A
scenario's spend ledger, when it yields any cost, covers that scenario
and its CSV is skipped, so the same usage is never counted twice.

The CSV estimate priced every row with nonzero live_calls, including
rows that mix live calls and cache replays, and rows whose live_calls is
blank or absent. An unpriced CSV row is now estimated only when
live_calls > 0 and cache_hit_calls == 0. Mixed groups rely on the ledger.

Tests: the recorded-cost test puts a priceable unpriced row beside a
recorded $0 or $0.70 row, in one CSV and across two. New tests price
only the unrecorded ledger calls and cover zero, blank, missing and mixed
CSV provenance. The governor fixtures carry known live provenance. The
exact-equality cost test now runs the second row at six and four
completion tokens, which between them distinguish both summation orders
for both models.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
Preview — 79515820 Deployed Dec 3, 2026 by vercel[bot]
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.

Supervisor balance call before resume validation; cost fallbacks with incomplete usage

1 participant