Skip to main content

Overview

This page traces a pull request review from the moment a developer opens a PR on GitHub to when Nectr posts the AI-generated review as a GitHub comment.
The entire flow is asynchronous and non-blocking. The webhook returns HTTP 200 within 1 second, then processes the PR in a background task.

PR Review Flow Diagram

Step-by-Step Walkthrough

Step 1: GitHub Webhook Event

Location: app/api/v1/webhooks.py When a developer opens or updates a PR, GitHub sends a pull_request event to the configured webhook URL:
GitHub sometimes sends duplicate webhook events (network retries, misconfigured hooks). Deduplication prevents processing the same PR twice within a 1-hour window.

Step 2: Fetch PR Data from GitHub

Location: app/services/pr_review_service.py:473
GitHub REST API calls:
  • GET /repos/{owner}/{repo}/pulls/{pr_number} - PR metadata
  • GET /repos/{owner}/{repo}/pulls/{pr_number}/files - Changed files
  • GET /repos/{owner}/{repo}/pulls/{pr_number} with Accept: application/vnd.github.v3.diff - Unified diff

Step 3: Pull MCP Context (Optional)

Location: app/services/pr_review_service.py (ReviewToolExecutor) If MCP integrations are configured, Nectr pulls live context:
If LINEAR_MCP_URL or SENTRY_MCP_URL are not set, these calls return empty lists gracefully.

Step 4: Build Review Context

Location: app/services/context_service.py:58
Parallel queries:
  1. Mem0: Project patterns, decisions, rules
  2. Mem0: Developer-specific patterns, strengths
  3. Neo4j: File experts (developers who touched these files most)
  4. Neo4j: Related past PRs (PRs that touched the same files)

Step 5: Agentic AI Analysis

Location: app/services/ai_service.py:536 Nectr supports two review modes:

Standard Mode (Default)

Claude receives:
  • PR metadata (title, body, author)
  • Diff (up to 15,000 chars)
  • File list (name, additions, deletions)
  • 8 tools to fetch additional context on-demand
Tool execution loop:
  1. Claude analyzes diff
  2. Calls read_file("app/auth/jwt_utils.py") - needs full context
  3. Calls search_project_memory("JWT token handling") - checks past decisions
  4. Calls get_file_history(["app/auth/jwt_utils.py"]) - finds experts
  5. Returns final review with verdict + inline suggestions
Tool result:

Parallel Mode (Opt-In)

Runs 3 specialized agents concurrently:
  1. Security agent - Injection, auth flaws, secrets
  2. Performance agent - N+1 queries, memory leaks, O(n²)
  3. Style agent - Missing tests, unclear names, dead code
Then a synthesis agent combines all findings into one review.

Step 6: Post Review to GitHub

Location: app/services/pr_review_service.py:716
GitHub REST API:
  • POST /repos/{owner}/{repo}/pulls/{pr_number}/reviews
Payload:
Inline suggestions use GitHub’s suggestion format. Users can click “Commit suggestion” to apply the fix directly.

Step 7: Index PR in Neo4j

Location: app/services/graph_builder.py:197
Cypher queries:

Step 8: Extract Memories to Mem0

Location: app/services/memory_extractor.py Claude extracts learnings from the PR review:
Memory extraction prompt:
Memories are stored in Mem0 and indexed by:
  • repo: Repository full name
  • developer: GitHub username (for developer-specific memories)
  • category: Memory type

Step 9: Update Event Status

Location: app/services/pr_review_service.py:744

Failure Handling

If any step fails (GitHub API error, Claude timeout, Neo4j unreachable), the workflow:
  1. Logs the error with full traceback
  2. Updates event.status = "failed"
  3. Stores error message in workflow.error
  4. Does not retry automatically (prevents duplicate reviews)
Users can view failed events in the dashboard and manually trigger a rescan if needed.

Performance Metrics

The webhook returns HTTP 200 in < 1 second. All processing happens in the background.

Next Steps

Service Layer

Deep dive into PR review, AI, and context services

Neo4j Graph

Learn about the knowledge graph schema