Skip to content

code.calibrate samples its probes from the namespace's own code - #2011

Open
KaloyanNaumov wants to merge 48 commits into
ClickHouse:mainfrom
KaloyanNaumov:pr/code-calibrate-namespace-probes
Open

KaloyanNaumov wants to merge 48 commits into
ClickHouse:mainfrom
KaloyanNaumov:pr/code-calibrate-namespace-probes

Conversation

@KaloyanNaumov

@KaloyanNaumov KaloyanNaumov commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: code.calibrate now 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; through code.calibrate on 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):

  • Improvement

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.calibrate derives a code namespace's thresholds from up to LOOM_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.calibrate read bench/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). A leading copy of the function's name is dropped from the query: Go opens a doc comment with it (33,927 of 41,555 documented Go functions on a running deployment, against at most 8% in every other language), and a question seldom names the function its answer is. The distractor keeps its own doc comment: it stands for a wrong hit, and every chunk search ranks carries its doc. A positive with its doc left in would score the query against its own text. 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. A probe text the provider refuses as too long is halved and sent again, as ingest did before storing the chunk's vector (embed_shrinking, which moves to server/embedding/documents.py so the calibration can use it). Without it a chunk over Gemini's 2048 tokens, or over the context of an OpenAI-compatible server that refuses long input, would fail the phase on every rerun of the same draw. With fewer than 20 documented functions the fixed corpus is certain, and the distractor pool is not read.

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.

fixed corpus vllm-xpu-kernels (C++/SYCL) Loom server/ (Python) vLLM vllm/ (Python)
distractor p90 0.417 0.518 0.528 0.498
abstain, distractors only 0.487 0.588 0.598 0.568
positive p10 / p50 / p75 0.514 / 0.604 / 0.647 0.512 / 0.611 / 0.651 0.513 / 0.625 / 0.667
own pairs under that abstain 38% 42% 29%
abstain, capped (this PR) 0.487 0.514 0.512 0.513

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, and code.search reads it only as a stand-in when the vector leg is off. The cap applies inside derive_thresholds, before the query-rewrite, HyDE and rerank-skip gates are clamped to the floor, so the confident-hit cosine stays the probes' 75th percentile under the cap. When the distractors' 90th percentile reaches the probes' 75th, no cosine separates a right function from an unrelated one: the cap is skipped and the calibration keeps no confidence scale, as an uncapped one does.

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:

thresholds correct rank-1 results that abstain
cluster calibration (0.662) 8 of 13
fixed corpus (0.486) 1 of 13
namespace probes, distractors only 2 of 13
namespace probes, capped (this PR) 1 of 13

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.calibrate itself, 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:

fixed corpus vllm-xpu-kernels (C++/SYCL) hindsight (Python) a Claude Code plugin (TypeScript)
probe_source fixture namespace namespace namespace
positive p10 / p50 0.490 / 0.604 0.514 / 0.621 0.516 / 0.601
distractor p90 0.518 0.521 0.529
abstain 0.487 0.490 0.514 0.516

The 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.calibrate only: the probe source and the cap. Memory calibration and the cluster probe derive their gates as before (the cap is a flag only code.calibrate sets); memory calibration shares the probe's changes below. 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 by cityHash64 of the id. One run costs three embeddings per probe (four with the embedding cache off, as in the code_calibration worker) and no LLM call: a pair passed as both positive corpora is embedded once. calibrate_embedder sends eight pairs at a time, so at most 16 embedding calls are in flight at any probe count, and a failed pair cancels the rest of its phase. At the default 200 probes that is 50 rounds of one query and one document embedding. The three reads, measured with system.query_log on the largest code namespace of a running deployment (328,619 live function chunks) at the default: documented symbols 1.12M rows, 218 MiB, 457 ms; their first chunks 1.07M rows, 1.27 GiB, 1,524 ms; the pool 1.07M rows, 1.21 GiB, 1,183 ms; peak memory 288 MiB. A calibration runs once per namespace and embedder.

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

  • Wire: code.calibrate returns two new fields, probe_source (namespace or fixture) and strata. positives and distractors now count the pairs used from either source.
  • Operator steps: new setting LOOM_CODE_CALIBRATE_PROBES (200). Rerun code.calibrate on each code namespace to replace a fixture-derived row.
  • Rollback: reverting leaves the namespace rows written by this version in loom.namespace_calibration_result; they serve until the next code.calibrate.

Tests

tests/unit/test_embedder_calibration.py checks that 200 pairs keep at most 16 embedding calls in flight and embed the positives once, that a failed pair stops its phase, and that the cap moves the trigger gates with the floor. tests/unit/test_code_calibration_probes.py covers 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 (another file when there is one), the store reads (RecordingCH), the namespace and fixture paths of the handler (under 20 documented functions no pool is read; one file, or no usable doc comment, falls back after sampling), probe texts shrunk under a provider that refuses long inputs with or without a stated limit, and the cap. The existing fixture test in test_embedder_calibration.py now runs through the fallback. tests/integration/test_code_calibration_units_live_ch.py runs the store reads against a real ClickHouse (a class skeleton, an unembedded stub and a documented test function are left out; each of those filters fails the test when removed): 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. Ran ruff 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

  • 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.

Note

Medium Risk
Changes how every code namespace's search abstention and retrieval_confidence scale are computed; operators must re-run code.calibrate to refresh stored rows, and wrong caps could still over- or under-abstain on repos with weak doc comments.

Overview
code.calibrate now builds abstention thresholds from each code namespace's own indexed functions instead of the shared code_calibration_probes.jsonl fixture. It reads up to LOOM_CODE_CALIBRATE_PROBES (default 200) documented function chunks from ClickHouse, turns each doc comment's first paragraph into a query, uses the embedded unit text with the doc stripped as the positive, and pairs a distractor from another language/directory stratum (or another file when the repo is homogeneous). Namespaces with fewer than 20 usable probe pairs still use the fixture; the response adds probe_source (namespace | fixture) and strata.

To avoid over-abstaining when same-repo distractors score almost as high as correct hits, threshold derivation gains cap_at_answers: for code calibration only, abstain is capped at the probes' 10th-percentile query→function cosine (noise floor 0.05 below), unless distractor p90 reaches positive p75—in which case the cap is skipped.

Embedder calibration is tightened for large probe runs: bounded in-flight embedding calls, one embed per pair when positives serve both paraphrase and question-fact roles, embed_shrinking on oversize probe texts, and embed_shrinking is moved from server/code/app/index/embed_text.py to server/embedding/documents.py (shared by ingest, embed recovery, and calibration). Docs, settings schema, SDK types, and tests cover the new behavior and CH read limits at max probe count.

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

KaloyanNaumov and others added 5 commits December 2, 2026 07:51
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>
@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 5, 2026 11:25pm UTC
loom-telemetry Ready Ready Preview Dec 5, 2026 11:25pm 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/store/index/search.py Resolved
KaloyanNaumov and others added 2 commits December 2, 2026 10:26
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>
@zlareb1 zlareb1 self-assigned this Dec 2, 2026
KaloyanNaumov and others added 2 commits December 2, 2026 10:31
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 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
zlareb1 previously approved these changes Dec 2, 2026

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

Both points are addressed at cfc0666, pushed after this review (it is on 4b5eafa). calibration_units now reads one chunk per documented function, its first piece (symbol_ids[1] IN ids … ORDER BY symbol_id, start_line LIMIT 1 BY symbol_id, 4fd9dd5), so each probe is a distinct function and the 20-probe threshold for namespace calibration counts distinct functions. test_code_calibration_units_live_ch.py stores a function as two chunks and asserts one unit, the first piece. Upstream main is merged and GitHub reports the branch mergeable. The live test also caught an aggregate alias that ClickHouse 26.10 and later refuse (ILLEGAL_AGGREGATION), fixed in d6963d6.

@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.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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>
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

Merged main and checked the generator rather than trusting it: 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 no generated byte is hand-written. fddd231

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_py_gen, sdk_ts_gen, sdk_rb_gen, sdk_rust_gen and docs_reference all report current — go build ./... && go test ./... passes for sdk/go in a golang:1.26 container, and the SDK codegen and contract tests pass (122), as do the calibration unit tests (23).

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>
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

Merged main and regenerated rather than resolved: the only conflict was the schema digest line in sdk/go/wire/models.gen.go, cleared by taking main's side and running the generator. The header carries digest 9bea62af, the file matches what build_source() emits for the merged registry, and --check reports both Go files current, so no generated byte is hand-written. 44d38df

Every other generator reports current without a rewrite. 145 passed across the SDK and calibration files.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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>
@zlareb1

