Skip to content

A brief stored at an older payload version is rebuilt on read, once per row and version - #2358

Merged
zlareb1 merged 30 commits into
mainfrom
fix/brief-rebuild-on-rule-change
Dec 6, 2026
Merged

zlareb1 merged 30 commits into
mainfrom
fix/brief-rebuild-on-rule-change

Conversation

@zlareb1

@zlareb1 zlareb1 commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

Related: #2040
Related: #2218

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

code.review_brief rebuilds a brief stored at an older payload version (a merged PR's from its merge commit, an open PR's at the same head) and stores the new one, so old briefs no longer stay unsettled with brief:v<n>. When it cannot rebuild, it serves the stored brief and names code.review_brief: stale_brief_served with the cause in degraded.

Why

A stored brief is served as it was built. A brief stored at a lower payload version answered unsettled with brief:v<n> on every read, with no way for it to settle. Rule changes that alter a brief's answer (#2268, #2269, #2310, #2315) did not bump the version, so a stored brief also kept a verdict the current rules would not give.

The version is now the version of the rules a brief is built and answered by. The comment beside PAYLOAD_VERSION says to bump it in any change that alters what a build stores or what brief_verdict answers over a stored brief. This PR bumps it to 3 for every rule change merged before it: the ones above, and #2359, which adds regression_prs to history rows. A read of a merged PR's brief stored at a lower version builds it again from its merge commit, using the same path as a miss, and stores it in place of the old row (same key, so the new insert replaces it).

Bounded cost: a read rebuilds at most once per stored row per version.

  • A read that cannot store does not build: store: false or a measurement consumer. Otherwise it would build again on every read. It serves the stored brief.
  • A host without the repository's mirror, or whose mirror has yet to fetch a merged row's merge commit, does not build and writes no marker. It could not read the diff, and the build would be left unstored. A host whose mirror holds the commit rebuilds it.
  • A build that raises, finds nothing or is left unstored (for example a diff it could not read) serves the stored brief, with stale_brief_served (rebuild failed) in degraded and the build's notes after it as they were (the stale note goes first, so the note cap cannot hide it); an exception from the build (such as a ledger read that times out) is caught the same way. It writes the old payload back with rebuilt_for: <version> and rebuild_notes, so later reads of that version serve it without building. A build of a newer version tries once more. That marker row keeps the replaced row's key (merge_sha column, which is the head for an open brief) and built_at, and takes its version plus one: a rebuild stored by any replica is stamped with its store time, so it wins in either order. Before writing, the read takes the row again. If another replica stored a rebuilt brief in the meantime, it serves that one; if a build of this or a newer version marked the row meanwhile, it keeps that marker. If the row was deleted while the build ran, it writes nothing. A merged row is rebuilt by its PR number and its own merge commit: the ledger is read by both, and the mirror by the commit. A commit whose subject names another PR is a miss, so the row is marked the same way. A rebuild's version is its host's clock, so on a host whose clock runs behind the stale row's writer by more than the time since that write, the rebuild loses to the row and reads build again until the clock passes it (rule 103 says so).
  • Concurrent first reads of one row can each build once, as concurrent misses do today. A read after a stored rebuild or a marker builds nothing.
  • The marker holds for the version whatever made the build fail, a passing failure on one host (a timed-out read, a failed git call) included. That keeps the bound at one build per stored row and version, as asked. The cost is that such a brief keeps its old answer (unsettled with brief:v<n>, or gaps) until a higher version tries again. Retrying after a delay was rejected because it would trade that bound for a time-based one. The one exception is a marker that cannot be written (the store refuses inserts): the row stays unmarked, and the next read builds again.

Rolling upgrades (rule 103): build N-1 serves N's newer payload as it is (its version is not lower), answering its verdict by its own rules, and never rewrites a stored row. The current release stores v1 briefs and has no brief verdict: it serves N's rows as stored sections and never rewrites a row on read, and the v1 rows its ingest writes are rebuilt once by N. A later bump that adds a cause N-1 does not know must ship N-1's reading of it first. N rebuilds only rows of a lower version, so at most once per row an N-1 build writes (a new merge it ingests). A row marked by N carries the old version, which N-1 serves unchanged.

Rejected: rebuilding on every read of an old row (no bound), and rebuilding without storing for reads that cannot store (no bound either).

Assumptions about the repository

None beyond what the miss path already reads. The change keys on the stored payload's version, the namespace's configured mirror (present_dir, and whether it holds the merge commit) and the merge facts the ledger or the mirror give for the PR. It reads no path layout, test convention, language or PR-title rule. The tests run on a made-up Python repository (greeter/, checks/, branch trunk), and the measurement below covers a C++ and a Python repository.

Scope and risk

  • Touches the stored-brief read in server/code/app/review_brief.py, the version constant and its comment, the point read's column list, the history docs page and a new rule 103 in docs/architecture/rolling-upgrades.md. An open PR's brief of an older version is rebuilt at the same head through the open build; one the merged read finds by number is served with stale_brief_served, never built as a merged brief.
  • The first read of each old merged brief pays one build, as a miss does today.
  • The worst outcome would be a rebuild that settles on a change that is not covered. The rebuild uses the current builder and verdict, so it settles exactly where a fresh build would.

Compatibility, rollout and rollback

  • Wire: no op or field change. The op's description (model docstring, MCP text) now names the rebuild, and the store field's description (and docs/reference/operations/code.md) says it also decides whether a stored brief of an older version is rebuilt. When a read names a merge commit, a brief the ledger does not hold is now looked up in the mirror by that commit (it was looked up by PR number when the read named both), and a commit whose subject names another PR than the one asked for is a miss. A brief built from a commit the read or the stored row names (every mirror rebuild included) discloses merge_commit: named_commit in its provenance (it was mirror_first_parent, although no first-parent placement was made). A served stale brief adds code.review_brief: stale_brief_served (<cause>) to degraded. An open PR's brief built without its items row (a failed read) now answers stored: false; it was never stored, but the answer said stored: true.
  • Operator steps: none. Old briefs are rebuilt as they are read.
  • Rollback: rebuilt rows are newer rows of the same key and stay valid. Marker keys in a stored payload are ignored by older builds.

Tests

  • New in tests/unit/test_code_review_brief_mirror.py, on a made-up repository:
    • a ledger-backed brief is rebuilt from its ledger row (source: built);
    • the marker row's version is the replaced row's plus one, and a failed build writes nothing over a brief another replica stored or a row deleted meanwhile;
    • a version-2 row is rebuilt once, stored at the current version and then served as stored;
    • store: false, a measurement consumer, a host without the mirror and a mirror without the merge commit and one git cannot read (mirror unreadable) serve the stale brief with no build and no write;
    • a build whose diff cannot be read serves the stale brief with its cause and marks the row, the next read builds nothing, and a newer version builds again;
    • a failed build serves the brief another replica stored meanwhile;
    • a rebuild whose ledger read raises serves the stored brief and marks the row;
    • a merged row is rebuilt at its own merge commit (the mirror is asked for that commit), so the brief is stored under the row's key;
    • a brief stored by a newer build is served as it is, and a build of a lower version builds nothing over a newer build's marker;
    • an open PR's brief built without its items row answers stored: false and stores nothing;
    • a stored rebuild keeps the notes its mirror lookup recorded;
    • a merge commit that names another PR builds nothing and marks the stale row, and the next read builds nothing;
    • a miss of PR 42 at a merge commit whose subject names another PR answers missing and stores nothing;
    • the stale note comes first when a rebuild's notes fill the note cap;
    • an open PR's brief of an older version is rebuilt through the real open build and stored under (PR, head); when its items row cannot be read the build is left unstored, so the row is marked and the next read builds nothing;
    • an open PR's brief of an older version is rebuilt at its head; left unstored, its marker keeps the (PR, head) key and built_at; read as merged, it is served without a build.
  • Hand-built stored payloads in test_code_review_brief_sections.py now carry the current version, and the version-1/2 rationale cases read with store: false. The pinned payload digest in test_code_review_brief_no_groups.py changes only by v (with PAYLOAD_VERSION = 2 the old digest still matches).
  • make format-check, ruff check, the function-length and secrets gates, the docs/reference/settings codegen checks and mypy on the changed modules are clean. Focused review-brief tests pass; tests/analyzer/shapes.txt is regenerated for the point read's added version column.
  • Measured on a large C++ repository's code namespace, read-only: 7357 stored briefs at v1 and 216 at v2. I took the 24 newest (12 v2, 12 v1) and rebuilt them in process with store=False and trace writes stubbed out. Stored answers: 17 unsettled, 7 gaps. Rebuilt answers: 10 gaps, 9 no_source_change, 5 unsettled.
    • 13 briefs whose only cause was brief:v<n> now settle as no_source_change or report gaps.
    • No rebuilt brief settled as covered_no_gaps or nothing_to_check.
    • Three v1 briefs that said gaps became unsettled with symbols:unmapped_changes. The current rules read lines the v1 build did not.
  • Measured the same way on the Loom repository's own namespace (Python and TypeScript; 3644 v1 and 216 v2 stored briefs), 20 newest (10 v2, 10 v1):
    • The 10 v2 briefs rebuilt to 4 gaps, 5 unsettled and 1 no_source_change. The no_source_change one had brief:v2 as its only cause. The gaps verdicts were unchanged, and the 5 unsettled ones lost brief:v2 and kept their causes.
    • The 10 v1 briefs name PRs that neither the ledger nor the mirror holds, so the build answers missing. That is the failure path: the stored brief is served, and the row is marked so later reads do not build again.
    • No rebuilt brief settled.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. The rolling-upgrade cases, the rebuild bound and the measurement were checked against the code and the stored rows.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Local format, lint, type checks and focused tests pass. The full make test-unit and applicable integration results are reported by CI; a full local run is not required before pushing.
  • Generated files are regenerated in this PR, not by hand: docs/reference/operations/code.md (python scripts/codegen/docs_reference.py) and tests/analyzer/shapes.txt (python -m tests.analyzer.corpus --write).
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code


Note

Medium Risk
Changes verdict and caching behavior for stored review briefs (including on-demand rebuilds and concurrent markers), but scope is bounded to one rebuild per row per version and is heavily covered by new unit tests.

Overview
code.review_brief no longer leaves old cached briefs stuck on unsettled with brief:v<n> after rule changes. PAYLOAD_VERSION moves to 3 (documented as the version of build/verdict rules), and a read of a stored brief with a lower v triggers a one-time rebuild at the same key (merged PR at merge commit, open PR at head), replacing the row on success.

When rebuild cannot run or persist (store: false, no/unready mirror, build failure, wrong PR on commit), the handler serves the stored payload and adds code.review_brief: stale_brief_served to degraded. Failed attempts can write a marker row (rebuilt_for, rebuild_notes, bumped version) so the same build version does not retry every read; newer versions can try again. During rollouts, briefs at a newer payload version are served as-is (documented as rolling-upgrade rule 103).

Related behavior tweaks: mirror miss path prefers a named merge_sha over PR-number first-parent lookup, provenance can expose named_commit, open builds without a readable items row answer stored: false, and the point read selects version from ClickHouse.

Reviewed by Cursor Bugbot for commit 65626a5. Bugbot is set up for automated code reviews on this repo. Configure here.

…read

A stored brief whose payload version is below PAYLOAD_VERSION answered
`unsettled` with `brief:v<n>` on every read, and rule changes that alter
a brief's answer did not bump the version. A read of a merged PR's brief
of an older version now builds it again from its merge commit through the
miss path and stores it in its place. The stored brief is served, with
`code.review_brief: stale_brief_served` in `degraded`, when the read may
not store, the host has no mirror, or the build fails or is left
unstored; a failed build marks the row with the version it tried, so it
runs at most once per stored row and version. A brief of a newer version
is served as it is. PAYLOAD_VERSION is 3, and its comment says when to
bump it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
@vercel

vercel Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Dec 6, 2026 10:11am UTC
loom-telemetry Ready Ready Preview Dec 6, 2026 10:11am UTC

Request Review

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/code/app/review_brief.py Resolved
…a deleted row

The marker row takes the version of the row it replaces plus one, below any
build's, so a rebuild another replica stores in either order wins. A row
deleted while the build ran is not written again. The new tests use a made-up
repository, and cover a ledger-backed rebuild.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/code/app/review_brief.py Resolved
…ts row's key

Raising the payload version left open-PR briefs unsettled until a push; they now
rebuild through the open build under the same bound. The failed-build marker is
written from the re-read row with its merge_sha key and built_at, so it never
lands under a new key or outranks a later build of another merge commit. An
open PR's brief found by a merged read is served, not built as a merged one.
rolling-upgrades.md gains rule 100 for the payload version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/code/app/review_brief.py Resolved
…its cause names every note

A merged rebuild the mirror places at another merge commit is stored under that
key and leaves the stale row; it now counts as not stored, so the row is marked
and a read of the old commit does not build on every call. The cause joins all
of the build's notes. _rebuild takes pr_number and the sha and calls the build
with it; the docstrings name the rebuild beside the miss.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
@zlareb1 zlareb1 changed the title A merged PR's brief stored at an older payload version is rebuilt on read, once per row and version A brief stored at an older payload version is rebuilt on read, once per row and version Dec 6, 2026
zlareb1 and others added 2 commits December 6, 2026 06:20
…ich rules N-1 answers by

The ledger read in the miss path raises outside its try; a rebuild now catches
any exception from its build and serves the stored brief with the cause. The PR
number comes from the stored row alone. The docs list a build stored under
another merge commit, and the rolling-upgrade rule says N-1 answers a newer
brief by its own rules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>

# Conflicts:
#	docs/architecture/rolling-upgrades.md

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/code/app/review_brief.py Resolved
zlareb1 and others added 3 commits December 6, 2026 06:29
…er write that fails is tested

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…ted through the open build

The store comment (and its reference page) names the rebuild of an older
brief. A test runs the real open build and checks the row is stored under the
PR's head. The _rebuild docstring points to the docs page; rule 101 notes an
N-1 without a verdict.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…rs a newer build's marker

The build's notes are listed in degraded (and stored in rebuild_notes) instead of
folded into one cut-off cause; stale_brief_served says rebuild failed. A re-read
that finds a marker of this or a newer version keeps it. _build_at builds for the
miss path and the rebuild alike, so _rebuild takes the row's key and PR number
explicitly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/code/app/review_brief.py Resolved
zlareb1 and others added 4 commits December 6, 2026 07:05
…the op text names the rebuild

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…t says a rebuild happens on a read

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/code/app/review_brief.py Resolved
zlareb1 and others added 2 commits December 6, 2026 07:45
…ing it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…rror has its own cause

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

There are 4 total unresolved issues (including 3 from previous reviews).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 529a568. Configure here.

Comment thread server/code/app/review_brief.py Resolved
zlareb1 and others added 6 commits December 6, 2026 07:59
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
… drop it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…he clock bound

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…ommit is a miss

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
… is pinned

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
zlareb1 and others added 9 commits December 6, 2026 09:13
…ests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…line says tracker

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…ommit_facts docstring

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…version marker

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…repeat

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
@zlareb1
zlareb1 merged commit e0ebd1a into main Dec 6, 2026
82 of 85 checks passed
@zlareb1
zlareb1 deleted the fix/brief-rebuild-on-rule-change branch December 6, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant