# ARR reconciliation: protocol

This file is the protocol of the study. Sections 1 to 8 are the declaration. They were written before
any model, check or fault code existed, and `tests/test_design_pin.py` pins their sha256: any later edit
to them fails the test. A change after that point goes in a new section at the end headed
`## Amendment N: <what changed>`, which the test allows.

## 1. Question

How do you build one ARR number a finance team can trust when revenue comes from free workspaces,
self-serve seat plans with metered usage billed by card, and sales-led contracts invoiced from the CRM?

The study answers with a constructed company, Northwind Workspace, a business collaboration app. It
defines ARR once, builds it in dbt on DuckDB from five raw extracts, reconciles it to billing and to
recognised revenue every month, and then breaks the extracts in seven declared ways to see which
breaks the checks catch.

## 2. Sources

A seeded generator (`warehouse/generate.py`, its own `random.Random` stream) simulates the company
from its first paid plan, about 27 months before the extract, and reports the last 18 complete months.
The same seed always writes byte-identical files. Customer behaviour stops at the last day of the
latest month; billing documents scheduled in the first five days after it (renewals, and usage billed
in arrears) are in the extract, which is taken on day 6 of the following month.

1. **Product** (`product_workspaces`, `product_plan_changes`, `product_workspace_monthly`): every
   workspace with its signup day; each change of plan kind (`free`, `self_serve`, `contract`); a
   month-end snapshot of active seats and plan kind.
2. **Card billing** (`card_price_list`, `card_customers`, `card_subscriptions`, `card_seat_changes`,
   `card_invoice_lines`, `card_refunds`): one billing customer per paying workspace; seat plans (Team
   and Business, monthly or annual, priced per seat, some with a recurring discount); seat changes
   (increases take effect on the day and are prorated to the period end; decreases take effect at the
   next period start); invoice lines (recurring, proration, usage, late usage); refunds of the unused
   part of a period when a subscription ends mid-period.
3. **Usage** (`usage_daily`): metered runs per workspace per day with the time each row was loaded.
   Runs are priced per run and billed monthly in arrears on day 5 of the next month. A small share
   of rows load after that day; they are billed on the following month's usage invoice as late usage.
4. **CRM** (`crm_accounts`, `crm_opportunities`, `crm_contracts`, `crm_contract_tiers`): accounts
   (most linked to a workspace, a declared share of about 12% without the link), opportunities (new,
   migration, renewal; won or lost, with the total contract value), contracts (signature day, service
   start, term, discount, annual or quarterly billing, optional onboarding fee) and ramp tiers (one
   per contract year, each with an annual list value). Self-serve customers with larger seat counts
   migrate to a contract: the card subscription ends the day before the contract's service start and
   the unused part of its period is refunded.
5. **Contract invoicing** (`contract_invoice_lines`, `contract_payments`, `contract_credits`): invoice
   lines from the contract schedule (recurring annual or quarterly in advance, one-off onboarding
   fees, usage and late usage), bank transfer payments, and credit notes (goodwill and service
   credits).

Identity is imperfect on purpose. One workspace maps to at most one billing customer and at most one
CRM account; some CRM accounts carry no workspace link. The generator also writes the true state
(true ARR by motion and month, true recognised revenue by stream and month, true naive ARR) to a
separate truth file that the warehouse never reads. Faults change only the extracts; the truth always
comes from the clean generator.

## 3. ARR definition

- Headline ARR at a month end is contracted recurring ARR plus usage run-rate ARR, always shown as
  two components and a total. ARR counts every line in service on the last day of the month.
- **Self-serve** (motion `self_serve`): seats in effect on the subscription times the seat price net
  of the recurring discount, annualised (monthly price times 12, annual price as is).
- **Contracts** (motion `sales_led`): the annual value of the ramp tier in effect, net of the
  contract discount, from the service start day to the service end day. Not from the signature day
  and not from any invoice.
