{"record":{"id":"cc123ce0f5b2797d","repo":"gastownhall/beads","slug":"iterate-dependency-sources-w","errorCode":null,"errorMessage":"iterate dependency sources: %w","messagePattern":"iterate dependency sources: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/issueops/dependencies.go","lineNumber":664,"sourceCode":"\tvar rekeys []rekey\n\tfor queryRows.Next() {\n\t\tvar id string\n\t\tvar issueTarget, wispTarget, external sql.NullString\n\t\tif err := queryRows.Scan(&id, &issueTarget, &wispTarget, &external); err != nil {\n\t\t\t_ = queryRows.Close()\n\t\t\treturn fmt.Errorf(\"scan dependency source: %w\", err)\n\t\t}\n\t\ttarget, ok := resolveDependencyTarget(issueTarget, wispTarget, external)\n\t\tif !ok {\n\t\t\tcontinue // ck_dep_one_target guarantees one target; skip defensively\n\t\t}\n\t\tif want := depid.New(newID, target); want != id {\n\t\t\trekeys = append(rekeys, rekey{oldRowID: id, newRowID: want})\n\t\t}\n\t}\n\t_ = queryRows.Close()\n\tif err := queryRows.Err(); err != nil {\n\t\treturn fmt.Errorf(\"iterate dependency sources: %w\", err)\n\t}\n\tfor _, rk := range rekeys {\n\t\tif _, err := tx.ExecContext(ctx,\n\t\t\t\"UPDATE dependencies SET id = ?, issue_id = ? WHERE id = ?\",\n\t\t\trk.newRowID, newID, rk.oldRowID); err != nil {\n\t\t\treturn fmt.Errorf(\"rekey dependency source id %s -> %s: %w\", rk.oldRowID, rk.newRowID, err)\n\t\t}\n\t}\n\treturn nil\n}\n\n// resolveDependencyTarget returns the single non-null dependency target — the value\n// depid.New and the uk_dep_* unique keys treat as the edge's target — following the\n// same precedence as DepTargetExpr (issue, then wisp, then external).\nfunc resolveDependencyTarget(issueTarget, wispTarget, external sql.NullString) (string, bool) {\n\tswitch {\n\tcase issueTarget.Valid:\n\t\treturn issueTarget.String, true","sourceCodeStart":646,"sourceCodeEnd":682,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/issueops/dependencies.go#L646-L682","documentation":"This error wraps rows.Err() after iterating the dependency-source result set in rekeyDependencySourceInTx. It surfaces driver/stream errors that occur mid-iteration (connection drop, query killed, replication error) rather than at query time or during a single Scan.","triggerScenarios":"UpdateIssueIDInTx rename, while streaming rows from `dependencies WHERE issue_id = ? OR issue_id = ?`: the underlying connection or result stream fails after some rows were already read.","commonSituations":"Long-running rename over many dependency edges with an unstable DB connection; server-side query timeout (max_execution_time); Dolt replica failover mid-scan.","solutions":["Read the wrapped error for the driver-level cause","Retry the rename — the transaction aborts atomically so no partial rekey persists","Increase query/connection timeouts if the edge count is large","Check DB server logs for killed queries or connection resets at the matching timestamp"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Sanity check connectivity and expected edge volume before starting\nif err := db.PingContext(ctx); err != nil {\n    return fmt.Errorf(\"database unreachable, postpone rename: %w\", err)\n}\nvar n int\ndb.Get(&n, `SELECT COUNT(*) FROM dependencies WHERE issue_id IN (?, ?) OR depends_on_issue_id = ?`, oldID, newID, oldID)\nlog.Printf(\"rename will touch %d dependency rows\", n)","typeGuard":null,"tryCatchPattern":"for attempt := 0; attempt < 3; attempt++ {\n    err := updateIssueID(tx, oldID, newID)\n    if err == nil { break }\n    if !isTransientDriverError(err) { return err }\n    time.Sleep(backoff(attempt)) // transaction rolled back; safe to retry\n}","preventionTips":["Set generous connect/read timeouts for Dolt/MySQL before bulk renames","Retry whole renames, never partial steps — the transaction makes retries safe","Avoid renaming issues with very large fan-in/out over unstable networks","Watch server logs for killed queries and raise max_execution_time if needed"],"tags":["database","sql","rows-iteration","connection"],"backgroundTag":"sql-rows-iteration-error","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}