Skip to content

bug(store): run usage_totals_json / cost_totals_json columns are never written by the runner #1394

Description

@dennisonbertram

Work type

Bug / regression

Observed behavior

store.Run.UsageTotalsJSON and CostTotalsJSON (internal/store/store.go:70-73) are read and written by internal/store/sqlite.go (lines 329, 532, 840) but no code in internal/harness or internal/server ever populates them (rg 'UsageTotalsJSON|CostTotalsJSON' internal/harness internal/server → no hits). The columns are always empty, so anything reading run totals from the store (e.g. the durable summary added in #1383, which had to fall back to scanning usage.delta events; GET /v1/runs listings; forensics) cannot use them.

Expected behavior

The runner persists the final usage and cost totals on the run row at terminal status (they are already computed for run.completed's payload), or the dead columns are removed with a migration note.

Reproduction

Complete any run with usage; sqlite3 runs.db "select usage_totals_json, cost_totals_json from runs" → empty strings.

User and operational impact

Store-backed listings and summaries show no usage/cost; #1383 works around it by event scanning, which is O(events) per summary.

Suspected seam and search evidence

Runner terminal persistence path (where store.Run status is set to completed/failed/cancelled, rg 'UpdateRun|SaveRun' internal/harness); RunUsageTotals/RunCostTotals types in internal/store.

Blast-radius impact map

Runner → store write on terminal status; durableRunSummary in internal/server/http_runs.go can prefer the stored totals when present. No wire change. Tests: internal/harness store persistence test, internal/server durable summary test.

Regression test first

Named below per item; red command go test <pkg> -run <Test>.

Fix boundaries

In scope: the single seam named. Out of scope: any wire or schema change.

Diagnostic and observability evidence

Grep evidence cited above.

Verification plan

Red/green; go test <pkg> -race; full regression script.

Rollout and rollback

None — no persisted or deployed behavior changes beyond populating an existing column / list; revert PR.

Documentation and handoff

Engineering log entry.

Definition of done

  • Red test preserved and green
  • Regression green

Process acknowledgement

  • I will preserve the failing regression test, update the issue if the root cause changes, and record any newly discovered bug as its own issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcorrectnessCorrectness bugs and logic errors

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions