{"record":{"id":"27386325934bdb04","repo":"gastownhall/beads","slug":"insert-compaction-snapshot-w","errorCode":null,"errorMessage":"insert compaction snapshot: %w","messagePattern":"insert compaction snapshot: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/issueops/derivedid.go","lineNumber":275,"sourceCode":"\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 {\n\t\treturn fmt.Errorf(\"insert compaction snapshot: %w\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":257,"sourceCodeEnd":279,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/issueops/derivedid.go#L257-L279","documentation":"This error wraps a failure inserting the compaction snapshot row into compaction_snapshots after a collision-free derived ID was chosen. It is raised when tx.ExecContext returns an error: typically a duplicate-key race, FK violation on issue_id, or an aborted transaction. The enclosing transaction (SnapshotIssueInTx) will roll back.","triggerScenarios":"INSERT INTO compaction_snapshots fails: primary-key collision on the derived ID (concurrent compaction of identical content), FK violation because the issue no longer exists, or the transaction was already aborted by a prior statement.","commonSituations":"Two processes compacting the same issue simultaneously deriving the same ID; the parent issue deleted between the dedup check and the insert; disk full on the Dolt server.","solutions":["Check the wrapped cause; on duplicate-key simply retry — the retry's same-content check will see the existing row and behave correctly","Verify issue_id exists in issues (FK integrity)","Serialize compaction per issue (lock or single-writer) to avoid concurrent derived-ID races","Check server disk space and transaction state if errors persist"],"exampleFix":"// before\nif _, err := tx.ExecContext(ctx, insertSQL, id, issueID, level, snap, createdAt); err != nil {\n    return fmt.Errorf(\"insert compaction snapshot: %w\", err)\n}\n// after\nif _, err := tx.ExecContext(ctx, insertSQL, id, issueID, level, snap, createdAt); err != nil {\n    if isDuplicateKeyErr(err) {\n        return nil // concurrent compaction already stored identical content\n    }\n    return fmt.Errorf(\"insert compaction snapshot: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// ensure the parent issue exists before snapshotting\nvar n int\ndb.QueryRow(\"SELECT COUNT(*) FROM issues WHERE id = ?\", issueID).Scan(&n)\nif n == 0 {\n    return fmt.Errorf(\"issue %s does not exist; cannot snapshot\", issueID)\n}","typeGuard":null,"tryCatchPattern":"err := SnapshotIssueInTx(ctx, tx, issue)\nif err != nil {\n    var derr *storage.DBError\n    if errors.As(err, &derr) && strings.Contains(err.Error(), \"insert compaction snapshot\") {\n        if isDuplicateKey(err) {\n            return nil // identical snapshot already stored concurrently; safe to proceed\n        }\n    }\n    return err\n}","preventionTips":["Serialize compaction per issue (single writer or per-issue lock)","Treat duplicate-key on this insert as success-by-idempotency","Ensure issue rows are not deleted while compaction is running","Monitor server disk space"],"tags":["database","sql","insert","constraint"],"backgroundTag":"sql-insert-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}