RFC: Upstream Infrastructure for AI Review of PRs

A couple of us (@cardigan1008, @dtcxzyw) have been experimenting with using LLMs to assist in the review process. These efforts have been focused on different areas such as automatic crash/miscompile reproducer generation and programmer’s manual enforcement but overall are in the same vein of using LLMs to assist with reviews and are complementary. We want to propose building out some infrastructure in an upstream LLVM repository to generate these reviews so that we can consolidate our efforts. Our primary motivations here are to provide trivial style/nit fixes to save reviewer bandwidth (e.g., enforce coding standards and area-specific guidelines like the InstCombine contributor guide and the CI best practices page), and to catch critical bugs to improve the code base quality.

NOTE: We are explicitly not proposing automatically putting the generated review comments anywhere where they would be visible to PR authors by default (e.g., as GitHub reviews through an app). They will be visible through a website, but a PR author/reviewer would explicitly need to seek them out. In the future, if we are able to produce high enough quality comments and there is sufficient community interest, we can look into automatically/upon review request posting some of the review comments directly to PRs.

The Proposal

Based on the success of current generation infrastructure (e.g., GitHub - dtcxzyw/llvm-hackme · GitHub and GitHub - cuhk-s3/Archer: Archer: Agentic Code Review for LLVM PRs · GitHub ) and the success of LLM review tooling in other OSS communities like Sashiko ( GitHub - sashiko-dev/sashiko: Agentic review of Linux Kernel code changes · GitHub ), we think that building infrastructure upstream where people can pool their efforts and avoid building out duplicate boilerplate components would be useful for further experimentation in the space. In the past 10 days alone, llvm-hackme has found 21 critical bugs across 78 PRs ( Pull requests · llvm/llvm-project · GitHub ). Archer has found 38 bugs across 200 open PRs and an additional 36 bugs in 328 commits post-commit ( Pull requests · llvm/llvm-project · GitHub , not all issues have been reported in PRs).

We want to start building out said infrastructure in llvm-zorg under a top level folder (e.g., llm-review/ or another name if preferred). This is our main ask. I plan on setting up initial hosting on our (Google’s) end to run this infrastructure and we should be able to provide enough resources (CPU+tokens) for experimentation. It’s also likely we should be able to provide enough resources for full scale usage, but given possible approvals needed, I don’t want to make any hard promises at this time. It will partly depend on resource-usage data from the experimentation phase, but token demand will likely be elastic in that if we run into cost issues we can optimize our usage. In addition to building out the infrastructure in llvm-zorg, we also plan on putting review “skills” in the monorepo under llvm/utils/review_skills. This makes it easier to keep in sync with code/other documentation, and can also help with local development as they are more easily available to IDEs.

Architecture

