{"record":{"id":"f9c6fd28971c4ffa","repo":"gastownhall/beads","slug":"schema-verify-fresh-bootstrap-working-set-got-d","errorCode":null,"errorMessage":"schema: verify fresh-bootstrap working set: got %d dirty entries, want 0","messagePattern":"schema: verify fresh-bootstrap working set: got (.+?) dirty entries, want 0","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/storage/schema/lock.go","lineNumber":140,"sourceCode":"\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\n// captured immediately after this logical open's exact CREATE DATABASE, and\n// endpoint must identify the connection pool used for migration. Before any\n// DOLT_RESET, MigrateUpWithLock revalidates the capability against the pinned,\n// locked session and consumes it atomically.\nfunc WithFreshBootstrapHeal(capability *FreshBootstrapHealCapability, endpoint string) MigrateLockOption {\n\treturn func(o *migrateLockOptions) {","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/schema/lock.go#L122-L158","documentation":"A freshly created database must have zero dirty entries in dolt_status. Non-zero means uncommitted working-set changes exist (e.g. tables created outside Dolt versioning or a previous crashed bootstrap), so the library withholds DOLT_RESET authority rather than discarding unknown work.","triggerScenarios":"Capture runs after something wrote to the database post-CREATE DATABASE (another process migrated first, DDL ran outside a commit, or an earlier interrupted bootstrap left tables behind).","commonSituations":"Concurrent bd/server instances initializing the same new database; a prior crashed init leaving dirty tables — the exact case the later heal path is meant to handle, but only via the locked, validated path.","solutions":["Ensure no other process can write between CREATE DATABASE and capture (hold the migration lock / single initializer).","If a previous crashed bootstrap left dirty tables, let MigrateUpWithLock's fresh-bootstrap heal path handle it instead of capture.","Run `CALL DOLT_RESET('--hard')` manually only if you have verified the working set is disposable.","Re-create the database cleanly if its contents are disposable."],"exampleFix":"// before\n_, _ = conn.ExecContext(ctx, \"CREATE DATABASE `x`\")\n// ...other code writes tables...\ncap, _ := schema.CaptureFreshBootstrapHealCapability(ctx, conn, endpoint, \"x\") // dirty\n// after\n_, _ = conn.ExecContext(ctx, \"CREATE DATABASE `x`\")\ncap, err := schema.CaptureFreshBootstrapHealCapability(ctx, conn, endpoint, \"x\") // capture immediately, before any DDL","handlingStrategy":"validation","validationCode":"var dirty int\nif err := conn.QueryRowContext(ctx, \"SELECT COUNT(*) FROM dolt_status\").Scan(&dirty); err != nil { return err }\nif dirty != 0 { return fmt.Errorf(\"working set dirty (%d); capture skipped\", dirty) }","typeGuard":null,"tryCatchPattern":"cap, err := schema.CaptureFreshBootstrapHealCapability(ctx, conn, endpoint, db)\nif err != nil && strings.Contains(err.Error(), \"dirty entries\") {\n    // do NOT reset blindly; let MigrateUpWithLock's guarded heal path decide\n}","preventionTips":["Capture immediately after CREATE DATABASE, before any DDL.","Hold the migration lock so no concurrent process dirties the working set.","Route interrupted-bootstrap dirty tables through the guarded heal path, not ad-hoc resets.","Single-writer policy for database initialization."],"tags":["go","database","dolt","bootstrap","working-set"],"backgroundTag":"dolt-dirty-working-set","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}