Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ce673f3
code.symbol and code.grep lead with each definition's callers, test c…
zlareb1 Dec 2, 2026
40dce79
The lead block is best effort: one definition, a bounded share of the…
zlareb1 Dec 2, 2026
d9e8d69
The lead's legs leave shared work outside their lane and add a few hu…
zlareb1 Dec 2, 2026
7971e65
One lead call holds half its lane, and process-wide fills run outside it
zlareb1 Dec 2, 2026
667e857
Merge remote-tracking branch 'origin/main' into feat/symbol-grep-lead…
zlareb1 Dec 2, 2026
801e3b2
Format the code-index operations table
zlareb1 Dec 2, 2026
5d378ae
The lead block serves its three legs beside every other block
zlareb1 Dec 2, 2026
b32c2f1
The history leg reads past PRs that miss the definition, and a leg's …
zlareb1 Dec 2, 2026
02cf25b
A best-effort deadline caps a statement's class bound, and every clai…
zlareb1 Dec 2, 2026
a80aa15
Name the fills that leave the best-effort lane and the tracker reads'…
zlareb1 Dec 2, 2026
eb299df
Test that no refused lane statement is kept, and that the shunt and d…
zlareb1 Dec 2, 2026
a8680a1
Say which definitions a lead block covers and how the lane's deadline…
zlareb1 Dec 2, 2026
d50bec1
Deadline tests run on a manual clock; every refused lane statement re…
zlareb1 Dec 2, 2026
9140dee
Wrap the code.symbol lead field comment
zlareb1 Dec 2, 2026
dff74b4
The lead's coverage leg counts the tests code.coverage_claim counts
zlareb1 Dec 3, 2026
c7c9204
The lead's history shows any PR it counts, and its wall follows the c…
zlareb1 Dec 3, 2026
ddbb242
In-process integration tests import every op first, as the server doe…
zlareb1 Dec 3, 2026
e57a6ca
A grep priced by its lead block reads its lessons inside that budget
zlareb1 Dec 3, 2026
efd43ea
Lead legs need a 100 ms wall and leave code.grep's lessons their bound
zlareb1 Dec 3, 2026
60408d5
A lookup whose lead legs did not run is priced as without the block
zlareb1 Dec 3, 2026
07b5ff4
Wrap the code.grep feature page line the pricing sentence lengthened
zlareb1 Dec 3, 2026
eada0df
Merge origin/main into feat/symbol-grep-lead-block
zlareb1 Dec 3, 2026
d521cfa
A lead leg's policy deny is a value, and the tracker gate reads outsi…
zlareb1 Dec 3, 2026
dfe0fda
A code.grep that reads no lessons reserves RESERVE_S for its lead legs
zlareb1 Dec 3, 2026
01af491
A lead block whose legs all refused at once keeps the call's base price
zlareb1 Dec 3, 2026
8b2f5e3
Merge origin/main into feat/symbol-grep-lead-block
zlareb1 Dec 3, 2026
d41f6a4
Keep handle_code_symbol within the function-length gate
zlareb1 Dec 3, 2026
774a47d
Name the best-effort claim a statement holds `claim`
zlareb1 Dec 3, 2026
5fd1ab5
Merge origin/main into feat/symbol-grep-lead-block
zlareb1 Dec 4, 2026
8377866
A lead leg that did not answer is noted with degradations.partial
zlareb1 Dec 4, 2026
9f0f2d9
A lead leg cut by the call's budget or denied by policy is not listed…
zlareb1 Dec 4, 2026
21ed0f2
lead: degraded lists a busy leg; a failed one is noted with its error
zlareb1 Dec 4, 2026
6447f52
lead: say each unlisted kind is a limit working, without a list
zlareb1 Dec 4, 2026
aae8448
lead: the docstring states the degraded rule without a partial list
zlareb1 Dec 4, 2026
4c6ea3a
Merge remote-tracking branch 'origin/main' into feat/symbol-grep-lead…
zlareb1 Dec 4, 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
6 changes: 5 additions & 1 deletion bench/code_grep_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _input(call: dict[str, Any]) -> Any:
"mode": call["m"],
"path_prefix": call["path_prefix"] or "",
}
for k in ("regex", "case_sensitive", "limit", "neighbours", "include_body"):
for k in ("regex", "case_sensitive", "limit", "neighbours", "include_body", "lead"):
if k in args and args[k] is not None:
kw[k] = args[k]
return CodeGrepInput(**kw)
Expand Down Expand Up @@ -267,6 +267,10 @@ def main() -> None:
if args.cold:
cold_reads()

