Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e21252d
A merged PR's brief stored at an older payload version is rebuilt on …
zlareb1 Dec 6, 2026
73b245d
A failed rebuild's marker loses to any rebuild and never brings back …
zlareb1 Dec 6, 2026
f38c51d
An open PR's stale brief is rebuilt at its head, and a marker keeps i…
zlareb1 Dec 6, 2026
94f5a42
A rebuild stored under another merge commit marks the stale row, and …
zlareb1 Dec 6, 2026
c738e7d
A rebuild whose reads raise serves the stored brief; rule 100 says wh…
zlareb1 Dec 6, 2026
bf3d22e
Merge origin/main
zlareb1 Dec 6, 2026
ee7a4dc
Rule 101 and the history page say which builds a marker stops; a mark…
zlareb1 Dec 6, 2026
bbcefb8
The store field says it decides a rebuild, and an open rebuild is tes…
zlareb1 Dec 6, 2026
01405fb
A failed rebuild lists the build's notes as they were, and never lowe…
zlareb1 Dec 6, 2026
2eac5db
A read by PR number serves a rebuild placed at another merge commit; …
zlareb1 Dec 6, 2026
ec81f93
The docs say a rebuild's marker holds for the version whatever the cause
zlareb1 Dec 6, 2026
f0e3e7a
The docs name the one exception to the rebuild bound, and the MCP tex…
zlareb1 Dec 6, 2026
b00d5ed
A rebuild of a merged brief looks the row up by its own merge commit
zlareb1 Dec 6, 2026
184c492
A host whose mirror lacks the merge serves a stale brief without mark…
zlareb1 Dec 6, 2026
529a568
Merge origin/main; the review brief rule is 102, and an unreadable mi…
zlareb1 Dec 6, 2026
f6ad467
An open rebuild left unstored by an unread items row marks the stale row
zlareb1 Dec 6, 2026
26ce713
Test the unstored open answer and a stored rebuild's notes
zlareb1 Dec 6, 2026
7f8b7f9
A stale brief's note comes before its build's, so the note cap cannot…
zlareb1 Dec 6, 2026
89e73f0
A rebuild stored for another PR marks the stale row; rule 102 names t…
zlareb1 Dec 6, 2026
c3fe335
A rebuild reads a merged row by its number and commit; another PR's c…
zlareb1 Dec 6, 2026
1c3f133
A brief built from a named merge commit discloses it; the ledger read…
zlareb1 Dec 6, 2026
96635ec
Mirror-built wording names the commit a read or row names; two more t…
zlareb1 Dec 6, 2026
59912f1
Merge remote-tracking branch 'origin/main' into fix/brief-rebuild-on-…
zlareb1 Dec 6, 2026
cc473a6
Mirror-built field comments name the tracker title and status
zlareb1 Dec 6, 2026
bd5f2d3
The other-PR check sits with the named-commit lookup; tracker wording
zlareb1 Dec 6, 2026
ab0f295
Merge origin/main; the review brief rule is 103, and the tracker log …
zlareb1 Dec 6, 2026
09c4219
The marker reads the row's build time and version as stored; mirror_c…
zlareb1 Dec 6, 2026
b3ee069
The marker reads merge_sha as stored; the re-read test covers a same-…
zlareb1 Dec 6, 2026
22342e7
The open miss test stubs only the head; _rebuild's docstring drops a …
zlareb1 Dec 6, 2026
65626a5
Open-row test helpers: the mirror names the head; the stale row is typed
zlareb1 Dec 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/architecture/rolling-upgrades.md
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,26 @@ See the [participant lifecycle baseline](cells.md#participant-lifecycle-baseline
migration's file name and the read of a row N-1 wrote, and the mixed-version gate
does not check this rule.

103. **A review brief's payload version** (`PAYLOAD_VERSION` in
`server/code/app/index/review_brief.py`, no migration): N rebuilds a stored brief of a
lower version on read and stores it under the same key; N-1 serves a brief of N's
higher version as it is, answering its verdict (where N-1 has one) by its own rules,
and never rewrites a row of its own version or higher, or one a newer build marked. So
a bump that adds a cause N-1 does not know ships N-1's reading of that cause first
(rule 3), or N-1 can settle a brief N leaves `unsettled`. A brief N-1's ingest writes
while both serve is of N-1's version, and N rebuilds it once. A build that cannot store
its brief writes the old one again with `rebuilt_for` set to its version, with the
replaced row's `version` column plus one, so any build stored later replaces it, and
neither build tries that row again until a higher version serves, whatever made the
build fail; a row whose marker could not be written is built again by the next read. A
rebuild's `version` is its host's clock: on a host whose clock runs behind the stale
row's writer by more than the time since that write, the stored rebuild loses to the
row, and reads build again until the clock passes it. Both builds read the same rows,
so a rollback leaves rebuilt briefs as newer rows N-1 serves as they are ([PR
history](../features/code-index/history-and-prs.md)). No gate holds the rollout.
`tests/unit/test_code_review_brief_mirror.py` checks N's side, and the mixed-version
gate does not check this rule.

## What checks them

`scripts/gates/mixed_version.py` (`make test-mixed-version`, the `mixed-version` CI job,
Expand Down
35 changes: 31 additions & 4 deletions docs/features/code-index/history-and-prs.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ values are tried in this order:
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.
- `brief:v<n>` for a brief stored at an older payload version, built by rules that
have changed since, when the read cannot rebuild it (see below).
- `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,
Expand Down Expand Up @@ -311,9 +312,35 @@ a changed file unreached when its parse time was spent or its parse could not ru
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`.
the file, and an open PR's `overlay_note` counts it. A build that replaces a brief of an
older version is tried once (below).

A change to what a brief stores or how its verdict reads it raises the payload version
(`v` in the payload). A stored brief of the current version is served as it was built.
A read of a brief of an older version builds it again, a merged PR's from its own merge
commit and an open PR's at the same head, and stores the new brief in its place
(`source` names the build); a read after that serves it as stored. The old brief is
served instead, its verdict `gaps`, or `unsettled` with `brief:v<n>`, and `degraded`
names `code.review_brief: stale_brief_served` with the reason. That happens when:

- the read does not store (`store: false`, a measurement consumer, a posted diff);
- the host has no mirror of the repository, its mirror does not hold the merge commit
or git cannot read it; a later read builds the brief once a mirror holds the merge;
- an open PR's brief is found by its number on a merged read;
- the build raised, found nothing (a merge commit whose subject names another PR
included) or was not stored.

In the last case `degraded` lists `stale_brief_served (rebuild failed)`, then the
build's notes. The stored row records the version that tried and those notes, and a
later read by a build that has this rule, of the same or a lower version, serves it with
the same notes and without a build. That holds whatever the cause, a passing failure on
one host (a timed-out read, a git call that failed) included: the cost stays at one
build per stored row and version, and the old brief answers until a build of a higher
version tries again. Only a row whose marker could not be written is built again by the
next read.

A brief stored at a newer version than the serving build's, during a rolling upgrade,
is served as it is.

`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
Expand Down
6 changes: 3 additions & 3 deletions docs/reference/operations/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,7 @@ A merged PR's review brief: the point read of what the ingest built at merge —
| `sections` | `list[Literal['paths', 'symbols', 'tests', 'settings', 'history', 'blame', 'qa', 'risk', 'do_not_flag', 'rationale']]` | *(computed)* | Serve only these of the tier's sections; empty = every section the tier carries. |
| `tier` | `Literal['trivial', 'standard', 'full']` | `'standard'` | Which sections: trivial (paths, symbols), standard (+ tests, settings, history, risk, rationale) or full (+ blame, qa). |
| `token_budget` | `int` | `0` | Estimated-token cap on served sections; 0 (default) is unlimited. |
| `store` | `bool` | `True` | Whether a brief this call builds on a miss is stored for the next reader (the default). |
| `store` | `bool` | `True` | Whether a brief this call builds on a miss is stored for the next reader (the default), and whether a stored brief of an older payload version is rebuilt: a read that does not store serves it as stored. |
| `open` | `bool` | `False` | The PR is OPEN — brief its head (`refs/pull/N/head` on the mirror) diffed against its merge-base with the indexed branch, with the post-image overlay on the impact read (added functions are seeds). |

| Output field | Type | Meaning |
Expand All @@ -1458,10 +1458,10 @@ A merged PR's review brief: the point read of what the ingest built at merge —
| `verdict_causes` | `list[str]` | The gaps (`uncovered_symbol`, `symbol_with_regressions`, `randomized_setting`, `rationale_check`), or each check that did not run in full, decide or rest on more than a co-change, as `<section>:<verdict or cause>` (`tests:not_claimed:3`… |
| `pr_number` | `int` | The PR the brief is of (from the stored brief when the request named only `merge_sha`). |
| `merge_sha` | `str` | The PR's merge commit; '' on an open brief or when no brief was found. |
| `source` | `Literal['precomputed', 'built', 'built_from_mirror', 'missing']` | precomputed (the ingest built it) \| built (this call built it from the ledger's row) \| built_from_mirror (no ledger row; the merge commit, title and files came from the mirror's first-parent chain and the reviewers from the tracker record)… |
| `source` | `Literal['precomputed', 'built', 'built_from_mirror', 'missing']` | precomputed (the ingest built it) \| built (this call built it from the ledger's row) \| built_from_mirror (no ledger row; the files, and the title when the tracker record has none, came from the mirror at the named merge commit, else at the… |
| `ledger` | `Literal['', 'present', 'absent']` | what the ledger said: present (this build read its row) \| absent (this or the stored build came from the mirror because the ledger had no row) \| "" (not consulted: the ingest built the row) |
| `stored` | `bool` | True when this call built the brief and stored it |
| `provenance` | `dict[str, Any]` | A mirror-built brief's disclosure — source, ledger, merge_commit, files, title (qa \| mirror), qa status, reviewers, author, has_test, is_backport_pr; {} for a ledger- or ingest-built brief |
| `provenance` | `dict[str, Any]` | A mirror-built brief's disclosure — source, ledger, merge_commit (mirror_first_parent: placed by PR number on the first-parent chain \| named_commit: the commit the read or the stored row named), files, title (tracker \| mirror), tracker… |
| `overlay` | `bool` | On the wire only for `open: true`. |
| `overlay_head_sha` | `str` | The open PR's head the brief was read or built at; '' when the mirror lacks it. |
| `overlay_added` | `int` | Functions the open PR adds (the symbols section's `via: added` rows). |
Expand Down
29 changes: 17 additions & 12 deletions server/code/api/models_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ class CodeReviewBriefInput(_CodeIdentity, _PrPostImage):
touched symbols with callers and fan-in, coverage verdicts, setting facts,
regression history, blame of the deleted lines, path classes, the tracker record and
the calibrated risk priors (`jit_risk` and `author_revert_prior`, ranking signals,
never a gate) — or a build on the first miss. `rationale`, read on every call and
never stored, lists the repository's design decisions and constraints that govern the
PR's files. `tier` selects sections (trivial: paths + symbols;
standard: + tests, settings, history, risk, rationale; full: + blame, qa);
`sections` narrows further; a positive `token_budget` limits the returned rows."""
never a gate) — or a build on the first miss, or again for a brief stored at an older
payload version. `rationale`, read on every call and never stored, lists the
repository's design decisions and constraints that govern the PR's files. `tier`
selects sections (trivial: paths + symbols; standard: + tests, settings, history,
risk, rationale; full: + blame, qa); `sections` narrows further; a positive
`token_budget` limits the returned rows."""

# The PR to brief; 0 = find it by `merge_sha`. Required with `open`. A PR merged
# after the commit the namespace indexes answers `missing`, as an unknown PR.
Expand Down Expand Up @@ -98,8 +99,9 @@ class CodeReviewBriefInput(_CodeIdentity, _PrPostImage):
# Estimated-token cap on served sections; 0 (default) is unlimited.
token_budget: int = Field(default=0, ge=0)
# Whether a brief this call builds on a miss is stored for the next reader (the
# default). A measurement consumer (`eval-*`, the bench sentinels) never stores,
# whatever it passes.
# default), and whether a stored brief of an older payload version is rebuilt: a read
# that does not store serves it as stored. A measurement consumer (`eval-*`, the bench
# sentinels) never stores, whatever it passes.
store: bool = True
# "pr_number or merge_sha" is checked by the handler, not a model validator: the
# namespace gate answers a refused principal (403/404) before any shape complaint,
Expand Down Expand Up @@ -137,8 +139,9 @@ def _drop_unset(self, handler: SerializerFunctionWrapHandler) -> dict[str, Any]:
# The PR's merge commit; '' on an open brief or when no brief was found.
merge_sha: str = ""
# precomputed (the ingest built it) | built (this call built it from the ledger's
# row) | built_from_mirror (no ledger row; the merge commit, title and files came
# from the mirror's first-parent chain and the reviewers from the tracker record) |
# row) | built_from_mirror (no ledger row; the files, and the title when the tracker
# record has none, came from the mirror at the named merge commit, else at the
# first-parent merge for the PR number, and the reviewers from the tracker record) |
# missing (neither the ledger nor the mirror names the PR, or no mirror to build
# from)
source: Literal["precomputed", "built", "built_from_mirror", "missing"] = "missing"
Expand All @@ -148,9 +151,11 @@ def _drop_unset(self, handler: SerializerFunctionWrapHandler) -> dict[str, Any]:
ledger: Literal["", "present", "absent"] = ""
# True when this call built the brief and stored it
stored: bool = False
# A mirror-built brief's disclosure — source, ledger, merge_commit, files, title (qa
# | mirror), qa status, reviewers, author, has_test, is_backport_pr; {} for a
# ledger- or ingest-built brief
# A mirror-built brief's disclosure — source, ledger, merge_commit
# (mirror_first_parent: placed by PR number on the first-parent chain | named_commit:
# the commit the read or the stored row named), files, title (tracker | mirror),
# tracker status, reviewers, author, has_test, is_backport_pr; {} for a ledger- or
# ingest-built brief
provenance: dict[str, Any] = Field(default_factory=dict)
# On the wire only for `open: true`. `overlay` true = the brief is of the PR's head
# (`overlay_head_sha`) against its merge-base (`overlay_base_sha` in the payload's
Expand Down
13 changes: 8 additions & 5 deletions server/code/app/index/review_brief.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@

logger = logging.getLogger(__name__)

# The payload's shape. A stored brief is served as it was built, and one of a lower
# version does not record its fan-out caps or the reads that raised, so its verdict
# cannot settle (`brief_verdict`).
PAYLOAD_VERSION = 2
# The version of the rules a brief is built and answered by. Bump it in the change that
# alters what a build stores (a section, a row field, a cap, a cause) or what
# `brief_verdict` answers over a stored brief: a read of a brief stored at a lower version
# builds it again (`server.code.app.review_brief._rebuild`). The previous release answers
# a brief of this version by its own rules, so a new cause ships its reading there first
# (rolling-upgrades rule 103).
PAYLOAD_VERSION = 3

SECTION_ORDER: tuple[str, ...] = (
"paths",
Expand Down Expand Up @@ -725,7 +728,7 @@ def brief_verdict(
(`symbols:ungraphed:<n>`), a changed file whose row records an index error
(`symbols:index_error:<n>`), an open PR's overlay that was off
(`overlay:<reason>`) or partial (`overlay:partial`), a brief stored at an older
payload `version`, which records no cap or failed read (`brief:v<n>`);
payload `version`, built by rules that have changed since (`brief:v<n>`);
- `no_source_change`: every changed path is a test, a document, configuration or
outside the index;
- `unsettled`, when a check did not run in full, did not decide or rests on a
Expand Down
20 changes: 11 additions & 9 deletions server/code/app/index/review_brief_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ async def mirror_commit_facts(
*,
timeout_s: float = 20.0,
) -> dict[str, Any] | None:
"""The same facts for a merge commit named by sha (a `merge_sha`-only
read with no ledger row): None when the mirror holds no such commit or its
subject names no PR. A mirror git cannot read raises."""
"""The same facts for a merge commit named by sha (a read or a stored row that
names the commit, when the ledger has no row): None when the mirror holds no such
commit or its subject names no PR. A mirror git cannot read raises."""
from server.code.app.index import gitrepo

if not await gitrepo.holds_commit(git_dir, sha, timeout_s=timeout_s):
Expand Down Expand Up @@ -168,15 +168,15 @@ async def tracker_pr_facts(org: str, ns: str, pr_number: int) -> tuple[str, dict

async def mirror_provenance(org: str, ns: str, facts: dict[str, Any]) -> dict[str, Any]:
"""The disclosure a mirror-built brief carries in its payload: where the
merge commit, files and title came from, the reviewers when the QA
record has them. The QA title, when there is one, replaces the merge
merge commit, files and title came from, the reviewers when the tracker
record has them. The tracker title, when there is one, replaces the merge
commit's in `facts` (the body's first line is the title as the author
typed it at merge time; QA carries the PR's current one). QA failing is
a fact on the record, never a failed brief."""
typed it at merge time; the tracker carries the PR's current one). The
tracker failing is a fact on the record, never a failed brief."""
try:
tracker_status, tracker_row = await tracker_pr_facts(org, ns, int(facts["pr_number"]))
except Exception as e: # noqa: BLE001 — the brief stands without the reviewers, unstored
logger.info("review_brief: qa facts for PR %s failed: %s", facts.get("pr_number"), e)
logger.info("review_brief: tracker facts for PR %s failed: %s", facts.get("pr_number"), e)
degradations.partial("code.review_brief", "reviewers_unread", e)
tracker_status, tracker_row = FAILED, {}
title_from = "tracker" if tracker_row.get("title") else "mirror"
Expand All @@ -185,7 +185,9 @@ async def mirror_provenance(org: str, ns: str, facts: dict[str, Any]) -> dict[st
return {
"source": BUILT_FROM_MIRROR,
"ledger": LEDGER_ABSENT,
"merge_commit": "mirror_first_parent",
# a commit the read or the stored row names is taken as named; a PR's number is
# placed on the mirror's first-parent chain
"merge_commit": "named_commit" if facts.get("named_commit") else "mirror_first_parent",
"files": "mirror_diff",
"title": title_from,
"tracker": tracker_status,
Expand Down
Loading
Loading