# Leave dry run

> What dry run records, how to read what a review would have posted, how to switch to posting, and how later reviews and their threads work.

Web page: https://visto-ai.com/docs/leave-dry-run/

In dry run, Visto AI runs every review and records it in its database, and **posts nothing to GitHub**. It is the safe way to start: you can read what each review would have said, check its scores and findings, and tune the config before anyone sees a comment. Dry run is the default: the service posts only when `dryRun` is written as `false`.

When you leave dry run, reviews are posted, later reviews follow up on the threads of earlier ones, and commands such as `/review` are answered on the pull request.

## What dry run does

- Every review runs as it would live, model calls included, and is recorded with its body, its inline comments and its cost.
- Nothing is read from or written to review threads. Every head is reviewed in full and scored afresh.
- A `/review` from someone with access is reviewed and recorded like any other job, in full, and nothing is written on the pull request. A head and base that already have a recorded review end the job as `already_reviewed`.
- The [merge gate](https://visto-ai.com/docs/merge-gate/) writes no check. A gated pull request still gets no review on a push, and `/done` works as `/review`.
- [Extension modules](https://visto-ai.com/docs/extension-modules/) are asked for context, but their notifiers are not told of reviews and their sinks are not told of alerts.

## Reading what a review would have posted

Every attempt at a review, finished or failed, is a row of `visto_ai.review_runs`:

```bash
docker compose exec db psql -U postgres -d visto -c "select id, owner, repo, number, outcome, cost, body from visto_ai.review_runs order by id desc limit 5"
```

| Column | What it holds |
|---|---|
| `body` | The text the review would have posted (or did post, out of dry run). |
| `comments` | The inline comments, and the [inline notes](https://visto-ai.com/docs/inline-notes/) when they are on. |
| `outcome` | How the run ended. |
| `cost` | What the model calls cost, as recorded (see the daily limit in [Running the service](https://visto-ai.com/docs/running-the-service/)). |

With the [UI](https://visto-ai.com/docs/the-ui/) on, Activity lists the recent reviews and the page of one review shows each file's score, the findings and the usage, marked as a dry run.

## Switch dry run off

Check the app's permissions first (see [Permissions](#permissions) and [Create the GitHub App](https://visto-ai.com/docs/create-the-github-app/)): from the switch on, the service writes to GitHub.

Then do one of these:

- **In the config file:** set `dryRun: false` and restart the service.
  ```yaml
  dryRun: false
  ```
- **In the UI:** in Settings, under General, switch Dry run off and save. Dry run is read once at start, so the page says `Saving this restarts the service.` and the save restarts it: the running reviews finish, the process exits with code 75, and its supervisor starts it again. Compose does this with the `restart: unless-stopped` of [compose.yaml](https://raw.githubusercontent.com/visto-ai/visto-ai/0faf484aa43f4fcdc1f30c1d5c056ea26c1c0d32/compose.yaml). A process run with no restart policy stays stopped, so give it one. Until the new start, the setting reads `Takes effect when the service restarts` and the sidebar still says `Dry run`.

### What happens at the switch

Nothing is posted at the switch itself. A review recorded in dry run is never posted later. Each open pull request gets a posted review at its next event: a push, a reopening or a `/review`.

Jobs that were waiting run as before and now post. After a stop, the service reads GitHub's delivery log (at most 10 pages) and asks again for the deliveries GitHub could not make, at most 200, so the pull requests they name are reviewed and posted.

## How a review is posted

Each review is posted once, as a comment review pinned to the commit it was computed for, with its inline comments. With [automatic approval](https://visto-ai.com/docs/automatic-approval/) on, it is posted as an approval when every condition holds.

If GitHub refuses the inline comments, the review is posted with their text in its body instead. With inline notes on, the notes are dropped first (see [Inline notes](https://visto-ai.com/docs/inline-notes/)).

### Asked first

Before computing a review, the service asks GitHub which reviews of its own the pull request already has, so it never pays twice for one it posted (this is skipped when a recorded review is waiting to be published):

- A review on the live head that the database does not know ends the job as `already_reviewed`.
- A review on another commit is recorded as posted when the database holds an unpublished review of that commit, and is otherwise logged as `unknown_review`.

## Reviews after the first

After its first review, a pull request is reviewed again when its head moves, when its base moves, and on `/review`. Pushes are reviewed after 180 quiet seconds, so pushes inside that window share one review. A draft, an ignored author, a filtered base branch and the daily limit stop a later review as they stop the first.

The exception is a pull request on a branch gated by the [merge gate](https://visto-ai.com/docs/merge-gate/) in `enforce` or `bypass` mode: it is reviewed only when someone asks.

### Which kind of review runs

The last review is the pull request's newest posted review that is not a re-check. The first rule that applies decides:

| Situation | Review |
|---|---|
| There is no last review, or its base branch is not the current one (or was not recorded) | **Full**, as the first was |
| A `/review` on the head and base of the last review | **Re-check** |
| Anything else | The repository's `newHead` setting: `incremental` or `full` |

`newHead` defaults to `incremental`. On a gated pull request (the gate is enabled, the base branch is in its `branches`, and the mode is `enforce` or `bypass`) it defaults to `full`. In `shadow` mode, and on a pull request that is not gated, it defaults to `incremental`. You can set it for all repositories or for one, in the config or in the UI's Settings, where a saved change applies at the next review (see [Configuration](https://visto-ai.com/docs/configuration/)).

```yaml
repositories:
  defaults:
    newHead: full
```

### What a full review reads

A full later review reads every file again, as the first did, and costs about as much. A moved file that already has its score is not read. A file whose diff a posted review already read, with every block already scored, is sent last, and the model is told which hunks are scored so it is not asked for them again.

### What an incremental review and a re-check read

They read:

- the files with a thread due a verdict;
- the files whose present diff no posted review has read: new files, files whose diff changed, and files moved or renamed with the same change.

They do not read a file whose diff a posted review has read and whose blocks are all scored, unless one of its threads is due. A file that only moved, once it has its score, is not read in any mode. For each file read, the request names the lines that changed since a posted review last read it, and carries the last review's overview, which costs input tokens.

**The trade-off:** a defect that the first review missed, in code that has not changed since, is not found by a later incremental review or re-check. Either the file is not read again, or a major on an unchanged line is listed and not posted (below). Set `newHead: full` to read everything at every head, and pay for it.

### The order of files

In every mode, the files with a thread due come first, then the files no posted review has read as they are now, then the rest. A pull request too large for one review is therefore covered over several. A file that finds no room and that no earlier review covers is listed under `Coverage` as not reviewed and counts as 100. A file that an earlier review covers and that finds no room keeps its scores and is not listed.

### Findings on unchanged lines

Whether a line has changed is measured per file, from the last posted review that read the file, by comparing its content then and now. When the earlier content cannot be read, or the file is new to the history, every line counts as changed. A finding moved to a neighbouring line to be placed counts as on changed code if the model raised it on a changed line. A line that enters the diff without its own text changing, as when the base branch moves under it, counts as unchanged.

In an incremental review or a re-check, a finding on an unchanged line is handled by severity:

| Severity | What happens |
|---|---|
| Blocker | Posted as usual. |
| Major | Listed in the body under `On code unchanged since the last review`, after `Findings`, and not posted as a comment. |
| Minor | Dropped. |

A full review posts them all, and only counts the blockers and majors among them in the log.

### How the review opens

- An incremental review opens with `**Incremental review** of the changes since` and the first 12 characters of the last review's head; after a `/review` it adds `requested by @<login>`.
- A re-check opens with `**Re-check** requested by @<login>.` and says whether earlier threads were judged again, none was waiting, or none could be judged.
- A full review opens with a line only when it was asked for with `/review`.

### A push with nothing new

When an incremental review started by a push or a change of base would read no file, owes no thread a verdict, and would show a person exactly what the newest posted review shows (the same score for every file, the same parts to read, the same files not reviewed), nothing is posted and the job ends as `nothing_new`. With automatic approval on, this does not apply when the newest posted review was an approval (see [Automatic approval](https://visto-ai.com/docs/automatic-approval/)).

The run is recorded without a body. It stores no scores for other pull requests, since every score in it was kept from an earlier run. The older review stays the newest one, so the next push is measured against it, and a `/review` on that head is not a re-check. A `/review` itself never ends as `nothing_new`: it gets a review, in the mode a push on that head would get.

### A head that was already reviewed

A push to a head and base whose review is the pull request's newest posted one is not reviewed again (`already_reviewed`). A head that comes back after another was reviewed (a force-push back, or a base changed and changed back) is reviewed again, against the newest review rather than the older one it matches. It is posted, unless it would show exactly what the newest one shows, in which case a push's job ends as `nothing_new`.

## Earlier threads

Before a later review is computed, the service reads the pull request's review threads from GitHub's GraphQL API. A thread is the service's own when its first comment is a finding it posted and the database holds.

### Which threads are judged

A thread is judged when its finding is a major or a blocker and the thread is not settled. A thread is settled when it is resolved and either a person replied in it or the app resolved it (GitHub names the app as the one that resolved it, and the app's own reply with its hidden line stands in the thread). With automatic approval on, the approval's thread rule must accept it too (see [Automatic approval](https://visto-ai.com/docs/automatic-approval/)).

### What the model is shown

The model is shown each of the service's own threads on a file it is shown: a judged thread with its replies, the others without them. For a judged thread, only the last 30 replies are shown, each cut at 2,000 characters.

A thread is not shown on a file that moved without a change, or when a file and its threads do not fit one call; in both cases it gets no verdict in that review. When they do not fit, the file's test goes first, then its full contents, then its threads; when the threads go, the test and the full contents come back if they then fit.

The threads' text is part of the call and is paid for. A judged thread can take about 22,000 tokens, and anyone who may comment on the pull request writes that text.

### Verdicts

For each judged thread the model may give one of three verdicts:

| Verdict | Rules |
|---|---|
| `fixed` | Needs a reason. Dropped when the review is of the head the thread was opened on. |
| `answered` | Needs a reason, and a reply in the thread by someone other than the app. |
| `open` | The finding still stands. |

A verdict is kept only for a judged thread.

### Replies in the threads

Once the review is posted and its job is finished, the service writes its verdicts into the threads:

- `fixed` or `answered`: a reply opening with `Fixed.` or `Answered.` and ending with a hidden line that names the review and the commit.
- `open`: a reply opening with `Still open.`, only when someone other than the app wrote last and the model gave a reason.

When the app's own reply is already last in the thread, a `fixed` or `answered` verdict rewrites it instead of adding another. An `open` verdict rewrites a confirmation to open with `Open again.`, and writes nothing after the app's own `Still open.` or when the thread has no reply.

Nothing is written into a thread where someone other than the app wrote after it was judged. It is judged again at the next review of a new head or base, or at a `/review`.

Writes are made one second apart. A write that fails is logged as `thread_write_failed`, is not tried again, and changes nothing else. The threads are read again just before the writes. If that read fails, if recording the publication fails, or if the service stops between posting the review and writing, no reply is written and nothing tries again; the threads are judged again at the next review of a new head or base.

### Findings already discussed

A new blocker or major finding that an earlier thread already raised is listed under `Already discussed`, with a link to the thread, and is not posted. A minor one is dropped without being listed.

A finding counts as already raised when an earlier thread on its file lies within 3 lines of it, on the same side of the diff, and is of the same class (blockers and majors together, minors apart). For a thread whose line is no longer in the diff, it counts when the thread quoted the same code. A minor thread never swallows a blocking finding, and a thread whose last verdict is `fixed` swallows nothing.

When a thread was due a verdict, the `Overall` line counts the threads cleared, still open and not judged.

### When a reply is judged

A reply is judged at the next review, not at once. Only a push, a change of base or a `/review` starts a review. On a gated pull request, the [merge gate](https://visto-ai.com/docs/merge-gate/) reads replies and resolves straight away for its check.

## Resolving threads

When the app has `contents` write, it resolves a thread whose verdict cleared it, after its reply landed. Without that permission the reply stands and the thread stays open, so it is judged again at each later review and the app's reply is rewritten each time. The service logs `feature_off` with the feature `resolving` at each start and raises an alert of that name.

The service reads the app's permissions once, at start, so restart it after changing them. It reads the permission the app asks for, not what each installation has accepted: until the owner accepts it, each resolve is refused and logged as `thread_write_failed` with `github_forbidden`.

## The /review command

A comment asks for a review when its first non-empty line is `/review`, in any letter case, alone or followed by a space and more text. Only an owner, a member or a collaborator of the repository is listened to. On a private repository (not an internal one), where only people with access can read, GitHub's NONE or CONTRIBUTOR for a person is read as collaborator: GitHub sends those for an organization member who keeps the membership private. A bot's command is ignored. A draft, an ignored author and the base-branch filter do not stop it.

- On the head and base of the last review, it is a **re-check**: the earlier threads are judged again, and files that no posted review has read as they are now are read (see [What an incremental review and a re-check read](#what-an-incremental-review-and-a-re-check-read)).
- On any other head, it gets the mode a push would give it, with the earlier threads.
- It is never ended as `nothing_new`.

An accepted command gets an eyes reaction. A refused or failed one gets a confused reaction and one sentence with a short code:

| Code | Kind | Meaning |
|---|---|---|
| `not_allowed` | Refused | The commenter is not an owner, member or collaborator. |
| `closed` | Refused | The pull request is closed. |
| `already_reviewed` | Refused | GitHub lists a review of the app's own on this head that the database does not know. |
| `head_moved` | Failed | The head moved while the review ran. |
| `review_failed` | Failed | The review failed. |
| `publish_rejected` | Failed | GitHub refused the review, even without its inline comments. |
| `render_failed` | Failed | The review's text could not be written. |
| `superseded` | Failed | Another job for the pull request was waiting when this one was put back. |

An answer is written once: when GitHub refuses it, the log says `answer_failed` and it is not tried again.

### Starting over

A command whose review ends because the head moved (`head_moved`), or ends without a posted review while the pull request's stored head is no longer the one it reviewed, starts over once: a new job for the new head takes its place, with the same requester and comment. It starts over only when the stored pull request was updated after the review started (GitHub's update time against the service's clock). A stored head that is merely behind, because the push's event has not arrived yet, starts nothing, and neither does a push whose event arrives only after the failure. The command that starts over says nothing; the new job's end answers. A command that has started over does not start over again. This costs one more review, with or without a gate.

### Commands that get no answer

- A command from someone without access that arrives while the pull request already has a job waiting (it is not stored).
- A command replaced, while it waits, by a later `/review` from someone with access.
- A command whose job was dropped because the pull request is gone (`not_found`) or no installation is known for it (`no_installation`).
- A command whose job the service gave up on: it ran out of starts or grew too old.
- A command whose job was cut by a restart, or met a database error before its review, while another job for the pull request was waiting.
- A command whose pull request was closed while the review ran.
- A command the service could not record.

A refused command from a stranger can still start a review: when no run is recorded yet for the head (no review and no failed try), the refusal gives that head its automatic job, since the command may have stood in the way of a push's job.

## Permissions

Beyond what dry run needs, posting needs `pull_requests` write and `issues` write. To resolve threads the app also needs `contents` write, which is optional: without it the app still replies. The manifest of `npm run app:create` asks for all three.

Other features need more:

| Feature | Needs |
|---|---|
| [Merge gate](https://visto-ai.com/docs/merge-gate/) | `checks` write and the event `check_run`; `statuses` read when `requiredChecks` are named; the organisation permission `members` read when a skip team is named |
| [Automatic approval](https://visto-ai.com/docs/automatic-approval/) | `administration` read, to read whether the base branch's protection dismisses stale approvals |

The manifest asks for these too. At start the service logs `feature_off` once for each thing a feature lacks, raises an alert of that name, and keeps running.

## Mentions and HTML in posted text

The service keeps text the model wrote from pinging people or rendering as HTML. Outside fenced code blocks, it puts a zero-width space after the `@` of a mention, after a `<` that could start HTML (one before a letter, `/`, `!` or `?`), and after the `&` of a character reference. This also applies inside inline code, so copying such inline code copies the invisible character.

Links are left as written, with these exceptions:

- In an address (text with `://` before it and no space between), an `@` that could start a mention is written `%40`; most sites read that as the same address. An `@` right after a letter or digit, as in `user@example.test`, never starts a mention and is left alone, so only an address whose user part ends in another character stops working.
- A link in angle brackets stays a link only when it starts with `http://` or `https://`, in lower case.
- A character reference inside an address still gets the invisible character, and so does an `@` in a link with no `://`, such as a relative path; such a link may stop working.

## Related

- [How a review runs](https://visto-ai.com/docs/how-a-review-runs/)
- [Scores kept across reviews](https://visto-ai.com/docs/scores-across-reviews/)
- [The merge gate](https://visto-ai.com/docs/merge-gate/)
- [Automatic approval](https://visto-ai.com/docs/automatic-approval/)
- [Configuration](https://visto-ai.com/docs/configuration/)
