{"record":{"id":"63dd86d21db3762d","repo":"gastownhall/beads","slug":"remote-migrate-gate-read-pending-versions-w","errorCode":null,"errorMessage":"remote-migrate gate: read pending versions: %w","messagePattern":"remote-migrate gate: read pending versions: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/schema/remote_migrate_gate.go","lineNumber":412,"sourceCode":"// both a configured sync remote and the on-disk remote-check fallback.\nfunc CheckRemoteMigrateGateForRemoteWithRemoteCheckAndAdopt(ctx context.Context, db DBConn, remoteName string, extraHasRemote func() bool, adopt *FastForwardAdopter) error {\n\treturn checkRemoteMigrateGate(ctx, db, remoteName, extraHasRemote, adopt)\n}\n\nfunc checkRemoteMigrateGate(ctx context.Context, db DBConn, remoteName string, extraHasRemote func() bool, adopt *FastForwardAdopter) error {\n\t// CurrentVersion treats a missing schema_migrations table as version 0, so a\n\t// brand-new database falls through the current==0 check below — nothing to fork.\n\tcurrent, err := CurrentVersion(ctx, db)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"remote-migrate gate: read current version: %w\", err)\n\t}\n\tif current == 0 {\n\t\treturn nil // fresh database — nothing to fork\n\t}\n\n\tpending, err := PendingVersions(ctx, db)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"remote-migrate gate: read pending versions: %w\", err)\n\t}\n\tif len(pending) == 0 {\n\t\treturn nil // already current — nothing to migrate\n\t}\n\n\thasRemote, err := anyDoltRemoteConfigured(ctx, db)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"remote-migrate gate: read remotes: %w\", err)\n\t}\n\t// dolt_remotes can read empty even when a remote is configured: a freshly\n\t// (auto-)started server has not yet synced CLI remotes from .dolt/config\n\t// (GH#2315). Consult the caller's on-disk probe before allowing migration.\n\tif !hasRemote && extraHasRemote != nil {\n\t\thasRemote = extraHasRemote()\n\t}\n\tif !hasRemote {\n\t\treturn nil // no remote — no cross-clone fork risk\n\t}","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/schema/remote_migrate_gate.go#L394-L430","documentation":"Wraps a failure from PendingVersions while the remote-migrate gate lists schema migrations not yet applied. PendingVersions returning an empty list means the DB is current and migration is skipped; this error means the query to compute that list failed. Thrown before any fork-risk checks, so no migration is attempted.","triggerScenarios":"PendingVersions(ctx, db) errors in checkRemoteMigrateGate — server unreachable, schema_migrations unreadable/inconsistent, context cancelled during store open.","commonSituations":"Startup auto-migration (`autoMigrateOnVersionBump`) against a remote-backed DB whose server was restarted or whose migrations table is mid-write from another clone pushing; network flakiness; insufficient privileges.","solutions":["Inspect the wrapped driver error and restore DB connectivity.","If another clone is actively migrating, wait for it to finish and `bd dolt pull` before reopening.","Verify schema_migrations is intact; repair from Dolt history if a partial write corrupted it.","Retry the store open — the gate is read-only up to this point and safe to re-run."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// verify the migrations table is readable before the gate runs\nvar n int\nerr := db.QueryRowContext(ctx, `SELECT COUNT(*) FROM schema_migrations`).Scan(&n)","typeGuard":"func isPendingReadErr(err error) bool {\n    return strings.Contains(err.Error(), \"remote-migrate gate: read pending versions\")\n}","tryCatchPattern":"if err := CheckRemoteMigrateGate(ctx, db, remote, extraHasRemote); err != nil {\n    if isPendingReadErr(err) && isTransientDB(err) {\n        time.Sleep(backoff)\n        return CheckRemoteMigrateGate(ctx, db, remote, extraHasRemote)\n    }\n    return err\n}","preventionTips":["Wait for other clones to finish migrating before opening (`bd dolt pull` first)","Ensure schema_migrations is not mid-write from a concurrent push","Keep the Dolt server reachable during store open","Retry the read-only gate on transient failures — it mutates nothing until the fork checks pass"],"tags":["database","migration","versioning","remote"],"backgroundTag":"migration-version-read-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}