# Product lifecycle metrics: protocol

A fourth question on the same synthetic company, the same generator and the same seed as `DESIGN.md`: which early
product action should count as activation, how long free workspaces take to pay and paying ones take to leave, which
guardrails catch an onboarding change that games a metric, and how the net revenue retention bridge splits by sales
motion. Sections 1 to 10 are the declaration. They were written before any code for this round existed and before any
product event, activation flag, survival curve or guardrail figure was computed. `tests/test_lifecycle.py` pins their
sha256; a later change goes in a new section at the end headed `## Amendment N: <what changed>`.

Nothing in `DESIGN.md`, `DESIGN-realization.md`, their results files, `warehouse/`, `dbt/` or `realization/` changes.
This round writes its own code (`lifecycle/`), its own dbt project (`lifecycle/dbt`) and its own results file,
`results-lifecycle.json`.

## 1. Overlap test

The nearest published studies, and why this is a round of this study rather than a new one:

- this study (`index.html`, `price-realization.html`): same synthetic company and data, different question. Those pages
  ask for one defensible revenue number and what existing customers kept; this one asks which product actions come
  before revenue, and splits the existing retention bridge by motion.
- the AI adoption measurement study: same question family (activation, and how big a test must be), but on assumed
  rates with no data.
- the self-service measurement study: when a success metric hides failures. It supplies the guardrail idea here, not
  the data.

Same data as this study, so it is a new round on this study's site folder, linked from its entry page.

## 2. Questions

1. Activation: of four declared candidate definitions, which best predicts that a new workspace pays and is still
   paying 90 days later, on sign-up cohorts the choice never saw; and what does the earliest signal cost against the
   most predictive one?
2. Survival: how long do free workspaces take to pay, and how long do paying self-serve customers stay, by plan, with
   intervals; and how far apart are logo retention and usage-weighted retention?
3. Guardrails: when an onboarding change raises activation without raising retention, or raises conversion while
   failed runs and support load rise, which guardrail in the metric tree catches it, and how often do the guardrails
   fire on a change that does nothing?
4. The net revenue retention bridge of `price-realization.html`, split by motion (self-serve seat plans, sales-led
   contracts, usage).

## 3. The event layer (a design step, before any outcome)

The generator emits sign-ups (`product_workspaces`), plan changes (`product_plan_changes`), month-end seats
(`product_workspace_monthly`) and metered runs on paid days (`usage_daily`). It emits no activity for free days, no
failed runs and no support tickets. This round adds one extract, `product_events`, written by `lifecycle/events.py`, a
new generator entry point. It reads `warehouse.generate.Company(seed).run()` and the clean `build(seed)`; every draw
uses its own `random.Random(seed + 11001)` (`EVENT_SEED_OFFSET`), so the generator's own draws, its 17 extracts and
every frozen results file stay byte-identical (a test checks the extracts).

Rows: `event_id`, `workspace_id`, `event_type`, `event_date`, only for the first 84 days after sign-up (weeks 1 to 12;
week 1 is the sign-up day and the six days after it) and never after the last day of the data.

- `run`: one row per successful run on a day the workspace is on the free plan. Runs on paid days are already in
  `usage_daily` and are not repeated here.
- `run_failed`: a failed run on any day, free or paid. Failed runs are never metered.
- `support_ticket`: a ticket opened by the workspace.

**Activity** on a day means a `run` event or a `usage_daily` row with runs above zero that day. Paid days are therefore
almost always active; that link between paying and activity is intended and is said on the page.

The model, with every parameter declared here:

- **Fit.** Each workspace has a hidden fit score f. For a workspace in the population of section 4 whose outcome is
  observed, f is drawn from a standard normal conditioned on its outcome Y (section 4) as if
  P(Y = 1 | f) = 1 / (1 + exp(-(a + 1.5 f))), by rejection sampling; a is solved at generation time so that the
  average of that probability over a standard normal equals the population's observed share with Y = 1. Every other
  workspace draws f from a standard normal. This makes fit and the frozen outcome agree at a strength set here (1.5);
  it does not change any outcome.
- **Free-day activity.** For each week k that has at least one free day, the workspace is active on free days with
  probability 1 / (1 + exp(-(w_k + 1.0 f))), w_1 = 0.5, w_k = -0.7 - 0.1 (k - 2) for k >= 2. When active, it runs on
  1 + Binomial(n - 1, 1 / (1 + exp(-(-1.0 + 0.5 f)))) distinct free days of the week (n free days), chosen uniformly.
  In week 1, when active, the sign-up day is one of them with probability 1 / (1 + exp(-(0.2 + 0.4 f))) (only if it is
  a free day). Each run day has 1 + Poisson(exp(0.3 f)) runs.
