JuliusBrussee/caveman · error · Error
cohort arms ( ) plus exclusions ( ) do not account for its…
Error message
${where} cohort arms (${comparedUnits}) plus exclusions (${excluded}) do not account for its ${item.cohort.family_unit_count} family units What it means
This is a fixture-integrity error thrown by the continuous-improvement report validator in packages/shared/contracts. A cohort case is supposed to partition the task family's analysis units into compared arms plus excluded units; the validator sums each arm's unit_count and each exclusion's unit_count and requires the total to equal cohort.family_unit_count. It throws when the partition arithmetic does not add up, meaning the fixture's counts were edited by hand or computed from a different unit population.
Solutions
- Recompute each arm's unit_count and each exclusion's unit_count from the family's analysis_unit_ids and set cohort.family_unit_count to that family's size so comparedUnits + excluded equals it
- Regenerate the fixture with the canonical generator instead of hand-editing counts
- Check for duplicate/overlapping exclusions or a missing exclusion entry that would break the partition
- Confirm the cohort still uses exactly the arms baseline,alternative in that order; extra or renamed arms break the accounting
Example fix
// before
"family_unit_count": 24,
"arms": [
{ "role": "baseline", "unit_count": 10 },
{ "role": "alternative", "unit_count": 10 }
],
"excluded_units": []
// after
"family_unit_count": 24,
"arms": [
{ "role": "baseline", "unit_count": 12 },
{ "role": "alternative", "unit_count": 12 }
],
"excluded_units": [{ "unit_id": "u9", "unit_count": 0, "reason": "ineligible" }] Defensive patterns
Strategy: validation
Validate before calling
const familyUnits = new Set(family.analysis_unit_ids);
const compared = cohort.arms.reduce((t, a) => t + a.unit_count, 0);
const excluded = cohort.excluded_units.reduce((t, e) => t + e.unit_count, 0);
if (compared + excluded !== cohort.family_unit_count) {
throw new Error(`cohort accounting mismatch: ${compared} compared + ${excluded} excluded != ${cohort.family_unit_count}`);
} Type guard
function isBalancedCohort(cohort) {
const sum = cohort.arms.reduce((t, a) => t + a.unit_count, 0)
+ cohort.excluded_units.reduce((t, e) => t + e.unit_count, 0);
return sum === cohort.family_unit_count;
} Try / catch
try {
validateReport(report);
} catch (err) {
if (err.message.includes('do not account for its')) {
console.error('Cohort unit accounting mismatch; regenerate the fixture.');
process.exitCode = 1;
} else throw err;
} Prevention
- Never hand-edit cohort unit counts; regenerate fixtures from the dataset snapshot
- Recompute family_unit_count from family.analysis_unit_ids.length whenever the family changes
- Add a CI check that arms + exclusions sum to the family size for every case
When it happens
Trigger: Running the validation script when a report fixture's cohort has arms/exclusions whose unit_count values sum to more or fewer than family_unit_count — e.g. after hand-editing unit counts, adding an arm without rebalancing, or updating family_unit_count after the family gained/lost analysis units without updating arms or exclusions.
Common situations: Hand-authoring or regenerating report fixtures and adjusting family_unit_count without touching arm unit_counts; adding a third arm while the validator requires exactly baseline+alternative; stale fixtures after analysis units were re-grouped into a different task family; a fixture generator bug that counts exclusions twice or omits them.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- canonical span
- expected exactly 2 agent conformance fixtures, found
- ${fixtureFiles[index]}…
- no theme relationship reached the shared-analysis-unit…
- no workflow motif recurred across two variants of one task…
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/9c3e5b786a4b965e.
Report an issue: GitHub.
Appendix: source
Thrown at packages/shared/contracts/scripts/validate-continuous-improvement.mjs:155
const where = `report fixture ${reportPaths[index]}: case ${item.id}`;
const family = familiesByID.get(item.cohort.task_family_id);
if (!family) throw new Error(`${where} cohort references a task family that is not in this report`);
const familyUnits = new Set(family.analysis_unit_ids);
if (item.cohort.family_unit_count !== familyUnits.size) throw new Error(`${where} cohort family unit count disagrees with the task family`);
const roles = item.cohort.arms.map((arm) => arm.role);
if (roles.join(",") !== "baseline,alternative") throw new Error(`${where} cohort arms are not baseline then alternative`);
const armVariants = new Map();
let comparedUnits = 0;
for (const arm of item.cohort.arms) {
const variant = variantsByID.get(arm.variant_id);
if (!variant) throw new Error(`${where} cohort arm ${arm.role} references a workflow variant that is not in this report`);
if (variant.task_family_id !== family.id) throw new Error(`${where} cohort arm ${arm.role} uses a variant of another task family`);
armVariants.set(arm.role, variant);
comparedUnits += arm.unit_count;
}
const excluded = item.cohort.excluded_units.reduce((total, exclusion) => total + exclusion.unit_count, 0);
if (comparedUnits + excluded !== item.cohort.family_unit_count) {
throw new Error(`${where} cohort arms (${comparedUnits}) plus exclusions (${excluded}) do not account for its ${item.cohort.family_unit_count} family units`);
}
const selectedPerArm = new Map();
for (const trace of item.representative_traces) {
const variant = armVariants.get(trace.arm);
if (!variant || variant.id !== trace.variant_id) throw new Error(`${where} representative trace names a variant that is not that arm's variant`);
if (!unitsByID.has(trace.analysis_unit_id)) throw new Error(`${where} representative trace ${trace.analysis_unit_id} is not an analysis unit of this report`);
if (!familyUnits.has(trace.analysis_unit_id)) throw new Error(`${where} representative trace ${trace.analysis_unit_id} is not a member of the cohort's task family`);
if (!variant.analysis_unit_ids.includes(trace.analysis_unit_id)) throw new Error(`${where} representative trace ${trace.analysis_unit_id} did not run that arm's workflow variant`);
selectedPerArm.set(trace.arm, (selectedPerArm.get(trace.arm) ?? 0) + 1);
}
for (const [arm, count] of selectedPerArm) {
if (count > 3) throw new Error(`${where} arm ${arm} carries ${count} representative traces, more than three`);
}
const slice = item.causal_slice;
const sliceVariant = variantsByID.get(slice.variant_id);
if (!sliceVariant) throw new Error(`${where} causal slice references a workflow variant that is not in this report`);View on GitHub (pinned to 3ee70a1026)