zlareb1 commented Dec 3, 2026

Copy link
Copy Markdown
Member

@KaloyanNaumov: can this PR also turn on code_calibration_enabled by default (server/settings/catalog.py, plus the settings snapshot and docs/reference/configuration.md)?

Why on:

Why here and not before this PR lands: the row is keyed by model@fingerprint only, and probe_source is in the reply but not in the stored row. If the default flips first, every namespace gets a row derived from the fixture, and needs_calibration then answers false until the next embedder change, so the namespace's own probes never replace it. Flipping the default in this PR means the rows the worker writes are the namespace-derived ones from the start. If it lands separately before this one, this PR would need to treat a fixture-derived row as stale for a namespace that now has enough documented functions.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The glob fix passes the focused calibration suite (35 tests). The output additions need to tolerate replies from a replica running the previous build.

Comment thread server/code/api/models_ingest.py Resolved
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>
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

The output additions now survive a reply from a replica running the previous build. 7f0c7e6

probe_source and strata are nullable with None as the default, and None means unknown because an older build answered — not empty. There is no honest old-build value to fall back to: 0 is the fixture's own value, and 'fixture' would assert a sampling that never happened.

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: ValidationError: probe_source, strata — Field required. On this head the same reply reads None/None, and the Rust contract test asserts explicit null rather than a missing key. 151 passed across the calibration suites and the output readers.

One thing this commit is, and the body should say plainly: a wire break for consumers. Both fields become optional in all five SDKs — Option<…> in Rust, ?:/| null in TypeScript — so a client that read them as always-present now has an Option to unwrap. That is the cost of tolerating an older replica; the alternative is a reply that fails to parse.

zlareb1 and others added 4 commits December 6, 2026 01:07
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
… probe phase

The abstain cap now applies inside derive_thresholds, before the trigger
gates are clamped to the floor, so rerank_skip_above stays the probes' p75
under the cap. Each probe phase runs in a TaskGroup, so a failed pair cancels
the rest, and a pair already measured is not embedded again. The documented
read drops test files before its limit, through query_all_sliced. A missing
embedder's error names its kind only, block closers match in lower case only,
and the worker logs the probe source it used.

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

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The focused calibration suite passed 65 tests. A controlled provider failure reproduced an embedding call that outlives the failed calibration. The inline finding describes the missing cancellation boundary.

async with in_flight:
with customer.system():
if query:
va, documents = await asyncio.gather(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2 — If the query embedding raises while the document embedding is still pending, gather propagates the error and leaves the document call running. The outer TaskGroup sees a finished pair, so calibration returns and releases its semaphore while the provider request remains active. A stub that waits for the document call to start before raising reproduces this: calibrate_embedder returns None before the document call reaches its cleanup. Own both calls in a TaskGroup inside the pair and test that a failing query cancels and joins the document call before returning.

zlareb1 and others added 6 commits December 6, 2026 02:19
…d raw docstrings

A cap applied when the distractors' p90 reaches the probes' p75 gave an
unrelated function full confidence; such a calibration now keeps its
distractor floor and has no confidence scale. Raw and unicode docstring
prefixes no longer reach the query. The documented-chunk read is one SELECT,
and the live test proves its kind, vector and test-file filters with rows.

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

Most documented Go functions open their doc comment with the function's name,
which their positive also carries, so the probe asked with the identifier a
real question seldom names. The symbols read now returns the name and drops
test files with the same pattern as is_test_path; the wire and calibration.get
descriptions name the abstain cap, and the probe's concurrency is a named
constant.

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

The documented-units read already drops test files, so sample_probes no longer checks
them. A distractor keeps its doc comment because search compares a query with the
chunk as indexed; the docs and module docstring say so. The code.calibrate budget
comment names the work it covers, and the recalibration bullet no longer claims a
per-namespace re-probe.

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

)
vb = documents[0]
else:
va, vb = await embedder.embed_many([a, b])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Failed probe leaves embed running

Medium Severity

In _embed_pair, asyncio.gather returns as soon as embed raises and does not cancel the in-flight embed_many. The pair task then exits, so the TaskGroup finishes and releases in_flight while that document embedding is still running. calibrate_embedder returns None and the provider request stays active past the probe.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b53de5d. Configure here.