- **Failed runs.** Each active day (free or paid) has Poisson(0.06) failed runs.
- **Tickets.** Each week with at least one active day opens a ticket with probability 0.02 + 0.25 when that week had a
  failed run.

The strengths above decide which candidate wins in section 5. The round shows how the choice is made and checked; it
cannot show which product action predicts retention in any real product.

## 4. Population, outcome and cohorts

- **Population:** every workspace that signed up in simulated months 1 to 19 (the first 19 of the generator's 27
  months, so every outcome below is observed before the data ends) and was not on a sales-led contract within 28 days
  of sign-up (workspaces created by a sales deal are not product sign-ups).
- **Outcome Y:** 1 when the workspace's first paid day (self-serve plan or contract, from the product's plan changes)
  is within 150 days of sign-up and it is on a paid plan on the 90th day after that first paid day; else 0. In plain
  words: paid, and still paying 90 days later.
- **Development cohorts:** sign-up months 1 to 10. **Held-out cohorts:** sign-up months 11 to 19. The choice of N in
  candidate 2 uses development cohorts only; every comparison in section 5 is on held-out cohorts.

## 5. Activation: candidates, metric and rule

| Candidate | Known on day | Definition |
|---|---|---|
| 1. First run on sign-up day | 1 | activity on the sign-up day |
| 2. Runs on N days in two weeks | 14 | activity on at least N distinct days of the first 14; N from 1 to 10 is the value with the highest phi on development cohorts (ties to the smaller N) |
| 3. Active in 2 of the first 4 weeks | 28 | activity in at least two of weeks 1 to 4 |
| 4. Paying within 28 days | 28 | a paid day within the first 28 days (reference) |

Candidate 4 is conversion, which has its own node in the metric tree, so it cannot be the activation metric: an
activation metric has to be a product action that onboarding work can move before payment. It is reported as the
reference a payment signal gives. Candidates 1 to 3 are eligible.

- **Metric:** phi, the correlation between the flag and Y, on held-out cohorts. Also reported: the share flagged,
  Y among flagged (precision) and not flagged, and the share of Y = 1 workspaces flagged (recall).
- **Intervals:** 2,000 bootstrap resamples of held-out workspaces (seeded, `random.Random(20261)`), 95% percentile
  intervals for each phi and for each eligible candidate's difference from the best eligible one.
- **Rule:** take the eligible candidate with the highest held-out phi. If an earlier eligible candidate's difference
  interval includes zero, the two are called tied on prediction and the earliest tied one is picked.
- **Stability:** the whole choice (N, phi, rule) rerun on 100 event seeds (offsets 11001 to 11100, the company fixed),
  on the generator-side calculation of section 8; reported as the share of seeds picking each candidate.

## 6. Survival and cohort retention

- **Time to first payment:** population workspaces of all 27 sign-up months, days from sign-up to the first paid day,
  censored at the last day of the data; Kaplan-Meier with Greenwood log-log 95% intervals; the share paying by day 30,
  90 and 150, overall and for sign-up months 1 to 9, 10 to 18 and 19 to 27.
- **Time to churn:** each self-serve customer's first subscription, days from its start to its last paid day; a move
  to a contract or the last day of the data censors it; Kaplan-Meier with the same intervals, by plan (team or
  business, monthly or annual); survival at 3, 6, 12 and 18 months.
- **Logo against usage-weighted retention:** self-serve customers grouped by the quarter of their first paid day, for
  the first 12 full calendar months after it. Logo retention: the share still paying at the month's end. Usage-weighted
  retention: the group's metered runs in the month as a share of its runs in month 1. Reported for each quarter whose
  12 months are observed.

## 7. Guardrails and the planted changes

The metric tree (`METRIC_TREE.md`) pairs each input metric with guardrails. For a test, each sign-up in the held-out
cohorts is assigned to a treated or a control half (seeded, `random.Random(20262)`), and the event layer is redrawn with
the change applied to treated workspaces only. Billing is not regenerated: conversion changes are applied to the
workspace table and the product events.

| Metric | Kind | Harmful direction |
|---|---|---|
| Activation rate (the picked definition) | primary for change A | (none) |
| Paying within 28 days | primary for change B | (none) |
| G1. Y among activated | guardrail | falls |
| G2. Activated workspaces active in weeks 5 to 8 | guardrail | falls |
| G3. Failed runs per 100 active days, first 28 days | guardrail | rises |
| G4. Tickets per 100 active weeks, first 4 weeks | guardrail | rises |
| Y, all workspaces | outcome | falls |

