{"record":{"id":"0ddb3067703d0b9b","repo":"gastownhall/beads","slug":"failed-to-commit-dependency-key-repairs-w","errorCode":null,"errorMessage":"failed to commit dependency key repairs: %w","messagePattern":"failed to commit dependency key repairs: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/doctor/fix/dep_keys.go","lineNumber":150,"sourceCode":"\t\t\t\tfmt.Printf(\"  Re-keyed %s row %s → %s\\n\", a.Table, mk[0], mk[1])\n\t\t\t}\n\t\t}\n\t\tfor _, id := range a.NullTarget {\n\t\t\t//nolint:gosec // G201: table is a hardcoded constant, never user input.\n\t\t\tif _, err := tx.Exec(fmt.Sprintf(`DELETE FROM %s WHERE id = ?`, a.Table), id); err != nil {\n\t\t\t\tfmt.Printf(\"  Warning: failed to remove %s row %s: %v\\n\", a.Table, id, err)\n\t\t\t\tfailed++\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tremoved++\n\t\t\trepairedTables[a.Table] = true\n\t\t\tif showIndividual {\n\t\t\t\tfmt.Printf(\"  Removed %s row %s (no dependency target)\\n\", a.Table, id)\n\t\t\t}\n\t\t}\n\t}\n\tif err := tx.Commit(); err != nil {\n\t\treturn fmt.Errorf(\"failed to commit dependency key repairs: %w\", err)\n\t}\n\n\t// Commit changes in Dolt, staging only the repaired tables so an unrelated\n\t// dirty working set is not swept under this message. Best effort: commit\n\t// advisory; repair already applied.\n\tif len(repairedTables) > 0 {\n\t\tfor table := range repairedTables {\n\t\t\t_, _ = db.Exec(\"CALL DOLT_ADD(?)\", table)\n\t\t}\n\t\t_, _ = db.Exec(\"CALL DOLT_COMMIT('-m', 'doctor: re-key dependency ids to deterministic values')\")\n\t}\n\n\tif failed > 0 {\n\t\tfmt.Printf(\"  Dependency keys: %d re-keyed, %d removed, %d FAILED — failed rows keep their old keys; resolve the warnings above and re-run bd doctor\\n\",\n\t\t\trekeyed, removed, failed)\n\t\treturn nil\n\t}\n\tfmt.Printf(\"  Fixed dependency keys: %d re-keyed, %d removed\\n\", rekeyed, removed)","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor/fix/dep_keys.go#L132-L168","documentation":"After applying all rekeys/removals inside an explicit transaction, repairDependencyKeys calls tx.Commit(); if commit fails the repairs are rolled back and the error is wrapped as \"failed to commit dependency key repairs: %w\". This indicates the fix did NOT persist and should be re-run once the cause is resolved.","triggerScenarios":"tx.Commit() fails after repairs were staged: Dolt server connection lost during the repair loop, server crashed/restarted, deadlock or lock conflict with another writer, or storage errors underneath the transaction.","commonSituations":"Dolt server with --no-auto-commit dropping the connection during a long repair; concurrent `bd` process mutating the same dependency rows causing conflicts; disk full on the database host.","solutions":["Re-run the dependency keys fix after confirming the server is healthy — the transaction rolled back cleanly so a retry is safe","Check Dolt server logs and disk space for storage-side causes","Avoid running concurrent bd write operations against the same database during repairs"],"exampleFix":"// before\nerr := repairDependencyKeys(ctx, db, verbose) // failed to commit dependency key repairs\n// after: retry with a fresh scan/commit cycle\nfor i := 0; i < 3; i++ {\n\tif err := repairDependencyKeys(ctx, db, verbose); err == nil {\n\t\tbreak\n\t}\n}","handlingStrategy":"retry","validationCode":"if err := db.PingContext(ctx); err != nil {\n\treturn fmt.Errorf(\"DB connection unstable, postponing commit-dependent repair: %w\", err)\n}\n// Also check disk headroom on the DB host if commits failed before.","typeGuard":null,"tryCatchPattern":"if err := repairDependencyKeys(ctx, db, verbose); err != nil {\n\tif strings.Contains(err.Error(), \"failed to commit\") {\n\t\t// transaction rolled back; a full retry is safe\n\t\ttime.Sleep(backoff)\n\t\treturn repairDependencyKeys(ctx, db, verbose)\n\t}\n\treturn err\n}","preventionTips":["Don't kill the server or network mid-repair; run fixes during maintenance windows","Avoid concurrent writers touching dependency rows during the fix","Monitor DB host disk space; commit failures often surface storage problems"],"tags":["database","transaction","commit","dolt","doctor"],"backgroundTag":"transaction-commit-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}