{"record":{"id":"8c1413f76b614a0b","repo":"gastownhall/beads","slug":"scan-same-content-compaction-snapshots-w","errorCode":null,"errorMessage":"scan same-content compaction snapshots: %w","messagePattern":"scan same-content compaction snapshots: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/issueops/derivedid.go","lineNumber":256,"sourceCode":"// InsertDerivedCompactionSnapshot inserts a compaction_snapshots row under\n// its content-derived id, with the same ordinal discipline as events. Two\n// clones compacting the same issue at the same tier in the same second\n// produce byte-identical snapshots and therefore the same id.\nfunc InsertDerivedCompactionSnapshot(ctx context.Context, tx DBTX, issueID string, level int, snapshotJSON []byte, createdAt string) error {\n\tif createdAt == \"\" {\n\t\tcreatedAt = NowAuxTime()\n\t}\n\tsnap := string(snapshotJSON)\n\tdigest := rowid.Digest([]sql.NullString{\n\t\tstr(issueID), str(fmt.Sprintf(\"%d\", level)), str(snap), str(createdAt),\n\t})\n\ttaken := make(map[string]bool)\n\trows, err := tx.QueryContext(ctx, `\n\t\tSELECT id FROM compaction_snapshots\n\t\tWHERE issue_id = ? AND compaction_level = ? AND snapshot_json = ? AND created_at = ?`,\n\t\tissueID, level, snap, createdAt)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"scan same-content compaction snapshots: %w\", err)\n\t}\n\tfor rows.Next() {\n\t\tvar id string\n\t\tif err := rows.Scan(&id); err != nil {\n\t\t\t_ = rows.Close()\n\t\t\treturn fmt.Errorf(\"scan same-content compaction snapshots: %w\", err)\n\t\t}\n\t\ttaken[id] = true\n\t}\n\t_ = rows.Close()\n\tif err := rows.Err(); err != nil {\n\t\treturn fmt.Errorf(\"scan same-content compaction snapshots: %w\", err)\n\t}\n\tif _, err := tx.ExecContext(ctx, `\n\t\tINSERT INTO compaction_snapshots (id, issue_id, compaction_level, snapshot_json, created_at)\n\t\tVALUES (?, ?, ?, ?, ?)`,\n\t\tfirstFreeDerivedID(\"compaction_snapshots\", digest, taken),\n\t\tissueID, level, snap, createdAt); err != nil {","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/issueops/derivedid.go#L238-L274","documentation":"This error wraps a failure while querying compaction_snapshots for pre-existing rows with identical content (issue_id, compaction_level, snapshot_json, created_at) inside InsertDerivedCompactionSnapshot. The library runs this same-content lookup before deriving a collision-free snapshot ID, so the error means the deduplication check itself failed at the SQL layer. It propagates the underlying driver/database error unchanged.","triggerScenarios":"The tx.QueryContext call on compaction_snapshots fails: table missing/corrupt, connection dropped mid-transaction, SQL/driver incompatibility, or context cancellation while the query executes. Reached via SnapshotIssueInTx during issue compaction.","commonSituations":"Dolt server restart or network blip during a compaction run; a migration that renamed/dropped compaction_snapshots; context deadline exceeded on a slow database; an older database file lacking the compaction_snapshots table.","solutions":["Inspect the wrapped %w cause for the real driver error and fix that underlying condition first","Verify the compaction_snapshots table exists with columns (id, issue_id, compaction_level, snapshot_json, created_at)","Check database connectivity and retry the compaction operation","Ensure the context passed to SnapshotIssueInTx has an adequate deadline"],"exampleFix":"// before\nif err != nil {\n    return fmt.Errorf(\"scan same-content compaction snapshots: %w\", err)\n}\n// after\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) {\n        return fmt.Errorf(\"scan same-content compaction snapshots (timeout, raise ctx deadline): %w\", err)\n    }\n    return fmt.Errorf(\"scan same-content compaction snapshots: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// before calling SnapshotIssueInTx\nrows, err := db.Query(\"SELECT 1 FROM compaction_snapshots LIMIT 1\")\nif err != nil {\n    return fmt.Errorf(\"compaction_snapshots table unavailable: %w\", err)\n}\nrows.Close()","typeGuard":null,"tryCatchPattern":"err := SnapshotIssueInTx(ctx, tx, issue)\nvar derr *storage.DBError\nif errors.As(err, &derr) && strings.Contains(derr.Error(), \"scan same-content compaction snapshots\") {\n    // inspect unwrapped cause, retry compaction after connectivity is restored\n    return fmt.Errorf(\"compaction snapshot dedup check failed, retry: %w\", err)\n}","preventionTips":["Keep the Dolt server reachable and monitor connection health during compaction","Pin and verify schema migrations so compaction_snapshots is never renamed/dropped silently","Give compaction contexts generous deadlines","Alert on the underlying driver error surfaced by %w"],"tags":["database","storage","sql","compaction"],"backgroundTag":"sql-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}