{"record":{"id":"ba3249eb500c836f","repo":"gastownhall/beads","slug":"dolt-reset-s-w","errorCode":null,"errorMessage":"dolt reset %s: %w","messagePattern":"dolt reset (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/schema/schema.go","lineNumber":800,"sourceCode":"func stagedDirtyTables(tables map[string]dirtyTableState) []string {\n\tvar staged []string\n\tfor table, state := range tables {\n\t\tif state.staged {\n\t\t\tstaged = append(staged, table)\n\t\t}\n\t}\n\tsort.Strings(staged)\n\treturn staged\n}\n\nfunc unstagePreExistingTables(ctx context.Context, db DBConn, tables map[string]dirtyTableState) error {\n\tstaged := stagedDirtyTables(tables)\n\tif len(staged) > 0 {\n\t\tlog.Printf(\"schema migration unstaging pre-existing staged tables: %s\", strings.Join(staged, \", \"))\n\t}\n\tfor _, table := range staged {\n\t\tif err := DrainCall(ctx, db, \"CALL DOLT_RESET(?)\", table); err != nil {\n\t\t\treturn fmt.Errorf(\"dolt reset %s: %w\", table, err)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc unstageIgnoredTables(ctx context.Context, db DBConn) error {\n\ttables, err := existingIgnoredTables(ctx, db)\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn unstagePreExistingTables(ctx, db, tables)\n}\n\nfunc dirtyTableSignatures(ctx context.Context, db DBConn, tables map[string]dirtyTableState) (map[string]string, error) {\n\tsignatures := make(map[string]string, len(tables))\n\tnames := sortedDirtyTableNames(tables)\n\tfor _, table := range names {\n\t\tsignature, err := dirtyTableSignature(ctx, db, table)","sourceCodeStart":782,"sourceCodeEnd":818,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/schema/schema.go#L782-L818","documentation":"unstagePreExistingTables unstages user-staged tables (found via dolt_status) with `CALL DOLT_RESET(?)` before migrations run, so the migration pass commits only its own changes. If DOLT_RESET fails for a given table, the error is wrapped as \"dolt reset <table>: %w\" and MigrateUp aborts before any migration step, preserving the user's staged state.","triggerScenarios":"MigrateUp (or unstageIgnoredTables) finds tables already staged in dolt_status and issues DOLT_RESET per table; the reset fails — typically because the table name is problematic for the driver, the connection is broken, or the Dolt working set is in a state where reset is refused (e.g. mid-merge/conflict).","commonSituations":"A user (or another tool) ran `dolt add` inside the .beads database before running `bd`; a previous crashed process left tables staged; an embedded Dolt engine returned an unexpected error resetting a conflicted table; connection dropped between status read and reset.","solutions":["Read the wrapped cause for the specific table; check `dolt status` inside the .beads Dolt directory to see what is staged.","Resolve any merge conflicts Dolt reports (dolt conflicts / dolt conflicts resolve), then retry `bd`.","If the staged changes are unwanted, manually run `dolt reset <table>` (or `dolt checkout <table>`) in the database directory and retry.","Ensure no concurrent `bd`/`dolt` process is mutating the working set while migrations run (use MigrateUpWithLock).","Verify disk permissions and that the embedded Dolt engine can write to the database directory."],"exampleFix":"// before: migration aborts on a staged table\n_, err := schema.MigrateUp(ctx, db)\n// after: unstage/pre-clean the working set through dolt CLI first, then migrate\n//   cd .beads && dolt reset\n_, err = schema.MigrateUp(ctx, db)","handlingStrategy":"validation","validationCode":"// Go: pre-check for staged tables via dolt_status before calling MigrateUp\nrows, err := db.QueryContext(ctx, \"SELECT table_name, staged FROM dolt_status\")\nif err != nil { return err }\nfor rows.Next() {\n    var name string; var staged bool\n    if err := rows.Scan(&name, &staged); err != nil { return err }\n    if staged {\n        return fmt.Errorf(\"table %s is staged; run dolt reset before migrating\", name)\n    }\n}","typeGuard":null,"tryCatchPattern":"err := schema.MigrateUp(ctx, db)\nif err != nil && strings.HasPrefix(err.Error(), \"dolt reset \") {\n    // table name is between \"dolt reset \" and \": \"\n    table := strings.SplitN(strings.TrimPrefix(err.Error(), \"dolt reset \"), \":\", 2)[0]\n    _ = table // guide the user to run `dolt reset <table>` manually\n}","preventionTips":["Do not run `dolt add`/`dolt commit` by hand inside the .beads database while bd may migrate","Use MigrateUpWithLock to serialize against other bd processes","Check `dolt status` is clean before opening the database after a crash","Resolve Dolt conflicts promptly instead of leaving the repo in a conflicted state"],"tags":["database","dolt","migration","git-like"],"backgroundTag":"dolt-reset-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}