{"record":{"id":"4a59d2b222970fa0","repo":"gastownhall/beads","slug":"schema-verify-fresh-bootstrap-history-got-d-com","errorCode":null,"errorMessage":"schema: verify fresh-bootstrap history: got %d commits, want 1","messagePattern":"schema: verify fresh-bootstrap history: got (.+?) commits, want 1","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/schema/lock.go","lineNumber":134,"sourceCode":"\t).Scan(&databaseName, &serverUUID, &initialHead); err != nil {\n\t\treturn nil, fmt.Errorf(\"schema: capture fresh-bootstrap identity: %w\", err)\n\t}\n\tif databaseName != expectedDatabase {\n\t\treturn nil, fmt.Errorf(\"schema: capture fresh-bootstrap identity: database is %q, want %q\", databaseName, expectedDatabase)\n\t}\n\tif serverUUID == \"\" {\n\t\treturn nil, errors.New(\"schema: capture fresh-bootstrap identity: empty server UUID\")\n\t}\n\tif initialHead == \"\" {\n\t\treturn nil, errors.New(\"schema: capture fresh-bootstrap identity: empty initial HEAD\")\n\t}\n\n\tvar commitCount, dirtyCount int\n\tif err := conn.QueryRowContext(ctx, \"SELECT COUNT(*) FROM dolt_log\").Scan(&commitCount); err != nil {\n\t\treturn nil, fmt.Errorf(\"schema: verify fresh-bootstrap history: %w\", err)\n\t}\n\tif commitCount != 1 {\n\t\treturn nil, fmt.Errorf(\"schema: verify fresh-bootstrap history: got %d commits, want 1\", commitCount)\n\t}\n\tif err := conn.QueryRowContext(ctx, \"SELECT COUNT(*) FROM dolt_status\").Scan(&dirtyCount); err != nil {\n\t\treturn nil, fmt.Errorf(\"schema: verify fresh-bootstrap working set: %w\", err)\n\t}\n\tif dirtyCount != 0 {\n\t\treturn nil, fmt.Errorf(\"schema: verify fresh-bootstrap working set: got %d dirty entries, want 0\", dirtyCount)\n\t}\n\n\treturn &FreshBootstrapHealCapability{\n\t\tendpoint:     endpoint,\n\t\tserverUUID:   serverUUID,\n\t\tdatabaseName: databaseName,\n\t\tinitialHead:  initialHead,\n\t}, nil\n}\n\n// WithFreshBootstrapHeal enables the fresh-bootstrap self-heal for the #4566\n// dirty-table guard (gastownhall/beads#5012). The capability must have been","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/schema/lock.go#L116-L152","documentation":"The fresh-bootstrap check requires exactly one commit (the initial Dolt init commit) in dolt_log. Any other count means the database is not pristine — either history already exists (migrations or writes ran) or the Dolt init didn't complete — so the library refuses to grant destructive DOLT_RESET authority.","triggerScenarios":"Calling CaptureFreshBootstrapHealCapability on a database that already existed (CREATE DATABASE was a no-op or raced with another process), after prior migrations ran, or on a database where Dolt init produced zero or multiple commits.","commonSituations":"Two processes racing to initialize the same database; re-running bootstrap against a long-lived database; a partially initialized Dolt database from a crashed prior run.","solutions":["Only capture immediately after a successful, fresh CREATE DATABASE of a truly new database.","Serialize database creation/migration with MigrateUpWithLock so no concurrent writer adds commits.","If commits already exist, the database is not fresh — skip heal and run normal migration; do not attempt to reset.","Check dolt_log contents to see what extra history was created and by whom."],"exampleFix":"// before\ncap, err := schema.CaptureFreshBootstrapHealCapability(ctx, conn, endpoint, db) // existing db: 12 commits\n// after\nif _, err := conn.ExecContext(ctx, \"CREATE DATABASE IF NOT EXISTS `\"+db+\"`\"); err == nil {\n    cap, err = schema.CaptureFreshBootstrapHealCapability(ctx, conn, endpoint, db)\n}","handlingStrategy":"validation","validationCode":"var commits int\nif err := conn.QueryRowContext(ctx, \"SELECT COUNT(*) FROM dolt_log\").Scan(&commits); err != nil { return err }\nif commits > 1 { return fmt.Errorf(\"database not fresh: %d commits exist; skip heal path\", commits) }","typeGuard":null,"tryCatchPattern":"cap, err := schema.CaptureFreshBootstrapHealCapability(ctx, conn, endpoint, db)\nif err != nil && strings.Contains(err.Error(), \"commits, want 1\") {\n    // not a fresh database — proceed with normal migration, no reset\n}","preventionTips":["Capture only immediately after a successful CREATE DATABASE of a brand-new database.","Serialize initialization across processes with the migration lock.","Never reuse a capture on a pre-existing database.","Audit dolt_log before assuming a database is fresh."],"tags":["go","database","dolt","bootstrap","race-condition"],"backgroundTag":"dolt-database-not-pristine","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}