小一's Codex-on-credits ledger read "5,482 · 1,094 failed" while many rows
said "2 tries/3 tries" and had been answered. "Failed" counted usage rows,
not requests: besides each request's final row, the gateway writes a row
for every try a vendor refused or turned away (hw.refused/hw.turnedAway),
and each of those was counted as a call and a failure even when a later
member answered. (Ordinary failovers write no row; 499 cancels and the
agent's own client-side retries are separate requests.) In the owner's own
usage.jsonl, 24 of the 71 "failed" rows were such refusals a later member
answered.
Now a request counts once, by how it ended:
- usage.Record gains `tries` (final row, when the route took more than one)
and `handed_on` (the row of a try that failed and handed the request on).
Totals.count skips handed-on rows; a failure is a request whose agent got
an error (LostRequest); one answered after a failed try is Totals.Retried
(RetriedRequest), with a `retried=1` filter.
- Logs written before this are read the same way: the log index marks a
failed, non-rejected row followed by another of the same route id as
handed on and raises the later row's tries (routeRows); the packed row
and its snapshot carry both.
- Panel card, Usage overview tile, ledger card, rankings and group rows,
`magpie usage` and the TUI say "N answered on a retry"; the CSV adds
`tries` and `handed_on` at the end. A row says "· handed on" (with why
in its title) or "· N tries".
- On the ledger's Requests card "N failed" and "N answered on a retry" are
buttons that switch the list to the Failed / new Retried filter, and back
when pressed again. The lines wrap rather than cut a button off (German).
zh, zh-TW, ja, de strings added.
- Docs: reference.md (counting, filter, CSV columns), gateway-routing.md.
Run:
- go test -tags nogui ./internal/usage ./internal/usageapi ./internal/tui
./internal/gateway . : ok. New TestRequestsCountedOnceWithTheirRetries
(JSONL fixture: legacy refused row + 200, handed_on + 200 tries 3, 502
tries 2, plain 200, routeless 429 → 5 calls, 2 failed, 2 retried, across
Ledger, QueryPage, Summarize, heatmap, filters, CSV) and
TestRetriedRequestCountsOnce (group a refuses, b 500s, c answers → 1
call, 0 errors, 1 retried; a lone 400 → 1 error).
- Broke each by hand (count without the HandedOn skip, gateway without
HandedOn, log index without routeRows): each test went red; restored.
- go test -tags nogui -timeout 40m ./... under the gotest lock, rebased on origin/main de1ba9f12: all ok
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui on ., the
usage, usageapi, tui, gateway and gui packages: clean.
- Playwright ledger-retried.test.cjs, Chromium and WebKit, en zh zh-TW ja
de, 420 and 1100 wide: 20/20 (German first failed on the cut-off line,
fixed by letting the button lines wrap). usage-*, api-key-usage,
purpose-filter (Failed is now the 2nd of 3 options), panel-usage,
click-scroll, request-archive-usage, both engines: all green except
purpose-filter's Routing case (1px focus scroll), which fails the same
on 909d76747 and de1ba9f12, in Chromium too; it is #1291 (commented)