fix: prevent FK constraint errors on concurrent issue creation (GH#956)

Root cause: CreateIssue used INSERT OR IGNORE which could silently skip
the insert (e.g., on duplicate ID from hash collision), then fail with
FOREIGN KEY constraint error when trying to record the creation event.

Fix: Add insertIssueStrict() that uses plain INSERT (fails on duplicates)
and use it for CreateIssue in both queries.go and transaction.go. The
existing insertIssue() with INSERT OR IGNORE is preserved for import
scenarios where duplicates are expected.

Added test TestCreateIssueDuplicateID to verify duplicate IDs are properly
rejected instead of silently ignored.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
wolf
2026-01-09 22:58:46 -08:00
committed by Steve Yegge
parent a851104203
commit 0777bb907c
4 changed files with 107 additions and 5 deletions

View File

@@ -212,8 +212,10 @@ func (s *SQLiteStorage) CreateIssue(ctx context.Context, issue *types.Issue, act
}
}
// Insert issue
if err := insertIssue(ctx, conn, issue); err != nil {
// Insert issue using strict mode (fails on duplicates)
// GH#956: Use insertIssueStrict instead of insertIssue to prevent FK constraint errors
// from silent INSERT OR IGNORE failures under concurrent load.
if err := insertIssueStrict(ctx, conn, issue); err != nil {
return wrapDBError("insert issue", err)
}