{"record":{"id":"c15461a49484db16","repo":"gastownhall/beads","slug":"failed-to-rebuild-pool-after-migration-w","errorCode":null,"errorMessage":"failed to rebuild pool after migration: %w","messagePattern":"failed to rebuild pool after migration: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/dolt/store.go","lineNumber":2035,"sourceCode":"\t}\n\n\t// A gateway server owns the schema: it provisions each project at its deployed bd\n\t// version, so a client must never run migrations (DDL) against it. Treat it like\n\t// ReadOnly for schema — the forward-drift guard above still protects a stale client\n\t// binary.\n\tif !cfg.ReadOnly && !cfg.Gateway {\n\t\tapplied, err := store.initSchema(ctx, dbFacts.bootstrapHeal)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to initialize schema: %w\", err)\n\t\t}\n\t\t// initSchema runs migrations over a separate pool (openMigrationDB).\n\t\t// The Ping above already pinned a connection in store.db to the\n\t\t// pre-migration session root; without a rebuild, the first read\n\t\t// through that stale connection returns 0 rows / table-not-found\n\t\t// and does not self-heal on retry (be-itm5). Only a migrating open\n\t\t// (applied > 0) needs this — rebuildPoolAfterMigration no-ops otherwise.\n\t\tif err := store.rebuildPoolAfterMigration(ctx, applied); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to rebuild pool after migration: %w\", err)\n\t\t}\n\t}\n\n\tif isLocalHost(cfg.ServerHost) {\n\t\tbeadsDir := cfg.BeadsDir\n\t\tif beadsDir == \"\" && cfg.Path != \"\" {\n\t\t\tbeadsDir = filepath.Dir(cfg.Path)\n\t\t}\n\t\t_ = persistResolvedPortFile(cfg, beadsDir)\n\t}\n\n\t// All writers operate on main — transaction isolation via RunInTransaction\n\t// replaces the former branch-per-worker approach (BD_BRANCH).\n\tstore.branch = \"main\"\n\n\t// Register observable pool gauges for diagnosing shared-server degradation (GH#3140).\n\t// These report sql.DB.Stats() on each OTel scrape — no-op when telemetry is off.\n\tstore.registerPoolGauges()","sourceCodeStart":2017,"sourceCodeEnd":2053,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/dolt/store.go#L2017-L2053","documentation":"This error wraps a failure from store.rebuildPoolAfterMigration. After initSchema applies migrations (>0 applied), the existing connection pool is pinned to the pre-migration session root; the pool must be rebuilt or subsequent reads return 0 rows / table-not-found (be-itm5). It is thrown when the rebuild itself fails.","triggerScenarios":"Opening a DoltStore where migrations were applied (applied > 0) and store.rebuildPoolAfterMigration(ctx, applied) returns an error — e.g. the old pool cannot be drained or new connections to the post-migration database fail.","commonSituations":"Server became unreachable between migration and rebuild; connection pool exhaustion; Dolt server restarted with a different data dir mid-open.","solutions":["Read the wrapped err and retry opening the store","Verify server connectivity (bd dolt status)","Restart the bd daemon so open runs again from scratch","Check server logs for connection/session errors at migration time"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"applied, err := store.initSchema(ctx, heal)\nif err == nil && applied > 0 {\n    if err := db.PingContext(ctx); err != nil { return err } // sanity before rebuild\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"failed to rebuild pool after migration\") {\n        // close store, wait, reopen from scratch\n    }\n    return err\n}","preventionTips":["Avoid killing the daemon during migrations","Verify server health before upgrading bd","Retry open on transient pool errors","Watch bd dolt status during version upgrades"],"tags":["database","connection-pool","migration","dolt"],"backgroundTag":"stale-connection-after-migration","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}