Skip to content

code.symbol and code.grep lead with each definition's callers, test coverage and changing PRs - #2048

Merged
zlareb1 merged 35 commits into
mainfrom
feat/symbol-grep-lead-block
Dec 4, 2026
Merged

zlareb1 merged 35 commits into
mainfrom
feat/symbol-grep-lead-block

Conversation

@zlareb1

@zlareb1 zlareb1 commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Part of: #2040

Changelog category (leave one):

  • New Feature

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.symbol and code.grep start their answer with a lead block: for the definition found, its callers (through overrides), its test coverage and the PRs that changed it, read in the same call as best-effort work that stops at what the call's latency budget leaves (600 ms in all for a plain code.symbol, 1000 ms for code.grep); lead: false leaves it out. code.symbol_history serves up to 120 PRs (limit, was 60), every PR it reads. Update the Claude Code and Codex plugins to 1.2.176: older plugins do not send lead: false, so their code shunt and prompt pack wait for the block and the prompt pack's 600-token lookup carries it. Plugins 1.2.176 need the next server release, which serves lead: against an older server their code shunt and loom-code skill name a lead block for callers that the server does not return.

Why

Item 4 of the issue. Agents answered plain lookups with a local text search and called Loom a few times per session at most, because the ops they did call (code.symbol, code.grep) returned what a text search returns: the definition and the lines. The answers a text search cannot give sat behind three other ops: callers across virtual dispatch (code.callers), measured test coverage (code.coverage_claim) and the function-level PR history (code.symbol_history). code.symbol and code.grep already hold the resolved definition those ops key on, so they now lead with those answers by default.

Design:

  • server/code/app/lead.py calls the three handlers in-process with the consumer symbol_lead or grep_lead, the way code.review_brief calls its ops. The numbers are the ones each op gives, and the trace rows can be told apart. No query is duplicated.
  • The block covers one definition: the first function, method, class or type definition (a Java record included) outside test files and documents, the kinds a caller, a test or a PR can reach (variables, fields, macros and document sections are skipped). One, not three: an exact name resolves one definition in the common case, the others an answer lists are a call away by path:line, and each more definition would add three legs and their statements to every call.
  • For code.symbol it is the first definition the name resolves to. The legs start with the body reads, before min_fan_in, sort_by: fan_in and token_budget pick what is served, so the block is left out when the answer does not serve its definition. When min_fan_in filters that definition out, the legs are cancelled as soon as the filter has run, so the call neither waits for them nor is priced by them. Starting the legs after that pick would add the fan-in read to every call's latency.
  • For code.grep it is the first-page enclosing definition whose name the pattern holds as a whole identifier (read_all for reader.read_all(, not read), else the first.
  • The callers and history legs read the definition by its symbol id, so they do not resolve the name again. The coverage leg takes the name, as code.coverage_claim does.
  • The entry has symbol, path, line and three compact answers, each with a few counts and at most three rows with paths: callers {count, files, through_overrides, dispatch, top, truncated, epistemic}, tested {verdict, tests, strongest_tier, measured, top}, changed_by {prs, level, fixes, reverts, top}. Call sites reached through an override sort first and registrations last. PRs whose diff the tracker read and found not naming the definition are left out, and those that name it sort first.
  • The block serves its three legs whatever other blocks the answer carries. The neighbours block and the uses brief hold direct edges only (a hub brief none), with no callers through dispatch and no coverage verdict or measured state, so neither answers what a leg answers; the overlap is at most three caller rows.
  • The history leg asks code.symbol_history for every PR of its window (PR_WINDOW, 120), drops those whose diff the tracker read and found not naming the definition, and keeps three. prs counts the touching PRs of the whole window, so a leg that read fewer rows could show an empty top beside a non-zero prs: at 60 rows, a definition whose only touching PR is the 61st to 120th newest of its file read {"prs": 1, "top": []}. The op's limit stopped at 60, below the 120 rows it reads and counts, so its bound moves to the window (one constant, server/code/domain/index/symbol_history.py). Those rows are already read; only the serialized answer grows.
  • The coverage leg asks code.coverage_claim at its default limit (20). The op reads three times its limit per evidence class and counts tests over what it read, so a smaller one would cap tests (9 at a limit of 3) and could weaken strongest_tier and the verdict. The leg's tests is the op's tests_total.
  • Each leg starts a stage wall of its own inside its lead.<leg> span, so the op's stage_ms holds each leg once, under its name, and a leg op's own resolve no longer adds to the parent's. The request's work bag (code_stage_ms, the event row's stage columns) counts every span's time, the legs' own spans included; its comment says so.
  • The serializers put lead first on the wire and leave it off when empty.

Load: the block is best effort, and its share of the server's ClickHouse capacity is bounded, not removed.

  • server/core/ch.py gains a best-effort lane (best_effort(), BestEffortSlots, BestEffortClaim, BusyError). Every statement a lead leg sends through it counts against one process-wide share of the pool: ch_pool_maxsize // 8, at least one slot, so 8 of the default 64 slots (8 when the pool is unbounded). A statement past that share, or one that finds the pool with no slot free at once, raises BusyError before it is sent, without the ch_pool_wait_ms wait a request's own read takes. The leg reads {"unread": "busy"}. An eighth leaves the requests' own reads seven eighths of the pool and still lets two calls' legs run at once; it needs no new setting.
  • One call's legs hold at most half the share at once (call_slots(), at least one, 4 at the default; the claim's width). The two-calls figure holds from a 16-slot pool up: below that the share is one slot and one call takes it whole. A statement past that waits for one of its own call's slots, up to the wall, and never for the pool. So busy means other calls hold the share or the pool is full, not that the call outran its own share. Measured with the real leg handlers on a real CHClient over a fake driver whose index resolves the definition and holds nothing else (no callers, tests or PRs): one call's legs gather 9 statements at once and about 30 in all. Before the width, the 8-slot share refused one of them, and a single call alone read tested: busy. With it, one call holds 4 and two calls at once hold at most 8, and every leg answers. 9 is a lower bound: an index with callers, tests and PRs can gather more, and the width caps it either way.
  • An op that swallowed a refused read is caught by the claim's refused flag and its leg reads busy too. Its answer is dropped rather than kept as partial: such an op answers as if the read found nothing (no callers, untested), so the numbers would be wrong, not short.
  • The claim carries the wall's deadline as a monotonic instant (wall + 0.25 s). Each leg statement's max_execution_time and client timeout is what is left of it, at least 1 ms and at most the statement's class bound, so ClickHouse stops a statement soon after the wall cancels its leg and a statement sent late is not given the whole bound again.
  • The exception is the history leg's tracker reads: they go through the tracker source's own ClickHouse client, outside server/core/ch.py, so they hold no slot of the share and keep that client's limits rather than the wall's. Loom stops waiting for one at 300 ms (a point read) or 900 ms (a text read), or when the wall cancels its leg, and on the tracker's server a statement can run to its max_execution_time (LOOM_TRACKER_LIVE_TIMEOUT_S, 1.5 s by default, or the read's 900 ms) after the wall.
  • Some work a leg does for others runs outside the lane and its deadline. A task that outlives the leg keeps the request's context without the lane (ch.shared_context()): a grant-cache load other requests join (grant_cache._shared_load), and tasks started by TaskSet.spawn and create_deferred_task (a leg's trace row, the policy decision row). Three fills awaited inline run outside the lane too (ch.shared_work()), since a refusal inside one would be kept as every request's answer until its next refresh: the schema guard's ledger refresh (schema_status, the pending tables) and the override-edge and constructor-edge probes (whose fail-closed answer is kept 30 s). The tracker-link override snapshot and the tracker source registry (refresh_db_sources, reached when a leg's tracker read finds its namespace's source not loaded yet) refresh outside the lane as well, for a smaller reason: a refused refresh keeps the previous snapshot and the time it was read, so the next request reads again, but each refusal would log a warning and leave that one call on the previous snapshot. A unit test refuses each of one call's 27 lane statements in turn, over an index whose probes and coverage positive control answer yes, through the real leg handlers. Each of the 27 runs reads exactly one leg as busy, whether its op swallowed the refusal or not, and every process-wide cache holds what a call with no refusal leaves, or nothing; a fill a refusal stopped is read again by the next request. It runs in about a second, and fails when the schema guard or the override-edge probe fills inside the lane, or when the positive control keeps a refused read as no. That call does not reach the constructor-edge probe (its definition is no constructor); the refuse-everything test covers that one. The coverage positive control, the index revision and the auth caches keep only reads that answered and fill inside the lane. A statement_timeout() around the block still reaches the spawned tasks: a lease's holding() bounds every statement of the work under a claim, its deferred writes included, so no write outlives the claim. That is why the wall's bound lives on the lane rather than in statement_timeout().
  • Each leg passes the history policy gate (policy_gate.gate) the transports run for its op, with the request's identity; a deny reads {"unread": "policy"}. The gate runs before the leg enters the lane, so its statements are not counted in the share: the rule read, cached per namespace, and, when a rule applies to the op, the agent_events flush and the rule evaluation a direct call of that op runs. It runs to its end through shielded() when the wall cancels the leg, because the flush sends the process's queued agent_events (every request's) and a cancelled flush drops the batch. A deny is the gate's answer, not an exception (_policy returns False): the gate may end after the wall cancelled its leg, when nothing awaits it, since asyncio.shield drops its callback once the outer wait is done, and a raised deny there was logged as "Task exception was never retrieved". A deny that comes after the wall reads deadline. The history leg's tracker binding gate (binding._gated: the namespace classification and the caller's grant on the tracker namespace, the grant read uncached) runs inside the leg's op and reads outside the lane too (ch.shared_work()): inside it, a full lane refused those reads, the gate failed closed with a logged error, and a caller holding the grant got the history without the tracker. The legs are not counted against per-op rate limits and write no agent_events row of their own: the parent call is rate-limited and writes its event, and each leg's trace row carries its *_lead consumer. 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 lead legs; a rule meant to count them names code.symbol or code.grep. The feature page says so.
  • Process-wide, the legs' statements hold at most 8 pool slots at the default pool size, whatever the call rate. The gate's statements and the shared fills above are not counted in that.
  • The legs start outside code.grep's caller-shaped block: they run their ops' own reads, not ones the caller's pattern shapes.

