Overview
When you connect a repository in Nectr, the system automatically:- Creates a webhook on the GitHub repository
- Generates a unique secret for signature verification
- Configures the webhook to listen for PR events
- Stores the webhook secret in the database
Automatic Webhook Installation
Webhooks are automatically installed when you connect a repository through the Nectr UI.Installation Process
User Connects Repository
User clicks “Connect” on a repository in the Nectr dashboard.Frontend calls:
POST /api/v1/repos/{owner}/{repo}/installInstall Webhook via GitHub API
Backend calls GitHub API to create the webhook:Events subscribed:
pull_request- PR opened, updated, closed, etc.issues- Issue opened, updated, closed, etc.
app/integrations/github/webhook_manager.py:10-48
Webhook Configuration
Webhook Properties
| Property | Value | Description |
|---|---|---|
| Payload URL | {BACKEND_URL}/api/v1/webhooks/github | Endpoint that receives webhook events |
| Content type | application/json | JSON-encoded payload |
| Secret | 64-character hex string | Used for HMAC-SHA256 signature verification |
| SSL verification | Enabled (insecure_ssl: 0) | Requires valid SSL certificate in production |
| Events | pull_request, issues | Only these event types trigger the webhook |
| Active | true | Webhook is enabled |
Per-Repo vs Global Secrets
Nectr uses per-repository webhook secrets for security:- ✅ Each repository has a unique webhook secret
- ✅ Secrets are generated automatically on connection
- ✅ Stored in the database
installationstable - ✅ Falls back to
GITHUB_WEBHOOK_SECRETenv var if not found
Signature Verification
Nectr verifies that webhook requests actually came from GitHub using HMAC-SHA256 signature verification.How It Works
GitHub Signs Every Webhook
GitHub Signs Every Webhook
GitHub calculates an HMAC-SHA256 signature of the webhook payload using the secret you provided:This signature is sent in the
X-Hub-Signature-256 header.Nectr Verifies the Signature
Nectr Verifies the Signature
hmac.compare_digest()? Prevents timing attacks by comparing strings in constant time.Verification is Enforced in Production
Verification is Enforced in Production
- Development: Signature verification is skipped
- Production: Invalid signatures are rejected with 403
Event Processing
1. Webhook Receiver
The webhook endpoint receives events and returns200 OK immediately to avoid GitHub’s 10-second timeout.
- Returns
200 OKwithin milliseconds - Actual PR review happens in background task
- GitHub’s 10-second timeout is avoided
2. GitHub App Event Filtering
Nectr uses per-repo webhooks, not GitHub App webhooks. GitHub App events are rejected:3. Deduplication
Nectr prevents duplicate reviews by checking for recent pending/processing events:- Same PR number
- Same repository
- Within 1 hour
- Status: pending or processing
4. Background Processing
PR reviews happen in background tasks that can take 30-60 seconds:app/api/v1/webhooks.py:41-93
Event Types
Nectr processes specific pull request events:| Event | Action | Description |
|---|---|---|
pull_request | opened | New PR created - triggers review |
pull_request | synchronize | PR updated with new commits - triggers review |
pull_request | reopened | Closed PR reopened - ignored |
pull_request | closed | PR closed/merged - ignored |
issues | * | Issue events - logged but not processed |
opened and synchronize events trigger AI reviews.
Webhook Management
Viewing Webhooks
Check installed webhooks for a repository:Disconnecting a Repository
When you disconnect a repository, Nectr automatically removes the webhook:Testing Webhooks
Local Development with ngrok
GitHub webhooks require a public URL. Use ngrok to expose your local server:Update BACKEND_URL
Set your Restart your backend for the change to take effect.
BACKEND_URL to the ngrok URL:Manual Webhook Testing
Test the webhook endpoint directly:Troubleshooting
Webhook Not Triggering Reviews
Webhook Not Triggering Reviews
Possible causes:
- Webhook not installed
- Check:
https://github.com/{owner}/{repo}/settings/hooks - Solution: Reconnect the repository in Nectr
- Check:
- Wrong webhook URL
- Check: Webhook payload URL should be
{BACKEND_URL}/api/v1/webhooks/github - Solution: Update
BACKEND_URLand reconnect repository
- Check: Webhook payload URL should be
- Event type not supported
- Only
pull_requestevents with actionsopenedorsynchronizetrigger reviews - Check GitHub webhook delivery logs for event details
- Only
- Signature verification failing
- Check logs for:
Invalid webhook signature for {repo} - Solution: Reconnect repository to regenerate secret
- Check logs for:
403 Invalid Webhook Signature
403 Invalid Webhook Signature
Cause: Webhook signature verification failed in production.Solutions:
- Reconnect the repository to generate a new webhook secret
- Check that
APP_ENV=productionis set correctly - Verify the secret in database matches the webhook configuration in GitHub
- Check that you’re not modifying the request body before verification
GitHub Webhook Delivery Failed
GitHub Webhook Delivery Failed
Cause: GitHub couldn’t reach your webhook endpoint.Solutions:
- Check that
BACKEND_URLis publicly accessible - Verify SSL certificate is valid (required for production)
- Check firewall/network rules
- View delivery details in GitHub webhook settings: Recent Deliveries tab
Duplicate Reviews Posted
Duplicate Reviews Posted
Cause: Deduplication logic not working or multiple webhooks installed.Solutions:
- Check for duplicate webhook configurations in GitHub settings
- Verify only one active
Installationrecord exists for the repo - Check logs for “duplicate_skipped” messages
- Ensure database is accessible (deduplication queries database)
Events Stuck in 'Processing' Status
Events Stuck in 'Processing' Status
Cause: Background task crashed or timed out.Solutions:
- Check backend logs for errors in
process_pr_in_background - Verify AI service (Anthropic) is accessible
- Check GitHub API rate limits
- Look for database connection issues
- Manually update event status in database if needed
Security Best Practices
Always Use Signature Verification in Production
Always Use Signature Verification in Production
Use HTTPS in Production
Use HTTPS in Production
GitHub requires valid SSL certificates for webhooks in production.Platforms like Railway, Heroku, and Fly.io provide SSL certificates automatically.
Keep Webhook Secrets Secure
Keep Webhook Secrets Secure
- Secrets are stored in plaintext in the database (they’re not sensitive like OAuth tokens)
- Each repository has a unique secret
- Secrets are generated with
secrets.token_hex(32)(cryptographically secure) - Never log or expose webhook secrets in error messages
Monitor Webhook Deliveries
Monitor Webhook Deliveries
Regularly check GitHub’s webhook delivery logs:
https://github.com/{owner}/{repo}/settings/hooks/{webhook_id}Look for:- Failed deliveries (red X)
- Response codes other than 200
- Timeout errors
Next Steps
Environment Variables
Configure webhook secrets and other settings
Feature Flags
Enable parallel review agents and other features