gastownhall/beads · critical

failed to archive pre-compaction snapshot: %w

Error message

failed to archive pre-compaction snapshot: %w

What it means

Before destructively overwriting the issue with the summary, CompactTier1 archives the original content via store.SnapshotIssue so `bd restore` can undo the compaction. If snapshotting fails, the whole compaction aborts with this wrapped error, leaving the original content intact by design.

Source

Thrown at internal/compact/compactor.go:137

	if err != nil {
		return fmt.Errorf("failed to summarize: %w", err)
	}

	// Check if compaction would actually reduce size
	compactedSize := len(summary)
	if compactedSize >= originalSize {
		warningMsg := fmt.Sprintf("Tier 1 compaction skipped: summary (%d bytes) not shorter than original (%d bytes)", compactedSize, originalSize)
		if err := c.store.AddComment(ctx, issueID, "compactor", warningMsg); err != nil {
			return fmt.Errorf("failed to record warning: %w", err)
		}
		return fmt.Errorf("compaction would increase size (%d → %d bytes), keeping original", originalSize, compactedSize)
	}

	// Archive the original content BEFORE the destructive overwrite, so the
	// compaction is reversible (bd restore reads this snapshot). If archiving
	// fails we abort with the original content intact rather than lose it.
	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)
	}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Inspect the wrapped error for the storage root cause
  2. Verify the database schema includes the compaction snapshot storage (bd doctor / migrate)
  3. Check disk space and write permissions on the database
  4. Retry once storage is writable — the abort is safe; no content was lost
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure storage is writable and snapshot storage is healthy before compacting
if err := store.SnapshotIssue(ctx, probeIssueID, 1); err != nil {
    return fmt.Errorf("snapshot storage unavailable: %w", err)
}

Try / catch

if err := c.CompactTier1(ctx, id); err != nil {
    if strings.Contains(err.Error(), "failed to archive pre-compaction snapshot") {
        // safe abort: original content intact, nothing overwritten
        log.Printf("snapshot failed for %s; compaction safely aborted", id)
    }
    return err
}

Prevention

When it happens

Trigger: store.SnapshotIssue(ctx, issueID, 1) returns a non-nil error — e.g. the snapshot table is missing/corrupt, the database is read-only, the write was rejected by a constraint, or the connection dropped mid-write.

Common situations: Database schema migrations missing the snapshot table; read-only database or filesystem; concurrent compaction of the same issue; disk full on the storage backend.

Related errors


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