# the server's boot import: a call that imports the registry itself (the `lead`
# legs' policy gate) would time the import
import server.operations.registry # noqa: F401

async def go() -> list[dict[str, Any]]:
from server.code.app.index.repo_registry import read_registry_or_exit
from server.core.ch import get_client
Expand Down
25 changes: 25 additions & 0 deletions docs/architecture/clickhouse.md
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,31 @@ errors get the one reconnect-retry. A statement that gets no pool slot within
`LOOM_CH_POOL_WAIT_MS` fails with 503 `OVERLOADED` (`LOOM_CH_POOL_MAXSIZE` slots per
process).

Best-effort work a request adds beside its own reads, such as the code ops' `lead`
block, runs in a lane of its own (`best_effort()`). Its statements hold at most their
kind's share of the pool and never wait for a pool slot: a statement past the share, or
one that finds no slot free at once, raises `BusyError` before it is sent and the work
reads as not done. Every claim caps the slots its caller's statements hold at once
(`width`). For the `lead` block the share is an eighth of `LOOM_CH_POOL_MAXSIZE`, at
least one slot, or 8 when the pool is unbounded (`LOOM_CH_POOL_MAXSIZE=0`), and one
call's width half of it, at least one: at the default pool size
(64) 8 slots and 4, so two calls fit; below 16 slots one call takes the whole share. A
statement past its caller's width waits for one of that caller's slots. What is left of
the lane's deadline caps each statement's bound (the class default or a
`statement_timeout()`; an unbounded class gets what is left), on the server and in the
client. A task that outlives the block, such as a load other requests join or a
deferred write, runs outside the lane and its deadline (`shared_context()`). So do the
fills awaited inline of three caches that would keep a refused read as every request's
answer: the schema guard's ledger read and the code index's override-edge and
constructor-edge probes (`shared_work()`). The tracker-link snapshot and the tracker
source registry refresh outside the lane too: a refused refresh keeps nothing, but it
would log a warning each time and leave its call on the previous snapshot. A cache that
keeps only reads that answered, such as the code index's coverage positive control,
fills inside the lane. The history policy gate a `lead` leg passes runs before the leg
enters the lane, and the tracker binding gate its history leg's op runs reads outside it
(`shared_work()`), so their statements hold ordinary pool slots and are never refused as
best-effort work.

