gastownhall/beads · warning

failed to add compaction comment: %w

Error message

failed to add compaction comment: %w

What it means

The final step of CompactTier1 adds an audit comment describing bytes saved. If store.AddComment fails, the issue and metadata are already written but the human-visible compaction comment is missing. Compaction itself succeeded; only the audit trail comment is lost.

Source

Thrown at internal/compact/compactor.go:161

		"design":              "",
		"notes":               "",
		"acceptance_criteria": "",
	}
	if err := c.store.UpdateIssue(ctx, issueID, updates, "compactor"); err != nil {
		return fmt.Errorf("failed to update issue: %w", err)
	}

	// Record compaction metadata with git commit hash
	commitHash := GetCurrentCommitHash()
	if err := c.store.ApplyCompaction(ctx, issueID, 1, originalSize, compactedSize, commitHash); err != nil {
		return fmt.Errorf("failed to apply compaction metadata: %w", err)
	}

	// Add comment about compaction
	savingBytes := originalSize - compactedSize
	comment := fmt.Sprintf("Tier 1 compaction: %d → %d bytes (saved %d)", originalSize, compactedSize, savingBytes)
	if err := c.store.AddComment(ctx, issueID, "compactor", comment); err != nil {
		return fmt.Errorf("failed to add compaction comment: %w", err)
	}

	return nil
}

// BatchResult holds the result of a single issue compaction in a batch.
type BatchResult struct {
	IssueID       string
	OriginalSize  int
	CompactedSize int
	Err           error
}

// CompactTier1Batch compacts multiple issues at Tier 1 concurrently.
func (c *Compactor) CompactTier1Batch(ctx context.Context, issueIDs []string) ([]BatchResult, error) {
	results := make([]BatchResult, len(issueIDs))
	sem := make(chan struct{}, c.config.Concurrency)
	var wg sync.WaitGroup

View on GitHub (pinned to 71377f2769)

Solutions

  1. Add the comment manually with `bd update <issueID> --notes` or a `bd` comment command if the trail matters
  2. Re-run compaction only if you need the comment; otherwise treat compaction as complete
  3. Check store/driver logs for the wrapped cause (lock, connection, disk)
  4. Retry `bd compact` — subsequent runs will append a fresh comment
Defensive patterns

Strategy: try-catch

Try / catch

if err := client.CompactTier1(ctx, issueID); err != nil {
	if strings.Contains(err.Error(), "compaction comment") {
		// compaction succeeded; comment is best-effort — safe to ignore or re-add
		log.Printf("compacted %s but comment failed: %v", issueID, err)
		return nil
	}
	return err
}

Prevention

When it happens

Trigger: store.AddComment(ctx, issueID, "compactor", comment) returns an error during CompactTier1 — driver write failure or DB unavailable at the last write step.

Common situations: Transient database lock or connection drop between the three sequential writes; comment storage quota or schema issue; concurrent write conflict on the same issue.

Related errors


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