Repository navigation
code.calibrate samples its probes from the namespace's own code - #2011
KaloyanNaumov wants to merge 23 commits into
Conversation
code.calibrate read a fixed corpus of 20 ClickHouse C++ probes, so every code namespace on one embedder got the same thresholds. It now samples up to code_calibrate_probes (200) documented functions of the namespace, round-robin across language and directory strata: the first paragraph of the doc comment is the query, the function without its doc comment is the positive, and a function from another stratum is the distractor. A namespace with fewer than 20 usable probes falls back to the fixed corpus. The reply names the source and the strata. Distractors from the same repository share its vocabulary: on bge-m3 their 90th percentile is 0.50 to 0.53, so the distractor-only derivation puts abstain at 0.57 to 0.60, above 29 to 42 percent of the namespace's own query/function pairs. code.calibrate therefore caps abstain at the positives' 10th percentile and keeps the noise floor 0.05 under it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
`code_calibrate_probes` is now 20 to 1000. A negative value failed in ClickHouse, a value under 20 silently meant the fixed corpus, and a large one fanned out an embedding request per pair at once. The doc-comment read took `any(doc_comment)` over both index tiers, which write rows under one symbol id. A merge of the SCIP tier could therefore change the drawn probes. It now reads the tree-sitter tier, whose ids the chunks carry. The `noise_floor` and `abstain_threshold` field docs now say what the capped derivation does, and the setting says that three embeddings per probe counts the embedding cache. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
Each probe re-parsed every pool path to pick a distractor from another stratum: size x 5 x size path parses on the event loop, 3.0 s at the default 200 probes and 75 s at the bound of 1,000 on Sonique. The pool's strata are now read once and the other-strata list is built once per stratum. The draws are the same as before, so the probes of a namespace do not change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
The only conflict was the generated sdk/go/wire/models.gen.go. It takes main's copy, regenerated with scripts/codegen/sdk_go_gen.py. Every other generator reports its outputs current on the merged tree. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
The field comment feeds the generated configuration reference, the settings schema and the example config, regenerated with their generators. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Hand-resolved conflicts: - sdk/go/wire/models.gen.go: header registry-schema hash differed on both sides (generated file); took upstream's side and regenerated with sdk_go_gen, which also refreshed the Go wire models and client. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
An oversized function is stored as several function chunks that share one symbol id. The documented-unit read matched any chunk carrying a documented id, so the tail pieces of such a function became positives for a doc comment they do not answer. Select only chunks whose own symbol (the first of symbol_ids) is a documented one, and keep one per symbol, the piece with the lowest start line, so each documented function yields one positive holding its start line and doc. The test asserts the read's shape and that the unit pairs the first piece with its doc. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
The documented-symbol read aliased any(doc_comment) AS doc_comment and filtered doc_comment != '' in the WHERE. ClickHouse resolves that name to the aggregate and refuses the query (ILLEGAL_AGGREGATION, seen on 26.10.8 and 26.12), so code.calibrate failed on every namespace against a real server; the unit tests answer from a fake and never ran the statement. Alias the aggregate doc, so the WHERE reads the column. A live-ClickHouse test runs calibration_units over real rows: it fails on the old statement with that error and passes now. It covers a documented and an undocumented function, a SCIP-tier row under the same id (which must not change the drawn doc), a tombstoned chunk and the pool read. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
Extend the live calibration_units test with an oversized function stored as three chunks of one symbol and a nested function's chunk whose first symbol is undocumented. The read must give the documented function one unit holding its first piece and its doc, and must not turn the nested chunk into a unit for the outer function's doc. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
zlareb1
left a comment
There was a problem hiding this comment.
The document-to-chunk finding blocks approval. A split function can contribute several positives with the same question and a different fragment as the answer. Distinct documented functions should supply the probes and determine whether there are enough to use namespace calibration. GitHub also reports a merge conflict with main. Please resolve it so CI can test the combined tree.
zlareb1
left a comment
There was a problem hiding this comment.
The calibration query now takes the first chunk per documented function and uses a separate name for the doc aggregate. The 34 focused calibration tests passed. The new ClickHouse test covers the store query in CI.
|
Both points are addressed at cfc0666, pushed after this review (it is on 4b5eafa). |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit cfc0666. Configure here.
zlareb1
left a comment
There was a problem hiding this comment.
GitHub reports a conflict with main in sdk/go/wire/models.gen.go. Reconcile the wire schema and regenerate the Go model.
GitHub reported sdk/go/wire/models.gen.go as conflicting with main. Main had not changed that file since this branch's base (git diff 60be594 3d29643 -- sdk/go/wire/models.gen.go is empty), and the merge is clean. `python -m scripts.codegen.sdk_go_gen --check`, with gofmt supplied from the golang:1.26 image, reports sdk/go/wire/models.gen.go and sdk/go/client.gen.go current against the registry model schema SHA 5bc197c6 and leaves git status clean, so nothing in the generated output is hand-written. The other generated artefacts are current on the merged tree too: sdk_py_gen, sdk_ts_gen, sdk_rb_gen, sdk_rust_gen and docs_reference all report current. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
|
Merged main and checked the generator rather than trusting it: Main had not touched that file since this branch's base, so the merge is clean rather than a resolution. The rest of the generated surface is current on the merged tree too — |
sdk/go/wire/models.gen.go conflicted on its schema digest. The conflict was cleared by taking one side, then scripts.codegen.sdk_go_gen rewrote the file, which now carries main's at_commit fields and memory.for_file printed row alongside this line's changes. Every other generator --check passed with no rewrite. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
|
Merged main and regenerated rather than resolved: the only conflict was the schema digest line in Every other generator reports current without a rewrite. 145 passed across the SDK and calibration files. |
zlareb1
left a comment
There was a problem hiding this comment.
The open probe-query finding still applies after the Go model conflict was resolved. Preserve the punctuation in a documented query and add a case for a line ending in a path glob.
`probe_query` removed trailing `*` and `/` from every comment line as a set of characters, so a documented description ending in a path glob (`testdata/*`) lost the glob before it was embedded as a query. Only the block-comment closer `*/` is removed now, so the punctuation a question ends in survives. `test_probe_query_keeps_a_glob_that_ends_a_line` covers both: a line ending in a glob keeps its `*`, and a `*/` closer still comes off. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
|
@KaloyanNaumov: can this PR also turn on Why on:
Why here and not before this PR lands: the row is keyed by |
zlareb1
left a comment
There was a problem hiding this comment.
The glob fix passes the focused calibration suite (35 tests). The output additions need to tolerate replies from a replica running the previous build.
The branch adds `probe_source` and `strata` to `code.calibrate`'s output. During a code-only rollout the call can land on a replica of the previous build, whose reply carries neither field. Required output fields made that reply fail validation; a default of 0 or "fixture" would misread it as the fixture. Rule 4 says N reads the old and the new wire format, so both fields are now nullable with a None default: unknown because an older replica answered, not empty. This build still writes both fields. The generated Rust contract decodes the old shape and asserts null, the Python model test does the same, and the operations page says an older reply reads as unknown. Assisted-by: Hermes:deepseek-v4.1-flash-1017 Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
|
The output additions now survive a reply from a replica running the previous build. 7f0c7e6
Rule 4 (N reads the old and the new format; only N+1 writes the new one) and rule 6 (an N−1 replica still answers during a code-only release) are what the shape follows. The operations guide and the reference page are updated in the same commit. Red was the old model reading a reply without the fields: One thing this commit is, and the body should say plainly: a wire break for consumers. Both fields become optional in all five SDKs — |
main added the `code_calibration` worker and its two settings, which also calibrates a namespace, and had rewritten `handle_code_calibrate` around an authored probe corpus. This branch samples a namespace's own documented functions and records `probe_source`/`strata`. The merge keeps both: the worker's seam `calibrate_namespace(org, ns)` stays and does the sampling, so a background pass and `code.calibrate` derive the same thresholds, and the fixed corpus is still the fallback below `MIN_NAMESPACE_PROBES`. - server/code/app/admin.py: `handle_code_calibrate` keeps main's docstring shape, `require_code_intel()` and identity resolution and delegates to `calibrate_namespace`, which keeps this branch's `_namespace_probes` + fixture fallback and returns `probe_source`/`strata`; `_fixture_probes` answers main's missing-corpus `ValidationError`. main's `repo_for_namespace` check on `code.reindex` lands beside the branch's imports. - schemas/loom-settings.schema.json, tests/unit/snapshots/settings_defaults.json: both sides added a setting; both are kept, and `settings_schema` regenerates them to the committed bytes. - The generated SDKs (python, typescript, go, rust, fixtures, docs reference) merged without a conflict and each `--check` reports them current. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
|
Merged upstream main ( Three conflicts, all composed rather than chosen. The one worth reading: main has rewritten The other two were additive on both sides ( 61 passed across the calibration files, 47 in the settings tests, and 1318 in the SDK/registry batch with one timing test that passes alone and as a file — a load artefact, not a result. |
zlareb1
left a comment
There was a problem hiding this comment.
Both new response fields decode as unknown on replies from older builds. The focused calibration tests passed. The operator-facing abstention guarantee needs to match what the sampled probe scores measure.
The two response fields added by this branch decoded as null when a replica on the previous build omitted them. Rust's Option collapsed "no key" and "null" into the same value, and the generated contract test pinned that null. The other SDK readers already keep absence and null apart. Mark the two fields presence-absent in the model schema and emit Option<Option<T>> with present_nullable for them in Rust, so a missing key decodes as absent while an explicit null still decodes as unknown. Regenerate the Rust and Go artifacts. The regression fixture is the previous build's six-field reply: before this change it re-encoded both fields as null, after it omits them. A second case keeps an explicit null distinct. docs/architecture/llm-architecture.md: the cap is the 10th percentile of the query-to-function cosines over up to 200 sampled probe pairs; it does not bound abstention for functions outside the sample or queries whose correct hit never enters the candidate set. The operations guide says the same and no longer calls an old reply "unknown". Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
|
Steady point:
70 pytest passed; Rust/Go/docs codegen |
zlareb1
left a comment
There was a problem hiding this comment.
The percentile description now matches the sampled probes. The Rust binding preserves a missing key and an explicit null as two distinct states. All 70 focused calibration and generator tests passed.
zlareb1
left a comment
There was a problem hiding this comment.
The new JSON fixture fails the pinned Biome format check. Format job
zlareb1
left a comment
There was a problem hiding this comment.
The pinned Biome check finds the same unformatted dashboard assertion in this run and on clean main. The separate repair formats that assertion. Failed job · Repair #2107
The regression fixture landed as one line, which the format gate rejects. This is the repository formatter's own output: npx --yes @biomejs/biome@2.5.14 format --write, reading the root biome.json (2-space, lineWidth 120). No other file is touched and the values are unchanged. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
Ten upstream commits: memory refusals and their erasure scope, observe.crystallize batching, a client timeout on the waiting ops and the TypeScript SDK reading it, the dashboard linking to the docs site, and CLI help text. The merge is clean; this branch's code_calibrate changes and the regenerated SDKs are unchanged by it. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
|
Steady point: Formatted with the repository's pinned Biome — 131 bytes on one line → 156 bytes formatted, and the pinned check now passes on this file. No other file touched. One environment note in case CI ever runs on an older base: the pinned glibc binary will not start on this host (AlmaLinux 8, glibc 2.28), so I ran the same 2.5.14 release's static musl build. The output is byte-identical in shape — six keys, two-space indent, trailing newline. |
zlareb1
left a comment
There was a problem hiding this comment.
The previous-build fixture passes Biome. The Rust round-trip test still needs to distinguish a missing field from an explicit null.
Conflict in sdk/go/wire/models.gen.go and sdk/rust/src/wire_models.rs: both sides regenerated, so both were re-emitted from the merged registry with sdk_go_gen.py and sdk_rust_gen.py rather than hand-merged. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
serde_json indexing returns Value::Null for an absent key as well as a present one, so encoded["probe_source"] == Value::Null passed with the key gone. Both fields now assert through .get: None for absence, Some(&Value::Null) for the new build's explicit unknown. Verified red against a serialiser that skips Option<Option<T>>::Some(None) and green with the real one. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
zlareb1
left a comment
There was a problem hiding this comment.
The Rust round-trip test distinguishes missing fields from explicit nulls. Namespace calibration still fails at its supported maximum.
…se#2011) At code_calibrate_probes=1000 a namespace samples 5,000 documented functions; bound whole as one Array(String) parameter those ids are 180,000 bytes, over ClickHouse's 128 KiB http_max_field_value_size, so the namespace probe read failed with "Field value too long" exactly at the ceiling. Read the ids in ch_params.chunks batches that fit, each statement returning its rows in the server draw order, and merge on cityHash64(chunk_id) so the merged first documented rows are the ones an unbounded read returned. Also note the embedder-unavailable probe fallback in degraded so the degraded-response gate holds and the reply names the fixed corpus.
|
Merged
The read now goes through The embedder-unavailable probe fallback now records a partial degradation note instead of only logging. |
zlareb1
left a comment
There was a problem hiding this comment.
Calibration splits the 5,000-ID lookup into bounded batches and preserves probe order. The degraded fallback is recorded. All 150 focused tests passed.
GitHub reports conflicts in the generated Go and Rust models. Please reconcile with main and regenerate both models.
Regenerate sdk/go/wire/models.gen.go and sdk/rust/src/wire_models.rs with the repo's generators instead of merging them by hand. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com> Assisted-by: Claude Code:claude-sonnet-5-5 Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
zlareb1
left a comment
There was a problem hiding this comment.
The namespace probe read batches the 5,000 symbol IDs at the supported ceiling and reassembles the server's draw order. All 99 focused tests passed, including the parameter-size and maximum-probe cases.

TL;DR:
code.calibratenow samples its probes from the namespace's own documented functions instead of a fixed corpus, so a namespace's thresholds come from its own answers. Same-repository distractors score high, so abstain is capped at the probes' 10th-percentile query-to-function cosine; throughcode.calibrateon three repositories it lands at 0.490 to 0.516, against 0.487 from the fixed corpus. A namespace with fewer than 20 usable functions still uses the fixed corpus.Related: #1558
Changelog category (leave one):
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.calibratederives a code namespace's thresholds from up toLOOM_CODE_CALIBRATE_PROBES(200) of its own documented functions, with the fixed probe corpus as the fallback for a small namespace, and reports which source it used.Why
code.calibratereadbench/fixtures/code_calibration_probes.jsonl, 20 probes over ClickHouse's C++ sources. The namespace argument only named where the row was stored, so every code namespace on one embedder got identical thresholds (#1558).A documented function is a query and an answer the repository already wrote. The first paragraph of its doc comment is the query. The positive is the function's embedded text with every copy of the doc comment removed (a Python chunk can carry the docstring twice). The distractor is a function from another language-and-directory stratum. Probes are drawn round-robin across strata, in an order seeded by the namespace, so one directory does not dominate and a rerun on an unchanged index reads the same probes.
Measured with bge-m3 (CLS pooling, normalised, as TEI serves it) on three repositories, 200 probes each. Run on the fixed corpus, the same embedder gives abstain 0.4873, against 0.48637 from TEI.
server/(Python)vllm/(Python)Functions from one repository share its vocabulary, so an unrelated function scores 0.50 to 0.53 against a query. With the distractor-only rule, abstain lands above about a third of the namespace's own right answers. That is the over-abstention #1558 reports, coming from the code side this time. The cap keeps abstain at the 10th percentile of the query-to-function cosines measured on the sampled probe pairs (up to
LOOM_CODE_CALIBRATE_PROBES, 200 by default). That percentile describes those sampled pairs, not the namespace: it places no bound on how often search abstains for a function the sample did not draw, or for a query whose correct hit never enters the candidate set. The noise floor stays 0.05 under abstain, andcode.searchreads it only as a stand-in when the vector leg is off.Harder distractors make it worse. A function from the same directory gives distractor p90 0.55 to 0.56 and abstain 0.62 to 0.63, above 57 to 63 percent of the right answers. Distractors therefore come from another stratum.
On the 19 queries from #1558, the top-hit similarity of a correct rank-1 result does not depend on the calibration. So the issue's quoted values give the abstention under each threshold:
The remaining one scores 0.44 and sits under every threshold. Bootstrap spread of the abstain threshold is 0.015 to 0.022 at 20 probes and 0.006 to 0.011 at 100, which is why the fallback starts under 20.
The same comparison through
code.calibrateitself, on stored rows copied from a running deployment (chunks, symbols and bge-m3 vectors; the query side embedded by the same bge-m3 weights), 200 probes per namespace:probe_sourcefixturenamespacenamespacenamespaceThe two Python and TypeScript repositories land together; the C++/SYCL one sits 0.025 lower, about three times the sampling spread at 200 probes. The cap was the binding rule in all three.
Scope and risk
code.calibrateonly: the probe source and the cap. The derivation for memory calibration and the cluster probe are unchanged. Three reads per run: the namespace's documented function symbols, their live chunks under the served embedding label, and a pool of live function chunks. Each read is capped at five times the probe count and ordered bycityHash64of the id. One run costs three embeddings per probe (six with the embedding cache off) and no LLM call.This does not trigger calibration on its own, and it does not change the code-owned fallback thresholds planned in #1558.
Compatibility, rollout and rollback
code.calibratereturns two new fields,probe_source(namespaceorfixture) andstrata.positivesanddistractorsnow count the pairs used from either source.LOOM_CODE_CALIBRATE_PROBES(200). Reruncode.calibrateon each code namespace to replace a fixture-derived row.loom.namespace_calibration_result; they serve until the nextcode.calibrate.Tests
tests/unit/test_code_calibration_probes.pycovers query extraction (Python docstrings, C++//and/** @brief */, comments that do not describe the unit) and doc removal, including a docstring carried twice. It also covers stratified sampling, stable draws per namespace, distractors from another stratum, the store reads (RecordingCH), the namespace and fixture paths of the handler, and the cap. The existing fixture test intest_embedder_calibration.pynow runs through the fallback.tests/integration/test_code_calibration_units_live_ch.pyruns the store reads against a real ClickHouse: a documented and an undocumented function, a SCIP-tier row under the same id, a tombstoned chunk, a function split into two chunks (one positive, the first piece), and the pool. It caught an aggregate alias the server rejects (ILLEGAL_AGGREGATION) that the recorded-statement tests could not. Ranruff check,ruff format --check, mypy on the touched modules, the mypy and function-length gates, every codegen--check, and the touched tests.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. I checked the measurement and every line of the diff.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make test-unitand applicable integration results are reported by CI; a full local run is not required before pushing.docs/reference/configuration.mdand thedocs/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).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.Note
Medium Risk
Changes code-search abstention thresholds and admin calibration behavior per namespace; wrong probes or caps could increase false abstains, though fixture fallback and wire-compat guardrails limit blast radius.
Overview
code.calibratenow builds probe pairs from each code namespace's own documented functions (doc-comment first paragraph as the query, embedded chunk text with the doc stripped as the positive, cross-stratum distractors), up toLOOM_CODE_CALIBRATE_PROBES(default 200). Namespaces with fewer than 20 usable probes—or no embedder when sampling—still usebench/fixtures/code_calibration_probes.jsonl.Abstain/noise floors are tightened for same-repo vocabulary: after the usual distractor-derived thresholds, abstain is capped at the 10th percentile of measured query→function cosines on those probes, with noise floor kept 0.05 below it. The handler adds
CodeRepo.calibration_units(batched ClickHouse reads so max probe settings stay under HTTP field limits) and returnsprobe_source/strataon the wire, withx-loom-presence: absentso older clients don't see keys that implyfixture/0.SDKs (Python/TS/Go/Rust), settings schema, example config, and operator docs are regenerated/updated; Rust codegen learns presence-absent nullable response fields, with compat tests for prior
code.calibrateJSON.Reviewed by Cursor Bugbot for commit 64a7915. Bugbot is set up for automated code reviews on this repo. Configure here.