One paid renewal reaches the ledger with cash, sale, and VAT legs

Read the model.

This page follows one Stripe renewal report into the ledger. A paid renewal posts its cash, sale, and VAT roles for the right attendee and listing. A replay leaves those same legs in place. A changed booking identity posts no money.

The bad outcome it rules out

A renewal posts money to the wrong attendee or listing, or a replay adds a second copy of one invoice.

The cast

Word Meaning
booking row One stored row that links an attendee to a listing and holds the subscription plan.
plan The recurring amount and the VAT inside it, frozen at checkout. Amounts are integer minor units.
invoice One paid charge from Stripe. Each paid invoice after the first one is a renewal.
ledger leg One transfer row with a source account, a destination account, an amount, and a reference.
pass One observed call for one attempt. The producer reads the ledger before and after the call.
eligible invoice A paid invoice in the site currency with an amount above zero. The first invoice of the checkout is not eligible.
fence The four stored values that name the booking: row id, attendee, listing, and subscription.

The walkthrough

Step 1: Start before the first pass

The model starts before the first observed pass of one scenario. The fixture has a plan and no renewal legs. The fixture seeds a trialing plan. The stale_status scenario replaces that status with canceled before its first pass. Statuses adds a blank word for a booking that a merge removed. ScenarioNames and ExpectedScenarioNames must agree before a pass can run.

Value This step
scenario normal
passIndex 0
storedStatus trialing
checksHold TRUE
arithmeticChecked FALSE

Model rule: Init

Init ==
  /\ \E index \in ScenarioFactsIndices :
       LET item == ScenarioFactsAt(index) IN
       /\ scenario := item.scenario /\ storedStatus := item.initialStatus
  /\ passIndex := 0 /\ checksHold := (Coverage /\ JoinCoverage)
  /\ arithmeticChecked := FALSE
  /\ joinsChecked := FALSE
  /\ readsChecked := FALSE

Model rule: TypeOK

TypeOK ==
  /\ scenario \in ScenarioNames /\ passIndex \in 0..2
  /\ storedStatus \in Statuses
  /\ checksHold \in BOOLEAN /\ arithmeticChecked \in BOOLEAN /\ joinsChecked \in BOOLEAN
  /\ readsChecked \in BOOLEAN

Model rule: Statuses

Statuses == LiveStatuses \cup EndedStatuses \cup {""}

Model rule: ScenarioNames

ScenarioNames == {item.scenario : item \in ScenarioFacts}

Model rule: ExpectedScenarioNames

ExpectedScenarioNames == {item.scenario : item \in ExpectedAttempts}

Production code: scripts/verify-models/subscriptions/renewal-cases.ts#RENEWAL_CASES