zlareb1 and others added 4 commits December 6, 2026 03:33
A chunk over the model's input limit (Gemini's 2048 tokens) was sent whole, the provider
refused it, and the phase failed on every rerun of the same draw. Ingest embeds such a
chunk by its head; the probe now clips to the same limit. Under 20 documented units the
fixed corpus is certain, so the distractor pool is no longer read: the store read is
split into calibration_units and calibration_pool. The docs, the calibrate_embedder
docstring and the worker's pass comment describe the current behaviour.

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

Each picked stratum built its own copy of the pool, up to ~5M references at the
1,000-probe ceiling; the pool is now sorted by stratum and file once and a distractor
is drawn from outside the probe's run in place. Tests cover the fixture fallback after
sampling (one file, no usable doc comment) and the one-stratum draw from another file.
The input-token limit is named max_tokens, apart from the row limits.

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

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The current head still returns from a failed calibration while the paired document embedding is active. The existing inline finding still applies. A controlled provider failure reproduced it on this head.

The 71 focused tests passed. The new inline finding covers a case outside that suite.

last = next((i for i in range(first, end) if doc[-1] in lines[i]), first)
if last + 1 < len(lines) and lines[last + 1].strip() in ('"""', "'''", "*/"):
last += 1
lines = lines[:first] + lines[last + 1 :]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2 — Removing the docstring also removes the function body when it shares the same source line. Parsing and chunking def total(): """Return the sum of both page counts."""; return 123 + 456 produces a calibration positive with only the context header. Strip the docstring without dropping the surrounding code and test a one-line function through the chunk path.

zlareb1 and others added 2 commits December 6, 2026 04:04
The docs and handler docstrings said a namespace falls back under 20 documented
functions; the guard counts probes that also have a distractor, and with one stratum the
distractor comes from another file. The sorted lists the draw bisects are named for
their order.

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

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The two open findings still reproduce on this head. The failed embedding returns before its paired request finishes, and docstring removal can discard the function body. The focused calibration suite passed 71 tests.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 3236b87. Configure here.

last = next((i for i in range(first, end) if doc[-1] in lines[i]), first)
if last + 1 < len(lines) and lines[last + 1].strip() in ('"""', "'''", "*/"):
last += 1
lines = lines[:first] + lines[last + 1 :]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Docstring strip drops same-line code

Medium Severity

without_doc drops every source line that contains the doc comment, not just the comment text. A one-line function keeps its body on that same line, and chunking also prepends the doc, so the second match deletes the declaration and body. The probe positive is only the context header, so those pairs no longer measure query-to-function similarity.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3236b87. Configure here.

zlareb1 and others added 4 commits December 6, 2026 04:18
…s alone

A distractor comes from another language or another directory two levels deep, and from
another file only when every function shares one of each; the docs said "only one".
Each distractor comes with a positive, so the fallback guard counts distractors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The clip covered only a provider that states its input limit. An OpenAI-compatible
endpoint states none, and one that refuses long input (413, or 400 past its context)
failed the phase on every rerun of the same draw. The probe now embeds each document
through embed_shrinking, the halving ingest stored the chunk's vector with, so a chunk
that was indexed can be probed. embed_shrinking and looks_too_long move to
server/embedding/documents.py, where the memory plane's calibration can reach them; the
clip in the handler is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
@KaloyanNaumov
KaloyanNaumov force-pushed the pr/code-calibrate-namespace-probes branch from a8ef2ba to 64a7915 Compare December 5, 2026 23:10
zlareb1 and others added 2 commits December 6, 2026 04:51
…ngest did

looks_too_long matched OpenAI's tokens-per-minute 429, whose detail names type=tokens,
so embed_shrinking halved the text after the retries ran out and the next call stored
or measured a cut text. A retryable status is now never a length refusal, for ingest's
per-text fallback, embed recovery and code.calibrate alike. The probe texts also go
through ingest's clip_for_embedding first, so a chunk over 20,000 characters is
measured by the head ingest embedded.

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

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Both open findings reproduce on this head. A stub query failure still returns while the paired document request is running, and stripping a same-line docstring still leaves only the chunk header. All 87 focused calibration and embedder tests passed. Request cleanup · Probe body

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Both integration failures reproduce on the clean CI base. The curator assertion reverses two proposals created in the same second, and the skill draft assertion omits the binding field. The fixes are on main. Curator PR job · Main job · Fix #2334. Skill draft PR job · Main job · Fix #2331.

This branch has not been deployed

No deployments
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.

2 participants