{"record":{"id":"ded75e1e8d0f5cab","repo":"gastownhall/beads","slug":"failed-to-create-issues-w","errorCode":null,"errorMessage":"failed to create issues: %w","messagePattern":"failed to create issues: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/cook.go","lineNumber":913,"sourceCode":"\t// Collect dependencies from depends_on\n\tfor _, step := range f.Steps {\n\t\tcollectDependencies(step, idMapping, &deps)\n\t}\n\n\t// Create issues, labels, and dependencies in a single atomic transaction.\n\t// This prevents orphaned issues if label/dependency creation fails.\n\terr := transact(ctx, s, fmt.Sprintf(\"bd: cook formula %s\", protoID), func(tx storage.Transaction) error {\n\t\t// Flatten unregistered step types to task (with a warning) before\n\t\t// inserting, mirroring cloneSubgraphInto (pour). Without this,\n\t\t// PrepareIssueForInsert rejects them with \"invalid issue type\" and\n\t\t// the whole cook --persist transaction rolls back.\n\t\tif err := flattenUnregisteredIssueTypes(ctx, storeMolWriter{DoltStorage: s, tx: tx}, issues, deps); err != nil {\n\t\t\treturn fmt.Errorf(\"checking custom types: %w\", err)\n\t\t}\n\n\t\t// Create all issues\n\t\tif err := tx.CreateIssues(ctx, issues, actor); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create issues: %w\", err)\n\t\t}\n\n\t\t// Add labels\n\t\tfor _, l := range labels {\n\t\t\tif err := tx.AddLabel(ctx, l.issueID, l.label, actor); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to add label %s to %s: %w\", l.label, l.issueID, err)\n\t\t\t}\n\t\t}\n\n\t\t// Add dependencies\n\t\tfor _, dep := range deps {\n\t\t\tif err := tx.AddDependency(ctx, dep, actor); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to create dependency: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\treturn nil\n\t})","sourceCodeStart":895,"sourceCodeEnd":931,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/cook.go#L895-L931","documentation":"Wraps a failure from tx.CreateIssues during the cook --persist transaction. All proto issues generated from the formula are inserted in one transaction; if any insert is rejected (validation, ID conflict, storage error), the message reports it and the whole transaction rolls back so no partial molecule is persisted.","triggerScenarios":"tx.CreateIssues rejects one of the generated issues: invalid field values after flattening, duplicate/conflicting issue ID (protoID collision), constraint violation, or underlying Dolt storage error during the write.","commonSituations":"Proto ID already exists in the database from a previous cook run; an issue field (priority, status, type) violates validation; database locked or corrupted; disk full during write.","solutions":["Read the wrapped cause to identify the offending issue; check for an ID conflict with an existing bead and remove/rename it","Validate generated fields (type, priority, status) are legal values before persisting","Re-run after a transient storage error — the transaction rolled back so state is clean","Check database health (`bd doctor`) if CreateIssues fails repeatedly","Use a distinct --prefix for proto IDs to avoid collisions across runs"],"exampleFix":"# before\nbd cook --persist formula-name   # proto ID collides with existing bead\n# after\nbd cook --persist formula-name --prefix molt-   # unique prefix per run","handlingStrategy":"try-catch","validationCode":"// Pre-check for proto ID collisions before persisting\nfor _, iss := range issues {\n    if existing, _ := s.GetIssue(ctx, iss.ID); existing != nil {\n        return fmt.Errorf(\"issue %s already exists; choose another --prefix\", iss.ID)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := tx.CreateIssues(ctx, issues, actor); err != nil {\n    return fmt.Errorf(\"failed to create issues: %w\", err) // transaction rolls back\n}\n// at call site:\nif strings.Contains(err.Error(), \"failed to create issues\") {\n    // inspect cause: ID conflict → remove stale proto or change --prefix; then retry\n}","preventionTips":["Use a unique --prefix per cook run to avoid proto ID collisions","Clean up stale protos from aborted runs before re-cooking","Validate generated issue fields (type/priority/status) before persisting","Monitor disk space and database health; CreateIssues is all-or-nothing"],"tags":["transaction","create-issues","persist"],"backgroundTag":"issue-insert-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}