{"record":{"id":"8eea2234633c8c36","repo":"gastownhall/beads","slug":"clear-s-constraint-violations-w","errorCode":null,"errorMessage":"clear %s constraint violations: %w","messagePattern":"clear (.+?) constraint violations: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/versioncontrolops/mergesettle.go","lineNumber":876,"sourceCode":"\t\tissueFKOnly, err := violationsAreIssueFKOnly(ctx, db, t)\n\t\tif err != nil {\n\t\t\treturn false, true, err\n\t\t}\n\t\tif !issueFKOnly {\n\t\t\treturn false, true, nil\n\t\t}\n\t}\n\n\tfor _, t := range tables {\n\t\tres, err := db.ExecContext(ctx, fkCascadeRepairDeletes[t])\n\t\tif err != nil {\n\t\t\treturn false, true, fmt.Errorf(\"cascade-repair %s: %w\", t, err)\n\t\t}\n\t\tn, _ := res.RowsAffected()\n\t\t// t is from the fixed fkCascadeRepairDeletes allowlist, never user input.\n\t\t//nolint:gosec // G201/G202: hardcoded table name.\n\t\tif _, err := db.ExecContext(ctx, \"DELETE FROM dolt_constraint_violations_\"+t); err != nil {\n\t\t\treturn false, true, fmt.Errorf(\"clear %s constraint violations: %w\", t, err)\n\t\t}\n\t\t//nolint:gosec // G202: hardcoded table name.\n\t\tif _, err := db.ExecContext(ctx, \"CALL DOLT_ADD('\"+t+\"')\"); err != nil {\n\t\t\treturn false, true, fmt.Errorf(\"stage repaired %s: %w\", t, err)\n\t\t}\n\t\tfmt.Fprintf(os.Stderr,\n\t\t\t\"Notice: pull merged %s row(s) referencing issue(s) deleted on another clone; applied the foreign key's cascade delete (%d row(s) removed)\\n\",\n\t\t\tt, n)\n\t}\n\n\t// The repair must leave nothing behind: a residual violation here means the\n\t// deletes above did not cover the constraint that fired, and committing\n\t// would persist a violated working set.\n\tremaining, err := constraintViolationTables(ctx, db)\n\tif err != nil {\n\t\treturn false, true, err\n\t}\n\tif len(remaining) > 0 {","sourceCodeStart":858,"sourceCodeEnd":894,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/versioncontrolops/mergesettle.go#L858-L894","documentation":"After cascade-deleting orphaned rows for table t, the repair clears the violation records via DELETE FROM dolt_constraint_violations_<t>. Failure here means rows were repaired but the violation ledger still lists them, leaving the table in a half-repaired state. The error is wrapped and repair aborts for this table.","triggerScenarios":"DELETE FROM dolt_constraint_violations_<t> fails — table doesn't exist (no violations actually recorded, engine version mismatch), permission issue, or engine refuses the delete inside the merge transaction.","commonSituations":"Dolt version where dolt_constraint_violations_<table> is not created unless violations exist; server vs embedded engine behavioral differences; concurrent process already cleared the table and dropped it.","solutions":["Check the wrapped %w error — 'table doesn't exist' usually means no violations remained; treat as benign or check dolt_constraint_violations first.","Query SELECT * FROM dolt_constraint_violations WHERE `table`='t' to confirm violations still exist before deleting.","Retry settle after concurrent writers finish.","Upgrade to a Dolt/beads version with matching constraint-violation table handling."],"exampleFix":"// before\nif _, err := db.ExecContext(ctx, \"DELETE FROM dolt_constraint_violations_\"+t); err != nil {\n    return false, true, fmt.Errorf(\"clear %s constraint violations: %w\", t, err)\n}\n// after: only clear when the violations table exists\nif _, err := db.ExecContext(ctx, \"DELETE FROM dolt_constraint_violations_\"+t); err != nil {\n    if !strings.Contains(err.Error(), \"doesn't exist\") {\n        return false, true, fmt.Errorf(\"clear %s constraint violations: %w\", t, err)\n    } // benign: violations table already gone\n}","handlingStrategy":"try-catch","validationCode":"var exists int\n_ = db.QueryRow(\"SELECT COUNT(*) FROM information_schema.tables WHERE table_name = ?\", \"dolt_constraint_violations_issues\").Scan(&exists)\n// exists == 0 means nothing to clear","typeGuard":null,"tryCatchPattern":"if _, _, err := TryRepairFKCascadeViolations(ctx, db); err != nil && strings.Contains(err.Error(), \"clear\") {\n    // half-repaired state: re-run settle from a clean merge\n    _, _ = db.ExecContext(ctx, \"CALL DOLT_MERGE_ABORT()\")\n    return err\n}","preventionTips":["Verify the per-table violations table exists before clearing","Keep engine and beads versions aligned","Avoid killing bd mid-settle"],"tags":["dolt","constraint-violations","merge-repair"],"backgroundTag":"constraint-violation-clear-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}