{"record":{"id":"23e6db0b382ab046","repo":"gastownhall/beads","slug":"count-edges-in-s-w","errorCode":null,"errorMessage":"count edges in %s: %w","messagePattern":"count edges in (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/issueops/edge_counts.go","lineNumber":151,"sourceCode":"// unit-of-work leg. CountDependentRecordsInTx de-duplicates instead, because it\n// must agree with a keyset PAGE of the same rows; a cardinality has no page and\n// has never de-duplicated.\nfunc tallyEdgesInTx(ctx context.Context, tx DBTX, anchors []string, request publicops.EdgeCountRequest) (map[string]int64, error) {\n\ttallies := make(map[string]int64, len(anchors))\n\tfor _, plane := range edgeCountPlanes {\n\t\tfor start := 0; start < len(anchors); start += queryBatchSize {\n\t\t\tend := start + queryBatchSize\n\t\t\tif end > len(anchors) {\n\t\t\t\tend = len(anchors)\n\t\t\t}\n\t\t\tbatch := anchors[start:end]\n\t\t\tquery := buildEdgeCountQuery(plane.dependencies, plane.sources, len(batch), request)\n\t\t\trows, err := tx.QueryContext(ctx, query, edgeCountArgs(batch, request)...)\n\t\t\tif err != nil {\n\t\t\t\tif optionalBlockedTable(plane.dependencies) && isTableNotExistError(err) {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\treturn nil, fmt.Errorf(\"count edges in %s: %w\", plane.dependencies, err)\n\t\t\t}\n\t\t\tfor rows.Next() {\n\t\t\t\tvar id string\n\t\t\t\tvar n int64\n\t\t\t\tif scanErr := rows.Scan(&id, &n); scanErr != nil {\n\t\t\t\t\t_ = rows.Close()\n\t\t\t\t\treturn nil, fmt.Errorf(\"count edges in %s: scan: %w\", plane.dependencies, scanErr)\n\t\t\t\t}\n\t\t\t\ttallies[id] += n\n\t\t\t}\n\t\t\t_ = rows.Close()\n\t\t\tif err := rows.Err(); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"count edges in %s: rows: %w\", plane.dependencies, err)\n\t\t\t}\n\t\t}\n\t}\n\treturn tallies, nil\n}","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/issueops/edge_counts.go#L133-L169","documentation":"tallyEdgesInTx failed while executing the grouped edge-count query against the plane's dependency table (dependencies or wisp_dependencies). The underlying driver error is wrapped with the table name for diagnosis. Only a missing wisp_dependencies table is tolerated (skipped); every other query error aborts the count.","triggerScenarios":"Calling CountEdges / ExecuteEdgeCount against a Dolt/MySQL backend where the query is invalid, the connection drops mid-query, the context is cancelled, or the dependencies table itself is missing/corrupt; schema migrations removing or renaming dependencies.","commonSituations":"Database connection timeout or restart during a long batch; a context deadline exceeded because the count was cancelled upstream; running against an old/partial schema missing the dependencies table; locked or corrupt table during migration.","solutions":["Inspect the wrapped driver error (errors.Unwrap / %w chain) for the root cause and fix accordingly.","Check database connectivity and retry transient failures (connection reset, deadlock) with backoff.","Verify the schema: run migrations so dependencies and wisp_dependencies exist.","Increase the context timeout or investigate why the operation was cancelled.","Check server logs for table corruption or lock contention if errors persist."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Ensure schema before calling:\n// SELECT COUNT(*) FROM dependencies — if this fails, run migrations first.","typeGuard":null,"tryCatchPattern":"res, err := ExecuteEdgeCount(ctx, tx, req)\nif err != nil {\n\tvar retryable bool\n\tif strings.Contains(err.Error(), \"count edges in dependencies:\") {\n\t\tretryable = isTransient(err) // e.g. driver.ErrBadConn, deadlock, cancelled\n\t}\n\tif retryable { res, err = ExecuteEdgeCount(ctx, tx, req) }\n}","preventionTips":["Keep the schema migrated so dependencies/wisp_dependencies exist","Use a context with adequate timeout for large anchor batches","Retry transient driver errors with backoff","Monitor DB connectivity before long batch reads"],"tags":["database","sql","dependency-graph","query-execution"],"backgroundTag":"sql-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}