Status: done (2026-11-11)
Priority: 3
Size: S
Arch: yardstick
Phase: implement
Design ref: none (code structure). docs/architecture/target-v2.md, section 4.1 (rules and explain); VB-197 (the rules registry).
Goal: The registry lets each contribution to a rule name its cause, but deathRoll (src/sim/deaths.js:28-33) does not read it. It computes the base hazard a second time (hazard(a) / YEAR_DAYS) and calls any death above it “hunger”. That is right today only because both contributions, hunger and frailty, have the cause hunger. Deaths from the first contribution with another cause (disease, slice 8) would be counted as hunger. The roll should take the cause from the rule.
Acceptance criteria:
sim/registry gives the cause of a draw for a product rule whose factors are all at least 1 (the ranges of death.hazard’s contributions). Given u below value(st, id, ctx): below the base, the cause is the base’s, from the rule’s owner (baseCause(age) for death.hazard). Above it, the excess over the base is shared among the contributions in proportion to the logarithm of each factor, and the cause is that of the share u falls in. The shares must not depend on load order (Kim, 9 November; target-v2 4.1): walking the running product would give the joint part of two causes to whichever module loads later. It refuses a rule whose factors may fall below 1, allocates nothing, and runs only when a death happens.deathRoll uses it, with one random draw as today; the base hazard is computed once.explain shows the same split, and that registering the contributions in the other order leaves each cause’s share unchanged.tests/registry.js and npm run verify pass.
Notes:allowance (VB-182) is the registry’s next rule; this keeps the first rule’s explanation honest before then.Rules.draw(st, id, ctx, u) (sim/registry): null when u is not below the rule’s value, else the cause. A rule opts in with baseCause(st, ctx) in its spec; seal then requires a product rule whose contributions all have range[0] >= 1 and a cause. Below the base: baseCause. Above: the excess value - base is split by ln(factor_i) / sum ln(factor); the shares are the same in any order of registering (the walk only finds which share u is in). The first pass reads the factors once (as value does, one ruleValue count); the factors are read again, with their logarithms, only when u is below the value, that is at a death. Nothing allocated.explain gives each part a share (hazard it adds) and the rule’s baseCause, the same split.deathRoll is one draw and one Rules.draw; the base hazard is computed once, deaths.js no longer calls hazard itself. Both contributions have cause hunger, so every death has the cause it had: behaviour is unchanged.order now puts the keys it names first and lets unnamed terms follow as registered (a new cause’s contribution must not make seal fail); a key it names that is not a contribution still fails.tests/causes.js (in npm test): two child processes register a disease and an exposure term before seeding, in each order, sweep u over the hazard, and check the deaths per cause against explain’s split, and between orders.
tests/registry.js (new seal refusal case), tests/causes.js, whole npm test, node tests/golden.js, node tests/counters.js: see the commit.
order may now leave terms unnamed (they follow); it was an exact list before (VB-232), which would have refused the registering of any new term. Said here because it loosens VB-232’s check.