- **Usage** (motion `usage`): per workspace paid on the last day of the month, the usage revenue of
  the last three complete months times 4. A month counts when the workspace was paid on every day of
  it. With one or two such months, their usage revenue times 12 divided by the number of months, and
  the row is flagged. With none, usage ARR is 0 and the row is flagged as too new. Month M's usage is
  final with the rows loaded before day 5 of month M+1; rows loaded later are listed as restatements
  and never change a reported month silently.
- Free workspaces carry 0. One-off fees, credits and refunds are revenue or billing items and never
  ARR.
- A self-serve customer that moves to a contract is a migration, not a churn plus a new customer:
  the self-serve ARR it had leaves as `migration_out` and enters sales-led as `migration_in`, and the
  difference between the contract and the old self-serve ARR is expansion or contraction. A migration
  can only be seen when the CRM account is linked to the workspace.
- **Naive ARR**, the comparison: every billing document dated in the month (card and contract
  invoice lines of every type, less credit notes and refunds) times 12.

## 4. Revenue recognition and the reconciliations

Revenue is recognised from a rule independent of invoice generation. The warehouse rebuilds the
schedule of charges from the subscription, seat change, contract and tier records (never from invoice
lines) and recognises each charge ratably by day over its service period; a subscription that ends
mid-period stops recognising on its last day (the rest is refunded). Usage is recognised in the month
consumed, from the usage rows. One-off fees are recognised on their invoice day. Credit notes reduce
revenue on the day they are issued. No accounting-standard judgement is exercised (no allocation
across obligations, no variable consideration, no capitalised costs).

- `fct_deferred_rollforward`, by month and stream (card, contract, usage): opening + billings -
  recognised must equal a closing balance computed independently from the documents: for each
  invoice line, its amount times the share of its own service period still to come (zero once the
  subscription ended and the refund was issued); for usage, minus the revenue of rows consumed but not
  yet billed under the day-5 rule. A negative balance is revenue earned but not yet invoiced.
- `fct_arr_to_revenue`, by month: headline ARR divided by 12, plus named reconciling items, equals
  recognised revenue. Items: ramps (contract tier steps inside the month), seat changes and proration
  (self-serve lines whose seats changed inside the month), starts and ends (lines that started or
  ended inside the month, migrations included), length of the month (revenue is earned by day,
  ARR/12 assumes equal months), usage actual versus run rate, one-off fees, credits.
- `fct_arr_bridge`, monthly by motion and consolidated: opening, new, expansion, contraction, churn,
  reactivation, migration_in, migration_out, usage_change, closing. Usage moves only through
  usage_change. In the consolidated view migration_in and migration_out net to zero.

## 5. Checks

dbt tests in six families, frozen with this declaration. Amounts are US dollars.

| Family | Tests | What fails |
|---|---|---|
| Schema | `unique`, `not_null`, `relationships`, `accepted_values` on the staging keys and codes | a repeated or missing key, a link to a missing row, an unknown code |
| Duplicates | `unique_combination` on usage (workspace, day), card lines (subscription, period start, line type), contract lines (contract, period start, line type) | two rows with one business key, whatever their ids |
| Identity | `assert_identity_bridge_coverage`; uniqueness of the workspace on the bridge | under 80% of contracts in service at the latest month end linked to a workspace; a billing customer on more than one workspace; a workspace on more than one CRM account |
| Billing schedule | `assert_card_invoices_match_schedule`, `assert_contract_invoices_match_schedule`, `assert_usage_invoices_match_usage`, `assert_payments_match_invoices` | a scheduled charge (period start on or before the last extract day) without exactly one matching line within US$0.01 of the same period; a recurring, proration or one-off line that matches no scheduled charge; a usage line that differs from its rows times the run price by more than US$0.01; a payment above its invoice or on a missing invoice |
| Contract integrity | `assert_contract_value_matches_opportunity`, `assert_contract_tiers_contiguous` | tier values times tier length more than US$1 from the won opportunity's amount; tiers with gaps or overlaps between service start and end |
| Motion and reconciliation | `assert_one_motion_per_workspace`, `assert_arr_bridge_reconciles`, `assert_deferred_rollforward_balances`, `assert_arr_to_revenue_walk_sums` | a workspace with both self-serve and sales-led ARR at one month end; a bridge month that does not add up within US$0.01 or does not open where the last closed, or consolidated migration not zero; a roll-forward month and stream more than US$1 from its document balance, or not opening at the last close; a walk more than US$0.01 from recognised revenue |

