Skip to content

feat(web): multi-phase review agent with per-file parallel LLM calls#1164

Open
fatmcgav wants to merge 3 commits into
sourcebot-dev:mainfrom
fatmcgav:feat-improve-agent-llm-efficiency
Open

feat(web): multi-phase review agent with per-file parallel LLM calls#1164
fatmcgav wants to merge 3 commits into
sourcebot-dev:mainfrom
fatmcgav:feat-improve-agent-llm-efficiency

Conversation

@fatmcgav
Copy link
Copy Markdown
Contributor

@fatmcgav fatmcgav commented Apr 30, 2026

Replace the per-chunk (N LLM calls) architecture with a two-phase approach:

  1. A single MR summary pass over all changed files to detect cross-file
    semantic changes (renames, signature changes, removed exports, etc.)
    that individual file reviewers should be aware of.
  2. Per-file LLM reviews that batch all hunks for a file into a single call,
    parallelised across files via a concurrency-capped pool
    (MAX_CONCURRENT_FILE_REVIEWS = 5).

This reduces LLM calls from one-per-hunk to one-per-file (plus one summary
call), while giving each file review the full picture via the MR summary
context.

Additional changes:

  • Export validateLogPath from invokeDiffReviewLlm for reuse in the
    summary node
  • Add "How it works" section to the review agent docs

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

Summary by CodeRabbit

  • New Features

    • Two-phase review: single MR summary pass plus parallel per-file reviews that post inline comments.
  • Improvements

    • Per-file review tasks run with a concurrency limit (max 5) for faster, bounded processing.
    • Per-file prompts now include the MR summary for cross-file context.
  • Documentation

    • Updated agent docs and changelog; manual trigger changed from "/review" to "review" (no guidance about leading slash).

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

Too much diff to scan? Review this PR in Change Stack to start with the highest-impact changes.

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4266d122-e4a5-40cb-b534-fc72d5945969

📥 Commits

Reviewing files that changed from the base of the PR and between 08481cd and 6bc5a12.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • docs/docs/features/agents/review-agent.mdx
✅ Files skipped from review due to trivial changes (2)
  • docs/docs/features/agents/review-agent.mdx
  • CHANGELOG.md

Walkthrough

Updates docs and changelog to describe the AI Code Review Agent’s new two-phase flow: a single MR-summary LLM pass for cross-file concerns, then parallel per-file LLM reviews (up to 5 concurrent) that post inline comments; also changes the manual trigger from /review to review.

Changes

Documentation & Changelog

Layer / File(s) Summary
How-it-works and trigger text
docs/docs/features/agents/review-agent.mdx
Describes the two-phase pipeline (MR summary + parallel per-file reviews) and updates the manual trigger keyword from /review to review.
Changelog entry
CHANGELOG.md
Adds an Unreleased entry documenting the two-phase MR-summary + parallel per-file review workflow (max 5 concurrent).

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ReviewAgent as ReviewAgent.generatePrReview
  participant MRLLM as LLM (MR Summary)
  participant FileLLM as LLM (Per-file Review)

  Client->>ReviewAgent: pr_payload
  ReviewAgent->>MRLLM: generateMrSummary(pr_payload)
  MRLLM-->>ReviewAgent: pr_summary context
  ReviewAgent->>FileLLM: per-file prompt + pr_summary + file diffs (parallel, max 5)
  FileLLM-->>ReviewAgent: file_diff_review (inline comments)
  ReviewAgent-->>Client: aggregated file_diff_review[]
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • sourcebot-dev/sourcebot#1134: Related export/centralization of review-agent log path validation (validateLogPath) used by review-agent modules.

Suggested reviewers

  • msukkari
  • brendan-kellam
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main architectural change: a multi-phase review agent with per-file parallel LLM calls, which aligns with the core objective to replace per-hunk calls with a two-phase approach (MR summary + parallelized per-file reviews).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
docs/docs/features/agents/review-agent.mdx (1)

6-23: ⚡ Quick win

Rewrite this new section in second person.

The new intro and How it works steps switch to third person (the agent runs, the agent posts, it returns). Please recast this as you/your to match the docs voice.

As per coding guidelines, docs/**/*.mdx should “write in second person present tense”.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/docs/features/agents/review-agent.mdx` around lines 6 - 23, Rewrite the
introduction and "How it works" steps to use second-person present-tense
phrasing (you/your) instead of third-person; change sentences like "This agent
provides", "When a review is triggered, the agent runs", "the agent posts", and
"it returns nothing" to address the reader directly and use present tense, and
update step headings and descriptions ("MR summary pass", "Per-file reviews",
"Inline comments") so they read like instructions to the user (e.g., "You run a
MR summary pass", "You run per-file reviews", "You post inline comments" or
similar) while preserving the original meaning and sequence.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/web/src/features/agents/review-agent/nodes/generateMrSummary.ts`:
- Around line 31-32: The code incorrectly uses the undefined variable modelName
in the models.find call inside the REVIEW_AGENT_MODEL branch; update the
predicate to compare m.displayName === env.REVIEW_AGENT_MODEL so it matches the
condition and the later usage (replace the modelName reference with
env.REVIEW_AGENT_MODEL in the models.find call that resolves the model).

---

Nitpick comments:
In `@docs/docs/features/agents/review-agent.mdx`:
- Around line 6-23: Rewrite the introduction and "How it works" steps to use
second-person present-tense phrasing (you/your) instead of third-person; change
sentences like "This agent provides", "When a review is triggered, the agent
runs", "the agent posts", and "it returns nothing" to address the reader
directly and use present tense, and update step headings and descriptions ("MR
summary pass", "Per-file reviews", "Inline comments") so they read like
instructions to the user (e.g., "You run a MR summary pass", "You run per-file
reviews", "You post inline comments" or similar) while preserving the original
meaning and sequence.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ab12e7a3-a174-49f2-b51f-16607592ad85

📥 Commits

Reviewing files that changed from the base of the PR and between 29dfe17 and f643f86.

📒 Files selected for processing (6)
  • docs/docs/features/agents/review-agent.mdx
  • packages/web/src/features/agents/review-agent/nodes/generateDiffReviewPrompt.ts
  • packages/web/src/features/agents/review-agent/nodes/generateMrSummary.ts
  • packages/web/src/features/agents/review-agent/nodes/generatePrReview.ts
  • packages/web/src/features/agents/review-agent/nodes/gitlabMrParser.ts
  • packages/web/src/features/agents/review-agent/nodes/invokeDiffReviewLlm.ts

Comment thread packages/web/src/features/agents/review-agent/nodes/generateMrSummary.ts Outdated
fatmcgav and others added 3 commits June 5, 2026 20:39
Replace the per-chunk (N LLM calls) architecture with a two-phase approach:

1. A single MR summary pass over all changed files to detect cross-file
   semantic changes (renames, signature changes, removed exports, etc.)
   that individual file reviewers should be aware of.
2. Per-file LLM reviews that batch all hunks for a file into a single call,
   parallelised across files via a concurrency-capped pool
   (MAX_CONCURRENT_FILE_REVIEWS = 5).

This reduces LLM calls from one-per-hunk to one-per-file (plus one summary
call), while giving each file review the full picture via the MR summary
context.

Additional changes:
- Export `validateLogPath` from `invokeDiffReviewLlm` for reuse in the
  summary node
- Add "How it works" section to the review agent docs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@fatmcgav fatmcgav force-pushed the feat-improve-agent-llm-efficiency branch from 08481cd to 6bc5a12 Compare June 5, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant