Skip to content

hydrator: persist derived cost/tokens back to runs so a terminal run is… - #1194

Merged
warren-auto-merge[bot] merged 3 commits into
mainfrom
warren/run_2p5vxqthybqk
Sep 2, 2026
Merged

warren-auto-merge[bot] merged 3 commits into
mainfrom
warren/run_2p5vxqthybqk

Conversation

@warren-run-bot

Copy link
Copy Markdown
Collaborator

Summary

k8s: WARREN_K8S_SPOT env knob pins run pods to GKE Autopilot Spot nodes (warren-2e2e) (#1190)

Agent notes

  • hydrateRunsUsage persists derived stats via new narrow RunsRepo.updateUsage
  • zero-envelope terminal candidates write costUsd=0, preserving bridge tokens
  • backfillTerminalUsage called from transitionToTerminal (reap finalize path)
  • handlers pass deps.repos.runs; no src/db/schema imports added
  • tests: usage-hydrate unit tests + dialect repo tests

Run

  • Warren run: run_2p5vxqthybqk
  • Agent: pi
  • Cost: $0.545 (264.3k in / 13.5k out / 1.5M cache-r)

Seeds

  • warren-b33e — hydrator: persist derived cost/tokens back to runs so a terminal run is hydrated at most once (write-through in hydrateRunsUsage + backfill on terminal reconciliation; write 0 when no envelopes exist)

Commits (4)

Files changed

.mulch/expertise/postgres.jsonl        |   1 -
 .mulch/mulch.config.yaml               |   1 +
 docs/RUNBOOK-K8S.md                    |  10 +++
 src/db/repos/runs.ts                   |  19 +++++
 src/db/repos/runs.update-usage.test.ts |  75 +++++++++++++++++++
 src/runs/reap/state.ts                 |   5 ++
 src/runs/usage-hydrate.test.ts         | 127 ++++++++++++++++++++++++++++++++-
 src/runs/usage-hydrate.ts              |  92 ++++++++++++++++++++++--
 src/runtime/k8s/pod-name.ts            |  40 +++++++++++
 src/runtime/k8s/pod-spec.ts            |  71 +++++++++---------
 src/runtime/k8s/pod-spot.test.ts       |  92 ++++++++++++++++++++++++
 src/runtime/k8s/pod-spot.ts            |  49 +++++++++++++
 src/server/handlers/runs/analytics.ts  |   2 +-
 src/server/handlers/runs/lifecycle.ts  |   4 +-
 14 files changed, 540 insertions(+), 48 deletions(-)

Prompt

Show prompt
Work seeds issue warren-b33e. First run `sd show warren-b33e --json` from the repo root; the issue body is the spec, this is only a digest.

Context: nothing from plan pl-6076 (Outgrow Supabase) has merged yet; you are the first hydrator step. A sibling run (warren-5dd5) will later narrow the events query in src/db/repos/events.ts; do NOT touch listUsageEvents' predicate here, keep your change in src/runs/usage-hydrate.ts, the RunsRepo, and the terminal-reconciliation (reap/finalize) path.

Scope: make hydrateRunsUsage write the derived costUsd + token columns back onto the run row (add a narrow RunsRepo.updateUsage if none exists), persist costUsd=0 for terminal runs with zero usage envelopes, leave cost_basis untouched, and backfill at terminal reconciliation so new runs never sit with a null cost when envelopes exist. Tests on both dialects via the existing repo harness: hydrated candidate is persisted and a second call issues no listUsageEvents; zero-envelope candidate writes 0; non-terminal rows untouched. Handlers must not import src/db/schema (check:layers); use the boot-wired repos.

Quality gates are terminal: `bun run check:all` must be green before you commit and report done. Close the issue with `sd close <id> --reason "<what you did, citing files>"` (substitute the issue id), then commit everything (including .seeds/). Do not push to any branch other than your workspace branch; warren opens the PR.


🤖 Opened by warren run run_2p5vxqthybqk

…onciliation (warren-b33e)

- hydrateRunsUsage persists derived stats via new narrow RunsRepo.updateUsage
- zero-envelope terminal candidates write costUsd=0, preserving bridge tokens
- backfillTerminalUsage called from transitionToTerminal (reap finalize path)
- handlers pass deps.repos.runs; no src/db/schema imports added
- tests: usage-hydrate unit tests + dialect repo tests
@warren-auto-merge
warren-auto-merge Bot enabled auto-merge (squash) September 2, 2026 20:00
@warren-auto-merge
warren-auto-merge Bot merged commit 70c8a37 into main Sep 2, 2026
8 of 9 checks passed
@warren-auto-merge
warren-auto-merge Bot deleted the warren/run_2p5vxqthybqk branch September 2, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant