---
title: History, PRs and releases
description: Inspect merged PRs, review comments and regression candidates in ClickHouse Loom. History collection is opt-in, and candidate rankings do not prove causation.
seo:
  title: PR history and regression candidates
lastModified: '2026-12-04T08:13:39.000Z'
sidebar:
  label: PR history and regression candidates in ClickHouse Loom
---

ClickHouse Loom's PR-history operations need merged-PR history. The `code_pr_history`
worker is off by default (`LOOM_CODE_PR_HISTORY_ENABLED`).

Loom's PR plane answers "how did the code get here". It lives in the same code namespace
as the index, so a history answer joins a merged PR's files against today's symbols,
callers and tests in one read, with no GitHub call at question time. A team's issue and
incident records join in through a linked [tracker](/docs/features/tracker/overview).

## The PR plane

| Table                     | Holds                                                                                                              | Filled by                                                                                   |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------- |
| `loom.code_pr_history`    | one row per merged PR of the namespace's branch: number, title, author, labels, files, linked issues, merge commit | the `code_pr_history` worker, back to `LOOM_CODE_PR_BACKFILL_MONTHS` (GitHub: with a token) |
| `loom.code_pr_reviews`    | inline review comments of merged PRs                                                                               | the same worker (`LOOM_CODE_PR_REVIEWS_ENABLED`, default on; needs a token)                 |
| `loom.code_gh_items`      | issues and PRs in any state, open PRs with the files their head touches                                            | the same worker (`LOOM_CODE_GH_ITEMS_ENABLED`, default on; skipped anonymously)             |
| `loom.code_backport_gaps` | the nightly set-wide backport report                                                                               | the `code_backport_gaps` worker                                                             |