Latency: the legs run at once. In code.symbol they start with the body reads right after the name resolves; in code.grep they start once the page's other reads are done. They share one wall: the effective budget of the shape the call is priced by (effective_budget_ms, so runtime and per-consumer overrides and the deployment multiplier apply), less the time the request has already spent, less a reserve for the rest of the answer: 100 ms in code.symbol (RESERVE_S). In a code.grep whose lessons read runs after the handler, the reserve is that read's bound (code_enrich_timeout_s, 0.5 s), so the lessons keep the bound they have on main however long the legs run. A code.grep that reads no lessons (include_lessons: false, code_result_lessons off, or a token narrowed below its namespaces) reserves RESERVE_S: result_lessons.lessons_read is the one check, which lessons_for makes too, and _grep_lead passes the reserve to definition_leads. code.grep also stops at the caller's deadline_ms, less the same reserve. No leg starts on a wall under 100 ms (MIN_LEG_WALL_S: the slowest leg's local p50 stage, 47 ms, and a margin). Under it each leg would read deadline while the call was priced by its lead budget, which would hide a call already past its base budget. The call serves no block instead, keeps its base price and its lessons keep code_enrich_timeout_s. A grep priced by its block still reads its lessons in no more than what is left of that budget (request_time_left_s), so work in the handler after the legs cannot push the call past it. A grep without a block keeps the read's own bound, as on main, since a budget bound there would drop the lessons of a plain grep already past its base budget. That bound is what the code enforces; the block adds no fixed latency on top of it.

  • The shape: lead for a plain code.symbol (600 ms) and for code.grep (1000 ms). A code.symbol lookup ranked by near_paths or pr_number runs its legs under its ranked budget (3000 ms), and one that reads the uses brief under uses_brief (1500 ms): both rank or read before or beside the legs, so a wall from the 600 ms lead budget left a ranked lookup whose ranking took 550 ms no block while the request was priced at 3000 ms. The shape is known before the legs start (_call_shape), and the request is priced by the same shape, so the wall never outruns the price. One change in pricing follows, for a lookup whose legs ran: when its uses brief was read but then withheld by token_budget, or came back empty, it is priced at uses_brief rather than lead, since the brief's read and the legs under that budget ran. A lookup whose legs did not run (lead: false, which the plugins send, a wall under the floor, or a definition min_fan_in filters out) is priced as on main: ranked by the change at hand, uses_brief only when the brief is served, the base budget otherwise.
  • The lead budgets are declared from the ops' own: code.symbol 600 ms (its 250 + 350), code.grep 1000 ms (its 600 + 400). Each addition is about what code.callers takes (400 ms declared), so that leg can answer in the common case; code.coverage_claim (1200 ms) and code.symbol_history (1800 ms) answer when they are fast. code.grep gets 50 ms more than code.symbol because its legs start only after the page's reads.
  • These budgets are not measured in production: no production latency or benchmark run was available for this change, so they are declared from the ops' own declared budgets. Local numbers on one index are under Tests. A leg still running at the wall is cancelled and reads {"unread": "deadline"}, and the rest of the answer is served on time. A deployment whose legs need longer raises the op's budgets with a multiplier in latency_budget_overrides (LOOM_LATENCY_BUDGET_OVERRIDES; {"code.symbol": "2x"} scales every shape, lead included). POST /v1/admin/budget.set is not a way to do it: it sets one fixed budget for every shape of the op, so 1200 ms for code.symbol would lower ranked from 3000 ms and raise the base from 250 ms. The catalog comment and the feature page say the same.
  • When no leg can start (the wall is under MIN_LEG_WALL_S), the block is left out, no degradation is noted and the request keeps the budget it has without the block: the base budget, or ranked or uses_brief for those lookups. A block whose legs all read busy, policy or unresolved before any of them held a lane slot is served, and the request keeps that same budget: the block counts as run (Block.ran) only when a leg's statement held a lane slot (BestEffortClaim.held, set by the client on a slot it took) or a leg ran until the wall, since only then did it add time. Priced by its lead budget, a 400 ms code.symbol whose legs were all refused in a full lane would read as inside its 600 ms, where the same call with lead: false is flagged past its 250 ms base budget. A request whose legs ran is priced at its shape's budget, even when token_budget then withholds the block.
  • code_enrich_timeout_s is a live setting and is now also the reserve of a code.grep that reads lessons. Set near the 1000 ms lead budget, it leaves such a call's legs no wall, so that call serves no block. Its field comment and the configuration reference say so. No degradation is noted then: a configured value is not a fallback.
  • A leg that raised reads {"unread": "failed"}. A definition name longer than a leg op takes (300 characters for code.coverage_claim and code.symbol_history, which a direct call refuses too) reads {"unread": "unresolved"} with no degradation note: it is a known limit, not a failure. The leg builds its input inside its try, and only a validation error that is all string_too_long counts as that; any other still reads failed. Each kind of unread leg is named in the entry and in the lead_unread trace argument and span attribute. A failed or busy leg is also noted once on the request's degradations list (degradations.partial(...)), which the transports put on the response's degraded (code.symbol: lead_tested_unread (busy)): a failure, or a fixed server-side bound (the lead's share of the pool, or a full pool), left it unread. A deadline, policy, ambiguous or unresolved leg is named in the entry and the trace only: each is a limit working, not a fallback. A failed leg's note shows a Loom error's code and message, and provider health records nothing. A call with lead: false writes lead: false in its trace row's arguments, for code.symbol and code.grep. A leg that raised after its call was cancelled is retrieved by a done callback, so it is not logged as lost.

Tokens: code.symbol budgets the uses brief first, the definitions in what it leaves, and the block in what both leave; a block that does not fit is withheld whole, as the brief is. The block never takes a definition's place: every definition and body lead: false serves under a budget, lead: true serves under the same budget.

Alternatives considered: one new statement that joins edges, coverage and the PR ledger would answer faster but repeat three ops' logic and drift from them. Running the legs after the bodies would add their latency to every call. A semaphore per leg would bound legs, not statements; the lane bounds the statements a leg sends. Leaving out a leg another block seems to serve would save at most three caller rows and drop answers those blocks do not hold. A width per call smaller than half the share would leave room for more calls but make each call's legs slower when they gather the most. Clearing statement_timeout() at every deferred spawn, instead of putting the wall's bound on the lane, would let a deferred write under a lease outlive its claim. Caching the block is left until a served p99 shows it is needed.

Scope and risk

  • Each default code.symbol or first-page code.grep call now runs up to three more handler calls, each with its own ClickHouse reads, bounded as above.
  • Callers inside Loom that read code.symbol or code.grep for their own purpose opt out with lead=False: memory code grounding, decision extraction, the presence and dependency-presence checks, code.edit_context's target lookup and its code.symbol read, and the assistant's first code lookup, which opens its prompt. A unit test checks that every input built for either op inside server/, whether by constructor, model_validate({...}), a by-name call with literal arguments or model_copy(update={...}) of an input sent to another namespace, names lead, since the unit-test stub would hide a forgotten opt-out. The plugins' code shunt and prompt pack and the dashboard send lead: false: none of them shows the block, and the prompt pack's 600-token budget stays with the definitions.
  • TaskSet.spawn and create_deferred_task now start their tasks outside any best-effort lane, and the schema guard, the override-edge and constructor-edge probes, the tracker-link snapshot and the tracker source registry run their fills outside it. Outside the lead, no lane is set, so their behaviour is unchanged.
  • Overloads under one qualified name: the callers and history legs read the served definition by its symbol id; the coverage leg reads every definition of the name together, as code.coverage_claim does. A row without a symbol id falls back to the name and can read {"unread": "ambiguous"}.
  • Out of scope: code.review_brief, code.test_gate and code.tests_for, which other items of the issue change.

Compatibility, rollout and rollback

  • Wire, added: lead: bool = true on code.symbol and code.grep input (left out of the MCP tool schemas; the tool descriptions say the answer starts with a lead block); lead: list on code.symbol output and on code.grep output. The output model code.edit_context shares with code.symbol carries the field, always empty; its comment says so. New budget shapes: code.symbol lead 600 ms, code.grep lead 1000 ms. Changed default: both ops' default answers include the block. The coding listing stays within its token ceiling.
  • Wire, widened: code.symbol_history limit accepts 1–120 (was 1–60), the PRs the op reads; the default stays 15.
  • Python SDK, added: CodeClient.symbol() and CodeClient.grep() take lead: bool = True and send lead: false only when it is false. The TypeScript SDK has no hand-written client for either op; its generated op types carry lead?. The SDK code tools' loom_code_lookup (Python and TypeScript) sends no lead, so its answer carries the block: that lookup serves an agent's tool loop, which the block is for.
  • Tool descriptions, removed: the coding code.symbol text drops "uses_brief: true summarizes callers" and the assistant's drops "uses_brief: true adds the top call sites". The block's callers now answers what the hint pointed agents to, through overrides, and MCP always serves the block, since lead is left out of its tool schemas. uses_brief keeps its field description in the schema for the longer list. The coding code.grep text drops "at the same path and line" and "and notes" to stay within the listing ceiling: the coding listing is at its 9,100-token ceiling, so a restored hint would need other text cut.
  • Plugin text: the code shunt's symbol-grep denial pointed agents to loom_code_symbol ... uses_brief: true for callers; it now says a plain loom_code_symbol call's lead counts the callers and lists the first three, and names loom_code_callers for all of them or more hops. The loom-code skill's "who calls X" row says the same, and the code overview's step 2 points to the lead. Both plugin copies, the served and standalone skill bundles are regenerated, at 1.2.176.
  • Break, plugins before 1.2.176: they send no lead, so against this server their code shunt (a blocking 2500 ms PreToolUse hook) and the prompt pack's code.symbol lookup (token_budget 600) get the block and wait for its legs, up to the lead budget. The prompt pack's lookup still serves the definitions it served, since the block only takes what they leave. Upgrade advice: update the Claude Code and Codex plugins to 1.2.176 or later. Both manifests move to 1.2.176, past main's 1.2.173. A plugin at this version talking to an older server sends lead: false, which that server serves and names in ignored_args, but its code shunt's denial and its loom-code skill's "who calls X" row then name a lead block that server does not return, where they named uses_brief: true. So both plugins need the next server release, as the changelog entry says; MIN_SERVER_VERSION stays at 1.4.0 here, and the release pull request raises it.
  • Operator steps: none. The lead budgets can be raised with the budget overrides above.
  • Rollback: reverting leaves nothing behind; no rows, settings or migrations are added.

Tests

  • tests/unit/test_code_lead.py (marked code_lead): definition selection (one, with its symbol id) and grep's whole-identifier pick; the pool share and the per-call width; the three compactions and their ordering. The legs through stubbed handlers:

    • callers and history read by symbol id, coverage by name, all as the *_lead consumer;
    • the history leg shows three touching PRs when the 12 newest of 40 miss the definition, and the only touching PR when it is the 80th newest of the op's 120, through the op's real input model (fails at 60 rows);
    • the wall starts from the budget of the call's shape (lead 0.6 s, ranked 3 s, uses_brief 1.5 s) through the real effective_budget_ms, and {"code.symbol": "2x"} in latency_budget_overrides doubles each; the handler runs its legs under, and prices, ranked for near_paths and for pr_number, uses_brief for the brief, also when token_budget withholds it;
    • the trace row names lead: false only when the call sent it, for code.symbol and code.grep;
    • through the real _grep_lead and the lessons wrapper, on a manual clock that moves only while every task waits (idle_time, with time.monotonic and time.perf_counter patched), so each call's seconds are exact: a grep whose legs hang to the 0.3 s wall still serves a lessons read that answers in 0.3 s and ends at 0.6 s (fails with a 100 ms reserve, which leaves it 0.1 s); with 0.3 s of handler work after the legs and a lessons read that never answers, the call ends at its 0.8 s price (1.1 s without the request_time_left_s bound); a grep that reads no lessons, with include_lessons: false and with a token pinned to one user, holds back RESERVE_S: after 0.1 s of other reads a 0.5 s callers leg answers inside the 0.8 s wall and the call ends at 0.9 s (fails when the grep always reserves the lessons bound, which leaves the leg 0.4 s, and, for the pinned token, when the check leaves out narrowing);
    • a wall above 0 but under MIN_LEG_WALL_S starts no leg and serves no block, and through the real _grep_lead keeps the base price and the lessons' own bound: a 0.3 s lessons read is served, and the call ends at 0.3 s, where the 200 ms lead price would cut it (fails without the floor);
    • a qualified name over 300 characters reads unresolved in the coverage and history legs, with no degradation note, while the callers leg answers;
    • a Java record declaration is a definition the block covers;
    • the block survives the MCP shaping (lean_result, lean_code) first and whole for both ops, every key of every leg included (fails when lean_code drops it);
    • over 15 mapped test files, through the real code.coverage_claim handler on a real CHClient, the coverage leg's tests and strongest_tier equal the op's at its default limit (a limit of 3 reads 9);
    • the Python SDK's symbol() and grep() send lead: false only when asked;
    • the op's stage table holds a leg once, under its name, with none of its op's resolve;
    • a failed and a deadline leg read unread, and only the failed one is listed in degraded;
    • Block.ran over a real CHClient: false when every leg is refused at once, true when one leg's statement held a lane slot and when one leg ran to the wall (fails when the client does not record the slot it took);
    • on a manual clock, through _grep_lead and through code.symbol, a block whose legs are all busy, all policy, all unresolved or one of each is served with those reasons and keeps the base price, lead: false's, and a control whose callers leg runs to the wall is priced by lead (fails when every block counts as run, and when either op prices by the block's entries);
    • lead_unread is left off the span when every leg answered, for both ops, as it is off the trace row (fails with the empty attribute);
    • a BusyError and a swallowed refusal read busy, and a policy deny reads policy, with every leg passing the gate with the request's identity;
    • the gate runs outside the lane and its deadline and to its end after the wall cancels its leg;
    • a deny is never left unretrieved: on a manual clock, with a loop exception handler that records every call and gc.collect() after the gates end, a gate that denies after the 0.1 s wall logs nothing and its leg reads deadline, and one that denies inside the wall reads policy (fails when the deny is raised: "Task exception was never retrieved");
    • a grant-cache load a leg starts runs outside the lane while the leg's own statements carry the wall's bound;
    • a leg's statement carries max_execution_time of what is left of wall plus margin (exactly 0.75 s for a 0.5 s wall, on a manual clock) and no caller-shaped setting even under caller_shaped();
    • only the legs asked for run; no time left starts no leg and serves no block; cap_s caps the wall; the wall arithmetic, with RESERVE_S unless the caller names its reserve;
    • a cancelled block leaves no unretrieved leg exception.
  • The lane with the real leg handlers on a real CHClient over a counting fake driver: one call's legs hold at most call_slots() (4) at once and every leg answers; two calls at once both answer and hold at most lead_slots() (8). Refusing each of one call's lane statements in turn reads exactly one leg as busy and leaves no process-wide cache holding what a call with no refusal does not. With a lane that refuses every statement, a leg's call still runs the schema guard's ledger refresh, the override-edge and constructor-edge probes, the tracker-link snapshot and the tracker source registry refresh outside it: each answers from the driver, schema_status holds no error and no pending table, the snapshot is stamped and the registry holds its source (fails with the registry read inside the lane).

  • As the caller, through code.symbol with auth on and the real leg handlers over the fake driver:

    • a code namespace bound to a restricted tracker namespace: a token that names only the code namespace passes the gate on the tracker namespace, is refused, and the history leg reads no tracker data and names none of it (level: file, no PR marked as naming the definition); a token that also names the tracker namespace gets the tracker's read (level: function, the PR it names first);
    • the same binding with the lane full, through the binding gate itself (authorized_tracker_namespace): the tracker gate's classification and grant reads are sent outside the lane, nothing at WARNING or above is logged, and the caller who holds the grant gets the tracker namespace (fails with the gate's reads in the lane: the classification read is refused, logged as an error, and the gate denies);
    • a token pinned to one user (read_user_id): every leg sends a query its op's transport admits for that token (gates.read_scope) as that user, at code.symbol's role, every leg answers, and no statement reads a memory table.
  • Through the handlers: code.symbol leads by default and notes the lead shape, and passes the call's agent and user_id to the legs (as code.grep does); lead: false and code.edit_context build no block; a handler that fails before it joins its legs (a fan-in read that raises) cancels the lead task with the others (_SymbolLegs.cancel()); beside a neighbours block or a uses brief the block keeps all three legs; for every token_budget from 40 past the whole answer in steps of 25, sorted by score and by fan-in (the block's definition second), lead: true serves the definitions and bodies lead: false serves, and the block once they leave room for it; min_fan_in filtering out the block's definition while another is served leaves the block out and cancels it rather than run its legs, which hang, to the 2 s wall (fails without the cancel: the block runs to its wall and the call is priced lead), at the base price; a lookup whose legs did not run, with lead: false and with a wall under the floor, is priced as main prices it: the base budget, ranked for near_paths and for pr_number, uses_brief when the brief is served and the base budget when token_budget withholds it (fails at the previous head, which priced that lead: false lookup at uses_brief); code.grep through handle_code_grep leads with the definition its pattern names, notes the lead shape, caps the wall at deadline_ms less the reserve, and builds no block with lead: false, without bodies, on a continuation page or for a related answer. An AST check finds every in-process caller of either op and requires a lead argument: constructors, model_validate({...}) and ("code.symbol", {...}) with a dict literal, and copies sent to another namespace. A self-check pins each form it reads; a dict held in a variable cannot be read without running the code, which the docstring says, and no caller in server/ outside the transports builds an input that way (the assistant's model tool calls go through the op transport, as an agent's do).

  • tests/unit/test_ch_client_hygiene.py: a best-effort statement past its share is refused at once and never reaches the driver while a request's own read runs; a full pool refuses one without the ch_pool_wait_ms wait; a caller's statements past its width wait for its own slots; a statement cancelled while it waits for its width releases nothing, and one cancelled in flight gives its width back; a statement is bounded by what is left of its deadline, which caps a class bound below it and never raises it (on a manual clock, with exact values); a best-effort statement cancelled mid-flight gives its share and its pool slot back; TaskSet.spawn and create_deferred_task inside a lane run outside it while a surrounding statement_timeout() still applies.

  • tests/unit/conftest.py: an autouse fixture keeps the block empty in unit tests not marked code_lead, since its legs open their own repositories and would reach a ClickHouse listening on the host.

  • tests/integration/test_code_plane.py: the grep and symbol tests assert the block for the fixture's DB::Squasher::squashImpl (its caller DB::Squasher::flush, every leg answered); two of them pin the wall with lambda *_args: 30.0.

  • tests/integration/conftest.py: a session fixture imports the op registry, as the server does at boot (server/transport/http.py). A leg's policy gate reads the registry, so in a test process that had not imported it the first code.symbol with the block imported it inside the call (about 0.7 s on the event loop), and the definition's lessons read timed out at its 0.5 s bound: test_memory_code_links.py::test_a_rename_alone_moves_the_link failed alone, and whenever it made the run's first such call. CI's shard passed it because an earlier file had imported the registry. The server never pays that import inside a request.

  • bench/code_grep_handler.py replays a trace row's lead with its other arguments and imports the op registry before its run, as the server does at boot.

  • integrations/claude-code-plugin/tests/code-shunt-hook.test.mjs: the shunt's code.symbol lookup sends lead: false. frontend/src/api/code.test.ts: the dashboard's codeSymbol sends lead: false. The prompt pack's is in the shared code-query-wire.json fixture.

  • Updated: tests/unit/test_shape_budgets.py, tests/unit/test_code_grep_scan.py and the plugins' code-query-wire.json fixture.

  • CI at c7c9204 failed two integration tests this change caused: test_code_plane.py patched lead.wall_s with a two-argument lambda, which the shape argument broke (fixed here, above). CI at dff74b4 failed three unit tests, fixed at c7c9204:

    • test_tunable_constants: the lead's LEAD_ROWS, RESERVE_S, MIN_LEG_WALL_S and _MARGIN_S and the lane's _PAST_DEADLINE_S say why they are not settings (the block's documented shape; part of the wall each lead budget is declared for, which an operator raises instead; a floor under which a leg cannot answer; ClickHouse reads a 0 bound as no limit). PR_WINDOW moves to the domain with its marker (the wire bound derives from it), and its old line leaves tunable_constants.txt.
    • test_session_content_senders: the code shunt hook and the prompt pack, in both plugins, each add only a fixed lead: false to a code.symbol body, so their exceptions' reasons hold; their four reviewed hashes are renewed.
    • test_i18n: the translation check compares each present translation's table cells with the current English by position, stale pages included, so the feature page's two new tables shifted every later cell, and the stale translations' freshness.md link cells no longer lined up. The two tables are lists now, which keeps the page's cells as its translations have them. Any change that adds table cells above a protected cell of a translated page meets the same check.
    • Not from this change: the dependency review stopped on incomplete dependency snapshots (the only pyproject.toml change is a pytest marker); the Windows on Arm plugin job failed a timing check of the test-gate hook (1666 ms after its request), which this change does not touch; at dff74b4 the WSL job was cancelled at its 30-minute limit, and at c7c9204 it failed one timing test of the record hook (a detached flush job left in the sandbox), which this change does not touch either.
  • Integration, run locally on a native ClickHouse 26.7 and a server from source in CI's main posture (auth off, fake providers, workers off, budget multiplier 10): test_code_plane.py, test_mcp.py, test_mcp_code_identity.py, test_code_grep_needles_live_ch.py, test_code_grep_source_coordinates.py, test_code_reconciliation_parameters.py, test_code_result_lessons.py, test_code_search_token_budget.py, test_ch_reader_user.py, test_cross_principal_leakage.py, test_memory_code_links.py, test_restricted_namespace_leakage.py and test_search_statements_pass_analyzer.py, the files that call code.symbol or code.grep, at ddbb242: 391 passed, 1 failed, 43 skipped (no reader user, no code org, no end-user issuer, auth off). The failure was this change's, fixed in tests/integration/conftest.py (above); test_memory_code_links.py then passed whole (222 passed). At e57a6ca test_code_result_lessons.py (4 passed) ran again on the same setup, at 60408d5, before the merge of main at 24950d9, test_code_plane.py (49 passed), and at d521cfa, after that merge, test_code_plane.py again (51 passed).

  • Measured locally, on one index: this branch's server/code/ and tests/unit/test_code* (801 files, 22,546 symbols, 33,992 edges, 20,905 chunks). It holds no PR history and no imported coverage, so changed_by reads no PRs and tested reads name-mapped tests only (19 of 27 definitions had some). One laptop shared with other work, native ClickHouse 26.7, server from source at the default budgets (multiplier 1), auth off. 30 functions and methods with at least one caller, each called by qualified name (code.symbol) and as <name>( (code.grep), once with lead and once without, alternating which goes first, after 3 warm-up calls per op. Times are client wall time; statements are the system.query_log rows carrying the call's request id. With 30 calls, the max stands in for p99.

    op lead p50 ms p90 ms max ms block served statements per call, p50 (max)
    code.symbol false 61 73 114 – 13 (14)
    code.symbol true 100 118 149 29/30 38 (40)
    code.grep false 46 89 141 – 14 (37)
    code.grep true 95 120 153 30/30 39 (64)
    • In that run every leg answered in all 59 blocks, and no trace row has lead_unread. Leg stage times, p50/max ms: code.symbol callers 47/71, tested 40/64, changed_by 22/44; code.grep 44/84, 37/51, 18/29. The one code.symbol call without a block is is_test_path in server/code/domain/index/test_gate.py, a file the test-path rule reads as a test, so no definition is picked.
    • The block adds about 25 statements per call, mostly on code_edges, code_symbols and code_symbol_names (callers), code_test_map, code_files and code_coverage_files (tested) and code_pr_history (changed_by).
    • The run before it started right after the server booted, and a script error lost its client timings. By the trace rows' server-side latency_ms: code.grep with lead p50 210 ms and p90 902 ms, against 70 and 524 ms without; code.symbol 139 and 291 ms, against 44 and 181 ms. 4 of its 33 code.grep calls with the block read deadline at the 1000 ms wall (callers and tested in all 4, changed_by in 2), while those calls' own body reads took 200 to 285 ms.
    • Across every call this server served with the block (491), 6 had an unread leg, all deadline: callers in all 6, tested in 5, changed_by in 3. code.coverage_claim and code.symbol_history never read deadline without code.callers reading it too; each time the whole call was slow. In a further 120 warm code.symbol calls, one spent about 490 ms before the handler started (690 ms at the client, 199 ms in the handler), so no leg could start and the block was left out.
    • These runs had a 100 ms reserve in code.grep. Its wall is now 400 ms shorter when it reads lessons, as a default call does: at the default budgets, about 500 ms less what the request spent before its legs started. Every leg of the warm run answered within 84 ms. The 4 cold calls above, whose body reads took 200 to 285 ms, would now have had at most about 300 ms.
  • The ranked and uses_brief shapes, on the same index rebuilt from the same files (801 files, 22,546 symbols, 33,904 edges, 20,905 chunks) at the default budgets, after 120 warm-up calls: the same 30 definitions, ranked by short name with near_paths naming the definition's file (24 names resolved one definition, 6 resolved two to six), uses_brief by qualified name with uses_brief: true; each once with lead and once without, alternating which goes first. The trace rows show each call priced by its shape.

    shape lead calls p50 ms max ms block served calls with a deadline leg
    ranked false 30 67 125 – –
    ranked true 30 107 137 30/30 0
    uses_brief false 30 65 91 – –
    uses_brief true 30 101 164 29/30 0

    No leg read deadline or any other unread. The uses_brief call without a block is is_test_path again.

  • The block's tokens, by the repo's estimator (estimate_json_tokens) on the served JSON: a default code.symbol by qualified name and a first-page code.grep for <name>(, the same 30 definitions. MCP leaves lead out of the tool schemas, so an MCP client always pays these tokens on both ops.

    op calls with a block block tokens p50 block tokens max share of the answer, p50
    code.symbol 30 29 176 261 27%
    code.grep 30 30 176 261 7%

    The whole answers were 597 tokens p50 (1,582 max) for code.symbol and 2,476 p50 (11,615 max) for code.grep; both ops pick the same definition here, so their blocks are the same.

  • claude plugin eval integrations/claude-code-plugin, for the skill change: its guard refused all 4 cases before any ran ("a git directory of the plugin registers more linked worktrees than can be screened"), at $0. It was not worked around.

  • Ran: tests/unit/test_code_lead.py three times under -n auto -p randomly at d41f6a4 (74 passed each; five times at d521cfa, 60 passed each), and each test d521cfa, dfe0fda and 01af491 add or rewrite against the code without its fix (each fails: the raised deny, the gate's reads in the lane, a 100 ms grep reserve, the kept block, a grep that always reserves the lessons bound, a lessons check that leaves out narrowing, every block counted as run, a client that records no slot, either op pricing by the entries, the empty span attribute). After the merges of main at 24950d9 (the span keys keep lead_unread and at_dropped; the Go and Rust wire models are regenerated) and at eb98b9b (the plugin manifests, at 1.2.159), with every generator rerun changing nothing else, at 774a47d, the head before main was merged at c8ba404 (Responses served from a fallback say so in degraded, and ops.incidents lists current incidents #2047): make format-check, make lint (ruff, function-length gate at its baseline, every codegen --check), make mypy-gate (0 errors) and pytest -n 8 over the code-lead, client-hygiene, schema-guard, dispatch, constructor-edge, tracker-binding, code.symbol, code.grep, callers, coverage, edit-context, presence, background, MCP listing, shape-budget, op-budget, token-budget, package-contract, plugin-contract, doc, copy, agent-instruction, auth-cache, tunable-constant, session-content-sender, i18n, tracker-source, history, lean-shape and skill tests (2761 passed), the settings reference, file, defaults and live-setting tests, with the copy and doc-link tests (346 passed), the SDK surface, consumer-identity, code-tools, code.symbol uses, CLI snapshot, plugin and skill-bundle tests (271 passed), and, at ddbb242, Biome on the changed plugin files and the plugin's code-shunt and code-shunt hook node tests (81 passed); no commit of this PR changed a plugin file after it. The prompt-pack node tests and vitest on src/api/code.test.ts (2 passed) ran at an earlier head; no commit of this PR changed a prompt-pack or frontend file after it. Earlier heads also ran the grounding, decision-extract, settings, op census, assistant, policy-gate, shielded, lease and SDK codegen tests (2840 passed) and npm --prefix frontend run build; since then the frontend changed only in a test file. The frontend's other unit tests on this host (Node 25) fail 14 time-zone and locale tests that do not touch src/api/code.ts; CI runs them on its Node.

  • At 8377866, main is merged (Responses served from a fallback say so in degraded, and ops.incidents lists current incidents #2047): binding._gated authorizes through row_reach and keeps its notes, with the check inside shared_work(), and the override-edge and constructor-edge probes keep Responses served from a fallback say so in degraded, and ops.incidents lists current incidents #2047's cached failure note while their reads run outside the lane. The code.grep lessons bound follows Responses served from a fallback say so in degraded, and ops.incidents lists current incidents #2047's rule (a cut by the fixed bound is noted, a cut by the call's own budget is not) and counts what is left of the lead budget as the call's own. A lead leg that did not answer is noted with degradations.partial; test_degraded_unnoted.py::test_a_fallback_kept_out_of_provider_health_is_noted_with_partial and test_code_lead.py::test_a_failed_leg_is_noted_as_degraded_names_an_error fail without it. Both plugin manifests are at 1.2.176. Every generator --check is current and the analyzer corpus is unchanged; ruff format --check, make lint and make typecheck pass; pytest -n auto over the 284 test files that import what this PR touches passes 8492, and its 25 failures fail the same on a clean c8ba4042ea (test_native_command_retirement, test_namespace_audit, test_cell_retirement, test_mentor; a local clickhouse-local without enable_quantized_codec); the plugin's node tests pass but for two file-context hook tests that pass when run alone. git merge-tree --write-tree origin/main HEAD is clean against a229f49.

  • At 9f0f2d9, a lead leg is listed in degraded only when it read failed or busy, following the rule of Responses served from a fallback say so in degraded, and ops.incidents lists current incidents #2047: a leg cut by the lead wall or by the call's deadline_ms (deadline), or denied by a policy rule (policy), is that limit working, not a fallback, and is named in the entry, lead_unread and the span only. Before Responses served from a fallback say so in degraded, and ops.incidents lists current incidents #2047 merged, the lead's notes reached no response; now every response carries them. test_code_lead.py::test_a_leg_past_the_wall_reads_deadline_and_only_a_failed_one_is_listed, ::test_a_leg_the_history_policy_denies_reads_policy_and_is_not_listed and ::test_a_grep_leg_cut_by_the_callers_deadline_reads_deadline_and_is_not_listed (a code.grep with deadline_ms: 700, whose cap cuts the legs at 0.2 s) fail at 8377866 on the extra (deadline) or (policy) entries. Two new cases of test_code_result_lessons.py::test_a_file_whose_lessons_are_missing_is_noted_unless_the_deadline_cut_it pin the code.grep lessons bound under the lead shape: a file read cut by what is left of the lead budget lists nothing, and one cut by the fixed bound lists code_lessons: file_lessons_dropped (TimeoutError). They pass at 8377866, and fail when _bound_s drops its lead branch or lets the lead budget replace a smaller fixed bound. binding._gated holds only its row_reach read inside shared_work(); its notes and result are unchanged. The previous round note's claim that test_a_failed_leg_is_noted_as_degraded_names_an_error fails without partial was wrong: that test pins the error text (the error passed to the note, which caller_text renders) and passes with note(..., error, health=False); test_degraded_unnoted.py::test_a_fallback_kept_out_of_provider_health_is_noted_with_partial pins the partial spelling. ruff, make typecheck, the function-length gate and every codegen --check pass; pytest -p randomly over the code-lead, result-lessons, scan, tracker-binding, client-hygiene, public-copy, doc-link and package-contract tests passes 558.

  • At 4c6ea3a, main is merged again (Loom holds the checks for MCP worker source setup #2126, entity_communities: a namespace that fails no longer skips the rest of the pass #2131, test_degraded_unnoted lists the enrollment challenge spend, so main's unit job passes #2132, Collection administrators can list and approve source worker profiles #2133): the Go and Rust wire models conflicted and are regenerated from the merged registry; every generator --check (the SDKs, the Rust fixtures, docs_reference, op_reach_census, the settings files, the plugin copies and skill bundles) is current, both plugin manifests stay at 1.2.176, and no other open PR uses that version. Between 9f0f2d9 and this merge the _DEGRADED comment, the module docstring and the feature page state the rule without listing the unlisted kinds, and _DEGRADED holds busy alone, since a failed leg is noted with its error before the set is read. The SDK surface, session-content-sender, package-contract, code-lead, scan, doc-link and public-copy tests pass (429).

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. Checked: the leg handlers' inputs and outputs against their models, that every internal caller of code.symbol and code.grep opts out, the slot and width accounting on every exit of a statement, which work leaves the lane and which bounds it keeps, which process-wide caches a refusal could fill, the wall arithmetic and cancellation, and the MCP listing budget.

  • 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: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump), the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py) and the standalone skill bundles (python3 scripts/codegen/standalone_skills.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • 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; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.
  • I signed the Contributor License Agreement (CLA) if CLA assistant requested a signature.

🤖 Generated with Claude Code

…overage and changing PRs

The answers a text search cannot give sat behind three other ops. Both
ops now start with a `lead` block for up to three definitions: callers
one hop across virtual dispatch (code.callers), test evidence and
measured coverage (code.coverage_claim) and the PRs that changed the
definition (code.symbol_history). Each leg is its op's handler called
in-process as the consumer `symbol_lead` or `grep_lead`.

The legs run concurrently under the effective budget of the op's new
`lead` shape less the time already spent; a leg still running or
failed reads `unread` and notes a degradation, and the answer is
served on time. `lead: false` leaves the block out; Loom's own callers
of the two ops opt out, and code.edit_context never builds it.

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

vercel Bot commented Dec 2, 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 4, 2026 9:39am UTC
loom-telemetry Ready Ready Preview Dec 4, 2026 9:39am 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/lead.py Resolved
… pool

The lead's statements run in a new best-effort lane of the ClickHouse
client: between them they hold at most an eighth of `ch_pool_maxsize`
(8 of the default 64) process-wide, and a statement that finds no slot
free at once raises BusyError before it is sent instead of waiting, so
the request's own reads keep the pool. A leg refused that way reads
`unread: busy`.

The block covers one definition (three legs a call, not nine). The
callers and history legs read it by symbol id. Each leg passes the
history policy gate its op has (`unread: policy` on a deny). The legs
start inside a statement bound at the wall plus a margin and outside
code.grep's caller-shaped block. code.grep subtracts the reserve from
the caller's deadline and leads with the definition its pattern names.

A leg another block of the answer reads (callers and tests beside
`neighbours`, callers beside a uses brief) is left out. A `token_budget`
the block does not fit beside the uses block withholds it whole. Legs
that did not answer are named in `lead_unread` on the trace row and the
span.

The plugins' code shunt and prompt pack and the dashboard send
`lead: false`; both plugin manifests move to 1.2.151.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <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/grep.py Resolved
Comment thread server/code/app/grep.py Resolved
Comment thread server/code/app/symbol/symbol.py Resolved
…ndred ms

The best-effort lane now carries the wall's deadline, so a leg's
statements stop near the wall on ClickHouse and in the client. Work a leg
starts for others leaves the lane and that deadline: a grant-cache load
other requests join, and tasks from TaskSet.spawn and create_deferred_task
(`ch.shared_context`). A statement_timeout() around the block, such as a
lease's bound, still reaches them. The history policy gate runs before the
leg enters the lane and runs to its end when the wall cancels the leg, so
a flush of the process's queued events is never cut.

The `lead` budgets are the op's own plus a few hundred ms: code.symbol
600 ms, code.grep 1000 ms. They are priced, not measured, and the budget
overrides raise them. When no leg can start, the block is left out and
nothing is noted.

code.symbol fits the block after the first definition's card and leaves
it out when the answer does not serve its definition. code.grep picks the
definition whose name the pattern holds as a whole identifier. The lead
module handles one definition only, sizes its pool share once and
retrieves a leg that raised after its call was cancelled. The assistant's
first code lookup sends lead: false, and a test requires every caller
inside Loom to pass `lead`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <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/lead.py Resolved
Comment thread server/code/app/lead.py Resolved
zlareb1 and others added 3 commits December 3, 2026 02:48
One call's legs gathered 9 reads at once over an index that resolves the
definition and holds nothing else, more than the 8-slot lane, so a single
call read `busy`. A call's legs now share a width of half the lane; a
statement past it waits for its own call's slot, never for the pool's, and
two calls fit.

A refused read inside a leg could be kept as every request's answer: the
schema guard's ledger refresh, the override-edge and constructor-edge
probes, and the tracker-link snapshot ran in the lane. They run outside it
(`ch.shared_work`).

The lane deadline is an instant: each statement is bounded by what is
left of it. The block is fitted after the definitions, so it takes only
what they leave of `token_budget`. A leg another block serves is dropped
when that block serves it: code.grep skips it when its neighbours block
has the definition, code.symbol drops it at assembly.

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

The plugins' version is one past main's and past the one another open PR holds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <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 high effort and found 1 potential issue.

There are 3 total unresolved issues (including 2 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 801e3b2. Configure here.

Comment thread server/code/app/lead.py Resolved
zlareb1 and others added 19 commits December 3, 2026 03:43
A leg was dropped when the neighbours block or the uses brief seemed to
serve it, but neither does: the brief holds direct edges only and a hub
brief none, so an override's callers through its base were lost, and a
neighbours entry has neither dispatch callers nor a coverage verdict. The
overlap is at most three caller rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…spans stay out of its op's stages

The history leg read 10 PR rows and dropped those whose diff does not
name the definition, while `prs` counts the whole window, so it could
answer 37 PRs and no row. It now reads the op's most, 60.

The legs reported into the op's stage wall, so coverage_claim's and
symbol_history's resolve spans added to code.symbol's `resolve`. Each
leg starts a wall of its own; the op's table holds the leg under its
name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…m has a width

With no statement_timeout() scope, what was left of the lane's deadline
replaced the class default instead of capping it, so a read class bound
below the wall was raised to it. An unbounded class still takes what is
left. `width` is required: the one caller sets it, and the tests now take
the path it takes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
… own limits

The pages said every process-wide fill leaves the lane, but the coverage
positive control fills inside it, safely, since it keeps only reads that
answered. They also said every leg statement stops near the wall, but the
history leg's tracker reads go through the tracker source's own client
and keep its limits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…ashboard ask for no lead block

Each of one call's 27 lane statements is refused in turn, over an index
whose probes answer yes, and every process-wide cache must then hold what
a call with no refusal leaves, or nothing. It runs in about a second and
fails when the schema guard or the override-edge probe fills inside the
lane.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
… caps a bound

The block covers the first function, method, class or type definition
outside test files and documents; code.grep's field names every case with
no block. The lane page says every claim has a width, that the deadline
caps a statement's bound rather than acting as a statement_timeout(), and
that the tracker-link snapshot keeps no refused read: it refreshes outside
the lane so a refusal neither logs a warning nor leaves its call on the
previous snapshot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…ads busy end to end

The deadline tests read `time.monotonic` from a ManualClock and assert
exact bounds instead of racing the wall clock. The refusal sweep now also
requires each run to read exactly one leg as busy, through the real
handlers, whether the op swallowed the refusal or not. A handler that
fails before joining its legs cancels the lead task with the others.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The leg asked code.coverage_claim for 3 rows, and the op reads three
times its limit per evidence class and counts `tests` over what it
read, so a definition with 15 linked test files read 9. It now asks at
the op's default limit; a test over 15 mapped files compares the leg
with the op through the real handler.

The refusal sweep's coverage positive control answers yes, so a refused
control read kept as `no` shows. The Python SDK's CodeClient.symbol()
and grep() take `lead` and send `lead: false` only when it is false.
The descriptions say grep's block falls back to the first qualifying
definition, `token_budget` covers the block, the block is absent when
no time is left to start a leg, and the docs give the lane's share at
the default pool size with its floor below 16 slots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…all's shape

code.symbol_history counted the touching PRs of its 120-PR window but
served at most 60 rows, so a definition whose only touching PR was the
61st to 120th newest read `prs: 1` with an empty `top`. The op's `limit`
now reaches its window (PR_WINDOW, in the domain) and the history leg
asks for all of it.

The legs' wall started from the 600 ms `lead` budget even for a lookup
priced at `ranked` (3000 ms) or `uses_brief` (1500 ms), so a ranked
lookup whose ranking took most of 600 ms got no block. The handler now
knows the shape before the legs start, bounds the wall by that shape's
budget and prices the request by the same shape.

The tracker source registry refresh runs outside the lane, as the
tracker-link snapshot does. Trace rows name `lead: false`. The code
shunt's denial, the loom-code skill and the overview point to a plain
code.symbol call for callers instead of `uses_brief`. The feature page
says lead legs write no agent_events row, so a history rule meant to
count them names code.symbol or code.grep, and gives the wall by shape
instead of an unmeasured latency.

The fixed numbers the lead added say why they are not settings, the
reviewed hashes of the shunt hook and prompt pack are renewed (each adds
only `lead: false`), and the feature page's two new tables are lists so
its translated pages' cells stay in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…s at boot

A lead leg's policy gate reads the op registry. In a test process that had
not imported it, the first code.symbol with the block imported it inside the
call, and the definition's lessons read timed out at its 0.5 s bound; the
integration conftest now imports the registry once per session. The two
wall_s patches in test_code_plane take any arguments, since the wall now
takes the call's shape.

The plugin text says a plain code.symbol lead counts the callers and lists
the first three, with code.callers for all of them or more hops. The
feature page keeps the budget per shape, how to raise it and what busy
means, and links the ClickHouse page for the share and the work outside the
lane, which now also names the policy gate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The lessons read after the code.grep handler was bounded by
code_enrich_timeout_s and the caller's deadline_ms only, so a default grep
whose legs ran to the wall could end about 0.4 s past its 1000 ms price.
A grep priced by its block now reads its lessons in what is left of that
budget, the reserve its legs leave; a grep without a block keeps the
read's own bound.

The block covers a Java record declaration. The grep replay harness
replays a trace row's lead and imports the op registry before its run.
The caller check's docstring says a dict held in a variable is not read,
and a self-check pins the literal forms it reads. The architecture page's
code.grep and code.symbol rows name the legs and the lane, and the lane
paragraph gives the share for an unbounded pool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
No leg starts on a wall under MIN_LEG_WALL_S (0.1 s, about the slowest
leg's local p50 and a margin). Under it each leg read `deadline` while
the call was priced by its `lead` budget; the call now serves no block,
keeps its base price and its lessons keep code_enrich_timeout_s.

code.grep's wall, and its cap at deadline_ms, reserve the lessons read's
own bound (code_enrich_timeout_s) instead of 100 ms, so the read that
runs after the handler keeps that bound however long the legs run.
code.symbol keeps RESERVE_S.

A leg builds its op's input inside its `try`: a name past the op's bound
(300 characters for coverage and history) reads `unresolved` with no
degradation note, as a direct call would refuse it. Any other validation
error still reads `failed`.

definition_leads takes `agent` and `user_id` in place of the op's input.
The feature page says a tracker statement can keep running on the
tracker's server after the wall, and two long lines are rewrapped.

Tests: the floor (no block, base price, the lessons' own bound through
the real _grep_lead), a 0.3 s lessons read served after legs that run to
the wall, a name over 300 characters, and, through code.symbol with auth
on, a restricted tracker namespace the caller may not read and a token
pinned to one user.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
code.symbol prices a lookup whose legs did not run (`lead: false`, which
the plugins send, a wall under the floor, or a definition `min_fan_in`
filters out) as the op does without the block: `ranked` by the change at
hand, `uses_brief` only when the brief is served, the base budget
otherwise. A `lead: false` lookup whose brief `token_budget` withheld was
priced at `uses_brief`.

When `min_fan_in` filters out the block's definition, the legs are
cancelled once the filter has run, so the call no longer waits for a
block `code_lead.fit` would withhold, nor is priced by it.

The feature page and the `lead` budgets' catalog comment point only to a
multiplier in `latency_budget_overrides`: `admin/budget.set` sets one
fixed budget for every shape of an op. code_enrich_timeout_s's comment
says code.grep holds it back from its `lead` budget, so a value near that
serves no block; the settings reference, schema and example are
regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The span keys keep both `lead_unread` and main's `at_dropped`; the Go and
Rust wire models are regenerated over the merged ops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…de the lane

The shielded policy gate can end after the wall cancelled its leg, when
nothing awaits it: asyncio.shield drops its inner callback once the outer
wait is done, so a raised deny was logged as never retrieved. `_policy`
now returns False on a deny and `_leg` reads it as `policy`.

The history leg's tracker binding gate read the namespace classification
and the caller's grant inside the best-effort lane. A full lane refused
them, the gate failed closed with a logged error, and a caller holding
the grant got the history without the tracker. `_gated` now reads them
in `ch.shared_work()`.

The grep lessons tests run on a manual clock and assert exact seconds,
and the min_fan_in test asserts the block was cancelled instead of timing
the call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
code.grep held back `code_enrich_timeout_s` from its lead wall on every
call, though `lessons_for` skips the lessons read for
`include_lessons: false`, with `code_result_lessons` off and for a
narrowed token. A default grep with `include_lessons: false` that had
spent 0.1 s gave its legs 0.4 s instead of 0.8 s, so a 0.5 s callers leg
read `deadline` in a call priced at 1.0 s.

`result_lessons.lessons_read` is now the one check for whether the read
runs, and `lessons_for` uses it too. `_grep_lead` reserves the read's
bound only when it is true, else `RESERVE_S`, and passes the reserve to
`definition_leads` and `wall_s`; `lead.reserve_s` is removed.

The client-hygiene test drops two asserts the refusal and the driver's
calls already prove.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
`definition_leads` returned an entry whenever a leg started, so a call
whose legs all read `busy`, `policy` or `unresolved` straight away was
priced by its `lead` budget (600 or 1000 ms). A 400 ms code.symbol in a
full lane was priced at 600 ms; the same call with `lead: false` is
flagged past its 250 ms base budget.

A best-effort claim now records that one of its statements held a lane
slot (`BestEffortClaim.held`). `definition_leads` returns a `Block` of
its entries and whether a leg ran: one held a slot or ran until the
wall. code.symbol and code.grep price the `lead` shape only when it did,
and still serve the block.

code.symbol and code.grep no longer stamp an empty `lead_unread` span
attribute when every leg answered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
zlareb1 and others added 10 commits December 3, 2026 13:28
Both plugin manifests conflicted on the version: main is at 1.2.158, so
this branch's move goes to 1.2.159. Every generator rerun changed nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Unpacking the lead `Block` where the handler awaits it keeps the `fit`
call on one line, so the handler stays at 200 lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The local in `_with_retry` was `held`, the same name as the
`BestEffortClaim.held` flag it carries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Conflicts:
- binding._gated authorizes through authz.row_reach and notes an unverified
  or failed gate, as on main, with the check inside shared_work().
- result_lessons._bound_s returns what narrows the read (None for the fixed
  bound, as on main); a code.grep priced by its lead block also counts what
  is left of that budget.
- The override-edge and constructor-edge probes cache main's noted failure,
  and their reads run inside shared_work().
- Plugin manifests at 1.2.176; session_content_senders pins the merged
  sources; the Go and Rust wire models are regenerated; the code-index
  table keeps main's code.search row and the lead rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The note is the handler's own step, so it goes through partial, and a
failed leg passes its error, which degraded shows as for any other note: a
Loom error's code and message, another error's kind. The transports now put
the request's notes on every response, so the docstring and the feature
page say the response's degraded names the leg. A scan fails on any
note(..., health=False) left in server/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
… in degraded

A leg cut by the lead wall or by the call's deadline_ms is the call's own
budget working, and a policy deny is the operator's rule working, so
neither is a fallback. Each still reads `unread: deadline` or `unread:
policy` in the entry, lead_unread and the span. A failed leg, and a busy
one that the lead's fixed share of the pool left unread, are still
listed. Two cases pin the code.grep lessons bound under the lead shape.
The tracker binding gate holds only its row_reach read in shared_work.

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

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

# Conflicts:
#	sdk/go/wire/models.gen.go
#	sdk/rust/src/wire_models.rs
@zlareb1
zlareb1 merged commit 12b6c0e into main Dec 4, 2026
97 of 103 checks passed
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