dotFactory

Pull request triage automation: stop paying senior people to be a queue

By Simone Mosciatti

How do you triage pull requests automatically? Let an agent give every PR a quick first look, sort it into one of a few fixed buckets, and let the file decide what happens next.

Most teams that start using coding agents hit the same wall. The pull requests pile up, they all look alike in the list, and a senior engineer ends up opening each one just to work out what it is.

The fix people reach for is an agent that reviews everything. I get the appeal, but I think it's the wrong first move.

Review is expensive, and you can't afford to run it on every PR. Triage is cheap, and you can. So start there.

Part of the Patterns for a software factory series.

The cost of a pile of PRs isn't the reading. It's the sorting.

Someone opens a PR, scrolls, thinks "this is a one-liner" or "this touches billing" or "this is way too big", and closes it again. Multiply that by a team and you're paying people with a lot of context to act as a queue.

Agents make it worse, because they open PRs faster than anyone can read them. One engineer with a couple of agents can produce a dozen a day.

Triage doesn't ask whether the change is correct. It asks one thing: what kind of change is this?

That's all. It's a small workshop that does one job, and does it every time.

One step that fires on every PR, early. One step that reads the description and the changed files. One step that picks a bucket from a short, fixed list. One step that says why, in a single line. One step that hands the verdict to the rest of the file as data, and never merges anything.

Three buckets is plenty: small_fix, needs_review, too_big.

The verdict has to be data, not prose. If triage writes "looks fairly small, but maybe someone should glance at it", what is your next step supposed to do with that?

This is where I think determinism matters. The agent's wording can change from run to run, and I'm fine with that. But the prompt, the files it gets to see and the list of possible answers should all be known in advance.

In dotFactory, the answer is a choice from the types: a tagged value where each tag can carry its own fields. A when: guard branches on it with is.

So too_big can carry a hint on how to split, and needs_review can carry the area it touches. Anything outside the list is an error, not a surprise. I wrote more about this in typed outputs for AI agents, and the short, gentler version is typed dataflow.

The file

The trigger is a kind: github step that fires when a PR is opened, updated (synchronize) or reopened. An OpenCode step reads the PR through pr_context and returns the typed verdict. Each bucket then posts a review with github_comment.

type PullRequest = { number: int, url: text }
type TriageCall  = { token: secret, prompt: text }
type PrContext   = { title: text, body: text, files: [text] }

type Triage = choice {
  small_fix    { reason: text }
  needs_review { reason: text, area: text }
  too_big      { reason: text, split_hint: text }
}

type GithubAccess = enum { read, write, admin }
type GithubScope  = map(text, GithubAccess)

external port credential(key: text) -> secret
external port github_token(repo: text, scope: GithubScope) -> secret
external port pr_context(token: secret, repo: text, number: int) -> PrContext

runner triager:
  kind: opencode
  in:   TriageCall
  out:  open

trigger on_pr:
  kind: github
  config: {
    path:    "/api/github/webhook"
    target:  { one: { repo: "acme/app" } }
    event:   pull_request
    actions: ["opened", "synchronize", "reopened"]
  }
  out: { pr: PullRequest, commit: text }

step triage:
  runner: triager
  in:
    token:  credential(key: "triage")
    prompt: "Sort this pull request. small_fix: tiny, low-risk, one area. needs_review: a real change a person should read; name the area. too_big: too large to review well; suggest how to split it. Give a one-line reason. Do not review correctness."
    context: pr_context(
      token:  github_token(repo: "acme/app", scope: { "pull_requests": "read" })
      repo:   "acme/app"
      number: on_pr.pr.number
    )
  out: { result: Triage, summary: text }

step note_small:
  kind: github_comment
  when: triage.result is small_fix
  config: { event: "COMMENT" }
  in:
    token:  github_token(repo: "acme/app", scope: { "pull_requests": "write" })
    repo:   "acme/app"
    number: on_pr.pr.number
    body:   triage.summary

step note_review:
  kind: github_comment
  when: triage.result is needs_review
  config: { event: "COMMENT" }
  in:
    token:  github_token(repo: "acme/app", scope: { "pull_requests": "write" })
    repo:   "acme/app"
    number: on_pr.pr.number
    body:   triage.summary

step ask_to_split:
  kind: github_comment
  when: triage.result is too_big
  config: { event: "REQUEST_CHANGES" }
  in:
    token:  github_token(repo: "acme/app", scope: { "pull_requests": "write" })
    repo:   "acme/app"
    number: on_pr.pr.number
    body:   triage.summary

The model's key comes from credential. The GitHub calls use a scoped github_token: read to look, write to comment, nothing more.

Triage doesn't merge and it doesn't approve. It only posts a COMMENT or a REQUEST_CHANGES. Sorting a PR is not signing off on it.

too_big pushes back on purpose. A PR nobody can review well is a risk, so the file asks for a split instead of letting it sit. Agents are usually happy to redo the work in smaller pieces.

The comments are just the start. The same guards can start anything. Small fixes can go to risk-based review routing, and the ones that need review can go to an adversarial reviewer or a human approval gate.

If you also want GitHub labels, that's a small custom container step. I kept this example to review comments.

Where I'd skip it

Skip it when the volume is low and one person already knows every PR. You don't need a workshop for a queue of three.

Triage is also not a review. Don't let a small_fix tag stand in for CI, or for a reviewer on code that matters. The verdict will sometimes be wrong, so treat it as a sorting hint.

And if every push fires a new comment, it gets chatty. Trigger only on opened and reopened if that bothers you.

Triage and routing are different questions. Triage sorts by size and shape. Routing decides who signs off. They work well together, and they can even be one agent call if you want to save tokens.

The idea underneath is the one I keep coming back to: the agent can say anything, but the file decides what happens next. I wrote about that in Put your software factory in a file.

This is what I like about building a factory out of small workshops. A triage step is boring, it's cheap, and it makes every step after it simpler.

If you want to try it, copy the snippet into a .fct file and run it on dotFactory. The Getting started guide walks you through your first factory.

Frequently asked questions

What is pull request triage automation?

It gives every new PR a quick first look and sorts it into a bucket, like small fix, needs review or too big. Reviewers no longer have to open every PR just to decide what it is.

Can AI triage pull requests reliably?

It's good at judging the size and area of a change from its description and files. Keep the buckets few and fixed, and treat the verdict as a hint, not a sign-off.

Should a triage agent be allowed to merge small PRs?

No, triage should only sort and comment. If you want small PRs to land on their own, use CI-gated auto-merge, which pins the merge to the commit CI checked.

How is PR triage different from AI code review?

Triage decides where a PR goes, and review looks for what's wrong with it. They are separate steps, and triage is cheap enough to run on every PR, whether an agent or a person opened it.

Portrait of Simone Mosciatti

Written by

Simone has spent more than 10 years building software, from research at CERN to big tech at AWS and fast-growing startups like Rippling. These days he's building dotFactory, because he thinks writing software should feel a lot more like running a well-oiled factory.