{"record":{"id":"fd8e562f499a53a5","repo":"JuliusBrussee/caveman","slug":"where-operations-are-not-a-contiguous-subsequen","errorCode":null,"errorMessage":"${where} operations are not a contiguous subsequence of variant ${variantID}'s signature","messagePattern":"(.+?) operations are not a contiguous subsequence of variant (.+?)'s signature","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-continuous-improvement.mjs","lineNumber":119,"sourceCode":"  }\n  relationshipCount += report.relationships.length;\n\n  // A motif is a structural count over variants this report carries, so every\n  // part of it must be re-derivable from those variants.\n  const variantsByID = new Map(report.workflow_variants.map((variant) => [variant.id, variant]));\n  const familyIDs = new Set(report.task_families.map((family) => family.id));\n  for (const motif of report.motifs) {\n    const where = `report fixture ${reportPaths[index]}: motif ${motif.id}`;\n    if (!familyIDs.has(motif.task_family_id)) throw new Error(`${where} references a task family that is not in this report`);\n    if (motif.support_variant_count !== motif.variant_ids.length) throw new Error(`${where} support variant count disagrees with its variant ids`);\n    let runs = 0;\n    let weighted = 0;\n    for (const variantID of motif.variant_ids) {\n      const variant = variantsByID.get(variantID);\n      if (!variant) throw new Error(`${where} references workflow variant ${variantID} that is not in this report`);\n      if (variant.task_family_id !== motif.task_family_id) throw new Error(`${where} supporting variant ${variantID} belongs to another task family`);\n      if (!contiguouslyContains(variant.signature, motif.operations)) {\n        throw new Error(`${where} operations are not a contiguous subsequence of variant ${variantID}'s signature`);\n      }\n      runs += variant.eligible_runs;\n      weighted += (motif.operations.length / variant.signature.length) * variant.eligible_runs;\n    }\n    if (motif.support_run_count !== runs) throw new Error(`${where} support run count ${motif.support_run_count} != ${runs}`);\n    const expectedShare = runs > 0 ? weighted / runs : 0;\n    if (Math.abs(motif.structural_cost_share - expectedShare) > 1e-6) {\n      throw new Error(`${where} structural_cost_share ${motif.structural_cost_share} != ${expectedShare}`);\n    }\n  }\n  motifCount += report.motifs.length;\n\n  // The causal investigation of every case: the cohort's arms, the traces it\n  // selected from them, and the backward hard-dependency slice.\n  const unitsByID = new Map(report.analysis_units.map((unit) => [unit.id, unit]));\n  const familiesByID = new Map(report.task_families.map((family) => [family.id, family]));\n  for (const item of report.cases) {\n    const where = `report fixture ${reportPaths[index]}: case ${item.id}`;","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L101-L137","documentation":"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.","triggerScenarios":"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.","commonSituations":"Signatures changed after motifs were mined; hand-authoring motifs by copying steps non-adjacently; signature dedup/normalization altering step order.","solutions":["Re-mine or re-order motif.operations so they form a contiguous run within each supporting variant's signature.","Remove the non-matching variant from variant_ids if the motif only applies to a subset.","Regenerate signatures and motifs together from the same pipeline run."],"exampleFix":"// before\nmotif.operations = [\"plan\", \"review\", \"edit\"] (signature: plan, edit, review, edit)\n// after\nmotif.operations = [\"plan\", \"edit\"] (contiguous in signature: plan, edit, review, edit)","handlingStrategy":"validation","validationCode":"function contiguouslyContains(haystack, needle) {\n  for (let i = 0; i + needle.length <= haystack.length; i++) {\n    if (needle.every((op, j) => haystack[i + j] === op)) return true;\n  }\n  return false;\n}\nfor (const m of report.motifs) for (const id of m.variant_ids) {\n  const v = report.workflow_variants.find(v => v.id === id);\n  if (!contiguouslyContains(v.signature, m.operations)) throw new Error(`motif ${m.id}: operations not contiguous in ${id}`);\n}","typeGuard":"const motifIsContiguous = (motif, report) => motif.variant_ids.every(id => contiguouslyContains(report.workflow_variants.find(v => v.id === id)?.signature ?? [], motif.operations));","tryCatchPattern":"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; }","preventionTips":["Mine motifs directly from signatures so contiguity holds by construction","Re-run motif mining whenever signatures change","Check contiguity in a pre-commit fixture test"],"tags":["fixture","sequence","validation"],"backgroundTag":"shape-mismatch","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}