{"record":{"id":"daf47c79cee18afd","repo":"gastownhall/beads","slug":"failed-to-query-child-parent-dependencies-w","errorCode":null,"errorMessage":"failed to query child-parent dependencies: %w","messagePattern":"failed to query child-parent dependencies: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/doctor/fix/validation.go","lineNumber":152,"sourceCode":"\tdefer db.Close()\n\n\tif skip, err := guardFixTarget(\"Child-parent dependencies fix\", db, beadsDir, cfg); skip {\n\t\treturn err\n\t}\n\n\t// Find child→parent BLOCKING dependencies where issue_id starts with depends_on_id + \".\"\n\t// Only matches blocking types (blocks, conditional-blocks, waits-for) that cause deadlock.\n\t// Excludes 'parent-child' type which is a legitimate structural hierarchy relationship.\n\t//nolint:gosec // G202: fixDependencyUnionSQL returns a fixed internal SELECT fragment.\n\tquery := `\n\t\tSELECT d.dep_table, d.issue_id, d.depends_on_id, d.type\n\t\tFROM (` + fixDependencyUnionSQL() + `) d\n\t\tWHERE d.issue_id LIKE CONCAT(d.depends_on_id, '.%')\n\t\t  AND d.type IN ('blocks', 'conditional-blocks', 'waits-for')\n\t`\n\trows, err := db.Query(query)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to query child-parent dependencies: %w\", err)\n\t}\n\tdefer rows.Close()\n\n\ttype badDep struct {\n\t\tdepTable    string\n\t\tissueID     string\n\t\tdependsOnID string\n\t\tdepType     string\n\t}\n\tvar badDeps []badDep\n\n\tfor rows.Next() {\n\t\tvar d badDep\n\t\tif err := rows.Scan(&d.depTable, &d.issueID, &d.dependsOnID, &d.depType); err == nil {\n\t\t\tbadDeps = append(badDeps, d)\n\t\t}\n\t}\n\tif err := rows.Err(); err != nil {","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor/fix/validation.go#L134-L170","documentation":"ChildParentDependencies runs a SELECT over the union of dependencies and wisp_dependencies looking for blocking dependencies (blocks/conditional-blocks/waits-for) that point from a child issue to its parent (issue_id = depends_on_id + '.' suffix), which create deadlock cycles. If db.Query fails — before any analysis — the function aborts with this wrapped error, mirroring the OrphanedDependencies query error path.","triggerScenarios":"db.Query on the child-parent detection SQL fails at validation.go:150: missing `dependencies`/`wisp_dependencies` tables, lost connection to the Dolt server, SQL rejection (permissions/timeout), or a corrupted database preventing table reads.","commonSituations":"Dolt server down or restarted during `bd doctor --fix-child-parent`; database directory missing tables after a partial migration; remote Dolt connection timing out; running against a misconfigured beadsDir pointing at an absent/incomplete database.","solutions":["Verify the Dolt server/database is up and reachable, then re-run the fix.","Confirm schema with `bd dolt sql -q \"SHOW TABLES\"`; restore missing dependency tables if absent.","Read the wrapped driver error (%w) to distinguish connectivity vs. schema vs. permission causes and fix that root cause.","If the database is corrupt, restore from backup or a Dolt branch before re-running doctor."],"exampleFix":"// before: query fails because server is unreachable\nrows, err := db.Query(query)\nif err != nil {\n\treturn fmt.Errorf(\"failed to query child-parent dependencies: %w\", err)\n}\n// after: bring the server back up, then retry\n// dolt server &  # or fix connection config\nrows, err := db.Query(query)\nif err != nil {\n\treturn fmt.Errorf(\"failed to query child-parent dependencies: %w\", err) // now succeeds\n}","handlingStrategy":"try-catch","validationCode":"// verify both dependency tables exist before the child-parent scan\nfor _, t := range []string{\"dependencies\", \"wisp_dependencies\"} {\n\trows, err := db.Query(\"SELECT 1 FROM \" + t + \" LIMIT 1\")\n\tif err != nil {\n\t\treturn fmt.Fprintf(os.Stderr, \"table %s unavailable: %v\\n\", t, err)\n\t}\n\trows.Close()\n}","typeGuard":"var sqlErr *driver.Error\nif errors.As(err, &sqlErr) && sqlErr.Number == 1146 {\n\t// ER_NO_SUCH_TABLE: schema problem, not a connectivity problem\n}","tryCatchPattern":"if err := fix.ChildParentDependencies(path, verbose); err != nil {\n\tif strings.Contains(err.Error(), \"failed to query child-parent dependencies\") {\n\t\t// check server availability and schema, then retry\n\t\trestartDoltServer()\n\t\terr = fix.ChildParentDependencies(path, verbose)\n\t}\n\tif err != nil {\n\t\tlog.Fatalf(\"child-parent fix aborted: %v\", err)\n\t}\n}","preventionTips":["Run `bd doctor` read-only checks before --fix-child-parent to validate database health.","Confirm the workspace beadsDir/dolt_data_dir config points at the real database.","Keep Dolt server and driver versions aligned to avoid schema-read failures.","Only run this opt-in fix on a healthy, backed-up database."],"tags":["go","database","dolt","sql","doctor"],"backgroundTag":"sql-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}