Skip to content

fix: prevent duplicate webhook tasks for same PR branch#1156

Open
j-bennet wants to merge 1 commit into
kelos-dev:mainfrom
datagravity-ai:fix/duplicate-webhook-task
Open

fix: prevent duplicate webhook tasks for same PR branch#1156
j-bennet wants to merge 1 commit into
kelos-dev:mainfrom
datagravity-ai:fix/duplicate-webhook-task

Conversation

@j-bennet

@j-bennet j-bennet commented May 19, 2026

Copy link
Copy Markdown

/kind bug

What this PR does / why we need it:

The webhook handler generated task names using sha256(deliveryID), so multiple GitHub events for the same PR (labeled, ready_for_review, etc.) each created a separate task. This adds branch-based deduplication that skips task creation when an active task already exists for the same spawner and branch. Also makes task names human-readable by including the repo name and PR/issue number (e.g., babysitter-dquality-pr-30170-a1b2c3d4).

Which issue(s) this PR is related to:

Fixes #1155

Special notes for your reviewer:

  • buildWebhookTaskName constructs human-readable names with repo/PR number and a short delivery hash for uniqueness
  • sanitizeK8sNameSegment ensures all name segments comply with DNS label requirements
  • Dedup logic lists active tasks by spawner+branch label and skips creation if one exists
  • On dedup check failure, logs error but proceeds with task creation rather than dropping the event

Does this PR introduce a user-facing change?

Fix duplicate task creation when multiple webhook events fire for the same PR by adding branch-based deduplication and human-readable task naming.

Summary by cubic

Prevents duplicate webhook tasks for the same PR branch by adding branch-based deduplication in the internal/webhook handler. Also switches to human-readable, DNS-safe task names that include repo and PR/issue number. Fixes #1155.

  • Bug Fixes
    • Skip creating a task when an active task already exists for the same spawner + branch; allow a new task after the previous one is Succeeded/Failed.
    • Build readable names in the form <spawner>-<repo>-<pr|issue>-<number>-<hash> (fallback: <spawner>-<event>-<hash>), with all segments sanitized for Kubernetes DNS rules.
    • On dedup check errors, log and proceed with task creation to avoid dropping events.

Written for commit ce77926. Summary will update on new commits. Review in cubic

* fix: prevent duplicate webhook tasks for same PR branch

The webhook handler generated task names using sha256(deliveryID), so
multiple GitHub events for the same PR (labeled, ready_for_review, etc.)
each created a separate task. Add branch-based deduplication that skips
task creation when an active task already exists for the same spawner
and branch. Also make task names human-readable by including the repo
name and PR/issue number (e.g., babysitter-dquality-pr-30170-a1b2c3d4).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: sanitize repo name in task naming and fall through on dedup error

Address review feedback:
- Lowercase and replace underscores in RepositoryName before embedding in
  K8s task names to comply with DNS label requirements
- On dedup check failure, log the error but proceed with task creation
  rather than silently dropping the webhook event

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: sanitize Generic and Linear IDs for K8s DNS label compliance

User-supplied IDs from generic webhook field mappings and Linear events
can contain uppercase, dots, slashes, and other chars invalid in K8s
resource names. Extract a sanitizeK8sNameSegment helper that lowercases
and strips non-[a-z0-9-] characters.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: use sanitizeK8sNameSegment consistently in all task name paths

Apply the shared sanitizer to GitHub repo names (handles dots) and
Generic eventType (handles uppercase/underscores in URL path segments).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@CLAassistant

CLAassistant commented May 19, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Webhook handler creates duplicate tasks when multiple GitHub events fire for the same PR

2 participants