Skip to content

Conversation

snagasuri
Copy link

Summary

  • Adds database unique constraints to prevent duplicate synced issues
  • Implements webhook deduplication using delivery headers
  • Adds transaction-safe issue creation to prevent race conditions

Problem

After creating an issue, SyncLinear was infinitely recreating the same issue. This happened after synclinear renamed issues with the Linear ID, causing a cascade of webhook events that would all try to create new issues simultaneously.

Root Causes

  1. No database constraints: The SyncedIssue table allowed duplicate entries
  2. Race conditions: Multiple webhooks could check for existing issues simultaneously
  3. No webhook deduplication: Linear's retry mechanism could reprocess the same event
  4. Circular triggering: Renaming issues triggered more webhooks

Solution

  1. Database Layer: Added unique constraints on issue ID combinations
  2. Webhook Layer: Track processed webhook events using delivery headers
  3. Application Layer: Use database transactions for atomic check-and-create operations

Changes Made

  • Modified prisma/schema.prisma to add unique constraints and webhook tracking table
  • Updated pages/api/index.ts to check and store webhook delivery IDs
  • Refactored utils/webhook/linear.handler.ts to use transaction-safe issue creation
  • Created migration for database changes

Test Plan

  • Code builds successfully (pnpm build)
  • Linting passes (pnpm lint)
  • Deploy to test environment
  • Create Linear issue with Public label
  • Verify only one GitHub issue is created
  • Simulate webhook retries
  • Test with rapid label changes

Fixes #175

This commit addresses the bug where SyncLinear infinitely recreates issues
after renaming them with Linear IDs. The fix includes:

1. Database constraints: Added unique constraints to prevent duplicate
   syncedIssue entries for the same Linear/GitHub issue pairs

2. Webhook deduplication: Track processed webhook events using
   Linear-Delivery and X-GitHub-Delivery headers to prevent reprocessing

3. Transaction safety: Implement atomic operations for issue creation
   to prevent race conditions when multiple webhooks arrive simultaneously

The root cause was a race condition where multiple webhook events could
check for existing issues simultaneously, all find none, and proceed to
create duplicates before any were recorded in the database.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Copy link

vercel bot commented Jul 14, 2025

@snagasuri is attempting to deploy a commit to the Rubric Labs Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: Infinitely recreates issues
1 participant