The US$1 roll-forward tolerance covers cent rounding of prorations and refunds across a month of
lines; every declared fault below moves far more than that.

## 6. Faults and predictions

Each fault edits only the extracts, chooses rows in stable id order, and raises an error if it touches
nothing (so a fault that fails to apply can never score as a miss).

| Fault | Source edited | What changes | Predicted | Test predicted to fire |
|---|---|---|---|---|
| `card_left_active_after_migration` | card billing | the six most recent migrations' card subscriptions are left active: no end day, no refund, and the card keeps being invoiced on schedule | caught | `assert_one_motion_per_workspace` |
| `usage_rows_duplicated` | usage | every row of ten paid workspaces on three days in the latest month loads twice under new ids | caught | `unique_combination` on usage (workspace, day) |
| `ramp_loaded_flat` | CRM | three ramp contracts in service at the latest month end, not yet on their last tier, are loaded with one tier at the final tier's value for the whole term | caught | `assert_contract_invoices_match_schedule` |
| `goodwill_credit_as_recurring` | contract invoicing | the five most recent goodwill credits leave the credit notes and appear as negative recurring invoice lines | caught | `assert_contract_invoices_match_schedule` |
| `annual_invoiced_as_monthly` | card billing | up to ten annual renewals invoiced in the latest month carry one month's amount and a one-month period | caught | `assert_card_invoices_match_schedule` |
| `invoice_before_service_start` | contract invoicing | the first recurring invoice of up to four contracts that started in the last six months is dated 45 days before service start, and its period starts on that day | caught | `assert_contract_invoices_match_schedule` |
| `discount_wrong_consistent` | CRM and contract invoicing | three contracts in service carry a discount 15 points higher than signed, in the contract, the opportunity amount, every recurring invoice and the payments that follow those invoices | missed | none |

Expected side effects, not scored: the duplicated usage rows also break the usage invoice match and
the usage roll-forward; the flat ramp also breaks the opportunity value check; the credit and the two
mis-timed or mis-sized invoices also break the deferred roll-forward. The discount fault is the
declared miss: every system agrees with every other, so only a document outside them (the signed
order form) could show it.

## 7. Scoring

The clean control runs first and must fail no test. Each scenario is a fresh DuckDB file; dbt `seed`,
`run` and `test` run separately, so a failing source test cannot stop the marts being built. A
scenario is caught when at least one test fails. A test that errors is reported separately and never
counts as a catch. Each scenario records its prediction, its outcome, whether the named test failed,
the families that fired, and its effect against the truth: headline ARR and each component at the
latest month end, naive ARR, recognised revenue for the latest month and the closing deferred
balance. Each fault runs once; none is changed after its result is seen.

## 8. What this design cannot show

The same author wrote the definition, the checks and the faults, knowing all three, so a held
prediction shows the checks do what they were built to do, not how often they would catch real
failures. The company and its rates are assumptions. One currency, no tax, and a simple recognition
rule. A fault that keeps every system consistent with every other is invisible to checks inside them
by construction, and an unlinked CRM account turns a migration into a churn plus a new customer.
## Amendment 1: corrections to the record after the fault runs

Written after all seven faults ran once. Sections 1 to 8 are unchanged, and no fault, check, prediction
or scoring rule changed. These lines correct how the record reads against what was built.

- Section 7 says dbt `seed`, `run` and `test` run separately. The extracts are landed by the loader,
  not by dbt `seed`; `run` and `test` do run separately.
- The fault runner changed twice after the runs, for reporting only: a reconciliation table by month,
  and the largest single-customer churn and new ARR in each month. The code hash in the results is the
  hash at assembly. The clean reproduction runs every scenario again on the current code and must give
  the same results.
