Skip to content

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

Open
fatmcgav wants to merge 3 commits intosourcebot-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 intosourcebot-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 pipeline: a single MR summary pass followed by parallel per-file reviews that use that summary.
  • Improvements

    • Per-file reviews run with a concurrency limit (max 5) for faster processing.
  • Documentation

    • Updated agent docs and changelog to describe the new workflow.

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>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

Walkthrough

Introduces a two-phase review pipeline: a single MR-summary LLM pass over the entire PR, then per-file LLM review calls (parallelized, max 5 concurrent) that consume each file’s diffs, PR metadata, configured context, and the MR summary; documentation and prompts updated accordingly.

Changes

Cohort / File(s) Summary
Documentation
docs/docs/features/agents/review-agent.mdx
Describe two-phase pipeline (MR summary + parallel per-file reviews) and change manual trigger from /review to review.
Review Orchestration
packages/web/src/features/agents/review-agent/nodes/generatePrReview.ts
Precompute MR summary via generateMrSummary, append its context to per-file prompts, switch to bounded-concurrency parallel processing (max 5), include oldFilename in outputs, and aggregate settled promises with failure logging.
MR Summary Generation
packages/web/src/features/agents/review-agent/nodes/generateMrSummary.ts
New exported function to produce a cross-file PR summary via a single LLM call, with model selection, optional log output, and returns a sourcebot_context or null.
Prompt Generation
packages/web/src/features/agents/review-agent/nodes/generateDiffReviewPrompt.ts
Signature changed to accept sourcebot_diff[]; builds combined # Input with indexed hunks and renders multiple old/new snippets per file.
Utilities & Logging
packages/web/src/features/agents/review-agent/nodes/gitlabMrParser.ts, packages/web/src/features/agents/review-agent/nodes/invokeDiffReviewLlm.ts
Minor debug logging tweak and validateLogPath made publicly exported.
Changelog
CHANGELOG.md
Add 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 Review Agent\n(generatePrReview)
    participant MRLLM as LLM\n(MR Summary)
    participant FileLLM as LLM\n(Per-file Reviews)

    Client->>ReviewAgent: pr_payload
    ReviewAgent->>MRLLM: generateMrSummary(pr_payload)\n(entire PR diff)
    MRLLM-->>ReviewAgent: pr_summary context
    ReviewAgent->>ReviewAgent: iterate files (parallel, max 5)
    ReviewAgent->>FileLLM: per-file prompt + pr_summary + file diffs
    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

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
Title check ✅ Passed The title clearly and specifically describes the main architectural change: moving to a multi-phase review process with parallelized per-file LLM calls.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

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

Warning

Review ran into problems

🔥 Problems

Timed out fetching pipeline failures after 30000ms


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
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