{"record":{"id":"5a36791ead22d661","repo":"gastownhall/beads","slug":"stage-repaired-s-w","errorCode":null,"errorMessage":"stage repaired %s: %w","messagePattern":"stage repaired (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/versioncontrolops/mergesettle.go","lineNumber":880,"sourceCode":"\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 {\n\t\treturn false, true, nil\n\t}\n\treturn true, true, nil\n}","sourceCodeStart":862,"sourceCodeEnd":898,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/versioncontrolops/mergesettle.go#L862-L898","documentation":"After clearing constraint violations, the repaired table is staged with CALL DOLT_ADD('<t>') so the fix is part of the merge commit. Failure means the repaired rows are deleted but unstaged, so the merge will not capture the fix. Repair aborts with this wrapped error.","triggerScenarios":"DOLT_ADD fails for table t — merge transaction in an inconsistent state, working-set/table not recognized by the engine, server refuses DOLT_ADD inside the current transaction, or table was dropped by the schema side of the merge.","commonSituations":"Engine/server version differences in DOLT_ADD behavior during a merge; interrupted settle leaving metadata inconsistent; permission or lock conflicts with another bd process.","solutions":["Read the wrapped %w error for the engine-side cause.","Run CALL DOLT_ADD('<table>') manually inside the same session to see the raw error.","If the merge is stuck, DOLT_MERGE_ABORT() and redo the pull/settle.","Ensure only one bd/dolt process is operating on the database during settle."],"exampleFix":"// before\nif _, err := db.ExecContext(ctx, \"CALL DOLT_ADD('\"+t+\"')\"); err != nil {\n    return false, true, fmt.Errorf(\"stage repaired %s: %w\", t, err)\n}\n// after: retry staging once before giving up\nif _, err := db.ExecContext(ctx, \"CALL DOLT_ADD('\"+t+\"')\"); err != nil {\n    if _, rerr := db.ExecContext(ctx, \"CALL DOLT_ADD('\"+t+\"')\"); rerr != nil {\n        return false, true, fmt.Errorf(\"stage repaired %s: %w\", t, rerr)\n    }\n}","handlingStrategy":"retry","validationCode":"// confirm the table exists in the working set before staging\nvar one int\n_ = db.QueryRow(\"SELECT 1 FROM issues LIMIT 1\").Scan(&one)","typeGuard":null,"tryCatchPattern":"if _, _, err := TryRepairFKCascadeViolations(ctx, db); err != nil && strings.Contains(err.Error(), \"stage repaired\") {\n    // rows deleted but unstaged: abort merge and redo the pull\n    _, _ = db.ExecContext(ctx, \"CALL DOLT_MERGE_ABORT()\")\n    return retryPull(ctx)\n}","preventionTips":["Single-writer discipline during merge settle","Retry staging before aborting the merge","Keep Dolt version consistent across clones"],"tags":["dolt","dolt-add","staging","merge-repair"],"backgroundTag":"dolt-add-stage-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}