{"record":{"id":"0ad92ab74c73d621","repo":"gastownhall/beads","slug":"remote-migrate-gate-read-current-version-w","errorCode":null,"errorMessage":"remote-migrate gate: read current version: %w","messagePattern":"remote-migrate gate: read current version: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/schema/remote_migrate_gate.go","lineNumber":404,"sourceCode":"func CheckRemoteMigrateGateForRemoteWithRemoteCheck(ctx context.Context, db DBConn, remoteName string, extraHasRemote func() bool) error {\n\treturn checkRemoteMigrateGate(ctx, db, remoteName, extraHasRemote, nil)\n}\n\n// CheckRemoteMigrateGateForRemoteWithRemoteCheckAndAdopt is\n// CheckRemoteMigrateGateForRemoteWithRemoteCheck plus the injected\n// fast-forward ancestry callbacks (mybd-ae1i piece 2); see\n// CheckRemoteMigrateGateWithAdopt. Server mode uses this form: it already has\n// 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","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/schema/remote_migrate_gate.go#L386-L422","documentation":"Wraps a failure from CurrentVersion while the remote-migrate gate decides whether applying pending schema migrations would fork a remote-backed Dolt database. CurrentVersion treats a missing schema_migrations table as version 0, so this error means the version read itself failed (not that the table is missing). Callers are the CheckRemoteMigrateGate* family used before auto-migration on store open.","triggerScenarios":"SELECT of the current schema version fails during checkRemoteMigrateGate — Dolt server unreachable, schema_migrations table corrupt/unreadable, context cancelled during store open.","commonSituations":"`bd` startup against a remote-backed database whose SQL server is down or whose schema_migrations table is damaged; permission problems after a credentials rotation; network partition to the Dolt server.","solutions":["Inspect the wrapped driver error and restore connectivity to the Dolt server.","Check whether schema_migrations is corrupt; restore from Dolt history (`dolt checkout` an earlier commit of the table) if needed.","Verify DB credentials and SELECT permissions after any rotation.","Retry opening the store — the gate re-reads the version each open."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// check reachability before opening the store\nif err := db.PingContext(ctx); err != nil {\n    return fmt.Errorf(\"cannot run remote-migrate gate: %w\", err)\n}","typeGuard":"func isVersionReadErr(err error) bool {\n    return strings.Contains(err.Error(), \"remote-migrate gate: read current version\")\n}","tryCatchPattern":"if err := CheckRemoteMigrateGate(ctx, db, remote, extraHasRemote); err != nil {\n    if isVersionReadErr(err) && isTransientDB(err) {\n        return CheckRemoteMigrateGate(ctx, db, remote, extraHasRemote) // retry after reconnect\n    }\n    return err\n}","preventionTips":["Ensure the Dolt SQL server is running before `bd` startup auto-migration","Monitor schema_migrations integrity; repair from Dolt history if corrupted","Rotate credentials carefully and re-verify SELECT permissions","Handle remote outages before opening the store"],"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"}