Commit Graph
3 Commits
Author SHA1 Message Date
yetone ec15f87393 sessions: a Codex Desktop fork's replayed parent checkpoints book no usage, so a thread_spawn session isn't counted ~1000x (#2234, zlxdengtianhei)
A token_count event that can't be paired with a response record fell
back to the cumulative total's delta whenever a previous total existed,
even when the event's own last_token_usage was there. A Codex Desktop
subagent fork (thread_spawn) writes two cumulative counters into one
rollout: its parent's, replayed with last=0, and its own. Each switch
from the fork's lower counter back up to the parent's booked the gap,
tens of millions of tokens, as one call. The reporter's day read 187.4B
tokens where ~10.3B was real.

last_token_usage is the request's own usage, exact even when zero, so it
is used whenever it is valid; only a missing or invalid last falls back
to the delta, and with no previous total to the total itself, as before.

Run:
- TestCodexUsageForkReplayCountsOnlyLast (new), on the reporter's own five
  lines (testdata/codex-fork-replay-checkpoints.jsonl, numbers untouched),
  checking both Calls and the session summary. Old code: FAIL "calls
  booked {Input:832145 Output:281374 CacheRead:82834688 ...}, want
  {Input:3273 Output:1201 CacheRead:72448 ...}". New: PASS, on macOS and
  on the Windows box with every TestCodex* test.
- TestCodexUsageUnpairedCountKeepsLegacyDelta and the other Codex usage
  tests still pass; go test -tags nogui ./... on macOS with this series:
  every package ok.
- gofmt -l, go vet ./... on darwin, linux (nogui) and windows: clean.

Not run: a reindex of the reporter's full dataset; the numbers above are
from their excerpt.
2026-10-15 03:34:58 +08:00
yetone 71d2da1f42 catalog, usage, gateway, gui: a price can have a long-context tier and a 1-hour cache write, and the price boxes take decimals (PAMI on Discord)
OpenAI bills gpt-6-astra, gpt-6.1-sol and gpt-6-luna over 272K input at 2× input and cache and 1.5× output, for the whole request. A price now has tiers: `magpie model price <m> 10,50,1,12.5 --tier 272k 20,75,2,25` (--tier can repeat). A tier applies when input + cache reads + cache writes is over its size, so 272,000 is not over and 272,001 is. The built-in prices take tiers only where models.dev lists one (cost.tiers of type "context"), and it does list one for those three. The ledger, each request and OTLP are costed at the tier the call reached. Session and day totals sum many calls, so they stay at the base price.

Anthropic bills a cache write kept for an hour at 2× input and one kept for 5 minutes at 1.25×. Its usage reports which is which in cache_creation.ephemeral_5m/1h_input_tokens. The gateway (API and Claude subscription) and Claude Code's transcripts now keep that split. A price's fifth part is the 1-hour write. When it isn't given, it is 2× input: that is Anthropic's rule, and only Anthropic reports 1-hour writes. Claude list prices carry the 2× too. cache_write_tokens is still the total, and the usage CSV adds cache_write_5m_tokens and cache_write_1h_tokens at the end. The app shows the split on a request's Cache and on the usage tooltips. Old prices and old records, which have no 1-hour part, read as before. The sessions cache (18) and the call cache (calls-v8) are re-read once.

In the GUI, the price boxes were number inputs and dropped what they didn't parse ("0,25"). They are now decimal text boxes that take both "0.25" and "0,25". A model's price row has a 1-hour box (empty means 2× input) and a quiet Long-context price row. That row shows the list's tier greyed in, or sits behind a link when the list has none. A bad size is refused by name. en/zh/ja/de.

Tests:
- New: TestPriceTiers, TestCostSplit, TestPriceJSON, TestModelPriceTiers, TestModelPriceTierCmd, TestAnthropicCacheWriteSplit and TestClaudeCacheWriteSplit. The ledger CSV test expects the new columns.
- model-price-tiers.test.cjs is new; model-price-edit and provider-price-rate are updated. All of them fail against the old assets and pass in WebKit. Chromium couldn't be launched here.
- go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass.
2026-10-05 21:56:59 +08:00
Fanbuz 67004a7e8f sessions: count Codex RECORD and compaction usage without a history parent (#695)
* fix: 按本地事件配对统计 Codex 响应与压缩用量

* fix: 限制用量索引内存并精简磁盘缓存

* fix: 淘汰解析索引后仍释放请求行缓存
2026-10-04 07:57:49 +08:00