gastownhall/beads · error
get next child ID: iterate children: %w
Error message
get next child ID: iterate children: %w
What it means
After the child-ID loop finishes, rows.Err() reports any deferred iteration error (e.g. connection loss during streaming); bd wraps it as "get next child ID: iterate children: %w". This catches failures that only surface after all rows appear consumed, preventing an undercounted child number.
Source
Thrown at internal/storage/issueops/child_id.go:48
AND id NOT LIKE CONCAT(?, '.%%.%%')
`, issueTable), parentID, parentID)
if err != nil {
return "", fmt.Errorf("get next child ID: query existing children: %w", err)
}
defer rows.Close()
for rows.Next() {
var id string
if err := rows.Scan(&id); err != nil {
return "", fmt.Errorf("get next child ID: scan child row: %w", err)
}
_, childNum, ok := ParseHierarchicalID(id)
if ok && childNum > lastChild {
lastChild = childNum
}
}
if err := rows.Err(); err != nil {
return "", fmt.Errorf("get next child ID: iterate children: %w", err)
}
nextChild := lastChild + 1
//nolint:gosec // G201: counterTable is one of two hardcoded constants.
if _, err := tx.ExecContext(ctx, fmt.Sprintf(`
INSERT INTO %s (parent_id, last_child) VALUES (?, ?)
ON DUPLICATE KEY UPDATE last_child = ?
`, counterTable), parentID, nextChild, nextChild); err != nil {
return "", fmt.Errorf("get next child ID: update counter: %w", err)
}
return fmt.Sprintf("%s.%d", parentID, nextChild), nil
}
View on GitHub (pinned to 71377f2769)
Solutions
- Retry the create; iteration-level connection errors are typically transient.
- Increase timeouts / avoid cancelling bd during large child creation batches.
- Verify child numbering afterwards (bd show parent) to ensure no duplicate child IDs were produced before the retry.
- For remote Dolt servers, check network stability; prefer local embedded mode for very large parents.
Defensive patterns
Strategy: retry
Try / catch
if err := rows.Err(); err != nil { /* inside lib */ }
// caller side:
if err != nil {
tx.Rollback()
return retry(fmt.Errorf("iterate children failed: %w", err))
} Prevention
- Avoid cancelling bd commands during large hierarchical creates.
- Increase DB timeouts for parents with many children.
- Prefer embedded/local Dolt mode when streaming large result sets over unreliable networks.
- Always retry the whole transaction after an iteration error; partial state rolls back.
When it happens
Trigger: Completing rows.Next() iteration when the connection broke mid-stream, the context was cancelled during iteration, or the driver hit a protocol error after partial reads.
Common situations: Large parents with thousands of children streamed over a flaky remote Dolt connection; cancelled bd commands mid-create; server timeouts on long result sets.
Related errors
- search %s: rows: %w
- search %s (id scan): rows: %w
- db: LabelSQLRepository.List: rows: %w
- db: LabelSQLRepository.ListByIssueIDs: rows: %w
- iterate dependency sources: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/6324821f7dd37a36.
Report an issue: GitHub.