Architecture overview
When a pull request is opened (or updated), GitHub sends a webhook to MergeWatch. The event flows through a serverless pipeline that ends with review comments posted back to the PR.Step-by-step flow
PR opened or updated
A developer opens a pull request or pushes new commits. GitHub fires a
pull_request webhook event (opened, synchronize, or reopened).Webhook received
API Gateway receives the POST request and invokes the WebhookHandler Lambda (256 MB, 30 s timeout). The handler validates the payload against the webhook secret using HMAC-SHA256. Invalid signatures are rejected with a 401.
Event queued
The handler publishes a message to an SQS FIFO queue. The message group ID is
{owner}/{repo}#{pr_number}, which guarantees sequential processing per PR — if a developer pushes twice in quick succession, reviews are processed in order, not in parallel.ReviewAgent invoked
SQS triggers the ReviewAgent Lambda (1024 MB, 300 s timeout). The agent fetches the PR diff from the GitHub API using the installation token, then fans out to five specialized agents.
Multi-agent parallel review
Five agents run concurrently via
Promise.all() — see the pipeline below. Each agent receives the diff and returns structured JSON findings.Orchestration
The orchestrator agent receives all findings, deduplicates overlapping comments, ranks by severity and confidence, and produces a merge readiness score (1—5).
The multi-agent pipeline
Five specialized agents run in parallel. Each is a separate Bedrock invocation with a focused system prompt.| Agent | Responsibility | Example finding |
|---|---|---|
| Security | SQL injection, XSS, secrets in code, dependency vulnerabilities | ”User input passed to exec() without sanitization” |
| Bug detection | Null derefs, off-by-ones, race conditions, logic errors | ”Array index i + 1 can exceed arr.length” |
| Style | Naming conventions, dead code, missing types, readability | ”Exported function processData has no JSDoc” |
| Summary | Human-readable summary of the PR’s intent and scope | ”Adds rate limiting to the /api/upload endpoint” |
| Diagram | Generates a Mermaid diagram of the changed control flow | Mermaid sequence or flowchart of the new code path |
Promise.all() — the total latency is bounded by the slowest agent, not the sum.
Agent output schema
Every agent (except summary and diagram) returns an array of findings in this shape:| Field | Type | Description |
|---|---|---|
file | string | Relative path to the file in the diff |
line | number | Line number in the new version of the file |
severity | "critical" | "warning" | "info" | How urgent the finding is |
confidence | number (1—100) | How confident the agent is that this is a real issue, not a false positive |
title | string | One-line summary of the finding |
description | string | Detailed explanation |
suggestion | string | Recommended fix |
Orchestrator behavior
After all agents complete, the orchestrator:- Deduplicates — if the security agent and the bug agent both flag the same line for the same root cause, only the higher-confidence finding is kept.
- Ranks — findings are sorted by severity (critical > warning > info), then by confidence descending.
- Scores — a merge readiness score from 1 to 5 is computed:
| Score | Meaning |
|---|---|
| 5 | No issues found. Ship it. |
| 4 | Minor suggestions only (info-level). |
| 3 | Warnings present. Review recommended before merge. |
| 2 | Critical findings with moderate confidence. Do not merge without addressing. |
| 1 | High-confidence critical findings. Merge blocked. |
Codebase awareness
MergeWatch v0.1 operates at diff-only awareness. The agents see the PR diff and nothing else.
| Version | Awareness level | What agents see |
|---|---|---|
| v0.1 (current) | Diff-only | The unified diff from the PR. No surrounding file context beyond what the diff hunk includes. |
| v0.2 (planned) | Diff + file fetch | Full contents of changed files fetched via the GitHub API, giving agents complete function and class context. |
| v0.3 (planned) | Diff + vector index | An embedding index of the full repository, enabling agents to understand cross-file dependencies and architectural patterns. |
Infrastructure details
WebhookHandler Lambda
- Memory: 256 MB
- Timeout: 30 seconds
- Role: Validate HMAC-SHA256 signature, parse event, enqueue to SQS
- Concurrency: Unreserved (scales with API Gateway)
ReviewAgent Lambda
- Memory: 1024 MB
- Timeout: 300 seconds (5 min)
- Role: Fetch diff, invoke agents, run orchestrator, post results
- Concurrency: Limited by SQS batch size (1 per message group)
SQS FIFO Queue
- Message group ID:
{owner}/{repo}#{pr_number} - Deduplication: Content-based
- Visibility timeout: 360 seconds (longer than Lambda timeout)
- Purpose: Guarantee sequential per-PR processing
DynamoDB Tables
installations— GitHub App installation config, repo settingsreviews— Review history, agent findings, scores (90-day TTL)- Billing mode: On-demand (pay-per-request)
Data flow and deployment models
Where your data goes depends on which deployment model you choose. This matters — read it carefully.Self-hosted
BYOC (Bring Your Own Cloud)
SaaS
Check Runs
MergeWatch uses the GitHub Check Runs API to report results. Each review creates a Check Run with:status:queued→in_progress→completedconclusion:success(score 4—5),neutral(score 3), orfailure(score 1—2)output.title: Merge readiness score and finding countoutput.summary: The summary agent’s output plus the orchestrator’s ranked findings
