{"record":{"id":"2c3e453594dd750c","repo":"gastownhall/beads","slug":"failed-to-delete-child-s-w","errorCode":null,"errorMessage":"failed to delete child %s: %w","messagePattern":"failed to delete child (.+?): %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/mol_squash.go","lineNumber":316,"sourceCode":"\t\treturn nil, fmt.Errorf(\"failed to create digest issue: %w\", err)\n\t}\n\tresult.DigestID = digestIssue.ID\n\n\t// Link digest to root as parent-child\n\tdep := &types.Dependency{\n\t\tIssueID:     digestIssue.ID,\n\t\tDependsOnID: root.ID,\n\t\tType:        types.DepParentChild,\n\t}\n\tif err := w.AddDependency(ctx, dep, actorName); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to link digest to root: %w\", err)\n\t}\n\n\t// Delete ephemeral children within the same transaction\n\tif !keepChildren {\n\t\tfor _, id := range childIDs {\n\t\t\tif err := w.DeleteIssue(ctx, id, actorName); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to delete child %s: %w\", id, err)\n\t\t\t}\n\t\t\tresult.DeletedCount++\n\t\t}\n\t}\n\n\t// Auto-close the root if it's a wisp — squash completes the molecule lifecycle\n\tif root.Ephemeral {\n\t\treason := fmt.Sprintf(\"Squashed: %d steps → digest %s\", len(children), result.DigestID)\n\t\tif err := w.CloseIssue(ctx, root.ID, reason, actorName); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to close wisp root %s: %w\", root.ID, err)\n\t\t}\n\t\t// Clear ephemeral so the closed root stops being re-emitted by every wisp-table export cycle.\n\t\tif err := w.UpdateIssue(ctx, root.ID, map[string]interface{}{\"wisp\": false}, actorName); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to clear ephemeral flag on root %s: %w\", root.ID, err)\n\t\t}\n\t\tresult.WispSquash = true\n\t}\n","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/mol_squash.go#L298-L334","documentation":"When keepChildren is false, squash deletes each ephemeral child issue inside the same transaction. A failed w.DeleteIssue is wrapped as 'failed to delete child %s: %w' with the child ID, and the entire squash rolls back.","triggerScenarios":"bd mol squash (without --keep-children) when deleting a child fails: foreign-key/dependency constraints referencing the child, storage write error, or database locked mid-transaction.","commonSituations":"Child still referenced by dependencies from outside the molecule; concurrent writer holding the lock; read-only filesystem or disk full.","solutions":["Read the wrapped cause and child ID; check for external dependencies blocking deletion","Remove or re-point dependencies that reference the child, or use --keep-children to skip deletion","Ensure no concurrent bd process is running against the same database","Retry after resolving storage constraints (writability, disk space)"],"exampleFix":"// before: squash fails outright\nbd mol squash <root>\n// after: keep children when deletion is blocked\nbd mol squash <root> --keep-children","handlingStrategy":"fallback","validationCode":"// Detect external dependencies on children before non-keeping squash\nfor _, id := range childIDs {\n    if deps, _ := s.GetDependencies(ctx, id); len(deps) > 0 {\n        // surface or switch to --keep-children\n    }\n}","typeGuard":null,"tryCatchPattern":"err := squashMolecule(ctx, s, root, children, false, summary, actor)\nif err != nil && strings.Contains(err.Error(), \"failed to delete child\") {\n    // fallback: retry with keepChildren=true\n    return squashMolecule(ctx, s, root, children, true, summary, actor)\n}","preventionTips":["Prefer --keep-children when child issues have external references","Clean up cross-molecule dependencies before squashing","Avoid parallel bd writers on the same database"],"tags":["go","storage","delete","transaction"],"backgroundTag":"issue-delete-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}