# Scores across reviews

> How a block's score is kept from one review to the next, reused from other pull requests, and held up when code is moved or rewritten.

Web page: https://visto-ai.com/docs/scores-across-reviews/

Out of dry run, a pull request is not scored from scratch at each new head. A block keeps the score it was given while it stays in the diff, so the list of parts for a person to read does not jump around between pushes, and pushing the same change again cannot lower its score. The model is asked only for blocks it has not scored among the same lines, which also saves model calls.

In dry run none of this is read or stored: every head is reviewed in full and scored afresh.

## Where earlier scores come from

- **This pull request's earlier runs**: every run recorded out of dry run that ended ok, published or not, with no age limit.
- **Other pull requests of the repository**: scores stored in the last 30 days. Scores are stored when a run is recorded, whether or not its review is then posted.

## How a block is recognised

A block is a hunk of a file, or a part of a hunk that the model split (see [The score](https://visto-ai.com/docs/the-score/)). Across reviews, a block is recognised by three things:

- **its file's path**, or the path it had before a rename;
- **its changed lines**: the text of its added and removed lines, without line numbers;
- **its surroundings**: every line of its hunk as the diff shows it, unchanged lines included, without line numbers. A part of a split hunk has the surroundings of its hunk.

A file the pull request adds, with no history under its own path, also answers to every other path of the pull request that held one of its blocks, whether that block had a score of its own or a whole-file score stood for it. GitHub shows a new file that a later push renames as added under its new name, with no earlier name, and a copy as added too; this keeps their scores.

## The rules

### A block keeps its score

While a block stays in the diff, its score does not fall. The model is not asked for it again, and its hunk is marked `scored` in what the model is shown. When a block has more than one earlier score, the highest is kept.

### The same lines elsewhere are scored again

The same changed lines can be harmless in one place and a decision in another. So the model is spared a block only when it was already asked about the same changed lines among the same surroundings: it scored the block there, left it to the file's whole-file score there, or split it there. A block whose surroundings are new (it was moved, or the lines beside it changed) is scored again.

What a block keeps, or cannot score below, is still decided by its changed lines alone: the highest score stored for them, wherever they stood. So a block scored again cannot score below that, and the score it was given is kept beside the one it is held to.

### A new or edited block cannot score below a block its file lost

When a block's changed lines leave the diff, its file remembers the score. The floor is the highest earlier score of a block of that file whose changed lines are no longer in the diff. A new or edited block scored below it is raised to it, and so is a whole-file score given in place of a block score. Only blocks scored in this review are held to it.

This stops an author from rewriting a flagged change in a different form to get a lower score.

### Whole-file scores

- **A whole-file score never falls.** When the review model gave a file a whole-file score in an earlier review, the file keeps at least that one. With a [second scorer](https://visto-ai.com/docs/second-scorer/), which never gives whole-file scores, a file that has blocks keeps none: only a file that moved does.
- **A file is closed to a new whole-file score only once it was read as it is.** A file whose blocks all have a score takes no new whole-file score while its diff is one a published review of this pull request read under the path it has now. Until then (its blocks' scores came from another pull request, a push changed its diff, or it was moved or renamed with the same change) it is sent to the model, its hunks are marked `scored`, and the model may give it a whole-file score; the higher of that and the one it keeps counts. So a file moved or renamed with the same change is read once more where it now stands.
- **A file that only moved is scored once.** It keeps its whole-file score and is not shown to the model again.

### Scores from other pull requests

A block with the same path, the same changed lines and the same surroundings, scored on another pull request of the repository in the last 30 days, takes that score (the highest, if there are several). The floor above applies to it. A hunk that the model split into parts has no score of its own as a whole, so another pull request does not reuse it as one.

### A second scorer has its own history

The scores of the review model and of a [second scorer](https://visto-ai.com/docs/second-scorer/) are kept apart. Naming a scorer, or dropping it, makes the next review of every open pull request score its blocks afresh, once.

## In the review

In the `Human review` section, one of three tags can follow a block's line:

| Tag | Meaning |
|---|---|
| `_(kept from an earlier review)_` | The score is the one an earlier review of this pull request gave to the same lines |
| `_(scored on another pull request)_` | The score was stored by another pull request of the repository. Its category is shown and its reason never is, at this review or a later one: the reason was written about another pull request |
| `_(N% was given; a block this file lost had scored M%)_` | The block was given N%, and a floor raised it to M%. The tag reads the same when the block was scored again and held to the score its own changed lines had |

## Limits

- **Surroundings are short.** They are only the unchanged lines the hunk shows, usually three before and three after. Lines scored where they were harmless keep that score when a later push, or another pull request within 30 days, puts them where the neighbouring lines read the same. A hunk with no unchanged line, as in a new file, has no surroundings to tell: its score is kept wherever a hunk of exactly those lines stands. In an incremental review, a push that only does that is not read again at all, and ends as nothing new when what it would show a person is unchanged.
- **Neighbours changing means a new read.** A block is scored again when the lines beside it change though its own do not, as after a merge of the base branch that touched them, or when a part of a split hunk comes to stand as a hunk of its own. Its score cannot fall, but its file is read again. A push that only merges the base can therefore get a review where it would have told nothing new. In a pull request too large to be read whole, a file that was left out as already read and now finds no room is not read, and goes to a person.
- **New files are one block.** A file the pull request adds keeps its scores when a later push moves, renames or copies it with its content unchanged, also when the model had scored it as a whole only. But a new file is one block, so any edit made in the same push as the rename gives it a fresh score, with no floor.
- **The floor applies only to blocks scored now.** An author can push the same change written several ways in one file and have each scored. A block that already has a score keeps it, and the floor applies only to a block that is new or edited, so the one that scored lowest can be the one kept.
- **High whole-file scores stay.** A whole-file score that was once high stays: fixing the file does not lower it.

## Related

- [The score](https://visto-ai.com/docs/the-score/): what the score measures.
- [Leaving dry run](https://visto-ai.com/docs/leave-dry-run/): incremental reviews and pushes that tell nothing new.
- [Memory](https://visto-ai.com/docs/memory/): a score raised while a memory record was on is kept by this history.