A metric **moves** when the 95% interval of the treated minus control difference (normal approximation; ratios by the
delta method, per workspace) excludes zero. A guardrail **fires** when it moves in its harmful direction.

| Change | What it does to treated workspaces | Predicted to move or fire | Predicted silent |
|---|---|---|---|
| A. Activation nudge | a guided run on the sign-up day with probability 0.5 when it is a free day, and in weeks 2 and 3 an inactive free week becomes active with probability 0.5; fit and Y untouched | activation rises; G1 and G2 fire | G3, G4, Y, paying within 28 days |
| B. Conversion push | of workspaces whose first paid day is day 29 to 150, 30% pay on a uniform day 7 to 28 instead (Y untouched); failed runs per active day become Poisson(0.12) | paying within 28 days rises; G3 and G4 fire | G1, G2, Y |
| 0. No change | nothing | nothing moves or fires | every metric |

**False alarms:** 200 further random splits of the held-out cohorts with no change (`random.Random(20263)`): the share
of splits in which each guardrail fires, and in which any of G1 to G4 fires.

## 8. Models and checks

`lifecycle/dbt` reads the main warehouse after `make build`, plus `raw.product_events`, and writes the schema
`lifecycle`:

- `stg_product_events`: typed events.
- `fct_workspace_lifecycle`: one row per workspace: sign-up day and month, population flag, first paid day and kind,
  activity flags and counts for the candidates, the outcome, the split, failed runs, tickets and active weeks, and the
  first self-serve subscription's plan, start, last paid day and censoring.
- `fct_lifecycle_monthly`: the metric tree per reported month: new workspaces, the candidates' activation rates for
  the month's sign-ups, conversions, paying workspaces at the month end, and the bridge's expansion, contraction, churn
  and new ARR from `fct_arr_bridge`.
- `fct_nrr_bridge_by_motion`: the cohort of `DESIGN-realization.md` section 2 (customer keys with ARR above zero at
  its starting point) over its measured year, one row per motion: starting ARR, each summed bridge move, usage rises
  and falls, ending ARR, NRR and GRR.

Checks, each labelled before it runs:

| Check | Kind | Fails when |
|---|---|---|
| `assert_motion_bridges_close` (dbt) | identity | for any motion, starting ARR plus every summed move differs by more than US$0.01 from ending ARR |
| `assert_motions_sum_to_cohort` (dbt) | identity | the motions added together differ by more than US$0.01 from the cohort's bridge computed straight from the monthly bridge rows and the ARR model, in any line |
| `assert_first_paid_matches_billing` (dbt) | can fail | any workspace's first paid day in the product's plan changes differs from the earliest card subscription start or contract service start for that workspace in the billing systems |
| `assert_events_inside_window` (dbt) | can fail | a product event names an unknown workspace, or falls before its sign-up day or after day 84 |
| lifecycle against the generator (Python) | can fail | any population workspace's first paid day, outcome, candidate flag or count, failed runs, tickets, or first subscription's dates differ from the generator's own calculation from its records and the event generator |

Plus `unique` and `not_null` on each mart's keys. The analysis of sections 5 to 7 reads `fct_workspace_lifecycle`
from the clean warehouse; the seed and scenario reruns use the generator-side calculation, which the last check ties
to the warehouse on the clean run.

## 9. Positive controls and predictions

Each runs once on a fresh copy. Data controls edit an extract and rebuild what reads it; code controls replace one
line of a copy of `lifecycle/dbt`. Each raises an error if it touches nothing.

| Control | Kind | What changes | Predicted to fire | Predicted silent |
|---|---|---|---|---|
| `event_before_sign_up` | data | the lowest-id population workspace's first `run` event moved 30 days before its sign-up | events inside window; lifecycle against the generator | the two identities; first paid matches billing |
| `plan_change_late` | data | the lowest-id population workspace that paid within 28 days has its first paid plan change moved 40 days later in the product extract | first paid matches billing; lifecycle against the generator | the two identities; events inside window |
| `motion_bridge_drops_usage_rise` | code | `fct_nrr_bridge_by_motion` leaves usage rises out of its lines | motion bridges close; motions sum to the cohort | first paid matches billing; events inside window; lifecycle against the generator |
| `two_week_window_off_by_one` | code | the 14-day activity count in `fct_workspace_lifecycle` counts 15 days | lifecycle against the generator | the two identities; first paid matches billing; events inside window |

The clean run must pass every check. A control holds when every check predicted to fire fails and every check
predicted silent passes. A dbt test that errors counts as neither.

## 10. Predictions for the results, and what this design cannot show

