{"record":{"id":"094570ed51b689e5","repo":"gastownhall/beads","slug":"resolving-formula-q-w","errorCode":null,"errorMessage":"resolving formula %q: %w","messagePattern":"resolving formula %q: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/cook.go","lineNumber":715,"sourceCode":"}\n\n// resolveAndCookFormulaWithVars loads a formula and optionally filters steps by condition.\n// If conditionVars is provided, steps with conditions that evaluate to false are excluded.\n// Pass nil for conditionVars to include all steps (condition filtering skipped).\nfunc resolveAndCookFormulaWithVars(formulaName string, searchPaths []string, conditionVars map[string]string) (*TemplateSubgraph, error) {\n\t// Create parser with search paths\n\tparser := formula.NewParser(searchPaths...)\n\n\t// Load formula by name\n\tf, err := parser.LoadByName(formulaName)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"loading formula %q: %w\", formulaName, err)\n\t}\n\n\t// Resolve inheritance\n\tresolved, err := parser.Resolve(f)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"resolving formula %q: %w\", formulaName, err)\n\t}\n\n\t// Validate any caller-provided variable values against enum/pattern/\n\t// required-empty constraints. This is deliberately presence-agnostic:\n\t// a var missing entirely is left to the caller's own UX (e.g. bd mol\n\t// pour/wisp's missing-var hint), but a var explicitly provided with a\n\t// value that violates its constraints must error here so it reaches\n\t// every caller of this shared path (pour, wisp, mol bond, mol seed) —\n\t// runCook does not go through this helper; it validates separately via\n\t// its own formula.ValidateVars call under --mode=runtime. Previously\n\t// only that `bd cook --mode=runtime` path enforced these (mybd-u2r6).\n\tif conditionVars != nil {\n\t\tif err := formula.ValidateProvidedVars(resolved, conditionVars); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"formula %q: %w\", formulaName, err)\n\t\t}\n\t}\n\n\t// Apply control flow operators - loops, branches, gates","sourceCodeStart":697,"sourceCodeEnd":733,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/cook.go#L697-L733","documentation":"After loading, the helper resolves formula inheritance via `parser.Resolve` and wraps failures as `resolving formula %q`. Resolution walks `extends`/parent chains, merges steps and compose config, and fails on missing parents, inheritance cycles, or merge conflicts. The named formula loaded fine but its lineage is broken.","triggerScenarios":"A formula `extends` a parent that cannot be loaded; circular `extends` chains (A extends B extends A); invalid override keys during merge; parent formula has a type incompatible with the child.","commonSituations":"Refactoring formulas and renaming a parent without updating children; copy formulas across repos losing the parent file; hand-edited inheritance creating a cycle; deep chains where a grandparent was deleted.","solutions":["Read the wrapped error to identify the failing parent in the `extends` chain and restore or fix it","Check for inheritance cycles and break them by flattening the duplicated steps into the child","Run `bd formula validate <name>` to validate the whole chain after edits","Flatten the inheritance if the chain has grown fragile: copy the resolved content into a single standalone formula"],"exampleFix":"// before (child formula)\nextends: base-deploy-v2   # renamed parent\n// after\nextends: base-deploy","handlingStrategy":"validation","validationCode":"// walk extends chain for cycles and missing parents before resolve\nseen := map[string]bool{}\nfor cur := f; cur != nil; {\n    if seen[cur.Name] { return fmt.Errorf(\"inheritance cycle at %s\", cur.Name) }\n    seen[cur.Name] = true\n    cur = loadParent(cur) // nil-stop on missing parent\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"cycle\") {\n        // flatten the extends chain\n    }\n    return fmt.Errorf(\"resolving formula %q: %w\", name, err)\n}","preventionTips":["Keep inheritance chains shallow (one or two levels)","When renaming a parent formula, update all children in the same commit","Run bd formula validate on the full chain in CI"],"tags":["formula","inheritance","resolution"],"backgroundTag":"formula-inheritance-resolution-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}