← all branches

feat/smarter-mrr

needs attentionviewing older commit
4d95793 · fullpre-PRreviewed 2026-08-07 19:28 UTC0H · 0M · 4L · 6I
The branch
Purpose
Add MRR visibility for Smarter (Energía Real), an off-platform client paying $20 USD per report (calculated bill). Smarter pays by bank transfer; this insight does not touch the billing pipeline.
Goal
Measure Smarter MRR natively in USD (measure-not-charge pattern, matching Neto/Pilgrim's) and surface it on the Revenue & MRR dashboard for finance reconciliation.
Sub-goals
  • Add mrr_smarter_usd insight: count(calculated bills)/month × $20 USD + display-only MXN approximation
  • Add tile to Revenue & MRR dashboard at y=36
  • Document Phase 2 discrepancy (per-report ~$62k MXN vs finance Billing $69k MXN — bundle difference) for future Stripe/USD plan work
The changes (whole branch)
What
Added one Terraform locals block (2 constants) and one posthog_insight resource in insights.tf (+52 lines); added one dashboard tile entry in dashboards.tf (+5 lines). No app code, no DB schema, no billing path.
Why
Smarter is paying off-platform; leadership needs MRR visibility without a full Stripe integration. Phase 1 = measure; Phase 2 (multi-plan-per-org / USD plan / Stripe) is a separate effort.
Areas
infra/posthog/insights.tf+520infra/posthog/dashboards.tf+50
Blast
57 lines added across 2 files in infra/posthog/ only. Zero app code, zero DB migrations, zero billing path changes. Confined to PostHog analytics IaC.
measure-only — no charging path change USD-native — does not route through MXN Stripe/ledger pipeline
ci· gh auth not available in this runner context; CI status not fetchedcoderabbit· no .coderabbit.yaml in repoterraform-validate· CI applies terraform to dev on every PR touching infra/posthog/ — subsumes validation

Findings · 10

correctness2

low

round() returns Float64 in ClickHouse/HogQL — mrr_mxn_aprox displays as e.g. 3360.0 not 3360

infra/posthog/insights.tf

round(count() * 20 * 18.5, 0) returns Float64 in ClickHouse semantics, so the column displays with a trailing .0. Column is display-only/approximate so not a bug, but toInt64(round(...)) would give a cleaner integer if desired.

low

FX constant baked into Terraform-rendered SQL — stale-value risk on re-apply

infra/posthog/insights.tf

Terraform interpolates usd_mxn_fx = 18.5 into the heredoc string at plan/apply time, so the literal 18.5 is sent to PostHog. This is intentional and documented, but a future re-apply with an unchanged local will silently keep the stale rate. The comment instructs manual refresh — confirm this is visible to whoever owns infra applies.

conventions3

info

locals block placed mid-file — prefer top of file or locals.tf

infra/posthog/insights.tf

Terraform convention is to declare locals{} near the top of the file or in a dedicated locals.tf. Placing it inline just before the resource that uses it makes constants harder to discover. Terraform is ordering-indifferent so this is not a bug.

info

FX refresh cadence: informal comment, no structured traceability

infra/posthog/insights.tf

The inline comment 'refresh manually alongside the D3 finance constants' is reasonable but informal. A more explicit marker (e.g., last-updated date or a Linear issue link) would make the update obligation traceable.

info

Dashboard tile comment separator is longer than existing separators

infra/posthog/dashboards.tf

The # ── Smarter (ER) MRR ... ────── line is noticeably longer than adjacent separators. Minor visual inconsistency.

tests1

info

No bill-status filter beyond source='calculated' — confirm all counted records are valid delivered reports

infra/posthog/insights.tf

The query counts every bill WHERE source='calculated' with no status guard. If the bills table can hold source='calculated' rows in errored, voided, or pending states, the count may overstate reportable MRR. The commit verifies live numbers match expectation (Jul 210, Jun 168), which is a strong signal all such bills are valid — but worth an explicit comment confirming whether a status filter is needed or ruled out.

improvement4

low

Hardcoded start date '2026-01' will age silently

infra/posthog/insights.tf

WHERE year_month >= '2026-01' is reasonable today but will exclude any backfilled or pilot rows before that date, and the bound may become confusing as the product matures. LIMIT 24 ORDER BY year_month DESC already caps the lookback — dropping the WHERE clause makes the query self-maintaining.

low

Manual FX rate has no enforcement mechanism — risk of stale data on revenue dashboard

infra/posthog/insights.tf

usd_mxn_fx = 18.5 is marked 'display-only; refresh manually'. A stale FX rate drifting >10% could quietly mislead the MXN column, especially given the known discrepancy between derived MRR and the finance Billing line. Consider (a) a Terraform variable with a description that surfaces the refresh obligation in plan output, or (b) removing the MXN column until a live FX source is available.

info

Triple count() — CTE would express the mrr derivation more clearly

infra/posthog/insights.tf

count() appears three times in SELECT. No performance issue (ClickHouse evaluates once per group), but a WITH base AS (SELECT year_month, count() AS reportes ...) CTE would make the derivation intent explicit. Minor readability improvement.

info

Dashboard tile leaves x=6..11 at y=36 empty

infra/posthog/dashboards.tf

Tile placed at x=0, y=36, w=6 — right half of the row is unused. If no companion tile is planned, widening to w=12 would use the space better. Purely cosmetic.

History · 4 commits

  1. 37de5d2safeincremental0H · 0M · 2L2026-08-10 19:05
  2. af89f54needs attentionincremental1H · 2M · 9L2026-08-10 17:36
  3. a4fbc2bneeds attentionincremental7H · 11M · 5L2026-08-08 00:42
  4. 4d95793needs attentionfull0H · 0M · 4L2026-08-07 19:28current