JuliusBrussee/caveman · error · Error

operations are not a contiguous subsequence of variant 's…

Error message

${where} operations are not a contiguous subsequence of variant ${variantID}'s signature

What it means

The motif's operations sequence must appear as a contiguous (unbroken) subsequence of each supporting variant's signature. The validator uses contiguouslyContains and throws when operations occur in a variant's signature only out of order or with interleaved steps, since the motif would not actually describe that workflow.

Solutions

  1. Re-mine or re-order motif.operations so they form a contiguous run within each supporting variant's signature.
  2. Remove the non-matching variant from variant_ids if the motif only applies to a subset.
  3. Regenerate signatures and motifs together from the same pipeline run.

Example fix

// before
motif.operations = ["plan", "review", "edit"] (signature: plan, edit, review, edit)
// after
motif.operations = ["plan", "edit"] (contiguous in signature: plan, edit, review, edit)
Defensive patterns

Strategy: validation

Validate before calling

function contiguouslyContains(haystack, needle) {
  for (let i = 0; i + needle.length <= haystack.length; i++) {
    if (needle.every((op, j) => haystack[i + j] === op)) return true;
  }
  return false;
}
for (const m of report.motifs) for (const id of m.variant_ids) {
  const v = report.workflow_variants.find(v => v.id === id);
  if (!contiguouslyContains(v.signature, m.operations)) throw new Error(`motif ${m.id}: operations not contiguous in ${id}`);
}

Type guard

const motifIsContiguous = (motif, report) => motif.variant_ids.every(id => contiguouslyContains(report.workflow_variants.find(v => v.id === id)?.signature ?? [], motif.operations));

Try / catch

try { validateContinuousImprovement(report); } catch (e) { if (String(e.message).includes('contiguous subsequence')) { console.error('Re-mine motif operations or drop the offending variant'); } else throw e; }

Prevention

When it happens

Trigger: motif.operations is not a contiguous slice of variant.signature for at least one variantID in variant_ids — e.g. operations reordered, an extra step inserted, or the motif mined from a different signature version.

Common situations: Signatures changed after motifs were mined; hand-authoring motifs by copying steps non-adjacently; signature dedup/normalization altering step order.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/fd8e562f499a53a5. Report an issue: GitHub.

Appendix: source

Thrown at packages/shared/contracts/scripts/validate-continuous-improvement.mjs:119

  }
  relationshipCount += report.relationships.length;

  // A motif is a structural count over variants this report carries, so every
  // part of it must be re-derivable from those variants.
  const variantsByID = new Map(report.workflow_variants.map((variant) => [variant.id, variant]));
  const familyIDs = new Set(report.task_families.map((family) => family.id));
  for (const motif of report.motifs) {
    const where = `report fixture ${reportPaths[index]}: motif ${motif.id}`;
    if (!familyIDs.has(motif.task_family_id)) throw new Error(`${where} references a task family that is not in this report`);
    if (motif.support_variant_count !== motif.variant_ids.length) throw new Error(`${where} support variant count disagrees with its variant ids`);
    let runs = 0;
    let weighted = 0;
    for (const variantID of motif.variant_ids) {
      const variant = variantsByID.get(variantID);
      if (!variant) throw new Error(`${where} references workflow variant ${variantID} that is not in this report`);
      if (variant.task_family_id !== motif.task_family_id) throw new Error(`${where} supporting variant ${variantID} belongs to another task family`);
      if (!contiguouslyContains(variant.signature, motif.operations)) {
        throw new Error(`${where} operations are not a contiguous subsequence of variant ${variantID}'s signature`);
      }
      runs += variant.eligible_runs;
      weighted += (motif.operations.length / variant.signature.length) * variant.eligible_runs;
    }
    if (motif.support_run_count !== runs) throw new Error(`${where} support run count ${motif.support_run_count} != ${runs}`);
    const expectedShare = runs > 0 ? weighted / runs : 0;
    if (Math.abs(motif.structural_cost_share - expectedShare) > 1e-6) {
      throw new Error(`${where} structural_cost_share ${motif.structural_cost_share} != ${expectedShare}`);
    }
  }
  motifCount += report.motifs.length;

  // The causal investigation of every case: the cohort's arms, the traces it
  // selected from them, and the backward hard-dependency slice.
  const unitsByID = new Map(report.analysis_units.map((unit) => [unit.id, unit]));
  const familiesByID = new Map(report.task_families.map((family) => [family.id, family]));
  for (const item of report.cases) {
    const where = `report fixture ${reportPaths[index]}: case ${item.id}`;

View on GitHub (pinned to 3ee70a1026)