{"record":{"id":"995966bb508ce765","repo":"gastownhall/beads","slug":"descendants-query-w","errorCode":null,"errorMessage":"descendants: query: %w","messagePattern":"descendants: query: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/db/issue_descendants.go","lineNumber":81,"sourceCode":"\tvar wispArgs []any\n\tif walkWisps {\n\t\twispWhereClauses, wispArgs, err = buildIssueFilterClauses(\"\", levelFilter, wispsFilterTables)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"descendants: wisps filter: %w\", err)\n\t\t}\n\t}\n\n\tissuePred := buildDescendantsPred(\"issues\", \"i\", \"issue_matches\", issueWhereClauses, issueArgs)\n\tvar wispPred predBundle\n\tif walkWisps {\n\t\twispPred = buildDescendantsPred(\"wisps\", \"w\", \"wisp_matches\", wispWhereClauses, wispArgs)\n\t}\n\n\tcte, allArgs := buildDescendantsCTE(rootID, walkWisps, issuePred, wispPred)\n\n\trows, err := r.runner.QueryContext(ctx, cte, allArgs...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"descendants: query: %w\", err)\n\t}\n\tpage, err := scanIDSrcPage(rows)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"descendants: %w\", err)\n\t}\n\n\tissuesByID, err := r.fetchIssuesByIDs(ctx, page.issueIDs, issuesFilterTables, filter)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"descendants: hydrate issues: %w\", err)\n\t}\n\n\tvar wispsByID map[string]*types.Issue\n\tif len(page.wispIDs) > 0 {\n\t\twispsByID, err = r.fetchIssuesByIDs(ctx, page.wispIDs, wispsFilterTables, filter)\n\t\tif err != nil && !dberrors.IsTableNotExist(err) {\n\t\t\treturn nil, fmt.Errorf(\"descendants: hydrate wisps: %w\", err)\n\t\t}\n\t}","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/db/issue_descendants.go#L63-L99","documentation":"GetDescendants wraps an error from r.runner.QueryContext executing the generated recursive CTE that walks parent-child edges (and dotted-ID fallbacks) across the issues and wisps tables. This is the raw SQL execution failure — syntax, engine, connection, or schema errors from the Dolt/MySQL backend — surfaced after the query was already assembled successfully.","triggerScenarios":"Calling GetDescendants when the WITH RECURSIVE descendants query fails server-side: engine analyzer bugs (e.g. the documented dolt 2.1.6 \"unable to find field with index N\" issue), missing tables/columns, connection drop, or cancellation of ctx mid-query.","commonSituations":"Running an older or newer Dolt engine with a known recursive-CTE analyzer bug; a database migrated from the pre-wisps schema missing wisp tables the CTE references; long-running walk killed by context timeout.","solutions":["Read the wrapped driver error; if it mentions \"unable to find field with index\", upgrade/downgrade Dolt to a version without the recursive-CTE analyzer bug","Run bd doctor to verify schema completeness (issues, wisps, dependencies, wisp_dependencies all present and consistent)","Increase the context timeout or check cancellation if the error is context deadline/canceled","Retry on transient connection errors; check Dolt server logs for the failing query"],"exampleFix":"// before: bare context that expires mid-walk\nctx := context.Background()\nissues, err := repo.GetDescendants(ctx, root, filter)\n// after: give deep hierarchy walks room\nctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)\ndefer cancel()\nissues, err := repo.GetDescendants(ctx, root, filter)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"issues, err := repo.GetDescendants(ctx, rootID, filter)\nvar netErr net.Error\nif err != nil && (errors.Is(err, context.DeadlineExceeded) || errors.As(err, &netErr)) {\n    // retry with a longer deadline\n}","preventionTips":["Keep Dolt engine version aligned with the version bd was built against (recursive-CTE analyzer bugs are version-specific)","Run bd doctor after upgrades to confirm schema compatibility","Use generous context timeouts for deep hierarchy walks","Monitor Dolt server logs for analyzer/query errors"],"tags":["database","sql","recursive-cte","dolt","query"],"backgroundTag":"sql-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}