Spend fidelity: cache classes conflated, requests hardcoded to 1, model not recorded — dollar cost is uncomputable #96

Closed
opened 2026-08-26 03:02:29 +00:00 by matou-build-agent · 3 comments

From the 2026-08-25 observability review.

Symptom. record-run-result.sh folds fresh input + cache-creation + cache-read into one input number (total_in=$(( in_tok + cache_c + cache_r ))), hardcodes --requests 1 per iteration, and records no model. Cache-read, cache-write, and fresh input differ ~10x in price, so no dollar figure (or budget-headroom estimate) can be derived from spend; the real API request count is discarded.

Direction. Additive columns on spend (cache_creation_tokens, cache_read_tokens, model) via swarm-db.py's ADDITIVE_COLUMNS migration path; write them from the RunResult usage block; pass the real request count when available. fleet-tui usage.py/probe spend_daily aggregates gain the new columns behind the same names.

Same commit: swarm-db + record-run-result + fleet-tui test updates.

From the 2026-08-25 observability review. **Symptom.** `record-run-result.sh` folds fresh input + cache-creation + cache-read into one `input` number (`total_in=$(( in_tok + cache_c + cache_r ))`), hardcodes `--requests 1` per iteration, and records no model. Cache-read, cache-write, and fresh input differ ~10x in price, so no dollar figure (or budget-headroom estimate) can be derived from `spend`; the real API request count is discarded. **Direction.** Additive columns on `spend` (`cache_creation_tokens`, `cache_read_tokens`, `model`) via `swarm-db.py`'s ADDITIVE_COLUMNS migration path; write them from the RunResult usage block; pass the real request count when available. fleet-tui `usage.py`/probe `spend_daily` aggregates gain the new columns behind the same names. Same commit: swarm-db + record-run-result + fleet-tui test updates.
Author
Member

This was generated by AI during triage.

Ruled by agent under ADR 0174 — veto anytime.
Ruling: ready-for-agent. Two-way door — additive columns via swarm-db.py's existing ADDITIVE_COLUMNS migration path (built exactly for this kind of change); revertible, provable by swarm-db + record-run-result + fleet-tui test updates.

Agent Brief

Category: enhancement
Summary: Stop conflating cache token classes and hardcoding request counts in spend rows.

Current behavior:
record-run-result.sh sums fresh input + cache-creation + cache-read tokens into one input figure, hardcodes --requests 1 per iteration, and records no model. Cache-read, cache-write, and fresh input differ roughly 10x in price, so no dollar figure or budget-headroom estimate can be derived from spend, and the real API request count is discarded.

Desired behavior:
spend gains additive columns (cache_creation_tokens, cache_read_tokens, model) via the existing ADDITIVE_COLUMNS path. record-run-result.sh writes these separately instead of pre-summing them into one input number, and passes the real request count through when the usage data exposes it. fleet-tui's usage.py and the probe's spend_daily aggregate gain the new columns under the same names.

Key interfaces:

  • swarm-db.py's ADDITIVE_COLUMNS list and the spend table/insert.
  • record-run-result.sh's per-iteration usage parsing (cacheCreationInputTokens, cacheReadInputTokens).
  • fleet-tui usage.py aggregation and the probe's spend_daily.

Acceptance criteria:

  • spend has cache_creation_tokens, cache_read_tokens, model columns, additive (existing rows unaffected)
  • record-run-result.sh writes these columns from the iteration's usage block instead of folding them into input
  • The real per-iteration request count is recorded when available, no longer hardcoded to 1
  • fleet-tui usage.py and the probe's spend_daily read/aggregate the new columns
  • swarm-db + record-run-result + fleet-tui tests updated

