gastownhall/beads · error

failed to get issue history: %w

Error message

failed to get issue history: %w

What it means

HistoryInTx queries the Dolt system table dolt_history_issues for all historical commits touching an issue and the query failed. The wrapper is contextual; the wrapped error indicates why the history query failed (missing history table, bad SQL, connection issue).

Source

Thrown at internal/storage/issueops/history.go:38

	rows, err := tx.QueryContext(ctx, `
		SELECT
			id, title,
			COALESCE(description, '') AS description,
			COALESCE(design, '') AS design,
			COALESCE(acceptance_criteria, '') AS acceptance_criteria,
			COALESCE(notes, '') AS notes,
			status, priority, issue_type, assignee, owner, created_by,
			estimated_minutes, created_at, updated_at, closed_at, close_reason,
			pinned, mol_type,
			commit_hash, committer, commit_date
		FROM (
			SELECT * FROM dolt_history_issues
		) h
		WHERE h.id = ?
		ORDER BY h.commit_date DESC
	`, issueID)
	if err != nil {
		return nil, fmt.Errorf("failed to get issue history: %w", err)
	}
	defer rows.Close()

	var entries []*storage.HistoryEntry
	for rows.Next() {
		var issue types.Issue
		var createdAtStr, updatedAtStr sql.NullString
		var closedAt sql.NullTime
		var assignee, owner, createdBy, closeReason, molType sql.NullString
		var estimatedMinutes sql.NullInt64
		var pinned sql.NullInt64
		var commitHash, committer string
		var commitDate time.Time

		if err := rows.Scan(
			&issue.ID, &issue.Title, &issue.Description, &issue.Design, &issue.AcceptanceCriteria, &issue.Notes,
			&issue.Status, &issue.Priority, &issue.IssueType, &assignee, &owner, &createdBy,
			&estimatedMinutes, &createdAtStr, &updatedAtStr, &closedAt, &closeReason,

View on GitHub (pinned to 71377f2769)

Solutions

  1. Confirm the backend is Dolt — dolt_history_issues only exists in Dolt databases; use a Dolt-backed database for history features.
  2. Read the wrapped error: 'no such table dolt_history_issues' → wrong backend or outdated schema; run migrations or use a Dolt DB.
  3. Verify the issue ID exists (bd show <id>) — history of a never-committed ID may error depending on backend.
  4. Retry on transient connection errors; check dolt sql-server health and logs.

Example fix

// before: calling history against SQLite backend
entries, err := store.History(ctx, "PROJ-1") // no dolt_history_issues in sqlite
// after: guard on backend capability
if !store.SupportsHistory() { return fmt.Errorf("history requires a Dolt-backed database") }
entries, err := store.History(ctx, "PROJ-1")
Defensive patterns

Strategy: type-guard

Validate before calling

func supportsHistory(tx DBTX) bool {
    var n int
    err := tx.QueryRowContext(context.Background(),
        "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 'dolt_history_issues'").Scan(&n)
    return err == nil && n > 0
}

Type guard

func isHistoryUnavailable(err error) bool {
    return err != nil && strings.Contains(err.Error(), "dolt_history_issues")
}

Try / catch

entries, err := store.HistoryInTx(ctx, tx, issueID)
if err != nil {
    if isHistoryUnavailable(err) {
        return nil, fmt.Errorf("history requires a Dolt-backed database (got %T)", store.Driver())
    }
    return nil, err
}

Prevention

When it happens

Trigger: Calling the history API (bd history/log of an issue) when the SELECT ... FROM dolt_history_issues WHERE h.id = ? ... fails — dolt_history_issues unavailable (non-Dolt backend or very old schema), malformed query against a changed schema, or DB error.

Common situations: Running history commands against a non-Dolt (SQLite) backend that lacks dolt_history_* tables; issue ID that doesn't exist combined with driver quirks; Dolt server upgrade changing history table columns; connection drops during large history scans.

Related errors


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