Fundamentally when reviewing a PR you have a couple elements that you can provide as input including the PR title, description, and diff. You also have one main form of output in the form review comments, which can either have a file/line number attached to be inline, or omit a file/line number to attach to the PR more generally. There are also a couple more common elements the review infrastructure is likely to need such as a build of LLVM with the PR applied for running opt/llc. It’s also important to note that different areas will have different review requirements and allow for different tooling. For example, InstCombine has its own contributor guide ( InstCombine contributor guide — LLVM 23.0.0git documentation ), only middle-end changes/IR only backend changes would benefit from Alive2, and some backends have support for translation validation (e.g., https://web.ist.utl.pt/nuno.lopes/pubs/armtv-oopsla25.pdf, https://youtu.be/znMGXxQC12A?si=3u9Xh_OdyGo75wFH).

Given the diversity in the project, we propose a pluggable architecture that allows for the addition of subagents that can trigger on certain criteria (e.g., a PR touches a certain file path). Subagents would then be responsible for taking in the contents of the PR and generating review comments (e.g., inline comments on style issues, or whole PR comments with validated miscompile/crash reproducers). This also makes it easy for different areas of the project to customize such infrastructure. For example, if I notice a couple of common issues in PRs submitted against llvm-exegesis, it would be easy for me to write up a prompt/subagent to generate comments pointing out such problems and run it on PRs touching llvm-exegesis.

In terms of the actual compute infrastructure, I think running this on a k8s cluster where review jobs get scheduled as separate pods makes the most sense. This would follow the design of the current premerge infrastructure and allow for easy autoscaling. Given in many cases we want to be able to build LLVM and run tools like Alive2, the CPU compute requirements might not be trivial, so autoscaling is important for efficient resource usage. Scheduling jobs as separate pods also allows compute requirements to scale based on what the PR touches and what the requested subagents need. For example, a PR touching a subproject that does purely LLM based review will need little CPU and can be scheduled on a lightweight pool. In addition to a hosted service, we also plan on ensuring that the infrastructure can be run locally to aid in development and also to allow people to get reviews before ever posting a PR.

We plan on having reviews triggered automatically (review is used generically here, this proposal does not include publishing anything to GitHub) through a polling mechanism that looks at new GitHub PRs for select subcomponents. Only people marked as contributors (have landed at least one commit) on LLVM will have reviews automatically requested.. This is for security reasons given we perform an LLVM checkout/build which allows for arbitrary code execution. While this is not a particularly hardened setup, we consider the security risk here acceptable, like premerge. Eventually (i.e., in a separate RFC), we would like to propose enabling contributors to request reviews natively in GitHub using a flow similar to how one requests CoPilot reviews currently.

In terms of foundational dependencies, we plan on using the Google ADK to interface with LLMs. It provides all the features that we need (e.g., tools), is reasonably standard currently, and is not specific to Google’s models. For example, it is trivial to write up ADK to use Claude instead of Gemini as the underlying LLM. We do plan on using Gemini models initially given they are easiest for us to get tokens for, reasonably performant, and do not have any major ToS concerns (with Vertex AI, data we send in is not used for training and we are allowed to do as we please with output). We will also need a simple web interface to display review comments, but I feel the exact choice of web server package does not matter too much here and we can go with whatever the implementers have the most experience with.

FAQ

Why llvm-zorg?

We discussed amongst ourselves whether we wanted a separate repository or if we want to put code in llvm-zorg. I advocated for putting all of the infrastructure pieces in llvm-zorg given it is the home for all other LLVM infrastructure that does not make sense to have in the monorepo, there is already some existing art in the form of the LLVM bazel bot, and I think using a separate repository adds additional unnecessary friction (e.g., permissions questions around the llvm-wg repo) that we can avoid entirely if we just also use llvm-zorg. I do not foresee this codebase becoming big enough to warrant its own repository either.

Some of these subagents seem more useful than others. Why have all of them?

Alive2 validated miscompiles generated by an LLM are of course likely to be more useful than LLM generated style comments or other forms of pure LLM review. I think the key here is that the information is pluggable, which allows us to experiment with different approaches. If the community wants to have some comments posted automatically upstream, but not others, the infrastructure will fully support that.

Why not use an existing LLM-based review system?

We have tried/seen existing LLM review systems that have native Github Integration such as Gemini, CodeRabbit, and CoPilot. They typically provide very poor-quality reviews, sometimes being outright wrong. We believe the key to good reviews based upon systems like Sashiko is in tailoring prompts (e.g., our coding standards, alive2, llubi) and tooling to LLVM specifically. This is only possible by building out some level of custom infrastructure.

Why upstream?

There is also the question of why doing this under the LLVM umbrella when this is still in the early stages rather than a downstream prototype. I think there are two main reasons for this: productionisation and collaboration. A lot of the ideas (e.g., LLMs to generate test cases that cause crashes/miscompiles) have already been prototyped and have proven to provide real value. Other ideas that we have done some experimentation with (e.g., automated coding standard comments) have shown some promise but need more evaluation. These ideas all share a lot of common infrastructure though and it would be nice to reuse it.

There is also sufficient interest from various groups that I think upstream collaboration makes sense.

17 Likes

Thanks for writing this up and working on it! I think this could be really helpful.

I think keeping LLM output out of the PR comment UI is the right call.

The bug finding / hackme tools are effectively test case generator services. It might be possible to take this idea really far, where the LLM pulls the PR to another fork, and then directly adds LLVM-style test cases on top of the PR, and the author simply adds the remote and pulls fresh test cases to their PR and keeps going.

I would certainly welcome LLM assistance with review in general. I think the true value would only come when it appears automatically in the PR UI, because that will help the less experienced contributors in particular, who are most likely to make mistakes and not know about any alternative interface (though the comment could come in the form of a link to another page of course).

The specific cases I can immediately think of are that an LLM would likely easily detect without high false positive rates are:

  • Missing Command Guide documentation for new tool options.
  • Areas where the code doesn’t conform to LLVM coding style (we have clang-format automate for some of the style guide, but chunks of the style guide aren’t covered by tools, e.g. our warning/error message style, or aren’t currently integrated, e.g. naming style).
  • Missing test cases for some code paths.

These are cases that I repeatedly pick up when reviewing in the areas I am reviewing in (primarily the binary utilities). Having these detected and reported before I even come and look at the PR would save my time. I’m sure there are other cases too.

This looks really interesting!

As most of LLVM developers probably experience, the bottleneck in progressing LLVM (or many other large pieces of software) is mostly not creating new code; but rather reviewing/testing/verifying/maintaining/understanding/explaining new and existing code and design. I am really happy to see someone exploring agents to help with those tasks, focussing on one of the main bottlenecks in LLVM development.

Do I understand correctly that the current sub-agents you have in mind (llvm-hackme and Archer?) focus mostly on correctness aspects?
It seems to me that review of patches (especially for runtimes) from a security point-of-view might also plausibly be valuable (one plausible tool that could be used for it could be https://github.com/arm/metis)?

I’m assuming that currently there may not be great agents to assist with aspects such as “taste”, modularity, maintainability, ease-of-understanding-by-humans, appropriate documentation, recording of design intent, etc?

Thanks for preparing the RFC @boomanaiden154-1 and for your support @kbeyls @jh7370 @rnk.

Although the RFC tentatively assumes we would use llvm-zorg, some of us would prefer a separate repository under the LLVM umbrella to host the new, agent-based infrastructure. Such a repository could:

  • Provide support for an LLVM-specific agent runtime, analogous to computer-use and browser-use.
  • Aggregate decorators/wrappers/combinations around LLVM tools that are especially useful to agents.
  • Contain transformed resources, references, and maintainer/reviewer experiences that are helpful for agents but not suitable for the llvm-project monorepo.
  • Based on the above, the lightweight PR review agent hackme and the heavyweight PR review agent Archer.
  • Potentially host agents for other purposes beyond PR review (for example, automated test-case reduction).

A separate repository would also make it easier to filter out issues unrelated to agents, keep a clear scope, and plan for future extensions.

This is still an open question, and we’d very much like to hear the community’s thoughts and preferences.

2 Likes

+1 to this.

Previous experience shows that different versions of the same model gives wildly different results. Would be good to show somewhere the version and setup info of the public service, so that people can verify the fidelity of their reproduction.

The reverse is also true: once you build the infra, you’ll age faster than public services. Our previous experience with Phabricator vs. Github is why we’re here now.

Not a negative to this proposal, but we have to acknowledge that this effort will be made stale reasonably quickly, so it either needs to have a continuous effort behind, or a migration plan once it’s deemed necessary.

Agree, from an LLVM point of view. Though, at the same time, we don’t want to encourage other people to fork this work (like we did with Meta’s Phabricator), and then make both irrelevant.

Perhaps this is an argument to avoid llvm-zorg, since if it’s separate and people outside of LLVM gather interest, it would be easier to move it out to an org of its own and we become mere users and collaborators, but not outright owners.

I would definitely not put the LLM output in the PR comment UI, at least to start.

Besides the fact that there are contributors that don’t want anything to do with LLMs currently and their opinions should be respected, there is a clear risk of prompt injection attacks that the community isn’t suited to address yet in implementing a homegrown solution in a public-facing CI. Hiding the results from potential attackers doesn’t remove the risk entirely (there’s always blind injection attacks) but it considerably impedes them.

I also personally think having a separate repo for the agent-based infrastructure is a better approach from the standpoint of context management. It also reduces disruption to vendors who already have their own AGENTS.md/skills set up in their downstream repos and respects customers who want nothing to do with AI.

1 Like

Regarding this thread, this is why we want to keep things out of GitHub for now and propose exposing comments directly to GitHub later, if at all. By that point we will have even more data about how well things work and can scope a more narrow proposal. I think it would be useful to directly expose through GitHub for discoverability purposes, but how exactly I think is an open question (for later discussion). We could do a single comment with a link, a fully native review, or possibly something else entirely.

In terms of prompt injection risk, the security model is going to be similar to premerge, which already runs arbitrary untrusted code on our infrastructure. Those who have landed a commit in tree (marked as contributors on GitHub) will automatically have reviews run. New contributors will need someone to manually approve the run after looking at the code to ensure there is nothing anomalous. This is exactly how premerge works today. The infrastructure will also be sufficiently isolated such that completely replacing it will not be a big deal with the only main lucrative targets being compute resources for which we will have monitoring setup, and potentially in the future a well-scoped GitHub app private key. So I don’t think prompt injection risk is a big deal.

In terms of respecting those who don’t want to see any LLM output, I think it depends on what sort of output we want to push. I think if we want to do something like automatically push verified miscompilation/crash reproducers with zero LLM text surrounding them, that would probably not be an issue, and in fact @cardigan1008 and @dtcxzyw have been publishing such messages on PRs manually. But we definitely don’t want to be publishing slop anywhere, and especially not to GitHub. I’m tired of it, a lot of other people are tired of it, and it doesn’t do anyone any good.

I guess those are my thoughts on the topic. With this proposal no comments will be automatically posted to GitHub, and any such posting would be discussed in a separate RFC, so a bit of a moot point, but I guess doesn’t hurt to discuss.

1 Like

I don’t see why llvm-zorg is a bad fit for any of these reasons. llvm-zorg is essentially a monorepo similar to the core llvm-project. There are top level folders that are somewhat independent projects. For example, there’s the buildbot infrastructure, there is the premerge infrastructure, and then there is even the Google Bazel Bot, and all are completely independent. We can put whatever we want in a top-level folder or potentially even create multiple if people think it makes sense. Given creating new repositories under the LLVM umbrella is not a well-ironed out process, I think avoiding the additional overhead of doing so would be nice.

Issue filtering can easily be accomplished with labels. The issue flow through llvm-zorg is already extremely low, so it would not be hard to manage. We somehow manage with the main llvm-project where we have a huge volume of issues distributed among somewhat independent subprojects.

I don’t think context management really matters here. Almost the entirety of the context should be coming from llvm-project (both prompts and code). We also want to put skills in the monorepo for discoverability. I don’t think where we put them (probably llvm/utils/review_skills) would interfere with anyone’s downstream skills. I also do not think it would be disruptive to people who want nothing to do with AI. Most people already don’t look at anything inside of llvm/utils (hence why we have python scripts that have never supported python 3 at least up until recently).

I’m not sure Phabricator vs GitHub is a good comparison here. Both provide essentially the same service (code review). We’re looking at custom infrastructure here because we want to customize this deeply to LLVM’s needs. For example, not many other projects would benefit from tool usage like Alive2 and llubi. The actual infrastructure should not end up being overly complicated (I would expect a month or two of implementation from a single person for the core of the infrastructure and less for a MVP).

For now, I think there will be a continuous effort behind it. There are multiple upstream contributors interested in driving this. If it ends up showing little value and going stale then I guess we call it a failed experiment and move on, but I don’t think that’s a likely outcome.

I don’t think there will be much interest outside of LLVM. The infrastructure is not going to be overly complex and quite tailored to LLVM. There aren’t many projects I would imagine wanting to fork it.

llvm-hackme sends crash/miscompilation reproducers and requests changes automatically. These reproducers are double-checked by deterministic oracles.

5 Likes

I agree that an LLM based solution could definitely help with review in these areas. I’ve done some initial experimentation on a coding style agent and have had pretty good success on generating review comments that point out real style issues (including some that I missed on a first pass). The idea is that the infrastructure is pluggable so one can either modify an existing review prompt or add an entirely new subagent that triggers on whatever paths/conditions to do these sorts of reviews.

I expect that certain areas where maintainers are interested in this would naturally grow their own review skills that are then run automatically. For example, I review a lot of the GitHub/CI PRs. We have https://llvm.org/docs/CIBestPractices.html which outlines what people should be doing, but there are often a lot of mistakes (including from me). An LLM should be able to easily do a first pass review and ensure compliance with what we have deemed as best practices.

I at least plan to work on sub-agents/review skills for GitHub Actions and the programming standards, so not entirely, but yes, a large focus will initially be on correctness aspects.

I definitely agree. I’m not sure we are going to have time and/or sufficient security experience to work on this initially for runtimes, but the infrastructure is designed to be pluggable, so it would be easy to add another agent and/or review skills that are specific to the runtimes.

Yes. We intend to scope review to things agents are good at and empower humans to do the aspects of review they are good at. This is intended to supplement human review and make it easier (or at least try and reduce the defect rate), not replace human review. I think an LLM might not be terrible at suggesting something should be documented in some cases or pointing out that documentation of design intent is insufficient in others, but there is certainly a lot of things LLMs are not likely to be good at, especially things like maintainability.

Agreed. I think it would be easy to include version numbers of all the tools being used somewhere, and is something that we plan on doing.

I was comparing your proposal with plain Github Copilot. You mention it’s not good enough (and I agree), but this is where the comparison matches: Github PRs were not good when we had just moved to Github, but soon our efforts in Phab waned and Github got “good enough”. Removing Phab was the right thing because we had outdated tool with no maintainers.

I’m not saying this will happen, just that there’s a long term cost of creating any personalized tools that we need to take into account. To be clear, even if it does happen, moving to Copilot would be a much smaller effort than Phab->PR. Especially if we keep things separate, as you propose.

For now, I think we can say that’s not a likely expectation (because we’re all excited with the new functionality), but over time the likelihood of that happening tends to increase, not decrease. :slight_smile:

I would still do it in a separate repo, but I don’t particularly mind if it goes into Zorg. Just raising the issue. It’s enough for the infra folks to be happy with it.

This is fine by me. To be clear, my comment was more about the ideal world and perhaps a long-term goal, rather than what we should do from the start, precisely for the reasons you’ve outlined. I do note that I’ve seen some contributors getting GitHub CoPilot to post review comments directly in PRs already, but I think that’s an orthogonal discussion.

1 Like

[edited to tone down]

It is incredibly frustrating to see this RFC. The prior RFC that introduced LLM copied content, was positioned as a one off for a trivial task. I raised concerns at the time that that RFC felt like an attempt to get a precedent for further expansion of LLM tooling into the project, and this RFC appears to confirm that. There was never any intent to restrain the expansion of the unethical tools, but rather to continuously push this slop into the project.

The result of this continued expansion is that it forces everyone involved in the project to be complicit in the unethical nature of these tools. For example: I believe it is unethical for code derived from other projects to be included in LLVM without credit or complying with the license, yet the use of these tools in the repository makes that mandatory for me if I wish to continue working on llvm and clang.

I would like the people who push this to at least acknowledge that what they are doing is forcing everyone else to use these tools. We may not be using it directly, but we’re now working in a codebase including stolen work of others? Even though “review” tools don’t generate code, they’re built on top of copied code for which they don’t follow the license, and as such those reviews are themselves unethical.

5 Likes

Some time ago in the AI discussion there was a sub-thread on this. IIRC, the agreement is that this is up to the PR author, and if they’re comfortable with Copilot reviews, we won’t stop them from using it.

But yes, Copilot reviews go straight into the PR (which is the whole point).

We had discussion that Copilot review is a violation of our AI policy (since there is no human in the loop verifying those comments before they are posted) but unfortunately there is no way to disable/bad Copilot reviews. We can just ask people to turn them off and hide those comments if found disturbing (mostly they are distrubing IMO)

1 Like

Discord discussions don’t reach a lot of people, so if something is important, I strongly advise to have the discussion here in the forum. The one I referred to was in the main AI policy thread.

On the discussion you linked, my impression is not as clear cut as you say. This is an option explicitly selected by (and often paid by) the author to do those reviews, and the human in the loop is the author themselves. That doesn’t seem to violate our policy because, AFAIU, no code is merged without the author accepting them.

This has the side-effect of pushing AI reviews to reviewers of those PRs, so it may exacerbate the problem, especially if the PR itself was written with assisted by AI tools. The policy allows reviewers to mark PRs as extractive, and I would extend that to AI reviews, too, if that makes the PR unusable / unreviewable.

Now, back to the topic of this thread, this is precisely why the proposal is not to have any interaction on PRs at all. I personally think a single comment with a link to the analysis (and a caveat that this is experimental, etc) would be fine, but I agree this may be a step too far at this stage.

If we treat these tools for what they are: an imperfect analysis that needs to be triple-checked by humans, then they can be useful and we don’t violate the AI policy.

1 Like

@waffles_the_dog. You’ve consistently tried to make your point on any thread about AI usage. However, the community has agreed that, subject to policies that have been agreed by consensus, it is acceptable to use LLMs. Repeating your belief that we shouldn’t use them at all on anything that even remotely goes near LLVM on every single thread about the topic in the way you do, is not helpful.

I want to understand why this keeps coming up - the lack of respect for the rest of the project, or in any of the projects these tools steal from, remains stunning

Simple: people do not share the same views as you that LLM tools are stealing from this or other projects, nor do they view them as “unethical slop machines”. Do they have problems? Yes, of course (and I don’t think anybody disagrees with you on that).

Please stop trying to force the inclusion of acceptance of this unethical behavior on the project.

Nobody is forcing it on anybody. What they are doing is starting a discussion as to whether this specific use-case is acceptable or not. You are welcome to disagree, with constructive comments. If the wider community agrees with you, then the proposal will be rejected. If it doesn’t, then it will be accepted. Move on and accept the decision in this case (and if you can’t, there’s nothing stopping you from forking LLVM and trying to start an LLM-free version).

“we’re willing to violate OSS licenses to help with our bazel files”

You may believe that LLMs violate OSS licenses, but plenty of companies with highly paid lawyers disagree with you on this. I’m assuming, though I don’t recall any specifics, that the LLVM foundation has also consulted on the general topic and determined that it’s fine. Stating that people are deliberately violating OSS licenses is going a step too far therefore, in my opinion.

At the same time I said that that RFC felt an attempt to get an initial foothold to justify further forced “consent” for the use of these tools.

I would argue that your claims that people are deliberately trying to get initial footholds to allow them to use more of these tools is equivalent to you saying that people are making RFCs in bad faith, which to me is a borderline code of conduct violation (specifically of the “be respectful” aspect of it), given the lack of evidence that they are doing so. You may fairly argue the slippery slope aspect of things, but not that people are deliberately trying to force it.

We are never bound by decisions that have been made in the past. We can revisit decisions as we come to understand things better/people’s beliefs change based on experience/new technologies and so on. If you really feel that the creation of this RFC somehow invalidates the agreement in the previous RFC, direct your comments back to that RFC or to a new thread, so as to not derail this RFC, which should be judged on its own individual merits.

8 Likes