Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(devex): fold token-cost-per-outcome rationale into engineering analytics docs (#64460)

Julian Bezd7dc5b80eab0
diff --git a/products/engineering_analytics/README.md b/products/engineering_analytics/README.md
index 0f8aa7aaf6dc..058c0ad1adb1 100644
--- a/products/engineering_analytics/README.md
+++ b/products/engineering_analytics/README.md
@@ -106,6 +106,31 @@ The specs read as cautious ("coarse", "deferred", "later") because they're writt
The gap between them is **just data ingestion** (the path from warehouse snapshots to lifecycle events). v1 lives on HogQL over `github_pull_requests` + `github_workflow_runs`; no event ingestion, no PR-as-group-type, no webhook receiver yet.
+## What pays for the destination: token cost per outcome
+
+The destination (lifecycle events + git history) is easy to defer while the payoff reads as "nicer CI metrics."
+Attaching **dollars** changes the calculus, and it's the strongest near-term reason to build it.
+
+LLM analytics already knows what agent work _costs_ — the `$ai_*_cost_usd` properties on generation events.
+What it structurally cannot know is whether that spend was _worth it_: it has no concept of merge, revert, or rework.
+That denominator — a PR's outcome and lifecycle — lives only here.
+Token cost alone is trivia; **token cost per outcome** is the metric, and the join only lands in this product.
+
+Roughly in order of "impossible elsewhere":
+
+- **Rework cost (needs git history).** Sum agent spend across a change _and its fixups_ — a reverted PR plus its two follow-up fixes is the true cost of churn, invisible without the commit/PR graph.
+- **Cost ÷ outcome.** "$X of agent tokens; Y% of those PRs merged, Z% reverted within a week" — a funnel with cost attached at each step.
+- **Cost per code area.** Which products/paths burn the most agent tokens, via the PR's changed files.
+- **The full three-ledger picture.** Human-hours + CI-minutes + tokens on the same unit (the PR) — the only place an agent-authored change and a human one are economically comparable.
+
+Division of labor matters: LLM analytics does the cost grouping itself (it groups by any key on the event).
+This product's job is the **join** — the agent stamps the **branch** at capture time (it knows the branch; the PR often doesn't exist yet), and we resolve that branch to a PR via `github_pull_requests.head.ref`, then enrich with outcome and lifecycle.
+Not the commit SHA: the PR snapshot is current-state-only, so a SHA join matches only the latest push and silently drops every earlier one — undercounting exactly the multi-push work.
+Review and CI-bot spend self-attributes (the PR exists by then); the coding slice is the part that needs us.
+
+So cost is a _payload_, not a new surface: it rides the same lifecycle model, and it's the forcing function that makes ingesting that model — and the git history behind it — worth funding.
+It serves both motivations — a DevEx dogfood metric, and the economics of the AI-to-prod loop.
+
## Locked decisions
Change one only in a separate PR with a written reason. Engineering-level decisions live in [SPEC.md](./SPEC.md) → Locked decisions.
diff --git a/products/engineering_analytics/SPEC.md b/products/engineering_analytics/SPEC.md
index 2038769a6004..c0e84eb159a7 100644
--- a/products/engineering_analytics/SPEC.md
+++ b/products/engineering_analytics/SPEC.md
@@ -190,6 +190,7 @@ Use the current default; revisit when the relevant data lands (§9).
- Commits-till-merged — same; comes with the lifecycle-event data.
- Provider Protocol — wait for a second provider. The read-layer boundary is already drawn to make extraction mechanical.
- Stateful / persisted UI (saved views, persisted filters) — a separate decision once the read-only scene proves out.
+- Cost attribution (agent-token and CI-minute cost per PR) — deferred. Token cost is an LLM analytics join: the `$ai_*_cost_usd` properties on generation events, resolved to a PR by **branch** (head ref → `github_pull_requests.head.ref`), not `head_sha` — the PR snapshot is current-state-only, so a SHA join matches only the latest push and drops every earlier one (undercount). The agent can stamp the branch at capture time even though the PR doesn't exist yet. The grouping is LLM analytics' own; this product owns the branch→PR join plus outcome/lifecycle enrichment. The lever is _cost per outcome_, which needs the lifecycle + git history data above (revert/fixup graph, changed files). See README → "What pays for the destination".
## 9. Data sources