{"record":{"id":"f2038ff6101b246a","repo":"gastownhall/beads","slug":"proto-s-already-exists-use-force-to-replace","errorCode":null,"errorMessage":"proto %s already exists (use --force to replace)","messagePattern":"proto (.+?) already exists \\(use --force to replace\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cmd/bd/cook.go","lineNumber":317,"sourceCode":"\t\t}\n\t\tif len(missingVars) > 0 {\n\t\t\treturn fmt.Errorf(\"runtime mode requires all variables to have values\\nMissing: %s\\nProvide with: --var %s=<value>\",\n\t\t\t\tstrings.Join(missingVars, \", \"), missingVars[0])\n\t\t}\n\n\t\t// Substitute variables in the formula\n\t\tsubstituteFormulaVars(resolved, inputVars)\n\t}\n\treturn outputJSON(resolved)\n}\n\n// persistCookFormula creates a proto bead in the database (persist mode)\nfunc persistCookFormula(ctx context.Context, resolved *formula.Formula, protoID string, force bool, vars, bondPoints []string) error {\n\t// Check if proto already exists\n\texistingProto, err := store.GetIssue(ctx, protoID)\n\tif err == nil && existingProto != nil {\n\t\tif !force {\n\t\t\treturn fmt.Errorf(\"proto %s already exists (use --force to replace)\", protoID)\n\t\t}\n\t\t// Delete existing proto and its children\n\t\tif err := deleteProtoSubgraph(ctx, store, protoID); err != nil {\n\t\t\treturn fmt.Errorf(\"deleting existing proto: %w\", err)\n\t\t}\n\t}\n\n\t// Create the proto bead from the formula\n\tresult, err := cookFormula(ctx, store, resolved, protoID)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cooking formula: %w\", err)\n\t}\n\n\tif jsonOutput {\n\t\treturn outputJSON(cookResult{\n\t\t\tProtoID:    result.ProtoID,\n\t\t\tFormula:    resolved.Formula,\n\t\t\tCreated:    result.Created,","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/cook.go#L299-L335","documentation":"In persist mode, `bd cook` writes a proto bead with the given ID. If a proto with that ID already exists in the store and `--force` was not passed, cook aborts to protect the existing proto subgraph from being silently replaced. The message tells you to re-run with `--force` to delete and recreate it.","triggerScenarios":"Running `bd cook <formula> --mode=persist` with a proto ID that already exists in the database and without `--force`; re-running a cook command after a previous successful persist; two runs targeting the same proto ID.","commonSituations":"Replaying a cook script (CI or local) without cleaning state; an earlier interrupted run left the proto in place; reusing an ID that another formula or teammate already cooked.","solutions":["If replacement is intended, re-run with `--force`: `bd cook <formula> --mode=persist --force` (this deletes the existing proto and its children first)","Choose a different proto ID if both protos should coexist","Inspect the existing proto first (`bd show <protoID>`) to decide whether to replace or keep it","Clean stale protos from prior runs before re-running persistent cook scripts"],"exampleFix":"// before\nbd cook deploy --mode=persist --proto bd-proto-1\n// after\nbd cook deploy --mode=persist --proto bd-proto-1 --force","handlingStrategy":"validation","validationCode":"if _, err := store.GetIssue(ctx, protoID); err == nil {\n    // proto exists: require --force or pick another ID before cooking\n    return fmt.Errorf(\"proto %s exists; pass --force to replace\", protoID)\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"already exists\") {\n    // decide: rerun with --force or choose a new proto ID\n    return err\n}","preventionTips":["Derive proto IDs uniquely per run (timestamp/prefix) in automated scripts","Check bd show <protoID> before persistent cook runs","Clean stale protos at the start of CI jobs that persist formulas"],"tags":["formula","persist","conflict","proto"],"backgroundTag":"proto-already-exists","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}