Written before any figure in sections 5 to 7 existed:

- Held-out phi: candidate 4 (paying within 28 days) highest, then 3, then 2, then 1. Candidate 4 flags under 5% of
  sign-ups with Y above 80% among them; candidate 1 flags the most and predicts least.
- The rule picks candidate 3, with candidate 2's difference interval excluding zero. N for candidate 2 is 3 or 4.
  Candidate 3 is picked on at least 90 of the 100 event seeds.
- Time to first payment: about 12% of sign-ups pay within 150 days, with the three sign-up groups' intervals
  overlapping (the generator converts at one rate throughout).
- Time to churn: monthly plans keep 70% to 78% at 12 months; annual plans keep above 95% until the first renewal and
  76% to 84% just after it.
- Usage-weighted retention at month 12 exceeds logo retention by more than 10 points in every observed quarter.
- Changes A and B behave as section 7 predicts. On no-change splits each guardrail fires in 1% to 5% of the 200 and
  any of the four in 4% to 15%.
- By motion: the sales-led motion's NRR is above the self-serve motion's; the self-serve motion loses ARR to the move
  to contracts, and the sales-led motion gains the same amount.

What it cannot show: the same author wrote the generator, the event model, its strengths, the checks, the controls and
the planted changes. Which candidate wins follows from the event model's declared strengths, so the comparison shows
the method (a declared comparison on held-out cohorts, intervals, an eligibility rule and the earliest-signal
trade-off), not which product action predicts retention anywhere else. The planted changes are caught because they
were built with known effects: a self-test of the guardrails' wiring and of their false-alarm rate, not of how often
they would catch a real bad change. One company, one seed; the event model alone is varied across seeds.

## Amendment 1: which workspaces the billing check can name

Written while writing the check's SQL, before any model or check had run. A contract reaches a workspace only through
its CRM account's workspace link, and some accounts are unlinked (the main study's identity bridge), so the billing
systems cannot name the workspace of every contract. `assert_first_paid_matches_billing` therefore compares: for a
workspace whose first paid plan change in the product is self-serve, that day against the earliest card subscription
start of the card customer on that workspace; for a workspace whose first paid plan change is a contract and whose
CRM account is linked to it, that day against the earliest service start of that account's contracts. A workspace whose
first paid plan is a contract on an unlinked account is not compared, and the page says so. Every prediction stands.

## Amendment 2: change A against every eligible definition (decided after the results)

Written after the analysis stage had run. The rule picked candidate 2 (runs on 7 days in two weeks), not candidate 3,
and change A, written with candidate 3 in mind, did not move the picked definition. Change A's comparison is therefore
repeated with each eligible definition in turn as the activation metric (and in G1 and G2), on the same assignment and
the same redrawn events. These figures were decided after the results: the page labels them so, and they are not
scored against section 10's predictions, which stay as recorded.

## Amendment 3: three descriptive figures asked for by an independent review (decided after the results)

Written after the results and after an independent review of the page, before any of these figures was computed. Three
figures are added, each from the same data and the same redrawn events as the declared run, none scored against
section 10's predictions, and each labelled on the page as decided after the results:

- Paid days in the activity counts. A paid day with metered runs counts as active, so part of candidates 2 and 3's
  activity can come from workspaces that already pay. For each eligible candidate, the number of flagged held-out
  workspaces whose first paid day falls before the day the flag becomes known; and each candidate's held-out fit and
  share found with paid days left out of the activity (free-day runs only), at the same N.
- Retention by motion without moves between motions. Each motion's net revenue retention with the ARR that moved from
  self-serve to a contract taken out: (ending ARR minus moved in plus moved out) over starting ARR.
- The threshold N chosen on each of the 100 event redraws, counted by value.

The declared stages are not re-run with different settings. The runner gains one stage for these figures; the whole run
is repeated in a fresh work directory under the new code, and every declared result must come out byte for byte as
before.

## Amendment 4: a fixed row order for the bootstrap (a correction found after the results)

Written after the results, when the whole run was repeated in a fresh work directory for Amendment 3. The repeat gave the
same point estimates, the same pick and byte-identical output for every stage except the bootstrap intervals of section
5, which moved in the third decimal. The cause: the analysis read the workspace lifecycle model with no row order, and
the bootstrap resamples rows by position, so the same seed drew different workspaces when the database returned rows in a
different order. The runner now reads the rows ordered by workspace id, so a rerun from the same code gives the same
intervals. The design is unchanged (2,000 resamples, the same seed, the same rule). The intervals the page reports are
the ones under the fixed order; the report records the earlier ones beside them, and the rule's decision is checked to
be the same under both.
