Token usage: keep cache/reasoning split, count only recorded steps, cost only when positive; captures fixture, docs and notes
This commit is contained in:
+26
-6
@@ -71,8 +71,9 @@ token-reporting stage reported one, and the summed cost, plus counts of stages
|
||||
that did or did not report a cost. A stage whose provider reported no cost is
|
||||
counted as cost-unknown and never contributes a fabricated or zero cost, and no
|
||||
cost/token count is inferred from output length or transcript text. The totals are
|
||||
the sum of the per-run totals `inspect` shows. `pipelines stats --json` exposes
|
||||
these aggregates.
|
||||
the sum of the per-run totals `inspect` shows. Only usage rows whose recorded
|
||||
step still exists are counted, so rows orphaned by an old history wipe are ignored
|
||||
(not deleted). `pipelines stats --json` exposes these aggregates.
|
||||
|
||||
Use `:status` on any TUI page to open server and ntfy information. Scroll with
|
||||
arrows or `j/k`, PgUp/PgDn; `r` refreshes and Esc closes without changing the page.
|
||||
@@ -349,8 +350,23 @@ Every run summary (`list_runs` rows, `get_run`, subscribe snapshots and terminal
|
||||
with turn documents and session exports, server-created Pi session directories,
|
||||
plus an estimate of its database rows). It is cached in `pipeline_runs.size_bytes`,
|
||||
invalidated by triggers when the run changes, measured on completion, and
|
||||
backfilled in the background; 0 means not measured yet. `delete_runs` removes
|
||||
finished runs to free space:
|
||||
backfilled in the background; 0 means not measured yet.
|
||||
|
||||
`list_runs` rows (and `get_run`) also carry `usage`, the run's totalled reported
|
||||
model usage, in the same shape as the run detail's total: `tokens_total`,
|
||||
`stages` and `tokens_known_stages` (the total is partial when fewer stages
|
||||
reported tokens than recorded usage), the `tokens_in`/`tokens_out` split with
|
||||
`split_known`, the `tokens_reasoning`/`cache_read`/`cache_write` components with
|
||||
`cache_known` (true only when every token-reporting stage recorded them;
|
||||
`tokens_total` includes cache reads, which dominate for a caching harness), and
|
||||
`cost_usd` with `cost_known_stages`/`cost_unknown_stages`. The list computes it
|
||||
with one grouped SQL aggregate per batch of 100 runs over the stored per-stage
|
||||
usage rows joined to their recorded steps, never a step load or transcript parse.
|
||||
It is omitted for a run with no recorded model usage; an older server omits it on
|
||||
every row, and clients then show nothing. Subscribe snapshots and `run_event`
|
||||
frames do not carry it, so a running run's total refreshes with the next list.
|
||||
|
||||
`delete_runs` removes finished runs to free space:
|
||||
|
||||
```json
|
||||
{"type":"delete_runs","id":"1","run_ids":[12,13,99]}
|
||||
@@ -627,8 +643,12 @@ per-step `provider`/`model`, and the run's graph shows the effective pair). Each
|
||||
model step also records the usage the harness reported, carried from the same
|
||||
accounting the stage already used for its budget: `usage.tokens_total`, the
|
||||
`tokens_in`/`tokens_out` split when the harness reported it (`split_known`),
|
||||
`cost_usd` when reported, and the explicit `tokens_known`/`cost_known`/
|
||||
`split_known` markers. The run detail totals those stages as `usage`, so a
|
||||
`cost_usd` when reported, the `tokens_reasoning`/`cache_read`/`cache_write`
|
||||
components when the harness reported the component split (`cache_known`; rows
|
||||
recorded before these were kept lack it, so their cache share is unknown), and
|
||||
the explicit `tokens_known`/`cost_known`/`split_known` markers. Some subscription
|
||||
providers report `cost_known` with no positive `cost_usd`; clients show that cost
|
||||
as not reported, never as $0. The run detail totals those stages as `usage`, so a
|
||||
mixed-model run shows each stage's model, tokens and cost and the run total. A
|
||||
stage whose provider reported no cost shows its tokens with `cost_known: false`
|
||||
(never a fabricated or zero cost), and a harness that reports only a total (Pi)
|
||||
|
||||
Reference in New Issue
Block a user