{"record":{"id":"6bd89f13ab8f967b","repo":"gastownhall/beads","slug":"hydrate-ready-row-s-dependency-counts-w","errorCode":null,"errorMessage":"hydrate ready row %s: dependency counts: %w","messagePattern":"hydrate ready row (.+?): dependency counts: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/issueops/claim_next.go","lineNumber":92,"sourceCode":"}\n\n// HydrateReadyRowInTx fills in the relationship cardinalities a ready row\n// carries, reading them in the caller's transaction so the counts describe the\n// state that transaction is about to commit.\n//\n// A failed count read is an error rather than a zero. The CLI's pre-role\n// hydration swallowed all three, which meant a broken database reported a\n// claimed issue with no dependencies rather than saying the read failed; here\n// the whole claim rolls back instead, because a result nobody can hydrate is\n// not a result.\nfunc HydrateReadyRowInTx(ctx context.Context, tx *sql.Tx, issue *types.Issue) (*types.IssueWithCounts, error) {\n\tif issue == nil {\n\t\treturn nil, nil\n\t}\n\tids := []string{issue.ID}\n\tdepCounts, err := GetDependencyCountsInTx(ctx, tx, ids)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"hydrate ready row %s: dependency counts: %w\", issue.ID, err)\n\t}\n\trecords, err := GetDependencyRecordsForIssuesInTx(ctx, tx, ids)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"hydrate ready row %s: dependency records: %w\", issue.ID, err)\n\t}\n\tcommentCounts, err := GetCommentCountsInTx(ctx, tx, ids)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"hydrate ready row %s: comment counts: %w\", issue.ID, err)\n\t}\n\n\tissue.Dependencies = records[issue.ID]\n\tcounts := depCounts[issue.ID]\n\tif counts == nil {\n\t\tcounts = &types.DependencyCounts{}\n\t}\n\tvar parent *string\n\tfor _, dep := range records[issue.ID] {\n\t\tif dep.Type == types.DepParentChild {","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/issueops/claim_next.go#L74-L110","documentation":"HydrateReadyRowInTx failed to read dependency counts for the just-claimed issue via GetDependencyCountsInTx. Per the function's contract, a failed count read is an error, not a silent zero, so the entire claim transaction is unwound rather than returning an issue that looks dependency-free.","triggerScenarios":"ExecuteClaimNext -> HydrateReadyRowInTx where the dependency-count query fails: broken/corrupt database, connection loss mid-transaction, lock contention, or a missing dependencies table.","commonSituations":"Database backend degraded or restarted during a claim; schema missing the dependencies table after a botched migration; network blip on a remote Dolt server.","solutions":["Inspect the wrapped cause (errors.Unwrap / %w chain) to find the underlying SQL failure","Retry the claim once the database connection or server is healthy — the claim rolled back so no partial state persists","Verify the dependencies table exists and the schema is current (bd doctor / migration check)"],"exampleFix":"result, err := store.ClaimNext(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"dependency counts\") {\n\t// underlying DB read failed; claim rolled back — safe to retry after health check\n\tif dbErr := checkDBHealth(ctx, store); dbErr == nil {\n\t\tresult, err = store.ClaimNext(ctx, req)\n\t}\n}","handlingStrategy":"retry","validationCode":"if err := store.Ping(ctx); err != nil {\n\treturn fmt.Errorf(\"database unavailable before claim: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"result, err := store.ClaimNext(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"dependency counts\") {\n\t// claim rolled back; safe to retry once DB is healthy\n\tif retryErr := waitForDB(ctx, store); retryErr == nil {\n\t\tresult, err = store.ClaimNext(ctx, req)\n\t}\n}","preventionTips":["Health-check the database before batch claim loops","Keep the claim context alive (no early cancels) for the duration of the call","Ensure schema migrations run before workers start claiming"],"tags":["database","hydration","claim-next"],"backgroundTag":"dependency-count-read-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}