# The score

> What the 0–100% human-review score measures, its bands, the threshold, and the paths that always go to a person.

Web page: https://visto-ai.com/docs/the-score/

Every changed block of a pull request gets a score from 0% to 100%. The score says how much the change needs a person's judgement. It is not the chance of a bug: findings cover bugs. A file with ten changes, of which one is a decision, sends the reviewer to that one change and not to the whole file.

Blocks that score at or above the threshold, 70% by default, are listed in the review for a person to read. When nothing reaches it, the review says no human review is needed, and with [automatic approval](https://visto-ai.com/docs/automatic-approval/) switched on the pull request can be approved.

## The bands

The model picks a band from what the code change does, then a position inside the band. What the pull request's description or a code comment claims about the change is not evidence.

| Score | Meaning | Examples |
|---|---|---|
| 0% to 19% | No judgement involved | Generated files, formatting, documentation text |
| 20% to 39% | Mechanical | A rename, new tests that mirror existing behaviour |
| 40% to 69% | A local behaviour change that follows an existing pattern | A bug fix inside one function, a new field passed through existing layers |
| 70% to 89% | A decision | A changed business rule, data model, public contract or permission check; a calculation of money or time; a structure that crosses modules; a new or upgraded dependency; a test removed, skipped or weakened; a lint, type or CI check switched off |
| 90% to 100% | A decision that is costly to get wrong | Authentication, tenant isolation, an irreversible data migration, billing, security configuration |

Two kinds of change look mechanical and are scored as decisions:

- **Dependencies.** A dependency added or moved to another version is a decision, in the manifest and in the lock file alike. A lock file is scored by what it changes, not by being a lock file.
- **Weakened checks.** Removing, skipping or loosening a test or an assertion, and switching off a lint rule, a type check or a CI step. Deleting a failing test counts as a weakened test, not as a test change.

The bands come from the [review contract](https://raw.githubusercontent.com/visto-ai/visto-ai/0faf484aa43f4fcdc1f30c1d5c056ea26c1c0d32/contract/review-contract.md), the instructions every review model is given.

## What a score carries

Each score comes with a category and, from 40% up, a one-sentence reason. The category is one of `generated`, `formatting`, `documentation`, `test`, `weakened_test`, `disabled_check`, `dependency`, `rename`, `refactor`, `fix`, `feature`, `business_rule`, `data_model`, `public_contract`, `permission`, `calculation`, `structure`, `authentication`, `tenant_isolation`, `migration`, `billing`, `security_configuration` or `other`.

Scores and findings are independent. A finding does not make a block score high, and a high score is not a finding. Test, documentation, generated, vendored and lock files are scored but get no findings.

## Blocks and files

A block is one hunk of the diff. The model may split a block of more than 30 changed lines into parts, each with its own score; a changed line that falls in no part has no score.

A file can also get a score of its own, in three cases:

- every block of it is the same kind of change, as in a lock file, and the file's score stands for its blocks;
- the decision lies in how several blocks fit together, and the blocks are scored too;
- the file moved to another directory with no content change, so it has no diff and is scored from its old and new path. A move can change a public URL where a framework routes by file path, and what other code can reach.

A file's final score is the highest of its blocks' scores and any score that applies to the file as a whole. The pull request's highest score is the highest final score of its files.

## The threshold

A block or file at or above the threshold needs a person. Set it under the `score` block of a repository's settings, as a whole number from 1 to 100:

```yaml
repositories:
  defaults:
    score:
      threshold: 70     # every repository; 70 when not written
  overrides:
    acme/shop:
      score: { threshold: 60 }   # one repository
```

An admin can also change it in the UI's Settings, under Repositories; it applies from the next review (see [Configuration](https://visto-ai.com/docs/configuration/)). When you name a [second scorer](https://visto-ai.com/docs/second-scorer/), `repositories.defaults.score.threshold` must be written.

The threshold is a trade-off between what people read and what slips through without them. Choose it from your own history with a [backtest](https://visto-ai.com/docs/backtest/), which replays the score on past pull requests and measures it against where people actually commented.

## Paths that always need a person

Some files skip the model's judgement and score 100%, so the review always lists them:

| What | Why |
|---|---|
| A path listed in the repository's `.visto-ai.yml` | The team marked it as always needing a person |
| `.visto-ai.yml` itself, `CODEOWNERS` (at the root, in `.github/`, `docs/` or `.gitlab/`), `.gitlab-ci.yml`, `Jenkinsfile`, `azure-pipelines.yml`, `bitbucket-pipelines.yml`, `.travis.yml`, and anything under `.github/workflows/`, `.circleci/` or `.buildkite/` | It changes the reviewer's own file, code owners or CI |
| Every file, when `.visto-ai.yml` cannot be used | An invalid file must not silently protect nothing |
| A file whose changed lines hold invisible or direction-changing characters | The model and a person reading the diff saw cleaned text, not what was changed |
| A file that was not read, or a block left without a score | Too large, a secret file, over the batch limit, or the model gave no score |

A renamed or moved file is checked by its old path as well as its new one, so moving a file out of a protected path does not unprotect it.

A team lists its own paths in `.visto-ai.yml` at the root of the repository, read from the default branch:

```yaml
# .visto-ai.yml
human_review:
  - db/migrate/
  - "app/**/policy.rb"
```

The file can only add protection. It cannot lower the threshold or change any other setting. [.visto-ai.yml](https://visto-ai.com/docs/visto-ai-yml/) gives the pattern rules.

## Scores set by rule

Two kinds of file are scored without the model:

| File | Score |
|---|---|
| A raster image or font with no diff (`png`, `jpg`, `gif`, `webp`, `woff2`, `ttf` and similar; not `svg`, which can carry script) | 10% |
| A file renamed within the same directory with no content change | 30% |

## In the review

The review body has a `Human review` section. It lists, file by file and highest score first, each block and whole-file score at or above the threshold, with its lines, its score, its category and the first line of its reason. It lists at most 50 entries and says how many more there are. When nothing reaches the threshold, it says so and gives the highest score. The `Overall` section ends with `Human review: needed` or `Human review: not needed`, with the highest score.

With [inline notes](https://visto-ai.com/docs/inline-notes/) on, each listed block also gets a short comment in the diff.

## Related

- [Scores across reviews](https://visto-ai.com/docs/scores-across-reviews/): how a score is kept when the pull request changes.
- [A second scorer](https://visto-ai.com/docs/second-scorer/): a separate decision model that scores the blocks.
- [Memory](https://visto-ai.com/docs/memory/): what earlier pull requests of a repository tell later reviews.
- [Automatic approval](https://visto-ai.com/docs/automatic-approval/): approving pull requests that need no person.
