gastownhall/beads · error

failed to apply compaction metadata: %w

Error message

failed to apply compaction metadata: %w

What it means

After successfully updating the issue, CompactTier1 records compaction metadata (tier, sizes, git commit hash) via store.ApplyCompaction. This error means the metadata write failed even though the issue text was already overwritten — the issue is compacted but the compaction bookkeeping is missing, leaving the store in a partially-compacted state.

Source

Thrown at internal/compact/compactor.go:154

	if err := c.store.SnapshotIssue(ctx, issueID, 1); err != nil {
		return fmt.Errorf("failed to archive pre-compaction snapshot: %w", err)
	}

	// Update issue with summarized content
	updates := map[string]interface{}{
		"description":         summary,
		"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

View on GitHub (pinned to 71377f2769)

Solutions

  1. Check the wrapped driver error in logs; fix the underlying storage problem (disk space, lock, connectivity)
  2. Re-run compaction for the same issue — ApplyCompaction is metadata-only and idempotent in practice
  3. Verify compaction state with `bd show <issueID>`; if the issue body was compacted but metadata is absent, manually re-apply or re-run tier-1
  4. If DB corruption is suspected, run `bd doctor` and restore from git-synced Dolt refs
Defensive patterns

Strategy: try-catch

Try / catch

err := client.CompactTier1(ctx, issueID)
if err != nil && strings.Contains(err.Error(), "apply compaction metadata") {
	// issue text may already be compacted; verify state before re-running
	log.Printf("partial compaction for %s, check metadata: %v", issueID, err)
}

Prevention

When it happens

Trigger: store.ApplyCompaction(ctx, issueID, 1, originalSize, compactedSize, commitHash) returns an error — driver write failure, DB unavailable, or a transaction that cannot be committed after the preceding UpdateIssue.

Common situations: Dolt database locked by a concurrent `bd` process; disk full after the large summary write; GetCurrentCommitHash returned a hash the store rejects; crash mid-sequence leaving partial state.

Related errors


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