Reads also carry per-traffic-class settings from `LOOM_CH_SETTINGS_BY_TRAFFIC_CLASS`
(`production`, `interactive`, `bench`, `background`): `priority`, `max_threads`, and for
background work a filesystem-cache bypass. They apply only to `SELECT`/`WITH` and never
Expand Down
4 changes: 2 additions & 2 deletions docs/architecture/code-index-architecture.md

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions docs/features/code-index/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,78 @@ underscores. Toolsets: [MCP reference](../../reference/mcp.md#toolsets).
| `code.map` | you want an orientation map of the repository's modules |
| `code.trace` | you have a stack trace: each frame resolved to its unit |

`code.symbol` and `code.grep` start their answer with a `lead` block: what a
text search cannot answer about the definition they found. It covers one
definition: the first function, method, class or type definition outside test
files and documents (variables, fields, macros and document sections are
skipped). For `code.symbol` it is the first such definition the name resolves
to, and the block is left out when the answer does not serve that definition
(`min_fan_in`, `token_budget`). For `code.grep` it is the first such enclosing
definition of a first page's bodies whose name the pattern holds as a whole
identifier, else the first such one. Its entry carries `symbol`, `path` and
`line` and three answers:

- `callers`, from [`code.callers`](../../reference/operations/code.md#codecallers)
one hop: `count`, `files`, `through_overrides` (callers reached through a base
or an override), `dispatch` seeds, the first three call sites, `truncated` and
`epistemic`.
- `tested`, from
[`code.coverage_claim`](../../reference/operations/code.md#codecoverage_claim):
`verdict`, `tests`, `strongest_tier`, `measured` (`executed` or `unexecuted` by
a verified coverage run) and the first three test files.
- `changed_by`, from
[`code.symbol_history`](../../reference/operations/code.md#codesymbol_history):
`prs`, `level` (`function` when the tracker read the diffs, `file` otherwise),
`fixes`, `reverts` and the first three PRs, those naming the definition first.

The three answers run at once: in `code.symbol` beside the op's own reads, in
`code.grep` once the page's reads are done. Each passes the
[history policy](../tasks-and-decisions.md#history-policies) gate its op has.
The answers write no `agent_events` row of their own, so a rule leaf that reads
past events (`formerly`, `count_within`, `not_since`) on `code.callers`,
`code.coverage_claim` or `code.symbol_history` does not count them: a rule meant
to count the reads a `lead` block makes names `code.symbol` or `code.grep`.

The answers share what the latency budget of the call's shape leaves after the
time already spent, less a reserve for the rest of the answer, and at most what
`deadline_ms` leaves. In a `code.grep` that reads lessons the reserve is the
lessons read's own bound (`LOOM_CODE_ENRICH_TIMEOUT_S`, 0.5 s): the answers leave
it its whole bound; it still ends where the `lead` budget does. A value near that
budget leaves the answers no time, and such a call serves no block. The shape is
`lead`, 600 ms for `code.symbol` and 1000 ms for `code.grep`; a `code.symbol`
lookup ranked by `near_paths` or `pr_number` keeps its `ranked` budget (3000 ms) and one that
reads the uses brief its `uses_brief` budget (1500 ms). These budgets are not
measured in production. Raise them with a multiplier in
`LOOM_LATENCY_BUDGET_OVERRIDES`: `{"code.symbol": "2x"}` scales every shape. A
tracker statement of `changed_by` can keep running on the tracker's server after
the wall; the answer does not wait for it.
The answers' ClickHouse statements hold a bounded share of the pool
(`LOOM_CH_POOL_MAXSIZE`) and never wait for a pool slot:
[statement classes](../../architecture/clickhouse.md#statement-classes-deadlines-and-traffic-classes)
gives the share, each call's width and the work that runs outside it. An answer
that does not come back reads `{"unread": why}`, and the rest of the response is
served:

- `deadline`: still running when the budget ran out.
- `busy`: other calls held the share, or the pool had no slot free at once.
- `failed`: the op raised.
- `policy`: a history policy rule denies the op.
- `ambiguous`: the op refused an ambiguous name.
- `unresolved`: the op did not resolve the definition.

The response's [`degraded`](../../reference/http-api.md#degraded-answers) names
each answer that read `busy` or `failed`, as
`code.symbol: lead_tested_unread (busy)`; a `failed` one names the error the op
raised. The other kinds are not listed: each is a limit working, not a fallback.

The uses brief and the definitions are fitted to `token_budget` first; a block
that does not fit what they leave is withheld whole. When less than 0.1 s is left
for the answers, none starts and the block is left out, so the call keeps the
budget it has without the block. A block whose answers all came back as `busy`,
`policy` or `unresolved` before any of them read in the share is served, and its
call keeps that budget too. `lead: false` leaves the block out.
`code.edit_context` has no `lead` block; it reads the definition's tests itself.

Pass `pattern` as a list of exact strings to find any of them in one scan. For
example, `["parse(", "parse_async("]` matches both fragments without escaping
the parentheses. All alternatives share a result limit, and each matching line
Expand Down
4 changes: 2 additions & 2 deletions docs/features/code-index/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ flowchart LR

1. **Find.** `code.search` for a question in words, `code.grep` for a string you hold.
Each hit names its enclosing unit, so you rarely open the file.
2. **Pin the symbol.** `code.symbol` returns definition, signature, body, recent PRs
and (with `uses_brief: true`) top call sites.
2. **Pin the symbol.** `code.symbol` returns definition, signature, body and recent
PRs, led by the definition's callers, tests and changing PRs (`lead`).
3. **Walk the graph.** `code.callers` with `depth` hops. Read `epistemic` to know
whether the list is exact or a lower bound.
4. **Measure the change.** `code.impact` with `files` or a unified `diff` returns the
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ The code index's network git (clone, fetch, ls-remote, submodule update) through
| `LOOM_CODE_CITATIONS_GIT_CALL_TIMEOUT_S` | `float` | `3.0` | live | Seconds one git call of code.verify_citations may run, within its request budget. |
| `LOOM_CODE_CONVENTIONS_DIFF_TIMEOUT_S` | `float` | `25.0` | live | Seconds the git diff behind code.conventions may run. |
| `LOOM_CODE_EGRESS_CONNECT_TIMEOUT_S` | `float` | `15.0` | live | Seconds a repository job's egress tunnel waits to connect to its upstream host. |
| `LOOM_CODE_ENRICH_TIMEOUT_S` | `float` | `0.5` | live | Seconds one enrichment of a code result may take before it is left empty. |
| `LOOM_CODE_ENRICH_TIMEOUT_S` | `float` | `0.5` | live | Seconds one enrichment of a code result may take before it is left empty. A code.grep that reads lessons holds it back from its `lead` budget (1 s), so a value near that serves such a call no `lead` block. |
| `LOOM_CODE_ENRICH_EXAMPLE_CANDIDATE_LIMIT` | `int` | `50` | | Incoming call sites read before ranking usage examples. The coverage lookup accepts up to 50 paths. |
| `LOOM_CODE_ENRICH_INDIRECT_TEST_CALLER_LIMIT` | `int` | `30` | | Indirect test callers ranked as backups. The edge query reads up to twice this many call sites, within its 60-site work limit. |
| `LOOM_CODE_ENTRY_LOCK_WAIT_S` | `float` | `14400.0` | live | A full pass waits this long for a delta on its entry (past any delta's harness timeout). |
Expand Down
13 changes: 9 additions & 4 deletions docs/reference/operations/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,12 +598,13 @@ Before editing, read source, tests and notes.

| Output field | Type | Meaning |
| --- | --- | --- |
| `lead` | `list[dict[str, Any]]` | code.symbol only (code.edit_context never reads it), first on the wire: for the first function, method, class or type definition outside test files and documents, what a text search cannot answer. {symbol, path, line, callers, tested… |
| `definitions` | `list[CodeUnit]` | Up to 10 name matches, or the members matched by file clues, fitted to `token_budget`. |
| `lessons_left_out` | `int` | Whole linked lessons omitted to preserve definitions within an explicit request budget. |
| `ambiguous` | `bool` | True when the served definitions carry more than one distinct name/signature pair. |
| `hierarchy` | `dict[str, list[dict[str, Any]]]` | For a class / interface / enum definition, its type hierarchy from the `inherits` edges of both tiers, folded by qualified name: {"supertypes": [...], "subtypes": [...]} of {symbol, kind, via (extends \| implements), tier, confidence, path… |
| `candidates` | `list[dict[str, Any]]` | Source pointers when nothing resolved, or other hits outside a file-clue target. |
| `tokens_returned` | `int` | Estimated tokens of the answer: definitions, uses, cited documents, neighbours and hierarchy blocks together. |
| `tokens_returned` | `int` | Estimated tokens of the answer: lead, definitions, uses, cited documents, neighbours and hierarchy blocks together. |
| `trace_run_id` | `str` | Id of this call's trace row; pass it to `code.outcome`. |
| `uses` | `list[dict[str, Any]] \| dict[str, Any] \| None` | The lines mentioning the symbol's bare name for `uses: true`, or the compact block of `uses_brief`; off the wire when no uses read answered, so an empty list says the read found no line. |
| `uses_truncated` | `bool` | True when `uses_limit` shortened the list or the token cap withheld `uses_brief`. |
Expand Down Expand Up @@ -788,11 +789,13 @@ Literal or regex search of indexed source with enclosing symbols and coverage.
| `neighbours` | `bool \| None` | `None` | The neighbours graph block in the SAME call, matches mode only: the hits' enclosing functions become anchors (at most 20, first appearance) and each carries up to `neighbour_k` callers, callees and mapped tests at edge confidence >= 0.8… |
| `neighbour_k` | `int` | `5` | With `neighbours`: at most this many callers and callees per anchor (1..20). |
| `deadline_ms` | `int \| None` | `None` | The request's wall-clock budget in ms, from arrival (values under 200 read as 200). |
| `lead` | `bool` | `True` | Lead with the callers through overrides, test coverage and changing PRs of the enclosing definition the pattern names, else the first such one; default true. |

| Output field | Type | Meaning |
| --- | --- | --- |
| `lessons` | `list[dict[str, Any]]` | The memories about the answer's top files, best first, capped at `code_result_lessons_tokens`; each row {path, memory_key, namespace, excerpt, code_state}, with `rev`, `first_written`, `changed_since`, `code_moved` and `supersedes_key`… |
| `lessons_left_out` | `int` | File lessons omitted by symbol focus, a token budget, truncation or supersession. |
| `lead` | `list[dict[str, Any]]` | First on the wire when `lead` read it: the block code.symbol leads with, for the first page's first function, method, class or type definition outside test files and documents whose name the pattern holds, else the first such one. |
| `matches` | `list[dict[str, Any]]` | {path, line, text, scope, scope_start_line, scope_end_line} per matching LINE, path/line ordered except when prioritize_patterns gives different literals first-page slots. scope_* is the span of the enclosing unit named by `scope` (0/0… |
| `related` | `RelatedGrepEvidence \| None` | Related source for a qualified argument or member, separate from literal matches. |
| `contexts` | `list[dict[str, Any]]` | Exact retained source windows for this page, with inclusive line bounds. |
Expand Down Expand Up @@ -1656,7 +1659,7 @@ Find an exact definition by name or path:line.
| `example_context_lines` | `int` | `0` | Retained source lines on each side of a usage example. |
| `include_lessons` | `bool` | `True` | Attach `lessons` to the first definition: the memories linked to the symbol from `lesson_namespaces` (over MCP the caller's memory home by default) and the repository's team namespace, each with its `code_state` (`fresh`, `moved`, or… |
| `lesson_namespaces` | `list[str]` | *(computed)* | The memory namespaces whose linked memories `lessons` reads besides the repository's team rules (over MCP the caller's memory home by default); one the caller cannot read is skipped. |
| `token_budget` | `int` | `0` | Estimated-token cap for definitions and `uses_brief`; 0 (default) is unlimited. |
| `token_budget` | `int` | `0` | Estimated-token cap for definitions, `uses_brief` and the `lead` block; 0 (default) is unlimited. |
| `min_fan_in` | `int` | `0` | Definitions carry `fan_in` when the weekly stats are enabled; min_fan_in drops the rest, sort_by='fan_in' puts the most-called definition of an overloaded/ambiguous name first. |
| `sort_by` | `Literal['score', 'fan_in']` | `'score'` | `score` keeps the resolver's order; `fan_in` puts the most-called definition first. |
| `uses` | `bool \| None` | `None` | `uses=true` returns the definition AND the lines that mention its bare name — what a separate code.grep on the name would return, read beside the definition from the same chunk index — minus the definition's own span(s). |
Expand All @@ -1668,15 +1671,17 @@ Find an exact definition by name or path:line.
| `presence` | `bool` | `False` | Answer per namespace in `namespaces` whether the definition is there (the `presence` / `summary` blocks) instead of returning definitions. |
| `neighbours` | `bool \| None` | `None` | The neighbours graph block for the resolved definitions themselves — k callers, callees, tests and citing documents per definition, in the same call. |
| `neighbour_k` | `int` | `5` | How many callers, callees, tests and citing documents (each) the `neighbours` block lists per definition. |
| `lead` | `bool` | `True` | Lead with the first definition's callers through overrides, test coverage and changing PRs; default true. |

| Output field | Type | Meaning |
| --- | --- | --- |
| `lead` | `list[dict[str, Any]]` | code.symbol only (code.edit_context never reads it), first on the wire: for the first function, method, class or type definition outside test files and documents, what a text search cannot answer. {symbol, path, line, callers, tested… |
| `definitions` | `list[CodeUnit]` | Up to 10 name matches, or the members matched by file clues, fitted to `token_budget`. |
| `lessons_left_out` | `int` | Whole linked lessons omitted to preserve definitions within an explicit request budget. |
| `ambiguous` | `bool` | True when the served definitions carry more than one distinct name/signature pair. |
| `hierarchy` | `dict[str, list[dict[str, Any]]]` | For a class / interface / enum definition, its type hierarchy from the `inherits` edges of both tiers, folded by qualified name: {"supertypes": [...], "subtypes": [...]} of {symbol, kind, via (extends \| implements), tier, confidence, path… |
| `candidates` | `list[dict[str, Any]]` | Source pointers when nothing resolved, or other hits outside a file-clue target. |
| `tokens_returned` | `int` | Estimated tokens of the answer: definitions, uses, cited documents, neighbours and hierarchy blocks together. |
| `tokens_returned` | `int` | Estimated tokens of the answer: lead, definitions, uses, cited documents, neighbours and hierarchy blocks together. |
| `trace_run_id` | `str` | Id of this call's trace row; pass it to `code.outcome`. |
| `uses` | `list[dict[str, Any]] \| dict[str, Any] \| None` | The lines mentioning the symbol's bare name for `uses: true`, or the compact block of `uses_brief`; off the wire when no uses read answered, so an empty list says the read found no line. |
| `uses_truncated` | `bool` | True when `uses_limit` shortened the list or the token cap withheld `uses_brief`. |
Expand Down Expand Up @@ -1708,7 +1713,7 @@ The regression history of one function: the merged PRs that touched it (with lin
| `consumer` | `str` | `''` | trace attribution: which integration is calling (clickgap\|claude-code\|…) |
| `name` | `str` | `''` | A qualified symbol name or `path:line`. |
| `symbol_id` | `str` | `''` | An index symbol id; wins over `name`. |
| `limit` | `int` | `15` | At most this many PR rows (1–60). |
| `limit` | `int` | `15` | At most this many PR rows, newest first (1–120, the PRs the op reads). |

| Output field | Type | Meaning |
| --- | --- | --- |
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/api/code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
// The dashboard renders only the code results, so its code reads ask for no lessons.
const post = vi.hoisted(() => vi.fn());
vi.mock("../api", async (importOriginal) => ({ ...(await importOriginal<typeof import("../api")>()), post }));
import { codeCallees, codeCallers, codeSearch } from "./code";
import { codeCallees, codeCallers, codeSearch, codeSymbol } from "./code";

const id = { org: "acme", namespace: "code-repo" };

Expand All @@ -21,4 +21,10 @@ describe("code client", () => {
["/v1/code.callees", false],
]);
});

it("asks code.symbol for no lead block, which the dashboard does not show", async () => {
post.mockResolvedValue({});
await codeSymbol(id, "f");
expect(post.mock.calls.map(([op, body]) => [op, body.lead])).toEqual([["/v1/code.symbol", false]]);
});
});
Loading
Loading