export const RENEWAL_CASES: readonly RenewalCase[] = [
  scenario("normal", [pass([cycle()]), pass([cycle()])]),
  scenario("partial", [pass([cycle(303)])]),
  scenario("tax_only", [pass([cycle(1)])], { price: 2, tax: 1 }),
  scenario("no_tax", [pass([cycle()])], { tax: 0 }),
  scenario("excess", [pass([cycle(900)])]),
  scenario("non_renewals", [
    pass([
      cycle(0, "zero"),
      { ...cycle(600, "first"), reason: "subscription_create" },
    ]),
  ]),
  scenario("other_reasons", [
    pass([
      ...Object.entries(OTHER_REASONS).map(([id, reason]) => ({
        ...cycle(600, id),
        reason,
      })),
      { ...cycle(600, "unknown"), reason: null },
    ]),
  ]),
  scenario("currencies", [
    pass([cycle(600, "home"), { ...cycle(600, "away"), foreign: true }], {
      observed: "canceled",
// ...

Source fingerprint: sha256:33e5919cdd802747

Production code: src/shared/subscriptions/plan.ts#SubscriptionStatusSchema

/** Every status Stripe gives a subscription. */
export const SubscriptionStatusSchema = v.picklist([
  "active",
  "canceled",
  "incomplete",
  "incomplete_expired",
  "past_due",
  "paused",
  "trialing",
  "unpaid",
]);

Source fingerprint: sha256:20bb8b15cf795087

Step 2: Every declared input needs one result

Coverage requires one observed result for each declared input. The inputs come before the calls. The producer declares 20 scenario names and 23 passes. Each pass has one renewal read, which makes 23 reads. The producer keeps every read argument, so a repeated call with equal arguments stays visible. A renewal read must name the subscription of its attempt.

Value This step
scenarios 20
passes 23
captured reads 23
arithmetic cases 11

Model rule: Coverage

Coverage ==
  /\ ScenarioNames = ExpectedScenarioNames /\ ScenarioNames # {}
  /\ Cardinality(ScenarioFacts) = Cardinality(ExpectedScenarioNames)
  /\ \A item \in ScenarioFacts :
       /\ item.steps \in {1, 2}
       /\ item.steps = Cardinality({attempt \in ExpectedAttempts :
            attempt.scenario = item.scenario})
  /\ \A expected \in ExpectedAttempts :
       Cardinality({op \in OperationFacts :
         op.attempt = expected.attempt /\ op.scenario = expected.scenario}) = 1
  /\ \A op \in OperationFacts :
       /\ op.scenario \in ScenarioNames
       /\ \E expected \in ExpectedAttempts :
            op.attempt = expected.attempt /\ op.scenario = expected.scenario
  /\ \A item \in ScenarioFacts : \A index \in {0, 1} : index < item.steps =>
       Cardinality({op \in OperationFacts :
         op.scenario = item.scenario /\ op.index = index}) = 1
  /\ InvoiceFactsCount = ExpectedInvoicesCount
  /\ \A expected \in ExpectedInvoices :
       \E invoice \in InvoiceFacts :
         invoice.attempt = expected.attempt /\ invoice.invoice = expected.invoice
  /\ {fact.caseId : fact \in ArithmeticFacts} = ArithmeticCases
  /\ Cardinality(ArithmeticFacts) = Cardinality(ArithmeticCases)
  /\ ReadCoverage

Model rule: ArithmeticCases

ArithmeticCases == {"planned", "half_up", "tax_only", "zero", "below_one",
  "below_plan", "above_plan", "excess", "no_tax", "below_half", "large"}

Model rule: RequiredReads

RequiredReads ==
  {[kind |-> "renewal", owner |-> item.attempt] : item \in ExpectedAttempts}

Model rule: ReadCoverage

ReadCoverage ==
  /\ \A expected \in RequiredReads :
       Cardinality({read \in ReadFacts :
         read.kind = expected.kind /\ read.owner = expected.owner}) = 1
  /\ \A read \in ReadFacts :
       /\ read.ordinal = 0
       /\ \E expected \in RequiredReads :
            read.kind = expected.kind /\ read.owner = expected.owner

Model rule: ReadIdentitySafe

ReadIdentitySafe(read) ==
  /\ read.kind = "renewal"
  /\ \E op \in OperationFacts :
       read.owner = op.attempt /\ read.target = op.snapshotSubscription

Production code: scripts/verify-models/subscriptions/renewal-facts.ts#renderRenewals

export const renderRenewals = (facts: RenewalFacts): string => ...

Source fingerprint: sha256:18813386e35719c2

Production code: scripts/verify-models/subscriptions/renewal-observations.ts#captureRead

export const captureRead = <Answer>(
  reads: RenewalFacts["reads"],
  kind: "renewal",
  owner: string,
  answer: () => Promise<Answer>,
): ((target: string) => Promise<Answer>) => { ... }

Source fingerprint: sha256:33b484128d325f7b

Production code: src/shared/stripe.ts#stripeApi

export const stripeApi: StripeApi = {
  cancelSubscription,
  cleanupOldWebhookEndpoints,
  createCheckoutSession,
  readInvoicePayments,
  readPaidInvoices,
  readPaymentIntent,
  readSubscription,
  refundCharge,
  retrieveCheckoutSession,
  setupWebhookEndpoint,
  testStripeConnection,
};

Source fingerprint: sha256:286f1821d7e5631a

Step 3: One pass writes or refuses

One pass runs the producer call for one attempt. The pass reads the ledger legs before and after the call. A refused read returns without a write. A refused write keeps both the status and every leg. A successful call checks each eligible invoice and leaves other invoices alone. An attempt with no eligible invoice posts no renewal legs.

Value This step
read found
outcome returned
refused read missing. The outcome is returned.
after a refusal The status and every leg stay the same.

Model rule: InspectPass

InspectPass ==
  \E index \in OperationFactsIndices :
    LET op == OperationFactsAt(index) IN
    /\ op.scenario = scenario /\ op.index = passIndex
    /\ op.beforeStatus = storedStatus
    /\ passIndex' := passIndex + 1
    /\ storedStatus' := op.afterStatus
    /\ checksHold' := ChecksStillPass(checksHold, AttemptSafe(op))
    /\ UNCHANGED <<scenario, arithmeticChecked, joinsChecked, readsChecked>>

Model rule: AttemptSafe

AttemptSafe(op) ==
  LET refused == op.outcome # "returned" \/ op.readStatus # "found" IN
  /\ op.outcome = ExpectedOutcome(op)
  /\ op.afterStatus = IF refused THEN op.beforeStatus ELSE ExpectedStatus(op)
  /\ \A invoice \in InvoiceFacts :
       invoice.attempt = op.attempt =>
         IF refused \/ ~Eligible(invoice)
         THEN LegsAfter(invoice) = LegsBefore(invoice)
         ELSE LegsSafe(LegsAfter(invoice), invoice)

Model rule: ExpectedOutcome

ExpectedOutcome(op) ==
  IF op.readStatus # "found" \/ ~HasEligible(op) THEN "returned"
  ELSE IF Conflicts(op) THEN "ledger_conflict"
  ELSE IF ~FenceHeld(op) THEN "booking_fence"
  ELSE IF op.fault THEN "write_fault"
  ELSE "returned"

Production code: scripts/verify-models/subscriptions/renewal-observations.ts#observePass

export const observePass = async (
  facts: RenewalFacts,
  scenario: RenewalCase,
  row: LiveRow,
  pass: RenewalPass,
  index: number,
  write: () => Promise<void> = async () => {
    await recordObserved(row, pass.observed);
  },
): Promise<void> => { ... }

Source fingerprint: sha256:ce0f3427ff9d8356

Production code: src/shared/subscriptions/record.ts#recordObserved

export const recordObserved = async (
  row: LiveRow,
  observed: SubscriptionStatus,
): Promise<ReportOutcome> => { ... }

Source fingerprint: sha256:1f91b97b1d8387d0

Step 4: Cash, sale, and VAT reach the right accounts

An eligible invoice posts three legs. Cash moves from external:world to the attendee. Sale moves the amount without VAT from the attendee to the listing revenue account. VAT moves to tax:vat. The law checks each role before the sum. A role with expected amount zero needs no leg. A positive role needs exactly one leg with the right account, reference, and paid time. Cash must equal sale plus VAT.

Value This step
invoice 600 with price 600 and tax 100
cash leg 600 from external:world to the attendee
sale leg 500 from the attendee to the listing revenue account
VAT leg 100 from the attendee to tax:vat
zero role No leg and no account.

Model rule: TaxShare

TaxShare(amount, price, tax) == (2 * amount * tax + price) \div (2 * price)

Model rule: RoleSafe

RoleSafe(count, amount, source, destination, reference, paidAt,
         expectedAmount, expectedSource, expectedDestination, expectedReference, expectedAt) ==
  IF expectedAmount = 0
  THEN /\ count = 0 /\ amount = 0 /\ source = "" /\ destination = ""
       /\ reference = "" /\ paidAt = 0
  ELSE /\ count = 1 /\ amount = expectedAmount
       /\ source = expectedSource /\ destination = expectedDestination
       /\ reference = expectedReference /\ paidAt = expectedAt

Model rule: LegsSafe

LegsSafe(legs, invoice) ==
  LET vat == TaxShare(invoice.amount, invoice.price, invoice.tax) IN
  /\ legs.otherCount = 0
  /\ legs.eventGroup = invoice.expectedGroup
  /\ RoleSafe(legs.cashCount, legs.cashAmount, legs.cashSource,
       legs.cashDestination, legs.cashReference, legs.cashPaidAt,
       invoice.amount, "external:world", invoice.attendee,
       invoice.cashReference, invoice.expectedAt)
  /\ RoleSafe(legs.saleCount, legs.saleAmount, legs.saleSource,
       legs.saleDestination, legs.saleReference, legs.salePaidAt,
       invoice.amount - vat, invoice.attendee, invoice.listing,
       invoice.saleReference, invoice.expectedAt)
  /\ RoleSafe(legs.vatCount, legs.vatAmount, legs.vatSource,
       legs.vatDestination, legs.vatReference, legs.vatPaidAt,
       vat, invoice.attendee, "tax:vat", invoice.vatReference, invoice.expectedAt)
  /\ legs.saleAmount + legs.vatAmount = legs.cashAmount

Model rule: LegsBefore

LegsBefore(row) ==
  [eventGroup |-> row.beforeEventGroup, otherCount |-> row.beforeOtherCount,
   cashCount |-> row.beforeCashCount, cashAmount |-> row.beforeCashAmount,
   cashSource |-> row.beforeCashSource, cashDestination |-> row.beforeCashDestination,
   cashReference |-> row.beforeCashReference, cashPaidAt |-> row.beforeCashPaidAt,
   saleCount |-> row.beforeSaleCount, saleAmount |-> row.beforeSaleAmount,
   saleSource |-> row.beforeSaleSource, saleDestination |-> row.beforeSaleDestination,
   saleReference |-> row.beforeSaleReference, salePaidAt |-> row.beforeSalePaidAt,
   vatCount |-> row.beforeVatCount, vatAmount |-> row.beforeVatAmount,
   vatSource |-> row.beforeVatSource, vatDestination |-> row.beforeVatDestination,
   vatReference |-> row.beforeVatReference, vatPaidAt |-> row.beforeVatPaidAt]

Model rule: LegsAfter

LegsAfter(row) ==
  [eventGroup |-> row.afterEventGroup, otherCount |-> row.afterOtherCount,
   cashCount |-> row.afterCashCount, cashAmount |-> row.afterCashAmount,
   cashSource |-> row.afterCashSource, cashDestination |-> row.afterCashDestination,
   cashReference |-> row.afterCashReference, cashPaidAt |-> row.afterCashPaidAt,
   saleCount |-> row.afterSaleCount, saleAmount |-> row.afterSaleAmount,
   saleSource |-> row.afterSaleSource, saleDestination |-> row.afterSaleDestination,
   saleReference |-> row.afterSaleReference, salePaidAt |-> row.afterSalePaidAt,
   vatCount |-> row.afterVatCount, vatAmount |-> row.afterVatAmount,
   vatSource |-> row.afterVatSource, vatDestination |-> row.afterVatDestination,
   vatReference |-> row.afterVatReference, vatPaidAt |-> row.afterVatPaidAt]

Model rule: Eligible

Eligible(invoice) ==
  /\ invoice.reason /= "subscription_create"
  /\ invoice.amount > 0
  /\ ~invoice.foreign

Production code: src/shared/accounting/mappers.ts#mapRenewal

export const mapRenewal = (facts: RenewalFacts): Promise<TransferInput[]> => { ... }

Source fingerprint: sha256:878e6ffba842d7cb

Production code: src/shared/subscriptions/plan.ts#renewalTax

export const renewalTax = (
  plan: { price: number; tax: number },
  paid: number,
): number => { ... }

Source fingerprint: sha256:1065ab9cd3151a14

Production code: src/shared/tax/assessment.ts#roundedRatio

export const roundedRatio = (
  amount: number,
  numerator: number,
  denominator: bigint,
): number => ...

Source fingerprint: sha256:4e59dac52bfe244b

Production code: src/shared/accounting/store.ts#postTransferGroups

export const postTransferGroups = async (
  groups: TransferInput[][],
  companionStatements: readonly SqlStatement[] = [],
): Promise<PostResult[]> => { ... }

Source fingerprint: sha256:360f164f7d4334e1

Step 5: A changed booking or a replay with different facts posts no money

A merge can replace the booking while Stripe answers. The fence compares the read row id, attendee, listing, and subscription with the stored row. A mismatch refuses the whole call. A replay of an invoice that already holds money must match the new facts exactly. A mismatch returns ledger_conflict and rewrites no old leg. The status rule lets an ended status replace a live one. A live status replaces only the status that the caller read, so an earlier cancel stays.

Value This step
identity_attendee outcome booking_fence
conflict first pass 600, second pass 601, outcome ledger_conflict
stale status before trialing, observed past_due, after past_due
ended observation A live row becomes ended.

Model rule: HasEligible

HasEligible(op) ==
  \E invoice \in InvoiceFacts : invoice.attempt = op.attempt /\ Eligible(invoice)

Model rule: FenceHeld

FenceHeld(op) ==
  /\ op.snapshotId = op.storedId
  /\ op.snapshotAttendee = op.storedAttendee
  /\ op.snapshotListing = op.storedListing
  /\ op.snapshotSubscription = op.storedSubscription

Model rule: Conflicts

Conflicts(op) ==
  \E invoice \in InvoiceFacts :
    /\ invoice.attempt = op.attempt /\ Eligible(invoice)
    /\ invoice.beforeCashCount > 0
    /\ ~LegsSafe(LegsBefore(invoice), invoice)

Model rule: ExpectedStatus

ExpectedStatus(op) ==
  IF op.observed \in EndedStatuses /\ op.beforeStatus \in LiveStatuses
  THEN op.observed
  ELSE IF op.beforeStatus = op.snapshotStatus THEN op.observed
  ELSE op.beforeStatus

Production code: src/shared/db/subscriptions.ts#renewalBookingGuard

export const renewalBookingGuard = (row: LiveRow): SqlStatement => ...

Source fingerprint: sha256:afa72fa1e3247a66

Production code: src/shared/db/subscriptions.ts#statusWrite

export const statusWrite = (
  row: LiveRow,
  status: SubscriptionStatus,
): SqlStatement => ...

Source fingerprint: sha256:d9061c70c1f72e5b

Production code: src/shared/subscriptions/record.ts#recordObserved

export const recordObserved = async (
  row: LiveRow,
  observed: SubscriptionStatus,
): Promise<ReportOutcome> => { ... }

Source fingerprint: sha256:1f91b97b1d8387d0

Step 6: The plan and the failed checkout keep their identities

JoinCoverage requires four plan phases and three failed checkout deliveries. JourneyLaw keeps one real checkout row through a stored phase, a plan edit, a renewal, and an owner cancel. A listing price edit and a tax edit cannot change the stored plan. The plan holds 1002 net plus 200 VAT, which is a total of 1202. FailedJoinLaw keeps a zero-quantity failed checkout across three deliveries. Delivery one holds the payment anchor and sends no refund. Delivery two ends Stripe and refunds 600 once. Delivery three repeats the stored work and keeps one refund.

Value This step
plan phases stored, edited, renewed, cancelled
plan 1002 net, 200 VAT, 1202 total
failed deliveries 3
delivery 1 held 1, refunds 0, authority 0
delivery 2 confirmed, refunds 1, cash 600
delivery 3 refunds 1. No second provider refund.

Model rule: JoinCoverage

JoinCoverage ==
  /\ Cardinality(JourneyFacts) = 4
  /\ {item.phase : item \in JourneyFacts} = {"stored", "edited", "renewed", "cancelled"}
  /\ Cardinality(FailedJoinFacts) = 3
  /\ {item.attempt : item \in FailedJoinFacts} = {1, 2, 3}

Model rule: JourneyLaw

JourneyLaw ==
  /\ \A item \in JourneyFacts :
       /\ item.booking > 0 /\ item.projectionCount = 1
       /\ item.attendee = item.expectedAttendee
       /\ item.listing = item.expectedListing
       /\ item.listing = item.requestedListing
       /\ item.listing = item.observedListing
       /\ item.subscription = item.requestedSubscription
       /\ item.subscription = item.observedSubscription
       /\ item.trialAt = item.expectedTrialAt
       /\ item.trialAt > item.checkoutAt
       /\ item.interval = item.requestedInterval
       /\ item.interval = item.observedInterval
       /\ item.price = item.requestedAmount
       /\ item.price = item.observedAmount
       /\ item.quantity = item.inputQuantity
       /\ item.requestedAmount = item.inputPrice * item.inputQuantity +
            TaxShare(item.inputPrice * item.inputQuantity, 10000, item.rate)
       /\ item.tax = TaxShare(item.observedAmount, 10000 + item.rate, item.rate)
       /\ item.status = IF item.phase \in {"stored", "edited"}
                         THEN item.observedStatus
                         ELSE IF item.phase = "renewed" THEN "active" ELSE "canceled"
       /\ item.cancelReturned = (item.phase = "cancelled")
  /\ \A left, right \in JourneyFacts : left.booking = right.booking
  /\ \A op \in OperationFacts : op.scenario = "joined" =>
       \A invoice \in InvoiceFacts : invoice.attempt = op.attempt =>
         \A item \in JourneyFacts :
           /\ invoice.price = item.price /\ invoice.tax = item.tax
           /\ invoice.attendee = item.attendeeAccount
           /\ invoice.listing = item.listingAccount

Model rule: FailedJoinLaw

FailedJoinLaw ==
  /\ \A item \in FailedJoinFacts :
       /\ item.booking > 0 /\ item.attendee > 0 /\ item.quantity = 0
       /\ item.listing = item.observedListing
       /\ item.subscription = item.observedSubscription
       /\ item.amount = item.observedAmount
       /\ item.interval = item.observedInterval
       /\ item.status = item.observedStatus
       /\ item.consumedReference =
            (IF item.refunds > 0 THEN item.observedReference ELSE "")
       /\ item.refundBeforeEnd = 0
       /\ item.refunds = (IF item.attempt = 1 THEN 0 ELSE 1)
       /\ item.confirmed = (item.attempt # 1)
       /\ item.held = (IF item.attempt = 1 THEN 1 ELSE 0)
       /\ item.authorityReturned = (IF item.attempt = 1 THEN 0 ELSE 600)
       /\ item.refundCash = (IF item.attempt = 1 THEN 0 ELSE 600)
  /\ \A left, right \in FailedJoinFacts :
       left.booking = right.booking /\ left.attendee = right.attendee

Production code: scripts/verify-models/subscriptions/journey.ts#observeJourney

export const observeJourney = async (facts: RenewalFacts): Promise<void> => { ... }

Source fingerprint: sha256:1acf5a9c7275d520

Production code: scripts/verify-models/subscriptions/journey.ts#failedJourneyFacts

export const failedJourneyFacts = async (): Promise<
  RenewalFacts["failedJoins"]
> => { ... }

Source fingerprint: sha256:6188d982c63c5feb

Step 7: Independent checks do not trust the pass order

Three separate checks do not depend on the pass order. InspectArithmetic compares every arithmetic fact with TaxShare. InspectJoins rechecks both joins. InspectReads rechecks every captured read identity. Each check keeps an earlier failure visible in checksHold.

Value This step
303 of 600 at 100 51 VAT
900 of 600 at 100 150 VAT
1 of price 2 at tax 1 1 VAT
checksHold Stays TRUE only when every check passes.

Model rule: InspectArithmetic

InspectArithmetic ==
  /\ ~arithmeticChecked
  /\ checksHold' := ChecksStillPass(checksHold,
       \A fact \in ArithmeticFacts :
         /\ fact.price > 0 /\ fact.tax >= 0 /\ fact.tax <= fact.price
         /\ fact.amount >= 0
         /\ fact.observedTax = TaxShare(fact.amount, fact.price, fact.tax))
  /\ arithmeticChecked' := TRUE
  /\ UNCHANGED <<scenario, passIndex, storedStatus, joinsChecked, readsChecked>>

Model rule: InspectJoins

InspectJoins ==
  /\ ~joinsChecked
  /\ checksHold' := ChecksStillPass(checksHold, JourneyLaw /\ FailedJoinLaw)
  /\ joinsChecked' := TRUE
  /\ UNCHANGED <<scenario, passIndex, storedStatus, arithmeticChecked, readsChecked>>

Model rule: InspectReads

InspectReads ==
  /\ ~readsChecked
  /\ checksHold' := ChecksStillPass(checksHold,
       \A read \in ReadFacts : ReadIdentitySafe(read))
  /\ readsChecked' := TRUE
  /\ UNCHANGED <<scenario, passIndex, storedStatus, arithmeticChecked, joinsChecked>>

Production code: src/shared/tax/assessment.ts#roundedRatio

export const roundedRatio = (
  amount: number,
  numerator: number,
  denominator: bigint,
): number => ...

Source fingerprint: sha256:4e59dac52bfe244b

Production code: scripts/verify-models/subscriptions/renewal-observations.ts#captureRead

export const captureRead = <Answer>(
  reads: RenewalFacts["reads"],
  kind: "renewal",
  owner: string,
  answer: () => Promise<Answer>,
): ((target: string) => Promise<Answer>) => { ... }

Source fingerprint: sha256:33b484128d325f7b

Step 8: Safety covers every pass and every refusal

Safety joins the type bounds with the memory of every failed law. The initial state sets checksHold from Coverage and JoinCoverage, so a missing fact fails at once. Next permits one pass, one arithmetic check, one join check, one read check, or no change. No fairness rule requires a retry, and the model does not prove that work finishes.

Value This step
passIndex 2
checksHold TRUE
Next A pass, an arithmetic check, a join check, a read check, or no change.

Model rule: Safety

Safety == TypeOK /\ checksHold

Model rule: Next

Next == InspectPass \/ InspectArithmetic \/ InspectJoins \/ InspectReads \/
  UNCHANGED <<scenario, passIndex, storedStatus, checksHold,
    arithmeticChecked, joinsChecked, readsChecked>>

Production code: scripts/verify-models/subscriptions/renewals.ts#renewalFacts

export const renewalFacts = async (
  corruption: "none" | "stored_vat" = "none",
): Promise<RenewalFacts> => { ... }

Source fingerprint: sha256:052ea2dff5d777fe

Production code: src/shared/accounting/store.ts#postTransfersTx

export const postTransfersTx = async (
  tx: TxScope,
  inputs: TransferInput[],
): Promise<PostResult> => { ... }

Source fingerprint: sha256:92e711a63a1d9dea

The safety claim

Every invoice role matches its expected amount. A positive role has exactly one leg with the right account, reference, and paid time. A zero role has no leg. Cash equals sale plus VAT. A refused call leaves every stored leg unchanged.

The model checks two things:

Together, these checks cover every finite run of the model.

What this model does not prove

How to read the model text

Symbol Meaning
== This line defines a rule. It does not assign a value.
x' The value of x after the step.
/\ Both conditions must hold.
\/ One of the conditions must hold.
\A Every supplied value must satisfy the rule.
\E At least one supplied value must satisfy the rule.
\in The value belongs to the set.
=> If the left condition holds, the right condition must hold.

Read the model verification guide for the method and its limits.