gastownhall/beads · error

failed to query child-parent dependencies: %w

Error message

failed to query child-parent dependencies: %w

What it means

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.

Source

Thrown at cmd/bd/doctor/fix/validation.go:152

	defer db.Close()

	if skip, err := guardFixTarget("Child-parent dependencies fix", db, beadsDir, cfg); skip {
		return err
	}

	// Find child→parent BLOCKING dependencies where issue_id starts with depends_on_id + "."
	// Only matches blocking types (blocks, conditional-blocks, waits-for) that cause deadlock.
	// Excludes 'parent-child' type which is a legitimate structural hierarchy relationship.
	//nolint:gosec // G202: fixDependencyUnionSQL returns a fixed internal SELECT fragment.
	query := `
		SELECT d.dep_table, d.issue_id, d.depends_on_id, d.type
		FROM (` + fixDependencyUnionSQL() + `) d
		WHERE d.issue_id LIKE CONCAT(d.depends_on_id, '.%')
		  AND d.type IN ('blocks', 'conditional-blocks', 'waits-for')
	`
	rows, err := db.Query(query)
	if err != nil {
		return fmt.Errorf("failed to query child-parent dependencies: %w", err)
	}
	defer rows.Close()

	type badDep struct {
		depTable    string
		issueID     string
		dependsOnID string
		depType     string
	}
	var badDeps []badDep

	for rows.Next() {
		var d badDep
		if err := rows.Scan(&d.depTable, &d.issueID, &d.dependsOnID, &d.depType); err == nil {
			badDeps = append(badDeps, d)
		}
	}
	if err := rows.Err(); err != nil {

View on GitHub (pinned to 71377f2769)

Solutions

  1. Verify the Dolt server/database is up and reachable, then re-run the fix.
  2. Confirm schema with `bd dolt sql -q "SHOW TABLES"`; restore missing dependency tables if absent.
  3. Read the wrapped driver error (%w) to distinguish connectivity vs. schema vs. permission causes and fix that root cause.
  4. If the database is corrupt, restore from backup or a Dolt branch before re-running doctor.

Example fix

// before: query fails because server is unreachable
rows, err := db.Query(query)
if err != nil {
	return fmt.Errorf("failed to query child-parent dependencies: %w", err)
}
// after: bring the server back up, then retry
// dolt server &  # or fix connection config
rows, err := db.Query(query)
if err != nil {
	return fmt.Errorf("failed to query child-parent dependencies: %w", err) // now succeeds
}
Defensive patterns

Strategy: try-catch

Validate before calling

// verify both dependency tables exist before the child-parent scan
for _, t := range []string{"dependencies", "wisp_dependencies"} {
	rows, err := db.Query("SELECT 1 FROM " + t + " LIMIT 1")
	if err != nil {
		return fmt.Fprintf(os.Stderr, "table %s unavailable: %v\n", t, err)
	}
	rows.Close()
}

Type guard

var sqlErr *driver.Error
if errors.As(err, &sqlErr) && sqlErr.Number == 1146 {
	// ER_NO_SUCH_TABLE: schema problem, not a connectivity problem
}

Try / catch

if err := fix.ChildParentDependencies(path, verbose); err != nil {
	if strings.Contains(err.Error(), "failed to query child-parent dependencies") {
		// check server availability and schema, then retry
		restartDoltServer()
		err = fix.ChildParentDependencies(path, verbose)
	}
	if err != nil {
		log.Fatalf("child-parent fix aborted: %v", err)
	}
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/daf47c79cee18afd. Report an issue: GitHub.