Pull Request Review with Merge Recommendation

Reviews a diff against your standards and returns a merge, merge-with-changes, or do-not-merge recommendation. Findings are ranked by severity, with evidence, suggested fixes, and open questions.

You get: Recommendation, change summary and findings table with columns

More like this

The prompt

pull-request-review-with-merge-recommendation.md
Role: You are a senior {language} engineer reviewing a pull request for {team_context}.Context: Your review supports one decision: merge, merge after changes, or do not merge. Use only the material supplied. Do not claim you ran the code or the tests.
Task: Review the change and produce a prioritized findings report with a merge recommendation.

Inputs:
- PR description: {pr_description}
- Diff or changed files: {diff}
- Related code, interfaces, or schemas: {related_code}
- Known risk areas: {risk_areas}
- Team standards: {standards}
- Test or CI results: {test_results}

Workflow:
1. List missing inputs that limit the review. Ask at most 5 questions, and only if they block the merge decision. Otherwise continue.
2. State assumptions in a separate list.
3. Summarize the intent of the change in at most 3 sentences.
4. Check correctness, security, performance, error handling, backward compatibility, readability, and test coverage.
5. Classify each finding as Blocker, Major, Minor, or Nit. Give the file and line if available, the evidence from the diff, why it matters, and a concrete fix.
6. Give the merge recommendation and the conditions that would change it.

Constraints:
- Do not invent code that is not in the diff. Mark anything unverifiable as Needs confirmation.
- Do not pad with style nits when blockers exist. Cap Nits at 5.
- Keep suggested code snippets under 15 lines each.

Output format:
1. Recommendation: one line plus a 2-sentence rationale.
2. Change summary.
3. Assumptions and missing information.
4. Findings table with columns: ID, Severity, Location, Evidence, Impact, Suggested fix.
5. Test gaps: a checklist of cases to add.
6. Risks if merged as-is.
7. Next actions: ordered list with an owner placeholder.

Acceptance criteria:
- Every Blocker and Major finding cites evidence from the supplied diff.
- The recommendation is consistent with the highest severity finding.
- Assumptions and unknowns are separate from findings.
- Each finding has an actionable fix.

Quality checks:
- Re-read the diff and confirm no finding contradicts it.
- Confirm that no claim about runtime behavior is stated as fact without evidence.
- Confirm that the findings table has no duplicate issues.
- Confirm that next actions map to findings.

Tool notes: In ChatGPT or Claude, paste the diff in a fenced code block and keep the inputs in the order above. In GitHub Copilot Chat, attach the changed files as context and ask for the output sections in order.

Example output

AI-written example
## 1. Recommendation
**Do not merge.**
The idempotency check and the write are not atomic, so concurrent retries can still issue duplicate refunds, which is the bug this PR set out to fix. Two Major issues also need changes first.

## 2. Change summary
Adds an `Idempotency-Key` header to `POST /refunds` in `payments-api`. Responses are cached in Redis so client retries don't trigger a second gateway refund.

## 3. Assumptions and missing information
- Assumes Redis is shared across all API replicas (Needs confirmation).
- Assumes refunds are per-merchant tenant, per `related_code` schema.
- Missing: the gateway's own idempotency support. If it has any, F1 may be solvable there.
- CI shows 41 passing tests, but none are concurrent, so no result covers the race.

## 4. Findings

| ID | Severity | Location | Evidence | Impact | Suggested fix |
|---|---|---|---|---|---|
| F1 | Blocker | `refunds/routes.py:58-71` | `if await store.get(key): return ...` runs before `await gateway.refund(...)`, and `store.set(key, result)` runs after | Two simultaneous retries both miss the cache and both refund | Reserve the key atomically before calling the gateway (snippet below) |
| F2 | Major | `refunds/routes.py:55` | Cache key is `f"idem:{key}"` with no merchant ID | Merchant B reusing a key gets merchant A's cached response, a data leak | Use `f"idem:{merchant_id}:{key}"` |
| F3 | Major | `refunds/routes.py:74-78` | `except GatewayTimeout: store.set(key, {"status": "failed"})` | A timeout may have succeeded at the gateway. Caching "failed" blocks legitimate retries and misreports state | Don't cache timeouts. Release the reservation and return 504 |
| F4 | Minor | `refunds/config.py:12` | `IDEM_TTL = 86400` hard-coded | Not tunable per environment | Read from settings |
| F5 | Nit | `refunds/routes.py:49` | Header parsed with an inline lambda | Readability | Extract a named dependency |

**F1 fix sketch:**
```python
reserved = await redis.set(k, "pending", nx=True, ex=IDEM_TTL)
if not reserved:
    cached = await redis.get(k)
    return replay_or_409(cached)  # 409 if still "pending"
result = await gateway.refund(...)
await redis.set(k, json.dumps(result), ex=IDEM_TTL)

5. Test gaps

  • [ ] Two concurrent requests with the same key produce exactly one gateway call
  • [ ] Same key from two merchants stays isolated
  • [ ] Gateway timeout followed by retry reaches the gateway again
  • [ ] Missing or malformed header returns 400
  • [ ] Expired key is treated as new

6. Risks if merged as-is

  • Duplicate customer refunds under load or client retry storms
  • Cross-tenant response exposure
  • Stuck refunds after gateway tim
Generated from this prompt by AI. Your results will vary.

Tips and common edits

Paste a unified diff and include surrounding interfaces when possible. For large PRs, run the prompt once per module and then ask for a combined recommendation. Treat output as a second reviewer, not a replacement for CI or human sign-off.

Questions about this prompt

More in Coding

Unit Test Plan and Test Code for an Existing Function

Builds a behavior-based test matrix for a function or module and then generates test code in your framework. Covers edge cases, failures, and mocking boundaries, with coverage gaps stated honestly.

Characterization Tests Before a Refactor

Writes tests that lock in a module's current behavior, including edge cases and quirks, so you can refactor safely.

Codebase Tour for a Specific Task

Explores a repo through the lens of your task and explains the architecture, key files and data flow, then says where to start.

Failing Test First Bug Fix

Reproduces a bug with a failing test, finds the root cause, applies the smallest fix and shows the test passing.

Root Cause Analysis from Stack Trace and Logs

Turns an error report, stack trace, and logs into ranked root-cause hypotheses. Includes the cheapest checks to confirm each one, a fix proposal, and a regression test plan.

Architecture Decision Record for a Technology Choice

Compares realistic options against your constraints and produces a decision record. The record has a weighted comparison, risks, a reversal plan, and a recommendation the team can approve or challenge.

Conventional Commit and PR Description from a Diff and Ticket

Produces a Conventional Commits message and a reviewer-ready PR description covering what changed, why, how to test it, and the risks, based on your diff and ticket.

Explain This Error with Ranked Causes

Explains an error and stack trace in plain words, ranks the three most likely causes and gives a confirming check for each.

Regex with Match and Non-Match Test Strings

Writes a regex for your pattern, explains each part and provides 8 strings that should match and 8 that should not.

SQL Query from Schema and Question

Writes a SQL query that answers your question from your schema, explains each clause and suggests indexes worth adding.

Cursor .mdc Rules to Portable AGENTS.md Converter

Converts your pasted Cursor .mdc rules into a single AGENTS.md that Codex, Copilot and Gemini CLI can read, plus a table of what does not carry over.

Checkable Guardrail Rules for a Coding Agent: Blocked Commands, Approvals, Secrets and Hooks

Produces a set of testable guardrail rules for your coding agent, covering blocked commands, approval gates, secret handling and hook checks.