{"record":{"id":"aef2d938d82e9277","repo":"gastownhall/beads","slug":"failed-to-commit-cross-table-duplicate-removals","errorCode":null,"errorMessage":"failed to commit cross-table duplicate removals: %w","messagePattern":"failed to commit cross-table duplicate removals: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/doctor/fix/validation.go","lineNumber":288,"sourceCode":"\t\t// Delete child rows first (FK-safe order), then the issues row.\n\t\tfor _, childTable := range []string{\"labels\", \"events\", \"dependencies\", \"comments\"} {\n\t\t\t//nolint:gosec // G202: childTable is from a hardcoded list above.\n\t\t\tif _, err := tx.Exec(fmt.Sprintf(\"DELETE FROM %s WHERE issue_id = ?\", childTable), id); err != nil {\n\t\t\t\tfmt.Printf(\"  Warning: failed to delete %s rows for %s: %v\\n\", childTable, id, err)\n\t\t\t}\n\t\t}\n\t\tif _, err := tx.Exec(\"DELETE FROM issues WHERE id = ?\", id); err != nil {\n\t\t\tfmt.Printf(\"  Warning: failed to delete issues row for %s: %v\\n\", id, err)\n\t\t} else {\n\t\t\tremoved++\n\t\t\tif showIndividual {\n\t\t\t\tfmt.Printf(\"  Removed stale issues-table copy of %s (canonical in wisps)\\n\", id)\n\t\t\t}\n\t\t}\n\t}\n\n\tif err := tx.Commit(); err != nil {\n\t\treturn fmt.Errorf(\"failed to commit cross-table duplicate removals: %w\", err)\n\t}\n\n\t_, _ = db.Exec(\"CALL DOLT_COMMIT('-Am', 'doctor: remove stale issues copies of wisps (be-iabdi)')\") // Best effort\n\n\tfmt.Printf(\"  Fixed %d cross-table duplicate(s)\\n\", removed)\n\treturn nil\n}\n\n// CountCrossTableDuplicates returns the number of IDs present in both the\n// issues and wisps tables. Returns 0 and an error if the database is\n// unreachable. Used by CheckCrossTableDuplicates in the doctor package.\nfunc CountCrossTableDuplicates(path string) (int, error) {\n\tbeadsDir, err := resolvedWorkspaceBeadsDir(path)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\n\tdb, _, err := openDoltDB(beadsDir)","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor/fix/validation.go#L270-L306","documentation":"CrossTableDuplicates deletes child rows (labels, events, dependencies, comments) then the stale issues row for each duplicate ID inside one transaction; tx.Commit() failure is wrapped as \"failed to commit cross-table duplicate removals: %w\". On this error nothing is persisted — the stale issues-table copies remain — and the fix returns an error instead of the \"Fixed N\" summary.","triggerScenarios":"tx.Commit() fails after the batch of DELETEs: connection dropped during commit, the transaction was implicitly rolled back by an earlier server error, or the Dolt server refused to finalize (storage/FK/autocommit-mode issues).","commonSituations":"Dolt server restart mid-fix; disk-full or Dolt storage errors at commit; FK enforcement rejecting a delete sequence on non-doctor schemas; network interruption at commit time.","solutions":["Re-run the doctor fix — the failed commit rolled back atomically, so a fresh run repeats the deletes safely","Read the wrapped cause: connection errors → restart `dolt sql-server`; storage errors → check disk and Dolt logs","If FK errors block deletes, ensure child tables are cleaned in the FK-safe order the fix already uses (or relax server FK mode temporarily)","Avoid interrupting the doctor process between Begin and Commit"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := tx.Commit(); err != nil {\n    _ = tx.Rollback()\n    // commit failure rolled back atomically: safe to re-run the whole fix\n    return fmt.Errorf(\"failed to commit cross-table duplicate removals: %w\", err)\n}","preventionTips":["Don't interrupt the doctor process between Begin and Commit","Check disk space and Dolt health before bulk cross-table deletes","On commit failure, always re-run the fix instead of manual row surgery","Keep commit windows short by batching reasonable duplicate counts per run"],"tags":["database","transaction","commit","dolt"],"backgroundTag":"transaction-commit-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}