Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
3f90d41
code.branch.diff lists how two branches differ
KaloyanNaumov Dec 1, 2026
2e691e5
The SDK public-API snapshot lists code.branch_diff
KaloyanNaumov Dec 2, 2026
d7baa68
The branch diff integration test is formatted
KaloyanNaumov Dec 2, 2026
50af90c
code.branch.diff lists a definition whose text changed in place
KaloyanNaumov Dec 2, 2026
0712609
code.branch.diff caps overlap candidates after checking they are read…
KaloyanNaumov Dec 2, 2026
6149124
code.branch.diff states the merge-base divergence of the two heads
KaloyanNaumov Dec 2, 2026
e6dd2fa
code.branch.diff fingerprints a definition from the chunk it owns
KaloyanNaumov Dec 2, 2026
9a4155b
code.branch.diff reads the divergence through the guarded git helpers
KaloyanNaumov Dec 2, 2026
8b8d5d0
code.branch.diff fingerprints a packed SQL statement from its whole c…
KaloyanNaumov Dec 2, 2026
fa8ad5f
Merge upstream main into code.branch.diff
KaloyanNaumov Dec 2, 2026
7de678b
code.branch.diff reports a side that is mid-publish as unstable
KaloyanNaumov Dec 2, 2026
a2cdf96
code.branch.diff fingerprints read the served embedding model's chunks
KaloyanNaumov Dec 2, 2026
e28372f
code.branch.diff overlaps match one overload, not every definition of…
KaloyanNaumov Dec 2, 2026
2c7441c
Merge upstream main into code.branch.diff
KaloyanNaumov Dec 2, 2026
c24195e
Operations reference states when heads_stable is false
KaloyanNaumov Dec 2, 2026
375f0f3
A commit is marked in progress from its first row until git_head moves
KaloyanNaumov Dec 2, 2026
f5617fc
code.branch.diff fences a commit an older worker is publishing
KaloyanNaumov Dec 2, 2026
f55dffd
code.branch.diff reads its four limits from server settings
KaloyanNaumov Dec 2, 2026
fd9055c
The N-1 publish window is rolling-upgrade rule 71
KaloyanNaumov Dec 2, 2026
09c4cd3
code.branch.diff counts a deletion's tombstones after the head
KaloyanNaumov Dec 2, 2026
2976e73
Merge upstream main into code.branch.diff
KaloyanNaumov Dec 2, 2026
079976d
Merge main into pr/1680-04-branch-diff
KaloyanNaumov Dec 2, 2026
866cc63
A branch diff gives provenance only for the head it pinned
KaloyanNaumov Dec 2, 2026
6b45bac
The missing-head lookup stays inside the divergence budget
KaloyanNaumov Dec 2, 2026
28eff76
The publish fence counts chunk rows too
KaloyanNaumov Dec 2, 2026
1a9e1ec
A merge-base timeout is reported as git_timeout
KaloyanNaumov Dec 2, 2026
87f7262
Leave the stored slice cursor alone when its read fails
KaloyanNaumov Dec 2, 2026
497748e
The publish fence holds across a hand-over to a slower clock
KaloyanNaumov Dec 2, 2026
ae14649
A Git read past its time raises a typed timeout
KaloyanNaumov Dec 2, 2026
00f421c
Merge upstream main (bd58b7b65) into pr/1680-04-branch-diff
KaloyanNaumov Dec 3, 2026
a4c1895
An unreadable slice cursor starts nothing
KaloyanNaumov Dec 3, 2026
f423412
The publish fence reads the head's tree, not only the writers' clocks
KaloyanNaumov Dec 3, 2026
76a88f5
Merge upstream main (c299aa504) into pr/1680-04-branch-diff
KaloyanNaumov Dec 4, 2026
56b26ee
Merge upstream main (5301f2920) into pr/1680-04-branch-diff
KaloyanNaumov Dec 4, 2026
445d85d
code.branch.diff: fence on the rows the read captured, not on the wri…
KaloyanNaumov Dec 4, 2026
53089e7
Merge upstream main (8c9e1dd49) into pr/1680-04-branch-diff
KaloyanNaumov Dec 5, 2026
c951c2c
The ancestry check of code.branch.diff treats a git error as unknown,…
KaloyanNaumov Dec 5, 2026
deeb183
A tree listing for code.branch.diff keeps the directory its paths share
KaloyanNaumov Dec 5, 2026
81bbc2e
The definition fence of code.branch.diff re-reads every path the read…
KaloyanNaumov Dec 5, 2026
0b2ce59
The publication fence of code.branch.diff covers a file a previous bu…
KaloyanNaumov Dec 5, 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
29 changes: 29 additions & 0 deletions docs/architecture/rolling-upgrades.md
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,35 @@ See the [participant lifecycle baseline](cells.md#participant-lifecycle-baseline
worker build. No gate holds the rollout. `tests/unit/test_worker_source_copies.py`
checks N's side, and the mixed-version gate does not check this rule.

78. **A commit an N-1 ingest worker is publishing** (`code.branch.diff`'s `heads_stable`):
N's worker sets the commit's slice cursor before its first row and clears it after
`git_head` moves. N-1 sets none for a commit of one round, and clears the cursor
before `git_head` moves, so a missing cursor does not show that N-1 has finished. A
code-only release keeps the workers on N-1 until it stops (rule 6). N's reader
therefore fences on what the read itself captured, not on the writers' clocks, and the
fence has two halves because a write can land on either side of the read. The rows it
founded the answer on — the tree-sitter `code_symbols` rows and the `code_chunks` rows
under the served embedding model — are digested when they are read and read again after
them, which catches a write that lands while the read runs. Each of those rows names the
commit it was written at, and every one of those commits must be the head or in its
history: one `rev-list` against the head catches a write that had already landed
before the read began, which is the N-1 shape, since N-1 flushes a round's chunk rows
before its symbol and file rows. A commit the mirror does not hold is unverifiable and
counted as neither, and so is ancestry git cannot read (a head the mirror lacks). The files are compared one way with the blobs the head's tree holds
at exactly the manifest's paths — a row whose path the tree does not hold, or whose blob
differs, is another commit's file, and a tree path with no live row is one the index
declines to hold (the denylist, a binary, a path outside the configured prefixes, a
submodule), so a settled partial index does not read as a publish. A deleted file has
no live row to compare, so a tombstone stamped after the head's row was written counts
as another commit's whatever version its writer gave it. The version count
over the three tables stays as the cheap first exclusion; it is not the fence, because a
previous build whose clock trails the head's is invisible to it. Without the mirror, the
two git legs are left out and the digest and head checks stand.
`tests/unit/test_code_branch_diff.py` replays N-1's write order on both sides of the
read; `tests/integration/test_code_branch_diff.py` runs its slower-clock apply against a
real head and reads the capture off the store. 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
51 changes: 51 additions & 0 deletions docs/features/code-index/history-and-prs.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ no merged-date search, so the branch is matched on each PR's `base.ref` and
| 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) |
| How do two branches differ, and which others change the same code? | `code.branch.diff` (`overlaps` for the others) |
| Which CI build first carried this commit? | `code.first_build` |

Arguments are in the [operations reference](../../reference/operations.md#code).
Expand Down Expand Up @@ -587,6 +588,56 @@ 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.

## Branch diff

`code.branch.diff` takes `namespace`, `against` (another namespace, usually the trunk's) and
an optional `path_prefix`, and answers what the two indexes hold differently: the files
added, removed and changed (judged by blob), then the definitions added, removed or changed
on those paths, from the tree-sitter symbol rows. A definition counts as changed when its
signature, the length of its line span or its text differs (`reasons`: `signature`, `size`,
`body`). The text is compared through the content hashes of the chunks that carry the
definition's text, so a one-line fix inside a body is a change: a function or container
chunk is the definition's by its first tag, and a chunk that packs several SQL test
statements (with statement records on) is every one of those statements', since its text
cannot say which of them changed. One that only moved down the file because lines were
added above it is counted in `definitions_moved` and not listed. A definition no chunk
carries (one nested in another's chunk, or a body-less declaration a container's skeleton
lists) is compared by signature and span only; the enclosing definition carries its edit.

It compares the two **indexed heads, tip to tip**, and pins both `git_head` values in the
answer (`head`, `base`). A change already on `against` and absent from `namespace` shows as
a removal, so `divergence` states how the heads relate: their `merge_base`, and `ahead` and
`behind`, the commits each head has that the other lacks. A branch with `behind: 0` is up
to date with `against`, and its removals are its own; otherwise some may be additions made
on `against` after the fork. The divergence is read from the git mirror both namespaces
share, never cloned or fetched for this: two git reads, each bounded at 2 s. Without that
mirror on the serving process, with a head the mirror lacks, or when git fails or runs out
of time, it is `unknown` with a `reason`, and the rest of the answer stands. If a side's
head moves while the rows are read, or the side is partway through publishing a
commit (its rows hold files, definitions or chunk text of a commit its head does not name yet),
`heads_stable` is false and the answer may mix two commits of that side. The same holds
for the head of every overlap row. A publish is decided by what the read captured, not by
the writers' clocks: the definition rows the answer is built from are digested when they are
read and read again after them, so a row that moves under the read is caught whatever
version its worker stamped, and every commit those rows name must be the head's, so a row
that had already landed before the read began is caught too; the files are compared, one
way, with the blobs
the head's tree holds at exactly the manifest's paths, so a row whose blob is not the head's
is another commit's file while a file the index declines to hold — a binary, a path outside
the configured prefixes — is not. Without the repository's mirror on the serving process,
the tree comparison is left out and the definition capture and head checks stand.

Both namespaces are authorized before any read, failing closed: one the caller cannot read
refuses the call, as in every named fan-out. `overlaps: true` adds the other namespaces of
the same repository that change a definition `namespace` changes against the same
`against`; a candidate the caller cannot read, or that has no index yet, is skipped and
named in `overlaps_skipped`. At most 16 readable candidates are compared; an unreadable one
takes no slot. Each list is cut at `limit`
(default 100, at most 500) with its total beside it; there is no continuation, so narrow a
large answer with `path_prefix`. A side that holds more than 200,000 files under the prefix
refuses and asks for a narrower one, and the definitions of at most the first 2,000
differing paths are read (`definitions_complete` says when more differ).

## First build

`code.first_build` takes a commit `sha` or a merged PR's `pr_number` and answers which CI
Expand Down
9 changes: 9 additions & 0 deletions docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,15 @@ One code namespace indexes one repository. No repository is configured by defaul
| `LOOM_CODE_CONVENTIONS_DIFF_MAX_BYTES` | `int` | `1500000` | | Max bytes of a PR patch code.conventions reads from the mirror; a longer patch is cut at a file boundary and flagged `diff_truncated`. |
| `LOOM_CODE_CONVENTIONS_WIDE_CALLER_DIRS` | `int` | `5` | | A touched function is "widely called" when its hop-1 callers span more than this many `src/<dir>` directories (rule wide_callers_untested). |

### code.branch.diff

| Variable | Type | Default | Live | Meaning |
| --- | --- | --- | --- | --- |
| `LOOM_CODE_BRANCH_DIFF_MAX_MANIFEST_FILES` | `int` | `200000` | | Files one side's manifest may hold under the path prefix before the call asks for a narrower `path_prefix` (the largest indexed repository holds about 40 thousand). |
| `LOOM_CODE_BRANCH_DIFF_MAX_DEFINITION_PATHS` | `int` | `2000` | | Differing paths whose definitions are read; the rest are counted and the answer says `definitions_complete: false`. |
| `LOOM_CODE_BRANCH_DIFF_MAX_OVERLAP_NAMESPACES` | `int` | `16` | | Readable sibling namespaces `overlaps` compares; the rest are named `over_cap`. |
| `LOOM_CODE_BRANCH_DIFF_DIVERGENCE_TIMEOUT_S` | `float` | `2.0` | | Seconds each git read of `divergence` (the merge-base and the ahead/behind count) may take before the answer is `unknown`. |

### Multi-repo and self-service

| Variable | Type | Default | Live | Meaning |
Expand Down
3 changes: 2 additions & 1 deletion docs/reference/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ python scripts/codegen/docs_reference.py --check # exit 1 when a region is stal
<!-- Generated by `python scripts/codegen/docs_reference.py`; edit the source, not this region. -->
<!-- prettier-ignore-start -->

387 operations in 43 groups. Every op is served at `POST /v1/<op>` and as the MCP tool `loom_<op>` (dots become underscores).
388 operations in 43 groups. Every op is served at `POST /v1/<op>` and as the MCP tool `loom_<op>` (dots become underscores).

Columns: **Role** is the minimum role (`viewer` < `writer` < `admin` < `org_admin` < `platform_admin`); **Kind** is `read` (idempotent, viewer, unaudited, writes nothing — MCP `readOnlyHint`), `idempotent` (safe to retry) or `write`; **Listed under `all`** says whether an MCP connection on the `all` toolset lists the op in `tools/list` (`code.*` ops only with `LOOM_MCP_CODE_TOOLS=true`); an op marked `no` is still callable by name or through `loom_op`, unless it is hidden from MCP; **Audit** marks ops that leave an `audit_log` row.

Expand Down Expand Up @@ -192,6 +192,7 @@ Fields for every `code` op: [operations/code.md](operations/code.md).
| [`code.backport_gaps`](operations/code.md#codebackport_gaps) | The set-wide backport report: which merged fixes labelled for backport does a release branch still owe? | viewer | read | no | |
| [`code.bisect_candidates`](operations/code.md#codebisect_candidates) | Rank PRs that may have introduced a bug; Loom does not test or reproduce it. | viewer | read | no | |
| [`code.blame_range`](operations/code.md#codeblame_range) | Which merged PRs last touched these lines, between release A and B? | viewer | read | no | |
| [`code.branch.diff`](operations/code.md#codebranchdiff) | The files, then the definitions, that `namespace` has and `against` lacks or holds differently: both branches' indexed heads compared tip to tip, files by blob. | viewer | read | no | |
| [`code.calibrate`](operations/code.md#codecalibrate) | Derive this namespace's calibration from the authored probe corpus and persist it: the code-specific abstention thresholds and the confident-hit cosine at the top of the `retrieval_confidence` scale. | admin | write | no | yes |
| [`code.callees`](operations/code.md#codecallees) | What does this symbol call — forward call edges (depth<=3), tier-marked like code.callers. | viewer | read | no | |
| [`code.callers`](operations/code.md#codecallers) | Find callers before editing shared code. | viewer | read | yes | |
Expand Down
41 changes: 41 additions & 0 deletions docs/reference/operations/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,47 @@ Which merged PRs last touched these lines, between release A and B?
| `tracker_unavailable` | `bool` | True when a tracker is bound but its read failed; the candidates stand without `has_test` / `caused_by` / `fixes`. |
| `trace_run_id` | `str` | Id of this call's trace row; pass it to `code.outcome`. |

## `code.branch.diff`

The files, then the definitions, that `namespace` has and `against` lacks or holds differently: both branches' indexed heads compared tip to tip, files by blob.

`POST /v1/code.branch.diff` · MCP `loom_code_branch_diff` · role `viewer` · read · not listed under the MCP `all` toolset

| Input field | Type | Default | Meaning |
| --- | --- | --- | --- |
| `org` | `str` | `''` | The tenant (first element of the identity tuple). |
| `namespace` | `str` | `''` | The namespace the op reads or writes. |
| `agent` | `str` | `'-'` | The writing or reading agent; `'-'` or `'*'` means any agent where the op allows it. |
| `user_id` | `str` | `'-'` | The end user the row belongs to; `'-'` for none. |
| `consumer` | `str` | `''` | trace attribution: which integration is calling (clickgap\|claude-code\|…) |
| `against` | `str` | required | The namespace to compare `namespace` against, usually the trunk's. |
| `path_prefix` | `str` | `''` | Compare only the paths under this prefix; '' compares every indexed path. |
| `overlaps` | `bool` | `False` | Also name the other readable namespaces of this repository that change the same definitions against the same base. |
| `limit` | `int` | `100` | At most this many rows in each list of the answer (1..500). |

| Output field | Type | Meaning |
| --- | --- | --- |
| `compares` | `str` | What the answer compares, in words: the two indexed heads, tip to tip. |
| `head` | `BranchDiffSide \| None` | `namespace`'s side, then `against`'s: each head is the commit pinned for every row below. |
| `base` | `BranchDiffSide \| None` | |
| `divergence` | `BranchDiffDivergence \| None` | The two heads' merge-base and how far each is from it, so a removal can be read as this branch removing a path or the trunk adding it after the fork. |
| `heads_stable` | `bool` | False when either side's indexed head, or an overlap row's, moved while the rows were read; was partway through publishing a commit; holds definition rows another commit's — changed under the read, whatever version their writer stamped… |
| `files_added` | `list[str]` | Paths `namespace` has and `against` lacks, removed paths the other way round, and paths both have with a different blob; each list is sorted and cut at `limit`. |
| `files_removed` | `list[str]` | |
| `files_changed` | `list[str]` | |
| `files_added_total` | `int` | |
| `files_removed_total` | `int` | |
| `files_changed_total` | `int` | |
| `definitions` | `list[BranchDiffDefinition]` | The definitions (tree-sitter tier) on the added, removed and changed paths that one side has and the other lacks or holds with another signature, span length or text, by path then name, cut at `limit`. |
| `definitions_total` | `int` | |
| `definitions_moved` | `int` | Definitions whose only difference is their start line. |
| `definitions_complete` | `bool` | False when more paths differ than the definition read covers; the definitions listed are those of the first paths in order. |
| `truncated` | `bool` | True when any list above was cut at `limit`. |
| `overlaps` | `list[BranchDiffOverlap]` | With `overlaps`: the other readable namespaces of the repository that change a definition `namespace` changes, against the same `against`. |
| `overlaps_skipped` | `list[dict[str, str]]` | Namespaces the overlap read left out, each {namespace, reason}: `not_readable`, `not_indexed` or `over_cap`. |
| `as_of` | `dict[str, Any]` | Provenance and freshness of `namespace`'s index (branch, commit, lag_commits, stale). |
| `against_as_of` | `dict[str, Any]` | The same for `against`'s index. |

## `code.calibrate`

Derive this namespace's calibration from the authored probe corpus and persist it: the code-specific abstention thresholds and the confident-hit cosine at the top of the `retrieval_confidence` scale.
Expand Down
Loading