Skip to content

feat(cost): share each attempt's spend across its statements, with coverage (#1330) - #1338

Merged
athvin merged 3 commits into
mainfrom
feat/1330-statement-cost
Nov 28, 2026
Merged

athvin merged 3 commits into
mainfrom
feat/1330-statement-cost

Conversation

@athvin

@athvin athvin commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Closes #1330

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

What

  • Pods record their statements. exec_task wraps a lake-writing pod task in er_cli::with_recorded_executions(session, run_id, task_id, …), the same recorder run_all uses. A read-only task (materialize_previews, export, extract, train, write_back_scan) records nothing, because the drain is a lake write.
  • statement_execution/read/durations_for_runs: per (run, stage, statement), the total ms and the execution count.
  • cost_roll gains a StatementSource (each dataset's own lake, in production) and statement_costs:
    • each (run, stage)'s spend is shared across its statements by statement time over attempt wall time, so uncovered time stays unattributed instead of inflating the statements;
    • more statement time than wall time (skew) is normalised, so a stage is never over-billed;
    • every roll-up's report now has statements: per dataset, spend_usd, attributed_usd, coverage (statement time / wall time), the top 10 statements by cost (each ≥ $0.01), rest, and below_one_cent, which is counted but never priced alone;
    • a dataset whose lake can't be read is left out of that section, never priced as zero.

Why

#1330 assumed statement attribution was already persisted. It was, but only on the composed run_all path (ExecutionScope in run_all_ensemble_observed). A DAG pod runs a stage_* function directly and recorded nothing, so the runner attempts the roll-up prices (run_costs) had no statements to share across.

Proof

  • pg_run_all_pipeline (eight real exec-task pods) now asserts statement_executions rows for ingest, standardize, match and reconcile under the job's run id. With recording disabled in exec_task, it fails with the ingest pod recorded no statements: {}.
  • pg_cost_roll with a fake StatementSource: every dataset is reported, coverage is within (0, 1], attributed ≤ spend, the top statement is named, and a sub-cent statement is counted, not priced.
  • Unit tests a_stages_spend_is_shared_by_statement_time_and_coverage_is_honest (exact $6.00 / $2.00 / $0.40, coverage 0.6) and nothing_under_a_cent_is_priced_alone_and_skew_never_overbills.
  • make check: exit 0 (entity analyser, skills drift, er-span's statement bound at 360).

Risk & rollback

A lake-writing pod now appends one batch of statement_executions per task. It's best-effort: a failure is logged and the task still succeeds, as on the composed path. Rollback is git revert <merge-sha>.

Post-merge ledger

Closed by: agent · session Claude Code:871c2645-29b1-4996-bd69-8809abfc82fe on brians-MacBook-Pro · 2026-11-28T05:01:52Z

  • main is green with this change on it — the merge SHA, and the run
    that proves it. A later head SHA with this commit as an ancestor counts;
    a cancelled run with zero jobs does not: c668141: rust 46108951351, frontend 46108951349, images 46108951381, infra 46108951350, devcontainer 46108951366, all success.
  • images built, or correctly never ran because nothing that goes into
    an image changed: built, run 46108951381 success.
  • deploy converged — proved by a line the running process emitted, not
    by the image digest and not by the workflow conclusion: converged: deploy 46109293404 at c668141, dev and prod legs success; runner pods launched from this image record their statements from now on.
  • the push-only surface no pull request can pre-test (deploy, drift,
    kind's nightly leg) is green, or knowingly red for a reason that is not
    this change: deploy green. drift is red on The er-alerts SNS email subscription has never been confirmed — 19 armed alarms reach nobody #1107's unconfirmed SNS subscriber, not this change.
  • the board card reached Done through the automation rather than by
    hand, and the issue closed: Cost: per-statement share of attempt spend, with coverage #1330 closed by the merge.
  • follow-ups are open for everything deferred here — numbers: none.
  • what was learned is written down where the next session will find it
    (a skill, a reference, memory) — or nothing new was learned: recorded in the PR: statement executions were recorded only on the composed run_all path, never by a DAG pod. with_recorded_executions now covers lake-writing pod tasks.

Specific to this change

  • The ticket's done-when on a real roll: a dataset's top statements by cost share, with coverage, appear in the er-cost-roll Job's report after runs that executed with this change. blocked: needs runs executed with this image and then the next scheduled er-cost-roll (07:17 UTC daily). The pg_cost_roll test proves the report's shape and the pipeline e2e proves the recording.

🤖 Generated with Claude Code

bmoore813 and others added 3 commits November 27, 2026 18:01
…verage (#1330)

The roll-up billed DAG pod attempts (run_costs), but statement executions
were recorded only on the composed run_all path, never by a pod, so the
attempts it priced had no statements to share across. A lake-writing pod
task now records its executions under its task id
(er_cli::with_recorded_executions around run_pod_task). A read-only task
records nothing, because the drain is a lake write.

cost_roll then shares each (run, stage)'s spend across its statements by
statement time over attempt wall time. What the statements don't cover stays
unattributed and shows as coverage below 1. Every roll-up reports each
dataset's spend, attributed spend, coverage, its top ten statements by cost,
and the rest. Nothing under a cent is priced alone; those statements are
only counted. Read through statement_execution/read/durations_for_runs from
each dataset's lake.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@athvin
athvin merged commit c668141 into main Nov 28, 2026
44 checks passed
@athvin
athvin temporarily deployed to marketing-preview November 28, 2026 04:44 — with GitHub Actions Inactive

This branch was previously deployed

1 inactive deployment
marketing-preview — f4ec7e6a Deployed Nov 28, 2026 by athvin via remove closed PR previews #116
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.

Cost: per-statement share of attempt spend, with coverage

2 participants