{"record":{"id":"23f7ddc85ffff8bf","repo":"gastownhall/beads","slug":"failed-to-archive-pre-compaction-snapshot-w","errorCode":null,"errorMessage":"failed to archive pre-compaction snapshot: %w","messagePattern":"failed to archive pre-compaction snapshot: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/compact/compactor.go","lineNumber":137,"sourceCode":"\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to summarize: %w\", err)\n\t}\n\n\t// Check if compaction would actually reduce size\n\tcompactedSize := len(summary)\n\tif compactedSize >= originalSize {\n\t\twarningMsg := fmt.Sprintf(\"Tier 1 compaction skipped: summary (%d bytes) not shorter than original (%d bytes)\", compactedSize, originalSize)\n\t\tif err := c.store.AddComment(ctx, issueID, \"compactor\", warningMsg); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to record warning: %w\", err)\n\t\t}\n\t\treturn fmt.Errorf(\"compaction would increase size (%d → %d bytes), keeping original\", originalSize, compactedSize)\n\t}\n\n\t// Archive the original content BEFORE the destructive overwrite, so the\n\t// compaction is reversible (bd restore reads this snapshot). If archiving\n\t// fails we abort with the original content intact rather than lose it.\n\tif err := c.store.SnapshotIssue(ctx, issueID, 1); err != nil {\n\t\treturn fmt.Errorf(\"failed to archive pre-compaction snapshot: %w\", err)\n\t}\n\n\t// Update issue with summarized content\n\tupdates := map[string]interface{}{\n\t\t\"description\":         summary,\n\t\t\"design\":              \"\",\n\t\t\"notes\":               \"\",\n\t\t\"acceptance_criteria\": \"\",\n\t}\n\tif err := c.store.UpdateIssue(ctx, issueID, updates, \"compactor\"); err != nil {\n\t\treturn fmt.Errorf(\"failed to update issue: %w\", err)\n\t}\n\n\t// Record compaction metadata with git commit hash\n\tcommitHash := GetCurrentCommitHash()\n\tif err := c.store.ApplyCompaction(ctx, issueID, 1, originalSize, compactedSize, commitHash); err != nil {\n\t\treturn fmt.Errorf(\"failed to apply compaction metadata: %w\", err)\n\t}","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/compact/compactor.go#L119-L155","documentation":"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.","triggerScenarios":"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.","commonSituations":"Database schema migrations missing the snapshot table; read-only database or filesystem; concurrent compaction of the same issue; disk full on the storage backend.","solutions":["Inspect the wrapped error for the storage root cause","Verify the database schema includes the compaction snapshot storage (bd doctor / migrate)","Check disk space and write permissions on the database","Retry once storage is writable — the abort is safe; no content was lost"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// ensure storage is writable and snapshot storage is healthy before compacting\nif err := store.SnapshotIssue(ctx, probeIssueID, 1); err != nil {\n    return fmt.Errorf(\"snapshot storage unavailable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := c.CompactTier1(ctx, id); err != nil {\n    if strings.Contains(err.Error(), \"failed to archive pre-compaction snapshot\") {\n        // safe abort: original content intact, nothing overwritten\n        log.Printf(\"snapshot failed for %s; compaction safely aborted\", id)\n    }\n    return err\n}","preventionTips":["Run migrations/`bd doctor` so snapshot storage exists and is current","Monitor disk space — snapshot writes fail on a full disk","Never disable or bypass the snapshot step; it is the undo path for bd restore","Ensure only one compaction process writes to an issue at a time"],"tags":["go","storage","write-failure","snapshot","data-safety"],"backgroundTag":"storage-write-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}