gastownhall/beads · error
failed to iterate issues for prefix %q: %w
Error message
failed to iterate issues for prefix %q: %w
What it means
After iterating rows in SeedCounterFromExistingIssuesTx, rows.Err() returned non-nil, meaning the row iteration was aborted by a driver/network error mid-scan (not a normal end of results).
Source
Thrown at internal/storage/issueops/helpers.go:304
defer rows.Close()
maxNum := 0
pfxDash := prefix + "-"
for rows.Next() {
var id string
if err := rows.Scan(&id); err != nil {
continue
}
suffix := strings.TrimPrefix(id, pfxDash)
if strings.Contains(suffix, ".") {
continue // skip child IDs
}
if n, err := strconv.Atoi(suffix); err == nil && n > maxNum {
maxNum = n
}
}
if err := rows.Err(); err != nil {
return fmt.Errorf("failed to iterate issues for prefix %q: %w", prefix, err)
}
if maxNum > 0 {
_, err = tx.ExecContext(ctx, "INSERT INTO issue_counter (prefix, last_id) VALUES (?, ?)", prefix, maxNum)
if err != nil {
return fmt.Errorf("failed to seed issue counter for prefix %q at %d: %w", prefix, maxNum, err)
}
}
return nil
}
// GetAdaptiveIDLengthTx returns the appropriate hash length based on database size.
//
//nolint:gosec // G201: table is a hardcoded constant
func GetAdaptiveIDLengthTx(ctx context.Context, tx DBTX, table, prefix string) (int, error) {
var count int
err := tx.QueryRowContext(ctx, fmt.Sprintf(`
SELECT COUNT(*)View on GitHub (pinned to 71377f2769)
Solutions
- Retry the ID-generation operation; seeding is idempotent and will re-scan.
- Increase the context timeout / remove the deadline so large scans can complete.
- Check connectivity to the Dolt server (dolt sql-server logs) for restarts or dropped connections.
- If persistent, run the seeding locally against the .beads DB rather than over the network.
Example fix
// before
ctx := context.Background() // no deadline, but network drops abort scan
// after: give the seeding scan explicit headroom and retry
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
err := retry.OnError(3, isTransient, func() error { return generateID(ctx) }) Defensive patterns
Strategy: retry
Try / catch
err := retry.Do(func() error {
return storage.GenerateIssueIDInTable(ctx, tx, "issues", prefix, issue)
}, retry.Attempts(3), retry.RetryIf(isNetworkError)) Prevention
- Give long seeding scans a generous context timeout.
- Keep network links to dolt sql-server stable; monitor for server restarts.
- Run counter seeding against the local .beads DB rather than over WAN where possible.
When it happens
Trigger: Long issues table scan during counter seeding interrupted by connection drop, Dolt server restart, or context cancellation while rows.Next() was streaming.
Common situations: Large issue databases over a flaky connection to a remote Dolt server; context timeout (ctx deadline exceeded) during seeding; server killed mid-query.
Related errors
- db: LabelSQLRepository.List: rows: %w
- db: LabelSQLRepository.ListByIssueIDs: rows: %w
- iterate wisp issues by label: %w
- iterate dependents from %s: %w
- iterate neighbors from %s: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/ea9531df26270f1a.
Report an issue: GitHub.