gastownhall/beads · error

check issue existence: %w

Error message

check issue existence: %w

What it means

resolveCommentPlaneInTx fails while probing whether the anchor issue exists: the EXISTS SELECT against the issues/wisps table returned a driver error (connection loss, context cancellation, lock timeout, schema problem). The error is wrapped as "check issue existence: %w" so the underlying database/sql error remains inspectable. This is an infrastructure failure, not a 'not found' — a missing issue yields ErrNotFound instead (error 3434).

Source

Thrown at internal/storage/issueops/commenter.go:77

}

// resolveCommentPlaneInTx names the comment table the anchor's thread lives in,
// refusing an id that names neither an issue nor a wisp.
//
// The existence probe is here rather than left to the insert's own so the
// refusal is TYPED: AddIssueCommentInTx reports a missing anchor as prose, and
// a caller of this role classifies with errors.Is. It resolves the plane in
// the same transaction the insert runs in, so a comment cannot land on a row
// an earlier read saw and this one did not.
//
//nolint:gosec // G201: issueTable comes from WispTableRouting ("issues" or "wisps")
func resolveCommentPlaneInTx(ctx context.Context, tx *sql.Tx, issueID string) (string, error) {
	isWisp := IsActiveWispInTx(ctx, tx, issueID)
	issueTable, _, _, _ := WispTableRouting(isWisp)
	var exists bool
	if err := tx.QueryRowContext(ctx,
		fmt.Sprintf(`SELECT EXISTS(SELECT 1 FROM %s WHERE id = ?)`, issueTable), issueID).Scan(&exists); err != nil {
		return "", fmt.Errorf("check issue existence: %w", err)
	}
	if !exists {
		return "", fmt.Errorf("%w: issue %s", storage.ErrNotFound, issueID)
	}
	if isWisp {
		return "wisp_comments", nil
	}
	return "comments", nil
}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Inspect the wrapped error with errors.Is/As (driver.ErrBadConn, context.DeadlineExceeded) to identify the infrastructure cause.
  2. Retry the whole AddComment operation (a fresh transaction) on transient errors like ErrBadConn; do not retry on context cancellation.
  3. Check database connectivity/server health and that the beads database schema is fully migrated.

Example fix

// before
err := store.AddComment(ctx, req) // opaque driver failure

// after
if err := store.AddComment(ctx, req); err != nil {
	if errors.Is(err, context.DeadlineExceeded) {
		ctx, cancel = context.WithTimeout(context.Background(), 30*time.Second)
		defer cancel()
		continue // retry with fresh context/tx
	}
	return err
}
Defensive patterns

Strategy: retry

Try / catch

var dbErr *driverError
if err := store.AddComment(ctx, req); err != nil {
	if errors.Is(err, driver.ErrBadConn) || errors.Is(err, context.DeadlineExceeded) {
		// recreate tx/connection and retry the whole operation
	} else if errors.As(err, &dbErr) {
		log.Errorf("db failure during comment: %v", err)
	}
	return err
}

Prevention

When it happens

Trigger: Calling AddComment/ExecuteAddComment when the Dolt/SQL connection has dropped mid-transaction; context deadline exceeded while the transaction is contended; the underlying table missing or locked by another writer.

Common situations: Long-running scripts hitting a server-side connection idle timeout; concurrent bd processes deadlocking on the issue row; deploying a schema migration while comments are being written; network blips against a remote Dolt server.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


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