{"record":{"id":"6e549548b6f89e51","repo":"gastownhall/beads","slug":"query-schema-migrations-conflicts-w","errorCode":null,"errorMessage":"query schema_migrations conflicts: %w","messagePattern":"query schema_migrations conflicts: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/versioncontrolops/mergesettle.go","lineNumber":724,"sourceCode":"\t\t\tkeys = append(keys, key.String)\n\t\t}\n\t}\n\treturn keys, rows.Err()\n}\n\n// schemaMigrationsConflictsAreVintageOnly reports whether every conflicted\n// schema_migrations row is the same migration version present on BOTH sides\n// whose content hashes are compatible: equal, or NULL/empty on exactly one side\n// (a pre-#4270 binary recorded the version without a hash, bd-6dnrw.29). Two\n// different non-empty hashes mean the clones applied different content for the\n// same version — the #4259 schema fork — and are never auto-resolved. A row\n// deleted on one side is not a vintage artifact either.\nfunc schemaMigrationsConflictsAreVintageOnly(ctx context.Context, db DBConn) (bool, error) {\n\trows, err := db.QueryContext(ctx, `\n\t\tSELECT our_version, their_version, our_content_hash, their_content_hash\n\t\tFROM dolt_conflicts_schema_migrations`)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"query schema_migrations conflicts: %w\", err)\n\t}\n\tdefer rows.Close()\n\n\tfor rows.Next() {\n\t\tvar ourVersion, theirVersion sql.NullInt64\n\t\tvar ourHash, theirHash sql.NullString\n\t\tif err := rows.Scan(&ourVersion, &theirVersion, &ourHash, &theirHash); err != nil {\n\t\t\treturn false, fmt.Errorf(\"scan schema_migrations conflict: %w\", err)\n\t\t}\n\t\tif !ourVersion.Valid || !theirVersion.Valid || ourVersion.Int64 != theirVersion.Int64 {\n\t\t\treturn false, nil\n\t\t}\n\t\tours, theirs := ourHash.String, theirHash.String\n\t\tif ours != \"\" && theirs != \"\" && ours != theirs {\n\t\t\treturn false, nil // real content skew (#4259) — operator decides\n\t\t}\n\t}\n\treturn true, rows.Err()","sourceCodeStart":706,"sourceCodeEnd":742,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/versioncontrolops/mergesettle.go#L706-L742","documentation":"This error comes from schemaMigrationsConflictsAreVintageOnly when the query against dolt_conflicts_schema_migrations fails. The function inspects every conflicted schema_migrations row to confirm all conflicts are 'vintage' (same version on both sides with equal or one-sided-empty content hashes) before the library auto-resolves them; if the query fails, the error is wrapped with 'query schema_migrations conflicts:' and auto-resolution is abandoned so the operator must resolve manually. Like its config counterpart, it is a wrapper over a driver-level failure.","triggerScenarios":"TryAutoResolveMergeConflicts runs after a merge that conflicted on schema_migrations, and 'SELECT our_version, their_version, our_content_hash, their_content_hash FROM dolt_conflicts_schema_migrations' fails — the table doesn't exist (no such conflict class on this Dolt version or the table was already resolved), the connection/transaction is dead, or the driver returns an I/O/lock error.","commonSituations":"Dolt version drift: older binaries (pre-#4270) recorded schema_migrations without a content_hash column, so conflict tables on upgraded repos may mismatch expectations; repos where a previous resolve already cleared the conflict table; embedded Dolt connection failures or flocks held by another bd process; network loss against a remote Dolt server.","solutions":["Confirm schema_migrations is actually in conflict (SHOW TABLES / dolt conflicts) — if the conflict table is absent on this Dolt version, upgrade Dolt or skip the pre-check.","Retry the auto-resolve after verifying the Dolt database is reachable and no other process holds the database lock.","Align bd and Dolt engine versions: a pre-#4270 binary's missing content_hash columns can make the conflict-table shape differ.","If the query keeps failing, resolve schema_migrations conflicts manually (dolt conflicts resolve --ours schema_migrations) after verifying versions/hashes yourself.","Check storage health with 'bd doctor' for embedded-mode issues."],"exampleFix":"// before: unconditionally query the conflict table\nrows, err := db.QueryContext(ctx, `\n\tSELECT our_version, their_version, our_content_hash, their_content_hash\n\tFROM dolt_conflicts_schema_migrations`)\nif err != nil {\n\treturn false, fmt.Errorf(\"query schema_migrations conflicts: %w\", err)\n}\n// after: treat 'table not found' as no conflicts\nrows, err := db.QueryContext(ctx, `\n\tSELECT our_version, their_version, our_content_hash, their_content_hash\n\tFROM dolt_conflicts_schema_migrations`)\nif err != nil {\n\tif isNoSuchTableErr(err) {\n\t\treturn true, nil\n\t}\n\treturn false, fmt.Errorf(\"query schema_migrations conflicts: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// Preflight: confirm schema_migrations is actually conflicted and the\n// conflict table is queryable before attempting vintage auto-resolution.\nvar n int\nif err := db.QueryRowContext(ctx,\n    \"SELECT COUNT(*) FROM dolt_conflicts_schema_migrations\").Scan(&n); err != nil {\n    return fmt.Errorf(\"schema_migrations conflict preflight failed: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"err := TryAutoResolveMergeConflicts(ctx, db)\nif err != nil {\n    if strings.Contains(err.Error(), \"query schema_migrations conflicts\") {\n        // driver-level failure: reconnect or resolve manually with\n        // dolt conflicts resolve --ours schema_migrations\n    }\n}","preventionTips":["Upgrade repos created by pre-#4270 binaries so schema_migrations carries content_hash consistently.","Verify no other bd/dolt process holds the database lock before merging.","Check DB reachability before starting merge or auto-resolve operations.","Treat a missing dolt_conflicts_schema_migrations table as 'no conflicts', not a hard failure.","Run 'bd doctor' after version upgrades to validate the storage layer."],"tags":["dolt","merge-conflicts","schema-migrations","sql-query"],"backgroundTag":"dolt-conflicts-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}