{"record":{"id":"46ebf92065995579","repo":"gastownhall/beads","slug":"failed-to-add-compaction-comment-w","errorCode":null,"errorMessage":"failed to add compaction comment: %w","messagePattern":"failed to add compaction comment: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/compact/compactor.go","lineNumber":161,"sourceCode":"\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\n}\n\n// CompactTier1Batch compacts multiple issues at Tier 1 concurrently.\nfunc (c *Compactor) CompactTier1Batch(ctx context.Context, issueIDs []string) ([]BatchResult, error) {\n\tresults := make([]BatchResult, len(issueIDs))\n\tsem := make(chan struct{}, c.config.Concurrency)\n\tvar wg sync.WaitGroup","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/compact/compactor.go#L143-L179","documentation":"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.","triggerScenarios":"store.AddComment(ctx, issueID, \"compactor\", comment) returns an error during CompactTier1 — driver write failure or DB unavailable at the last write step.","commonSituations":"Transient database lock or connection drop between the three sequential writes; comment storage quota or schema issue; concurrent write conflict on the same issue.","solutions":["Add the comment manually with `bd update <issueID> --notes` or a `bd` comment command if the trail matters","Re-run compaction only if you need the comment; otherwise treat compaction as complete","Check store/driver logs for the wrapped cause (lock, connection, disk)","Retry `bd compact` — subsequent runs will append a fresh comment"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := client.CompactTier1(ctx, issueID); err != nil {\n\tif strings.Contains(err.Error(), \"compaction comment\") {\n\t\t// compaction succeeded; comment is best-effort — safe to ignore or re-add\n\t\tlog.Printf(\"compacted %s but comment failed: %v\", issueID, err)\n\t\treturn nil\n\t}\n\treturn err\n}","preventionTips":["Treat the comment step as advisory; verify saved-bytes notes manually when it fails","Avoid concurrent writers on the same issue","Keep the store healthy so all three sequential writes succeed"],"tags":["compaction","audit","database"],"backgroundTag":"database-write-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}