{"record":{"id":"b96f9d91565a4a5a","repo":"gastownhall/beads","slug":"iterate-dolt-status-w","errorCode":null,"errorMessage":"iterate dolt_status: %w","messagePattern":"iterate dolt_status: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/versioncontrolops/fastforward.go","lineNumber":79,"sourceCode":"\trows, err := db.QueryContext(ctx, \"SELECT table_name FROM dolt_status\")\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"query dolt_status: %w\", err)\n\t}\n\tdefer rows.Close()\n\n\tclean := true\n\tfor rows.Next() {\n\t\tvar table string\n\t\tif err := rows.Scan(&table); err != nil {\n\t\t\treturn false, fmt.Errorf(\"scan dolt_status: %w\", err)\n\t\t}\n\t\tif table == \"wisps\" || strings.HasPrefix(table, \"wisp_\") {\n\t\t\tcontinue\n\t\t}\n\t\tclean = false\n\t}\n\tif err := rows.Err(); err != nil {\n\t\treturn false, fmt.Errorf(\"iterate dolt_status: %w\", err)\n\t}\n\n\treturn clean, nil\n}\n\n// FastForwardAdopt fast-forwards the current branch to ref via\n// CALL DOLT_MERGE('--ff-only', ref). ref must already be cached locally\n// (e.g. a remote-tracking ref updated by a prior fetch); this performs no\n// fetch of its own and fails if the merge would not be a pure fast-forward.\nfunc FastForwardAdopt(ctx context.Context, db DBConn, ref string) error {\n\tif err := issueops.ValidateRef(ref); err != nil {\n\t\treturn fmt.Errorf(\"invalid ref: %w\", err)\n\t}\n\n\tif _, err := db.ExecContext(ctx, \"CALL DOLT_MERGE('--ff-only', ?)\", ref); err != nil {\n\t\treturn fmt.Errorf(\"fast-forward to %s: %w\", ref, err)\n\t}\n\treturn nil","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/versioncontrolops/fastforward.go#L61-L97","documentation":"After iterating dolt_status rows, WorkingSetClean calls rows.Err() to catch any error that occurred during row iteration (connection drop mid-scan, server-side failure). Such an error is wrapped as \"iterate dolt_status: %w\" so a dropped connection is reported rather than misread as a clean working set.","triggerScenarios":"The database connection drops or the Dolt server restarts while rows are being streamed; context cancellation during iteration; network interruption on a remote sql-server connection.","commonSituations":"Long-lived connection hitting an idle timeout mid-iteration; flaky network to a remote Dolt server; server killed by OOM while serving the query.","solutions":["Retry WorkingSetClean after confirming the connection is healthy (db.PingContext).","Enable/idle-timeout-safe connection pooling or use a single dedicated connection for the check.","Investigate server-side logs for why the result stream aborted.","Honor the wrapped error's cause (context deadline vs connection reset) and adjust timeouts."],"exampleFix":"// before\nclean, err := versioncontrolops.WorkingSetClean(ctx, db) // flaky connection\n// after\nif err := db.PingContext(ctx); err != nil { return err }\nclean, err := versioncontrolops.WorkingSetClean(ctx, db)\nif err != nil && isTransient(err) {\n    clean, err = versioncontrolops.WorkingSetClean(ctx, db) // retry once\n}","handlingStrategy":"retry","validationCode":"if err := db.PingContext(ctx); err != nil {\n    return fmt.Errorf(\"connection unhealthy before iteration: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"var clean bool\nvar err error\nfor attempt := 0; attempt < 3; attempt++ {\n    clean, err = versioncontrolops.WorkingSetClean(ctx, db)\n    if err == nil || !isTransient(err) { break }\n    time.Sleep(time.Duration(1<<attempt) * 100 * time.Millisecond)\n}","preventionTips":["Use connection pooling with sane idle timeouts for remote Dolt servers.","Bound every call with a context deadline so dropped streams surface promptly.","Investigate server logs (OOM, restarts) if iteration errors recur.","Retry only transient errors; surface persistent ones."],"tags":["dolt","sql","connection-drop","iteration"],"backgroundTag":"connection-reset-during-query","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}