Out of scope:

  • Per-tool-call/per-request ingestion from session jsonl files (#98 depends on this ticket's schema landing first)
  • Historical backfill of existing spend rows
> *This was generated by AI during triage.* **Ruled by agent under ADR 0174 — veto anytime.** Ruling: `ready-for-agent`. Two-way door — additive columns via `swarm-db.py`'s existing `ADDITIVE_COLUMNS` migration path (built exactly for this kind of change); revertible, provable by swarm-db + record-run-result + fleet-tui test updates. ## Agent Brief **Category:** enhancement **Summary:** Stop conflating cache token classes and hardcoding request counts in `spend` rows. **Current behavior:** `record-run-result.sh` sums fresh input + cache-creation + cache-read tokens into one `input` figure, hardcodes `--requests 1` per iteration, and records no model. Cache-read, cache-write, and fresh input differ roughly 10x in price, so no dollar figure or budget-headroom estimate can be derived from `spend`, and the real API request count is discarded. **Desired behavior:** `spend` gains additive columns (`cache_creation_tokens`, `cache_read_tokens`, `model`) via the existing `ADDITIVE_COLUMNS` path. `record-run-result.sh` writes these separately instead of pre-summing them into one `input` number, and passes the real request count through when the usage data exposes it. fleet-tui's `usage.py` and the probe's `spend_daily` aggregate gain the new columns under the same names. **Key interfaces:** - `swarm-db.py`'s `ADDITIVE_COLUMNS` list and the `spend` table/insert. - `record-run-result.sh`'s per-iteration usage parsing (`cacheCreationInputTokens`, `cacheReadInputTokens`). - fleet-tui `usage.py` aggregation and the probe's `spend_daily`. **Acceptance criteria:** - [ ] `spend` has `cache_creation_tokens`, `cache_read_tokens`, `model` columns, additive (existing rows unaffected) - [ ] `record-run-result.sh` writes these columns from the iteration's usage block instead of folding them into `input` - [ ] The real per-iteration request count is recorded when available, no longer hardcoded to 1 - [ ] fleet-tui `usage.py` and the probe's `spend_daily` read/aggregate the new columns - [ ] swarm-db + record-run-result + fleet-tui tests updated **Out of scope:** - Per-tool-call/per-request ingestion from session jsonl files (#98 depends on this ticket's schema landing first) - Historical backfill of existing `spend` rows
Author
Member

swarm-claim host=elitebook-distributed-server-03 run=1160
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=elitebook-distributed-server-03 run=1160 (automated multi-host claim — lowest live claim id works this ticket)
Author
Member

close-report for #96 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 96,
  "status": "success",
  "commits": [
    "84ff66f"
  ],
  "changed_files": [
    "swarm-db.py",
    "record-run-result.sh",
    "fleet-tui/probe.py",
    "fleet-tui/usage.py",
    "tests/swarm-db-test.sh",
    "tests/record-run-result-test.sh",
    "fleet-tui/tests/test_probe.py",
    "fleet-tui/tests/test_usage.py",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "bash tests/swarm-db-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/record-run-result-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/fleet-tui-test.sh",
      "exit_code": 0
    },
    {
      "command": "for t in tests/*.sh onboarding/tests/*.sh; do case \"$t\" in *fakebin*|*fixtures*) continue;; esac; bash \"$t\" || echo FAIL; done",
      "exit_code": 0
    },
    {
      "command": "python3 -c 'run test_usage.py + test_probe.py functions directly (no venv/pip in-sandbox)'",
      "exit_code": 0
    }
  ],
  "criteria": {
    "spend has cache_creation_tokens, cache_read_tokens, model columns, additive (existing rows unaffected)": "swarm-db.py: SCHEMA spend table gains the three columns AND ADDITIVE_COLUMNS lists them so a pre-existing db gains them on migrate; tests/swarm-db-test.sh migration case asserts each column is ADDed to a legacy spend table and its old rows read NULL",
    "record-run-result.sh writes these columns from the iteration's usage block instead of folding them into input": "record-run-result.sh: input_tokens=$in_tok (fresh only), --cache-creation $cache_c --cache-read $cache_r; tests/record-run-result-test.sh asserts input=1000, cache_creation=200, cache_read=50 (was the folded 1250)",
    "The real per-iteration request count is recorded when available, no longer hardcoded to 1": "record-run-result.sh reads .iterations[i].usage.requests (fallback 1); tests/record-run-result-test.sh RUN96 asserts requests=7 from a block exposing it, RUN1 asserts the fallback 1",
    "fleet-tui usage.py and the probe's spend_daily read/aggregate the new columns": "fleet-tui/probe.py spend_daily sums cache_creation/cache_read and groups by model alongside account (spend_repo sums the cache classes too, both with older-pin try/except fallback); usage.py _sum_into/daily/by_host aggregate the cache columns; verified by test_probe.py and test_usage.py driven directly",
    "swarm-db + record-run-result + fleet-tui tests updated": "tests/swarm-db-test.sh, tests/record-run-result-test.sh, fleet-tui/tests/test_probe.py, fleet-tui/tests/test_usage.py all updated in this commit"
  },
  "summary": "spend rows record fresh input, cache-creation, cache-read, real request count and model as separate additive columns so a dollar cost is derivable.",
  "blockers": []
}
**close-report** for #96 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 96, "status": "success", "commits": [ "84ff66f" ], "changed_files": [ "swarm-db.py", "record-run-result.sh", "fleet-tui/probe.py", "fleet-tui/usage.py", "tests/swarm-db-test.sh", "tests/record-run-result-test.sh", "fleet-tui/tests/test_probe.py", "fleet-tui/tests/test_usage.py", "STATUS.md" ], "tests": [ { "command": "bash tests/swarm-db-test.sh", "exit_code": 0 }, { "command": "bash tests/record-run-result-test.sh", "exit_code": 0 }, { "command": "bash tests/fleet-tui-test.sh", "exit_code": 0 }, { "command": "for t in tests/*.sh onboarding/tests/*.sh; do case \"$t\" in *fakebin*|*fixtures*) continue;; esac; bash \"$t\" || echo FAIL; done", "exit_code": 0 }, { "command": "python3 -c 'run test_usage.py + test_probe.py functions directly (no venv/pip in-sandbox)'", "exit_code": 0 } ], "criteria": { "spend has cache_creation_tokens, cache_read_tokens, model columns, additive (existing rows unaffected)": "swarm-db.py: SCHEMA spend table gains the three columns AND ADDITIVE_COLUMNS lists them so a pre-existing db gains them on migrate; tests/swarm-db-test.sh migration case asserts each column is ADDed to a legacy spend table and its old rows read NULL", "record-run-result.sh writes these columns from the iteration's usage block instead of folding them into input": "record-run-result.sh: input_tokens=$in_tok (fresh only), --cache-creation $cache_c --cache-read $cache_r; tests/record-run-result-test.sh asserts input=1000, cache_creation=200, cache_read=50 (was the folded 1250)", "The real per-iteration request count is recorded when available, no longer hardcoded to 1": "record-run-result.sh reads .iterations[i].usage.requests (fallback 1); tests/record-run-result-test.sh RUN96 asserts requests=7 from a block exposing it, RUN1 asserts the fallback 1", "fleet-tui usage.py and the probe's spend_daily read/aggregate the new columns": "fleet-tui/probe.py spend_daily sums cache_creation/cache_read and groups by model alongside account (spend_repo sums the cache classes too, both with older-pin try/except fallback); usage.py _sum_into/daily/by_host aggregate the cache columns; verified by test_probe.py and test_usage.py driven directly", "swarm-db + record-run-result + fleet-tui tests updated": "tests/swarm-db-test.sh, tests/record-run-result-test.sh, fleet-tui/tests/test_probe.py, fleet-tui/tests/test_usage.py all updated in this commit" }, "summary": "spend rows record fresh input, cache-creation, cache-read, real request count and model as separate additive columns so a dollar cost is derivable.", "blockers": [] } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Matou/dev-factory#96
No description provided.