- Section 4's rule as built: each invoice period's charge is recognised by day over that period, so a
  ramped contract is recognised at the step billed, and an onboarding fee on its service start day.
  Under ASC 606 a ramp for an unchanged service is often straight-lined, and a fee that is not a
  separate service is usually spread over the contract term. This study applies neither; the
  recognition policy belongs to finance.
- Usage rows loaded on or after day 5 of the next month never change a reported month's ARR. Their
  revenue is recognised in the month the usage happened (US$1,216 over the whole period).
- The usage stream in the roll-forward is an unbilled balance (usage earned before it is invoiced),
  not deferred revenue.
- The walk's month-length line is what remains on each line after its rate changes, and migrations in
  and out are booked at the same value, so the walk and the migration netting hold by construction.
  The independent test is the match against the generator's own ARR and revenue.

## Amendment 2: version 2, contract recognition closer to ASC 606

Declared before any version 2 code. Version 1 (sections 1 to 8 and Amendment 1) and its results stay
as recorded: they are kept as `results-v1.json` and reported beside version 2.

What changes, for contracts only:

- Recurring contract revenue is recognised straight-line. Each contract's total scheduled value over
  its whole term (the sum of every period's scheduled charge as section 4 rebuilds them, through the
  service end) is spread evenly by day from service start to service end. A ramped contract earns its
  average price each day, while ARR keeps the step in effect.
- The onboarding fee is recognised the same way, by day over the contract's term, instead of on its
  invoice day.
- Card plans, usage and credits keep the section 4 rule.
- Balances, per contract: invoiced to date minus recognised to date. A positive balance is deferred
  revenue; a negative one is unbilled revenue (a contract asset). In the roll-forward, the contract
  stream's documents balance becomes this cumulative figure (invoice lines dated on or before the month
  end, less the straight-line revenue to that day); card and usage balances are unchanged. A new mart,
  `fct_contract_balances`, reports deferred and unbilled contract balances by month.
- The walk gains one line, straight-lining: straight-line contract revenue minus the section 4 figure
  for the same contracts. The one-off fees line carries the spread fee. `assert_arr_to_revenue_walk_sums`
  and the runner read the recognised revenue line by name instead of by position. No other check
  changes.
- The generator's truth recognises contracts and fees the same way, in its own code.
- A dbt variable selects the policy; version 1 is `recognition_policy: billing_period`.

Not changed: the ARR definition, the bridge, the seven faults, their predictions and named checks,
and the scoring in section 7.

Predictions for version 2: every fault's outcome and named check as in section 6 (six caught by the
named check, the discount missed). Side effects, not scored: the contract roll-forward now compares the
monthly sums with a cumulative balance built from the same invoices and the same straight-line rule, so
contract faults are expected not to break it; card and usage faults still do.

Pass bars: the clean control fails no test; warehouse ARR and revenue equal the generator's version 2
truth in every reported month to within US$0.01; the clean reproduction is byte-identical; version 1's
results stay unchanged and reported.

What version 2 still does not do: allocate the price across performance obligations, judge whether
the fee is a separate service or grants a right to renew cheaply, treat variable consideration, or tie
to a general ledger. The policy is a stated choice, not an accounting opinion.

## Amendment 3: what version 2's run showed about its side effects

Recorded after version 2 ran; nothing above is changed and no check, fault or prediction is affected.

- The contract leg of the roll-forward holds by construction under version 2: its documents balance
  and its monthly sums use the same invoices and the same straight-line rule. The three contract faults
  that broke it in version 1 (18, 3 and 6 month-and-stream failures) break it in none now, as
  Amendment 2 expected; each is still caught by its named schedule check.
- Amendment 2 expected the usage fault to keep breaking the roll-forward. It broke it in neither
  version (section 6 had listed this side effect too). Unscored.
- This company's data meets the straight-line conditions only in part: seats rise with each ramp step,
  and renewals carry no new onboarding fee. The page states both.