The worker uses `LOOM_CODE_GITHUB_TOKEN` or the entry's `github_token`, else GitHub's
anonymous rate limit. A release-branch namespace holds the PRs merged into that branch,
so "what changed on 2.4" reads the 2.4 namespace. A Forgejo entry's first sync starts
at the oldest day of `LOOM_CODE_PR_BACKFILL_MONTHS` (12) and reads forward. A GitHub
entry's sync reads the newest PRs since its cursor, so after the syncs each pass walks a
GitHub entry with a token back through that window, a day at a time from where the last
walk stopped. The walk reads at most `LOOM_CODE_PR_BACKFILL_PRS_PER_HOUR` (800) PRs an
hour across all entries, each counted as it is read, which leaves most of a token's 5,000
requests an hour to the syncs, and sends a token's search requests (one per 100 PRs of a
day) at most one every 2.5 seconds, under GitHub's 30 a minute. It does not read a day's
PRs the ledger already holds, so the days the sync filled cost their searches only, and
when the hour's share, the pass budget or a GitHub error stops the walk inside a day, it
keeps the PRs it read and the next pass reads the rest. A rate limit stops the walk on
that token until the next pass, a day GitHub fails is read again an hour later, and a
namespace being erased is not walked. A GitHub entry without a token is not walked:
`loom code backfill-prs` runs the same walk on the anonymous limits, resuming at its
cursor on each run until the window is done
([code index operations](/docs/operations/code-index-operations#first-index)).

### History stays inside the indexed head

The worker fills `loom.code_pr_history` from the forge up to now, and the mirror follows
its branch, whatever commit the index is at. A namespace that indexes an older commit (a
release branch, a pinned deployment, a bisect checkout) holds changes its code does not
have, such as a later fix and the test it added.

A namespace therefore answers about a change only when its indexed head contains it. A
change outside the head answers as one Loom has no record of: the same empty answer, with
nothing that says the change exists. Two checks decide, one per source.

- **The ledger.** The ingest pass, and `loom code backfill` for the commit it indexed,
  find the newest ledger change among the head's first-parent commits and publish its
  merge time as the `history_until` state row; a change merged after that time is not
  read. The bound is the forge's recorded merge time, not the head's committer time: a
  forge records a merge a second or more after the merge commit is made, and tens of
  minutes after it under a merge queue. The head's committer time is used only when the
  ledger names none of the head's last 200 first-parent commits.
- **The mirror.** A commit a caller names, or one the mirror's history names for a PR,
  counts when it is the indexed head or an ancestor of it. The mirror answers with
  `git merge-base --is-ancestor`, remembered per commit and head.

The issue and PR mirror (`code_gh_items`) follows the forge as the ledger does. A PR it
records as merged after `history_until` is not read by its number: `code.history`
(`numbers`), `code.verify_citations` (a `#N` citation) and the number lookups of memory
grounding answer as for a number nobody recorded. An issue is not a change and an
unmerged PR is outside every head, so both are read whole. One read takes the whole
mirror: the `as_of` gate of memory grounding
(`LOOM_MEMORY_ASK_PR_TEMPORAL_GATE`) asks when a number was opened, which is the
forge's fact at any head, so a memory citing a PR opened after the anchor is dropped
whether or not the index holds its merge.

| Reads                                                                                                                                                                                                                                                                                                     | Bound                                                                                                                                        |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| the history leg and history section of `code.search`, `code.history`, `code.symbol_history`, `code.impact`, `code.context_pack`, co-change, churn, the test map's co-change rows, review comments on a path                                                                                               | the indexed head                                                                                                                             |
| a merged PR by number or merge commit: `code.review_brief`, `code.history` (`numbers`), `code.conventions` (`pr_number`), `code.backport_gap`, `code.first_build`, `code.context_pack` and `code.context_packs` (`pr_number`), `code.verify_citations` (`pr_number`), `code.bisect_candidates` (`fix_pr`) | the indexed head                                                                                                                             |
| a commit: `code.verify_citations`, `code.test_gate` and `code.tests_for` (`at_commit`), `code.bisect_candidates` (`bad_sha`), `code.first_build` (`sha`)                                                                                                                                                  | the indexed head                                                                                                                             |
| a window: `code.blame_range`, the scan of `code.bisect_candidates`, `code.backport_gaps`                                                                                                                                                                                                                  | the indexed head, for the window's ends and for the changes inside it                                                                        |
| `code.index_status` with `commit`, `code.coverage.watch`                                                                                                                                                                                                                                                  | `ready` turns true when the index reaches the commit; until then the commit reads as one the mirror does not hold                            |
| `code.pr_check`                                                                                                                                                                                                                                                                                           | none: a later duplicate is a duplicate                                                                                                       |
| an unmerged change in the mirror: `open: true` on `code.review_brief`, the post-image of `pr_number` on `code.symbol`, `code.callers`, `code.callees` and `code.impact`, `head_sha` on `code.conventions`                                                                                                 | read against the indexed head while the change is unmerged or merged inside it; one merged after it reads as a head the mirror lacks (below) |
| a change the caller sends: `pr_files` and `pr_diff` on those reads, `files` and `diff` on `code.conventions` and `code.test_gate`                                                                                                                                                                         | none: it is the caller's own, read as sent against the indexed head                                                                          |

The mirror keeps a PR's `refs/pull/N/head` after the merge, so a read of an unmerged
change by `pr_number` first asks whether the PR was merged after the indexed head. It
was when its head is on the namespace's branch outside the indexed head, or when the
ledger or the issue and PR mirror records its merge after `history_until` (a squash or a
rebase leaves the head off the branch). Such a PR answers as one whose head the mirror
lacks (`head_not_in_mirror`), on `code.review_brief` with `open: true` and on the
post-image of `code.symbol`, `code.callers`, `code.callees` and `code.impact`.
`code.conventions` places a `head_sha` the same way, with the `pr_number` sent beside
it: a commit on the branch outside the indexed head, or the head of a PR recorded as
merged after it, is read as a commit the mirror lacks. A post-image the caller sends
(`pr_files`, `pr_diff`) is the caller's own and is read as sent; its brief takes a title
and an author from the issue and PR mirror only for a PR that mirror does not record as
merged after `history_until`.

A read of the state or the records that fails places nothing, so the head is not read,
and the server logs the failure as a warning. A read by `pr_number` then answers
`head_not_in_mirror`. `code.conventions` answers with its diff-dependent rules `unknown`
and the note `head_sha not placed`, and does not read the ledger's merge commit in the
head's stead.

Each such read places its head again, ahead of any cached post-image. One git process
reads the PR head and the branch tip, and the mirror answers an ancestry question once
per pair of commits, so a head, a branch tip and an indexed head that stand still cost
that one process. The indexed head and the merge records are read every time, since
either changes while the mirror stands still.

`code.blame_range` and `code.first_build` also answer across the branches of one
repository. For them a commit counts when the indexed head of the addressed namespace
contains it, or the indexed head of another namespace of the same repository that the
caller may read: a release-branch commit asked of the trunk, which that branch's own
namespace would answer too. `code.first_build` does not ask the tracker for the builds
of a change the ledger or the mirror holds outside those heads. The default start of a
`code.blame_range` window, the oldest release cut, counts only inside the addressed
namespace's own head.

A namespace at its branch tip reads the whole ledger and every commit of its branch:
each is inside the head. The `history_until` row is resolved again on every ingest pass,
so a change the ledger learns after the index reached its commit is inside the bound one
pass later. The `code_graph_stats` pass resolves it too, before it mines the test map's
co-change rows, and retires the rows the ledger inside the head no longer yields. A pass
reads 20,000 co-change pairs at most, the most co-changed first; a ledger that yields
that many is read in part, so the pass adds the pairs it read and retires nothing. A
namespace neither a pass nor a backfill has published for reads the whole ledger, and
one with nothing indexed has no head to stay inside. `pr_leg_before` on `code.search`
pins the history leg to an earlier instant on top of the bound.

## Forgejo hosts

An entry in `LOOM_CODE_REPOS_JSON` with `"forge": "forgejo"` and an HTTPS or SSH
`git_remote` reads its merged PRs from that host's REST API (`https://<host>[:port]/api/v1`)
into `loom.code_pr_history`; the Repositories page does not set `forge`. The entry's
`github_token` is then the host's access token (scope `read:repository`; a public
repository reads without one), never `LOOM_CODE_GITHUB_TOKEN`, which is not sent to a
Forgejo host. The entry's `repo` is `host/owner/name`; its PR links are built from
`git_remote`, port included. `backfill-prs` sorts by close time (`sort=recentclose`), which needs
Forgejo 12 or later. Review comments, the issue mirror and open-PR heads stay GitHub-only. The API has no target-branch filter and
no merged-date search, so the branch is matched on each PR's `base.ref` and
`backfill-prs` walks closed PRs newest close first back to
`LOOM_CODE_PR_BACKFILL_MONTHS`, resuming after the close time it stopped at.

## Which op answers which question

| Question                                                                  | Op                                                                                       |
| ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| Brief me on this PR, or on the change I am about to make                  | `code.context_pack` (`pr_number` or `task`; `sections` keeps only the blocks you act on) |
| Which merged PRs touched this symbol or path, and what did reviewers say? | `code.history`, `code.symbol_history`                                                    |
| Which merged PRs last touched these lines, between release A and B?       | `code.blame_range`                                                                       |
| What did reviewers check on this merged PR? What do they usually check?   | `code.review_brief`, `code.conventions`                                                  |
| Before I open a PR: does one like it already exist?                       | `code.pr_check`                                                                          |
| Which merged PRs could have introduced this bug?                          | `code.bisect_candidates`                                                                 |
| Which release branches still carry the bug a fix removed?                 | `code.backport_gap` (one fix), `code.backport_gaps` (every labelled fix)                 |
| Which CI build first carried this commit?                                 | `code.first_build`                                                                       |

Arguments are in the [operations reference](/docs/reference/operations#code).

### History of a symbol, a path or a line range

`code.history` lists the merged PRs that most recently touched a symbol (`name` or
`symbol_id`), a `path`, or given PR `numbers`: number, title, author, labels, and up to
`reviews_per_pr` (default 3, `0` = none) human review comments on that file. For a symbol
or a path, `limit` (default 5, at most 50) and `offset` (at most 10,000) page back through
the PRs of its files (every file that defines a name), newest first; a `numbers` lookup
answers in one page of up to `limit` PRs and refuses `offset`.
`code.symbol_history` narrows this to one function's regression history: the PRs that
touched its span, their linked issues and reverts, and the review comments inside it.

`code.blame_range` takes a `path`, a line range (at most 400 lines) and a window as
release versions (`from_version`, `to_version`) or commit shas. It combines the PR
ledger's file lists in the window (a floor) with `git blame -w -M -L` on the mirror,
each blamed commit mapped to its PR. On a release-branch namespace it also reads the
trunk namespace's ledger, only when the caller may read the trunk; otherwise the
trunk's rows are left out and `legs.ledger.skipped` names it. A release version
resolves to its branch namespace's indexed head when the caller may read that
namespace, else through the mirror's branch or `-new` tag. A window end read from the
mirror (a sha, a tag, a branch) resolves only
[inside an indexed head](#history-stays-inside-the-indexed-head), the first of a
version's refs that is; one outside answers `window_unresolved`, as a ref the mirror
does not have.

- `stage: "introduced"` (default) demotes backports, reverts and whitespace- or
  rename-only touches, and promotes a PR that names the enclosing function, drew a
  review comment inside it, or whose linked issue names the words in `mentions`.
- `stage: "last_touched"` keeps the blame order.

The answer is exact for "last touched", never for "introduced the bug"; its `note` says
so.

### Review briefs and conventions

`code.review_brief` reads the brief the ingest built when the PR merged: the class of
every changed file, the touched functions with their callers and fan-in, the tests that
cover them, and what reviewers said.

The answer comes first: `verdict` and `verdict_causes`, read off every section the brief
holds, whatever the tier serves, and off `rationale` when this read serves it. A verdict
other than `gaps` or `unsettled` says that every check it rests on ran in full. The
values are tried in this order:

- `gaps`: something to act on; `verdict_causes` names each: `uncovered_symbol` (the
  coverage claim of a touched function or setting says `uncovered`),
  `symbol_with_regressions` (a fix PR or revert names a touched function),
  `randomized_setting` (CI randomizes a touched setting), `rationale_check`.
- `unsettled`, when what the brief is of was not read in full:
  - `paths:no_paths`, `paths:diff_unread`, `paths:diff_cut` (a source path with hunks
    past the 200,000 characters of the diff impact reads), `paths:not_read:<n>` (source
    paths past the 50 files impact reads);
  - `symbols:<verdict>` when the impact read could not answer (`unknown`, `not_covered`,
    `no_match`; `symbols:code.impact:<error>` when it raised), and `symbols:<op>:<error>`
    for another read the section rests on that raised (`file_rows_for_paths`,
    `functions_for_paths`, `caller_counts`, `git_diff`, `git_head:unread`, and
    `detect_lang` for a file read by its text whose language rule's parse could not run);
  - `symbols:unmapped_changes` for a changed source line in no function that is not
    blank, and `symbols:new_side_unread` for a changed source file whose new side impact
    did not read to place the lines the diff adds (below), with
    `symbols:code.impact:new_side_failed` when that read failed and a later read may
    succeed;
  - `symbols:drifted:<n>` for changed source files that differ between the diff's old
    side and the commit the index rows are at;
  - `symbols:ungraphed:<n>` for changed files the index holds no file row of, of a path
    the ingest reads for its symbols and does not refuse;
  - `symbols:index_error:<n>` for changed source files, or files in no language, whose
    file row records an index error (a file over the size cap, a failed chunking or
    parse), whose symbol rows are an older commit's or none;
  - `symbols:not_read:<n>` for touched functions past the first 30;
  - `overlay:<reason>` for an open PR whose overlay was off (`no_repo_entry`,
    `head_not_in_mirror`, `no_merge_base`, `no_git_mirror`, `error`) and
    `overlay:partial` for one that did not read every changed file (its parse time was
    spent, or a parse could not run here), whose parse of a file raised or ran past its
    limits, or that parsed another head than the one the brief's diff is read at (a push
    between the two reads, `head moved` in `overlay_note`);
  - `brief:v<n>` for a brief stored at an older payload version.
- `no_source_change`: every changed path is a test, a document, configuration, a file
  the ingest reads no symbols of (an image, a file its denylist refuses) or outside the
  index; a file a lane parser reads for its symbols (C++, Python, shell, TypeScript, Go,
  CMake, a Kubernetes manifest and the rest) is source.
- `unsettled`, when a check did not run in full or did not decide: a read that raised
  (`tests:coverage_claim:TimeoutError`, named in the section's `failed` too), a cap or a
  request an op refuses (`tests:not_claimed:<n>`, `history:not_read:<n>`,
  `settings:not_read:<n>`), a row that did not decide (`history:unknown:<n>`,
  `settings:unknown:<n>`), a bound tracker `code.symbol_history` could not read
  (`history:tracker_unavailable:<n>`), a read `code.setting_facts` failed open
  (`settings:control_unread:<n>`, `settings:declaration_unread:<n>`,
  `settings:history_unread:<n>`, `settings:randomizer_unread:<n>`), `rationale:unknown`,
  `rationale:unread`, or a section verdict such as `tests:partly_covered`.
- `nothing_to_check`: the PR's source changes are blank lines in no function
  (`symbols:no_seeds_in_hunks`); a PR with no claim for any other reason (a change only
  in a language the call graph is not built for: `symbols:no_indexed_paths`) is
  `unsettled`.
- `covered_no_gaps`: every claim says `covered_by`, the regression record is clean or
  file-level, every setting is known and the rationale `clear` or `none`.
- `""`: no brief was found (`source` is `missing`).

The brief caps its fan-out: coverage claims for the first six touched functions and four
settings, regression records for the first six functions, facts for the first eight
settings, and the first 30 touched functions. Each cap that leaves a subject out is a
cause of its section, so the verdict stays `unsettled`; so is a subject an op refuses to
read, such as a compiler-tier name past a field's 300 characters, since every build
refuses it the same way. The paths section stores its first 200 changed paths as rows;
its `rows_total`, verdict and causes count every changed path. The `rationale` section
is never stored, so a read that does not serve it (the trivial tier, or `sections`
without it) answers `gaps`, `unsettled` with `rationale:unread`, or `no_source_change`.
A brief one of whose reads raised is served and not stored, and the next read builds it
again (the test home is advice: a read of it that raised or was refused decides no
verdict, though one that raised still keeps the brief unstored); so is an open PR's
brief built without its diff, or from an overlay that was off (`overlay:error` when git
could not read its diff), left a changed file unreached when its parse time was spent
or its parse could not run here, or parsed another head. A parse of a file that
raised or ran past its limits does the same on every build of that file, at an open
PR's head and at a merged PR's parent alike, so that brief is stored, `unsettled`:
`code.impact` names `new_side_unread` for the file, and an open PR's `overlay_note`
counts it. A stored brief is served as it was built: one of an older payload version
(`v` in the payload) records no cap or failed read, so its verdict is `gaps` or
`unsettled`.

`code.impact` maps a diff on its old side onto the index rows, which are at the indexed
head (at the merge commit when the ingest builds a merged PR's brief, before it moves the
head). A merged PR's brief sends it the diff reversed, whose old side is the merge
commit, so its lines fall on the functions the PR changed or added there; an open PR's
brief sends the diff as written, whose old side is its base. A changed source file that
differs between that old side and the commit the rows are at is `drifted`: its line
numbers land on other code, so the brief reads the file as unread and translates no
line. One `git diff --name-only` on the mirror finds them, and a failed read keeps the
brief unstored. A function the PR changes in a test file is not listed: it is no
coverage obligation.

A source file is one a lane parser reads for its symbols, by the language its file row
records; the ingest reads that language off the text, so a Kubernetes manifest, a Helm
template and an extensionless script are source. A file the diff adds or deletes whole
and the rows do not hold (one an open PR adds, one a merged PR deletes) is read by its
text in the diff, off the request's event loop: an extensionless file in a script
directory is shell when bash parses it, and when that parse could not run here the file
is unread and the read failed, so the brief is not stored. The ingest records such a
file as shell with its parse failed, not as a file in no language. A changed file the
index holds no row of is read by its path and the repository's denylist: the ingest
refused it, or reads no symbols of it, unless a lane parser reads a file of that path.

Impact places each changed line on its own side of the diff. A line the diff removes is
in the innermost function of the index rows at the old side that spans it. A line it
adds is in a function only where the diff's new side holds one that spans it: an open
PR's head, from its overlay's parse, where a function the PR adds holds its own lines;
or the parent of a merged PR, whose reversed diff adds the lines the PR removed, parsed
from the mirror as the ingest parses it, one file at a time on the overlay's parse pool
and none started after `LOOM_CODE_PR_OVERLAY_PARSE_WINDOW_S`. A function of the new side
is matched to the index's parser-tier rows of the file by the name the same parser gives
it, so a function the compiler tier names otherwise (a C++ function in an anonymous
namespace) is found under either name. A name the file holds as often on both sides
pairs in line order. A name held a different number of times (an overload added or
deleted), or one the index does not hold in the file (code a merged PR deleted), pairs
none of its functions, and their lines are in no function. A Python definition starts at
its `def` or `class`, and the decorators the diff adds or removes directly above it are
its lines too. A changed source file whose new side impact did not read is
`new_side_unread`: the overlay did not parse it, the file is absent at the parent or
past the ingest's size cap, or its parse raised or ran past its limits, as every build
of it leaves it. A read that failed and a later read may make (a git call that raised, a
mirror not ready, a parse that did not run in the window or could not run here: no
answer within its wall bound, a process killed twice or ended by a signal sent from
outside, one that did not start or failed outside its parse, tree-sitter or a grammar
loaded from outside the interpreter's site-packages) is `new_side_failed` too, a
failed read, so the brief is served and not stored. Every line the diff adds there is in
no function, and so is each line of a hunk sent with its header alone that replaces
lines. In a language the call graph is not built for (TypeScript, Go, CMake), every
changed line is a line in no function, and so is every line of a source file an open PR
deletes.

A changed source line in no function, outside every function or in a class body, is
`unmapped_changes` unless it is blank (spaces, tabs, form feeds and carriage returns). A
comment is not: the compiler reads some (a Go build constraint, a cgo preamble, a
TypeScript reference), and a prototype or a call in a class body can change what the
class holds. A registration above a changed signature, or a member below a function's
closing line, is in no function at the side that holds it. The rule reads one line at a
time, so a blank line inside a multi-line string or a heredoc reads as one.

The symbols section lists the wiring the PR adds as counts in `collapsed`, not as rows.
The fold is how the section shows them: their coverage claims and regression records
are read all the same. The kinds follow the index's
own name rules: `registration` (C++'s registry convention: `REGISTER_FUNCTION`,
`registerStorageMergeTree`), `factory` (`create`), `constructor` (`A::A`, `__init__`)
and `one_line` (a definition the parser holds as one line, such as a trivial override).
A touched function is collapsed only when its whole parser extent is lines the diff adds
in a block that deletes none, so wiring the PR changes keeps its row, and its call sites
were counted for it alone (one definition of its name in the file). A function only the
compiler tier holds (a file the parser does not read, a function a macro expands to)
has no parser extent, so it keeps its row. Call sites are counted in both tiers,
under each tier's id of the definition, and a site both record counts once. Then a
registration function of at most eight lines is collapsed when it has at most one call
site and that one is a registration (a registry method such as `registerFunction` is
called by every registration; a `registerStorageFoo` whose creator lambda checks the
engine's arguments keeps its row). A one-line definition, a
factory or a constructor is collapsed only as a member of a class the PR adds in the same
file (one the PR inserts into an existing class changes that class, so it keeps its
row): a one-line definition when no call site is outside a registration; a factory or a
constructor of at most eight lines when no call site is outside a registration or, with
at most eight sites, outside the methods of its own class (the
`std::make_shared<FunctionX>` in `FunctionX::create`). An open PR's diff is
its head's, which the index rows are not at, so its brief collapses nothing. The
section's `note` gives both counts.

Each `tests` row of a symbol or setting carries the coverage claim's `verdict`, its
`strongest_tier` (`code.coverage_claim`'s evidence tiers), up to two `tests` of that tier
by repository path, and `tests_at_tier`, how many tests of that tier the claim listed (it
lists at most five). The weaker tiers' tests are left out: a short name's grep can reach
thousands of files.

At the `standard` and `full` tiers the brief also has a `rationale` section: the design
decisions and constraints (rows typed `decision`, or tagged `decision` or `constraint`,
active or conflicted as the pre-edit block shows them) in the repository's trunk code
namespace whose `files` or code links touch the PR's files. It is read on every call, from
the trunk namespace only when the caller may read it, and never stored with the brief, so
a decision recorded or changed after the merge shows up on the next read. It reads the
first `LOOM_CODE_REVIEW_BRIEF_RATIONALE_PATHS` (10) changed files, source files first, of
those the brief stores, and keeps at most `LOOM_CODE_REVIEW_BRIEF_RATIONALE_ROWS` (8)
rows, those with something to check first. It serves whole rows, `check` rows first and
then constraints. `LOOM_CODE_REVIEW_BRIEF_RATIONALE_TOKENS` defaults to `0` (unlimited);
a positive setting or request token budget trims whole rows to fit. Each row
carries the pre-edit block's line for it with its value cut at the line length (source,
`(pinned)` and the code-change note kept), `pinned`, `code_state` and a `verdict`. The
line shows a code state that is not `fresh`; `code_state` holds the state of every row.
When a served row has a code state, `fresh` too, the section's `note` says what it was
compared with: the repository as Loom indexed it, not the caller's checkout. Each
changed file read is one `memory.for_file` read: four ClickHouse reads (files match, code
links, their memories, the linked rows; a file with many links slices the last), each
keeping up to 50 rows with up to `LOOM_MEMORY_FOR_FILE_WHOLE_TOKENS` × 48 bytes of value.

The check looks for two kinds of name: the code-shaped names in a row's `Rejected:`
clause, up to a `Realized:` one (backticked, qualified like `A::b`, or calls like `f()`),
and the snake_case names anywhere in a constraint's value, backticked or not, bare or
qualified (`Setting::distinct_spill_ratio`). It is a whole-word match on the lines the
diff adds, read up to 200,000 characters of a posted diff or 200,000 bytes of the
mirror's, so `check` means "read this row against the diff", not a violation found.

| Row verdict | Meaning                                                                                                                                                                                                                |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `check`     | the diff adds one of the row's checked names (`names`)                                                                                                                                                                 |
| `clear`     | the row has checked names and the diff adds none of them                                                                                                                                                               |
| `unknown`   | no name found, but the diff could not be read here (git failed, even part way), was cut, or has a hunk that miscounts its lines, or the row's value was cut (`diff_unread`, `diff_cut`, `diff_malformed`, `value_cut`) |
| `""`        | the row names nothing to check                                                                                                                                                                                         |

The section's verdict is `check` when any row says so, then `unknown`, then `clear`, and
`none` when no row has anything to check. It says `clear` or `none` only when every
changed path and every matching row was checked; otherwise it says `unknown`, and the
causes say what was left: no repository is configured for the namespace (`no_repo`), the
brief stores no changed path (`no_paths`), the caller may not read the trunk namespace
(`trunk_not_readable`), a stored changed-path list that may be cut (`paths_maybe_cut`: the
brief stores the first 50 changed files plus the files of the diff's hunks, up to 200, so
a list of 50 or more may hold fewer than the PR changed), changed paths of that list not
read (`paths_not_read`), a path whose read reached its 50 rows (`paths_at_row_ceiling`), a
path whose code-links read failed (`links_not_read`), or rows the row cap left out that
had something to check (`rows_not_read`).

`code.conventions` states the repository's recurring maintainer checks as facts over one
PR's diff (`pr_number`, `head_sha`, `files` or `diff`), never as opinions; `rules` narrows
which checks run. The diff it reads is capped at `LOOM_CODE_CONVENTIONS_DIFF_MAX_BYTES`.

## Pre-PR duplicate check: `code.pr_check`

An agent about to open a pull request passes the draft and gets one of three verdicts:
`duplicate_of` (an open PR is already doing this, or a merged one already did),
`related`, or `none`.

```python
from loom import Agent

async with Agent(org="acme", namespace="code-widgets", agent="pr-bot") as bot:
    check = await bot.call(
        "code.pr_check",
        title="Retry the upload when the token expires",
        paths=["src/upload/client.py"],
        symbols=["UploadClient.send"],
        issues=[1432],
    )
    if check["verdict"] == "duplicate_of":
        for item in check["items"]:
            print(item["pr_number"], item["state"], item["evidence"])
```

The same call over HTTP is `POST /v1/code.pr_check`, and over MCP the tool is
`loom_code_pr_check` (in the `coding` and `tracker` toolsets). A title, changed paths or
an issue number is required.

Candidates come from Loom's own ledgers through four legs, with no GitHub call:

| Leg             | Reads                                                                                                                    |
| --------------- | ------------------------------------------------------------------------------------------------------------------------ |
| open PRs        | every open PR in `code_gh_items`: its title and the files its `refs/pull/N/head` touches (no body)                       |
| closed unmerged | PRs closed without merging in the last `LOOM_CODE_PR_CHECK_CLOSED_DAYS` (180): "someone tried this"; capped at `related` |
| merged, by path | merged PRs that touched the draft's `paths`                                                                              |
| merged, by text | merged PRs whose text scores against the draft's title and symbols, and merged PRs closing the same `issues`             |

Each candidate is scored by one fixed rule: the share of the draft's title and symbol
tokens it carries (weighted by rarity), a small body term for merged PRs, path overlap
in both directions, and whether it closes an issue the draft names. There is no labelled
set to fit the weights on, since duplicate PRs are closed, not merged. The answer says
`epistemic: "heuristic"`, and a title alone never reaches `duplicate_of`.

| Setting                                  | Default | Effect                                                                  |
| ---------------------------------------- | ------- | ----------------------------------------------------------------------- |
| `LOOM_CODE_PR_CHECK_DUPLICATE_THRESHOLD` | 0.55    | score at which a candidate is `duplicate_of`                            |
| `LOOM_CODE_PR_CHECK_RELATED_THRESHOLD`   | 0.2     | score at which it is `related`                                          |
| `LOOM_CODE_PR_CHECK_MERGED_DAYS`         | 365     | merged PRs older than this do not vote as duplicates                    |
| `LOOM_CODE_PR_CHECK_MASS_FILES`          | 200     | a candidate touching more files is a mass change; its files do not vote |

`tracker.duplicate_check` is the issue-side sibling: on a `none` or `related` verdict it
carries `code.pr_check`'s PRs that may already address the draft as `related_prs`
([tracker overview](/docs/features/tracker/overview#duplicate-check)).

## Bisect candidates: `code.bisect_candidates`

Given a reported bug, which merged PRs should an engineer investigate first?
`code.bisect_candidates` prioritizes candidates; it is not an automated `git bisect`.
It does not build the repository, run tests, reproduce the report, discover good and bad
versions, or prove that a candidate caused the bug. A candidate's score is an
investigation ranking, not a probability of causation.

The regression boundary comes from evidence recorded before the call:

| Window input                  | Where it comes from                                                                                                               | What Loom does with it                                                                                                                              |
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| `bad_version`, `good_version` | A user, CI job, support workflow or testing agent has observed the bug on the bad release and observed the good release as clean. | Scans the releases between those observations. Loom does not retest either release.                                                                 |
| `issue_number`                | The linked tracker issue already has `reproduces_on` and `clean_on` triage observations, populated by the tracker workflow.       | Reads those observations when explicit versions were not supplied. The existence of an issue or triage value is not proof that the report is valid. |
| `after`, `before`             | The caller knows only an approximate merge-time interval, such as the last known-good date and first-seen date.                   | Narrows the PR-history scan to that interval; the dates are bounds, not reproduction results.                                                       |
| `bad_sha`                     | The caller knows a commit at or before the first observed failure.                                                                | Resolves the commit time on the repository mirror and uses it as `before` when `before` is absent. It does not run the commit.                      |

The caller then supplies whatever report evidence it has: crashing frames (`symbols`),
source `paths`, `patterns`, free `text`, an `issue_number` and, when known, a `fix_pr`.
When no precise release range is available, repository-history fallback uses the recent
history retained for this scan (`LOOM_CODE_BISECT_HISTORY_DAYS`, default 90), which is a
broader and less precise investigation window.

1. Frames resolve to files through the code index.
2. The candidate scan reads the merged, non-derivative PRs whose first release lies in
   the window and that touched those files, ranked by the frames their diff names. With
   a linked tracker it scans the tracker's PR diffs; the previously recorded triage
   columns of `issue_number` (`reproduces_on`, `clean_on`) can supply the window. With no tracker,
   or a tracker holding no changed files, it reads the repository's own PR history
   (`LOOM_CODE_BISECT_HISTORY_DAYS`, default 90), and the answer says
   `candidates_from: "code_history"`.
3. With no frame (a wrong-result report) and an `issue_number`, the scan is bounded by
   the issue's rarest identifiers in the window's diffs, the component's directories and
   the fix's files; `wideners` chooses which, `widened_by` says which applied.
4. Report-time fusion fuses the diff scan with vector, lexical, path, subtree and
   recency ranks; a PR the report names as introducing the bug leads. When the fused top
   is weak (margin over #2 under 0.1 and not a report-named suspect), a wider window
   (12 releases, or `LOOM_CODE_BISECT_WIDE_DAYS`) joins and one LLM call reranks the top
   20 (`LOOM_CODE_BISECT_LLM_RERANK_MODEL`; a timeout keeps the fused order), or
   `rerank: true` asks for it.
5. A report naming no fix and no issue borrows the fix of the issue the duplicate check
   matches, inside `LOOM_CODE_BISECT_DUPCHECK_TIMEOUT_S`.

Each candidate carries marks (backport, revert, reverted, re-land, whitespace- or
rename-only, `touches_symbol` from the diff's hunk headers); `marks: false` returns the
bare ranked list. Which paths count as source code is the tracker's
`bisect.code_prefixes` ([record contract](/docs/features/tracker/record-contract#source-entry-options)).
The rerank needs a real LLM provider; the other stages run on the stock stack once PR
history is loaded. The bisect settings are listed in the
[configuration reference](/docs/reference/configuration#code).

The example below ranks the merged PRs that landed between a good release and a bad one
and touched the files of a crashing function. `bad_version` is the first release where the
bug was seen and `good_version` the newest release seen clean; Loom tests neither.

The version window needs a tracker namespace linked to the repository whose PR records carry `minor_version` (the [record contract](/docs/features/tracker/record-contract)). With merged-PR history alone
(`LOOM_CODE_PR_HISTORY_ENABLED` or `loom code backfill-prs`; see [first index](/docs/operations/code-index-operations#first-index)), the versions
do not bound the scan: the op reads the last `LOOM_CODE_BISECT_HISTORY_DAYS` (90 by default) instead.

```python
from loom import Agent

async with Agent(org="acme", namespace="code-widgets", agent="triage-bot") as bot:
    result = await bot.call(
        "code.bisect_candidates",
        bad_version="26.3",
        good_version="26.2",
        symbols=["UploadClient.send"],
    )
    for candidate in result["candidates"]:
        print(candidate["pr_number"], candidate["score"])
```

The candidates come back ranked. The `score` says which PRs to investigate first; it does
not show that a PR caused the bug. An engineer or a CI job still has to reproduce the
bug and test the candidates.

The final verification remains external to this operation: an engineer, CI workflow or
testing agent must reproduce the issue and test the ranked candidates.

## Backport gaps

`code.backport_gap` names a merged fix (`pr_number`) or the issue it closes
(`issue_number`, resolved through the tracker's `fixes` edges or a recovered link) and
answers per release-branch namespace of the same repository, newest first, or the
`branches` you name (namespaces or versions such as `26.4`). Three legs meet: the backport
record (the tracker's `is_backport_pr`, `upstream_pr_number` and `base_branch`, beside the
branch ledger's merged backports), the fix's first release (a branch cut at or after it
carries the fix), and whether the functions the fix's hunks touch exist on each branch.

| Verdict        | Means                                                                                                                                |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `gap`          | no backport, the branch predates the fix, and the touched functions (or files) are present; `cherry_pick` names the PR and merge sha |
| `pending`      | a backport PR exists and is open                                                                                                     |
| `covered`      | a backport merged, the branch was cut at or after the fix's first release, or the issue's `fix_versions` names the branch            |
| `not_affected` | every touched function (or file) is absent on the branch                                                                             |
| `unknown`      | the record was unavailable while the code is present, the presence check ran out of time, or the branch has no version to match on   |

A symbol-level `gap` is a lower bound: the code exists on the branch, which does not
prove the bug does.

- `exact: true` checks the patch per hunk. Removed lines still present and added lines
  absent make `gap` exact; added lines present, removed lines gone and no backport
  recorded make `not_affected` exact.
- `history: true` (implies `exact`) also reads the branch's tree and history in the
  mirror for rows the lines leave undecided.
- `presence.patch` shows the mode and the overlaps as evidence.

`code.backport_gaps` is the set-wide report: every fix of the last 90 days that
maintainers labelled for backport, per release branch, gaps first. The
`code_backport_gaps` worker writes it nightly into `loom.code_backport_gaps` by running
`code.backport_gap(exact, history)` per fix (`LOOM_CODE_BACKPORT_GAPS_ENABLED`, default
on, effective only with `LOOM_CODE_PR_HISTORY_ENABLED`); the op reads that table.
`wanted_only: false` includes unlabelled fixes. Every branch namespace is authorized
before it is read, failing closed.

## First build

`code.first_build` takes a commit `sha` or a merged PR's `pr_number` and answers which CI
build first carried it. It needs the linked tracker's `version_history` table: a run
naming the sha is exact; otherwise the bases of the runs after the merge are checked on
the mirror (`git merge-base --is-ancestor`, at most ten) for the earliest descendant, and
the answer is a lower bound.

## PR and tracker planes

A maintainer links trackers to a repository with `code.repo.set_source`, primary first
([tracker overview](/docs/features/tracker/overview)). Then:

- `code.bisect_candidates` scans the tracker's PR diffs and checks suspects against
  known fixes;
- `code.backport_gap` reads the backport record, and `code.first_build` the tracker's
  CI runs;
- `code.history` and the history parts of `code.search` and `code.ask` carry the
  tracker record beside the PR when a binding resolves and the caller may read it;
- `code.context_pack` can include tracker items (`sections=["qa"]`).

Without a tracker the ops answer from the PR plane where they can, and name the
tracker-only parts as missing.

## Limits and failure modes

- **No history, no answer.** With `LOOM_CODE_PR_HISTORY_ENABLED` off and no
  `backfill-prs`, the history tables are empty and the ops answer with nothing to rank.
- **History stops at the indexed head.** A change merged after the newest one the
  indexed commit contains is left out of ranking and linking, and reads as unknown by
  its number or its merge commit ([the bound](#history-stays-inside-the-indexed-head)).
  These follow the forge or the branch and are not bounded: an issue and an unmerged
  PR in the issue and PR mirror (kind, title, state and dates, with no files), the
  tracker's records other than the builds `code.first_build` reads, and the lag and
  `clone_head` of `code.index_status`, which say how far the branch is ahead of the
  index. An open PR that branched from a commit after the indexed head is read against
  the index like any other, so a definition its base has and the index lacks reads as
  one the PR adds. A PR merged by squash or rebase after the head that neither the
  ledger nor the issue and PR mirror holds reads as an open one while its
  `refs/pull/N/head` is on the mirror. A review brief stored while the head held its merge is
  served by a host without the mirror when the ledger has no row for its PR. A test-map
  row mined from a later change stays until the next `code_graph_stats` pass
  (`LOOM_CODE_GRAPH_STATS_INTERVAL_SECONDS`, a week) retires it, and is not retired in
  a namespace whose history inside the head yields 20,000 co-change pairs or more.
- **Anonymous GitHub access** covers public repositories at the public rate limit; review
  comments, the issue mirror and the history-window walk need a token.
- **Open PRs are not indexed code.** `code.pr_check` sees an open PR's title and files,
  not its body or its symbols.
- **Heuristic verdicts.** `code.pr_check` is uncalibrated by design; `code.blame_range`
  is exact only for "last touched"; `code.bisect_candidates` ranks suspects and never
  names a culprit as fact.
- **Tracker outages degrade, never fail.** A tracker read that times out or trips its
  breaker sets `tracker_unavailable`; the PR-plane legs still answer.

## Related

- [Tracker overview](/docs/features/tracker/overview) and [record contract](/docs/features/tracker/record-contract)
- [Adding repositories](/docs/features/code-index/repositories)
- [Code index operations by question](/docs/features/code-index/operations)
- [Code index architecture](/docs/architecture/code-index-architecture)
- [Operations reference](/docs/reference/operations#code)
