Skip to content

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

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

KaloyanNaumov wants to merge 23 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). 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.

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.

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. 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 by cityHash64 of 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

  • 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_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, the store reads (RecordingCH), the namespace and fixture paths of the handler, 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 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 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.calibrate now 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 to LOOM_CODE_CALIBRATE_PROBES (default 200). Namespaces with fewer than 20 usable probes—or no embedder when sampling—still use bench/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 returns probe_source / strata on the wire, with x-loom-presence: absent so older clients don't see keys that imply fixture/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.calibrate JSON.

Reviewed by Cursor Bugbot for commit 64a7915. 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 2:11am UTC
loom-telemetry Ready Ready Preview Dec 5, 2026 2:11am 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.

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

Fix All in Cursor

Reviewed by Cursor Bugbot for commit cfc0666. Configure here.

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

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

Copy link
Copy Markdown
Contributor Author

Merged upstream main (cd5041645). cab53c0

Three conflicts, all composed rather than chosen. The one worth reading: main has rewritten code.calibrate around an authored corpus and added server/code/workers/calibration.py calling calibrate_namespace(org, ns). That seam is kept, and this branch's namespace-probe sampler now lives inside it — the worker and the handler share one sampler, and _fixture_probes still carries main's missing-corpus error. So the merged behaviour is that the calibration worker samples a namespace's own code, falling back to the authored corpus only when there is none — which is this PR's intent, but it is a change in what the worker does, and it should be read as one.

The other two were additive on both sides (code_calibrate_probes beside code_calibration_enabled/_calibration_interval_seconds in the settings schema and its snapshot), so both were kept. No generated file conflicted; every generator re-reports current under the pinned toolchains (rustfmt 1.8.0 from the 1.85.1 toolchain, gofmt 1.26.11).

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

Comment thread docs/architecture/llm-architecture.md Resolved
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>
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

Steady point: a5ebbc919, and the body now matches the code.

  1. Absent is not unknown. probe_source and strata are marked x-loom-presence: absent, and the Rust generator emits Option<Option<T>> with present_nullable / skip_serializing_if: a missing key stays absent (outer None), an explicit null remains Some(None). A fixture built from the old six-field reply pins it — red first (probe_source must stay absent, not become null), green after. Go and TypeScript already distinguished the two; the Go digest was regenerated.
  2. The doc no longer claims a bound it cannot support. The "abstains on at most one in ten of its own documented functions" sentence is gone. It now says the cap is the 10th percentile of the cosines measured on its sampled probe pairs — up to LOOM_CODE_CALIBRATE_PROBES (200 by default) — and that the percentile describes those 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 operations guide says the same.

70 pytest passed; Rust/Go/docs codegen --check current; cargo fmt --check clean; cargo test on the calibrate contract ok.

@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 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 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 new JSON fixture fails the pinned Biome format check. Format job

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

Copy link
Copy Markdown
Contributor Author

Steady point: fba30e817.

Formatted with the repository's pinned Biome — @biomejs/biome@2.5.14, the version in the Makefile's BIOME and ci.yml, using the root biome.json:

npx --yes @biomejs/biome@2.5.14 format --write sdk/rust/tests/fixtures/code_calibrate_previous.json

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 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 previous-build fixture passes Biome. The Rust round-trip test still needs to distinguish a missing field from an explicit null.

Comment thread sdk/rust/tests/code_calibrate_compat.rs Resolved
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 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 Rust round-trip test distinguishes missing fields from explicit nulls. Namespace calibration still fails at its supported maximum.

Comment thread server/code/store/index/search.py Resolved
Comment thread server/code/app/admin.py Resolved
…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.
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

Merged main (5301f2920) and fixed the ceiling failure at fc795eb51.

code_calibrate_probes is bounded at 1,000 and _namespace_probes asks for five documented functions per probe, so at the ceiling the store read binds 5,000 symbol ids - around 180,000 bytes as one Array(String) parameter, past the HTTP max_field_value_size of 128 KiB, which is why calibration failed exactly at its supported maximum.

The read now goes through ch_params.chunks and merges on the server by cityHash64(chunk_id) with symbol_id as the tie-break, taking the first documented of each symbol. That returns the same rows as the single unbounded read: each symbol's row is batch-invariant, the union of per-batch top-k contains the global top-k, and the client sort on (draw, symbol_id) is a total order that refines the old ORDER BY draw. The ceiling stays at 1,000.

The embedder-unavailable probe fallback now records a partial degradation note instead of only logging.

zlareb1
zlareb1 previously approved these changes Dec 5, 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.

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

Copy link
Copy Markdown
Contributor Author

Merged main (8c9e1dd) as 64a7915 and regenerated the Go and Rust models with sdk_go_gen.py and sdk_rust_gen.py, not by hand. Every codegen --check is clean, and the touched tests pass. Please re-review @zlareb1.

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

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