{"record":{"id":"0a09faccb1dfd44c","repo":"gastownhall/beads","slug":"failed-to-apply-compaction-metadata-w","errorCode":null,"errorMessage":"failed to apply compaction metadata: %w","messagePattern":"failed to apply compaction metadata: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/compact/compactor.go","lineNumber":154,"sourceCode":"\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}\n\n\t// Add comment about compaction\n\tsavingBytes := originalSize - compactedSize\n\tcomment := fmt.Sprintf(\"Tier 1 compaction: %d → %d bytes (saved %d)\", originalSize, compactedSize, savingBytes)\n\tif err := c.store.AddComment(ctx, issueID, \"compactor\", comment); err != nil {\n\t\treturn fmt.Errorf(\"failed to add compaction comment: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// BatchResult holds the result of a single issue compaction in a batch.\ntype BatchResult struct {\n\tIssueID       string\n\tOriginalSize  int\n\tCompactedSize int\n\tErr           error","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/compact/compactor.go#L136-L172","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the wrapped driver error in logs; fix the underlying storage problem (disk space, lock, connectivity)","Re-run compaction for the same issue — ApplyCompaction is metadata-only and idempotent in practice","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","If DB corruption is suspected, run `bd doctor` and restore from git-synced Dolt refs"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := client.CompactTier1(ctx, issueID)\nif err != nil && strings.Contains(err.Error(), \"apply compaction metadata\") {\n\t// issue text may already be compacted; verify state before re-running\n\tlog.Printf(\"partial compaction for %s, check metadata: %v\", issueID, err)\n}","preventionTips":["Keep exclusive access to the DB during compaction (no parallel bd writers)","Monitor disk space; metadata writes fail when full","Verify compaction metadata with `bd show` after any failure"],"tags":["storage","compaction","database"],"backgroundTag":"database-write-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}