From 3b857942172c10fd4c89b4ce09452aaffcc90e92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=B0=D1=82-=D0=9E=D1=80=D1=88=D0=B8=D1=85?= <34618353+orshih6@users.noreply.github.com> Date: Thu, 26 Nov 2026 19:12:10 +0000 Subject: [PATCH 1/3] The ingest pass and `loom code describe` skip the description writer on the fake LLM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Бат-Орших <34618353+orshih6@users.noreply.github.com> --- server/cli/code_maintenance.py | 9 ++- server/code/app/index/pass_stream.py | 27 ++++++- tests/unit/test_code_describe_fake_llm.py | 93 +++++++++++++++++++++++ 3 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 tests/unit/test_code_describe_fake_llm.py diff --git a/server/cli/code_maintenance.py b/server/cli/code_maintenance.py index 84963df0345..bbaa04c513c 100644 --- a/server/cli/code_maintenance.py +++ b/server/cli/code_maintenance.py @@ -445,8 +445,15 @@ async def _describe(args: argparse.Namespace) -> int: from server.code.store.index import CodeRepo from server.core.ch import get_client from server.embedding.embedder import get_embedder - from server.llm.client import get_llm_client + from server.llm.client import get_llm_client, llm_is_fake + if llm_is_fake(): + print( + "refusing to describe with the fake llm (LOOM_LLM_PROVIDER=fake, or its " + "API key is not set): its echo would be stored as chunk descriptions", + file=sys.stderr, + ) + return 2 await connect_code_plane(get_client(), args) org, ns = _identity(args) repo = CodeRepo() diff --git a/server/code/app/index/pass_stream.py b/server/code/app/index/pass_stream.py index 4dc7683a2b4..1167a09542d 100644 --- a/server/code/app/index/pass_stream.py +++ b/server/code/app/index/pass_stream.py @@ -41,6 +41,28 @@ async def _slice_done(repo: Any, org: str, ns: str, slice_key: str) -> int: return int(n) if key == slice_key and n.isdigit() else 0 +_fake_llm_warned = False + + +def _llm_is_fake() -> bool: + """True when the description writer would run on the fake client, whose echo + must never be stored (and embedded) as a chunk's `llm` description. Logs once + per process.""" + from server.llm.client import llm_is_fake + + global _fake_llm_warned + if not llm_is_fake(): + return False + if not _fake_llm_warned: + _fake_llm_warned = True + logger.warning( + "code_ingest: LOOM_CODE_CONTEXT_DESCRIPTION_ENABLED is on but the llm " + "provider is fake (configured so, or its API key is not set); chunks " + "get structural context instead of llm descriptions" + ) + return True + + class CommitStream: """One entry's pending commits, ingested one `step` at a time: the per-entry setup — the embedder, the describe gate, the @@ -99,7 +121,10 @@ async def _prepare(self) -> dict[str, Any]: describe = settings.code_context_description_enabled llm = None if describe: - if await namespace_over_cap(cfg.org, cfg.namespace): + if _llm_is_fake(): + describe = False + self.result.note = "describe skipped: the llm provider is fake" + elif await namespace_over_cap(cfg.org, cfg.namespace): describe = False self.result.note = "describe skipped: namespace over budget cap" else: diff --git a/tests/unit/test_code_describe_fake_llm.py b/tests/unit/test_code_describe_fake_llm.py new file mode 100644 index 00000000000..0dc528b7cf4 --- /dev/null +++ b/tests/unit/test_code_describe_fake_llm.py @@ -0,0 +1,93 @@ +"""The description writer never runs on the fake LLM client. + +With `llm.provider = fake` (or a keyed provider whose key is absent, which falls +back to the fake client) the fake's echo would be stored as the chunk's `llm` +description and embedded. The ingest pass gives those chunks structural context +instead, and `loom code describe` refuses to start.""" + +from __future__ import annotations + +import argparse +from types import SimpleNamespace +from typing import Any + +import pytest + +from server.code.app.index import pass_stream +from server.code.app.index.pass_budget import CodeIngestResult +from server.llm import client as llm_client +from server.settings import settings + + +def _stream() -> pass_stream.CommitStream: + cfg = SimpleNamespace( + org="o", namespace="ns", path_prefixes=(), embed_reuse_from=None, git_dir="/nowhere" + ) + return pass_stream.CommitStream(cfg, None, "head", "base", ["sha"], CodeIngestResult()) + + +@pytest.fixture +def prepare_env(monkeypatch: pytest.MonkeyPatch) -> None: + async def under_cap(*_a: Any) -> bool: + return False + + async def no_denylist(*_a: Any) -> None: + return None + + monkeypatch.setattr(settings, "code_context_description_enabled", True) + monkeypatch.setattr("server.observability.budget.namespace_over_cap", under_cap) + monkeypatch.setattr("server.code.app.index.denylist.load_denylist", no_denylist) + monkeypatch.setattr("server.embedding.embedder.get_embedder", lambda: object()) + + +def _no_client() -> Any: + raise AssertionError("the description writer must not build a client") + + +async def test_a_fake_provider_describes_nothing( + monkeypatch: pytest.MonkeyPatch, prepare_env: None +) -> None: + monkeypatch.setattr(settings, "llm_provider", "fake") + monkeypatch.setattr(llm_client, "get_llm_client", _no_client) + stream = _stream() + ctx = await stream._prepare() + assert ctx["describe"] is False + assert ctx["llm"] is None + assert stream.result.note == "describe skipped: the llm provider is fake" + + +async def test_a_keyed_provider_without_its_key_describes_nothing( + monkeypatch: pytest.MonkeyPatch, prepare_env: None +) -> None: + monkeypatch.setattr(settings, "llm_provider", "anthropic") + monkeypatch.setattr(llm_client, "provider_key_missing", lambda _p: True) + monkeypatch.setattr(llm_client, "get_llm_client", _no_client) + ctx = await _stream()._prepare() + assert ctx["describe"] is False + assert ctx["llm"] is None + + +async def test_a_real_provider_still_describes( + monkeypatch: pytest.MonkeyPatch, prepare_env: None +) -> None: + real = object() + monkeypatch.setattr(llm_client, "llm_is_fake", lambda: False) + monkeypatch.setattr(llm_client, "get_llm_client", lambda: real) + ctx = await _stream()._prepare() + assert ctx["describe"] is True + assert ctx["llm"] is real + + +async def test_the_describe_cli_refuses_a_fake_provider( + monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str] +) -> None: + from server.cli import code_maintenance + + async def no_connect(*_a: Any) -> None: + raise AssertionError("refused before connecting") + + monkeypatch.setattr(settings, "llm_provider", "fake") + monkeypatch.setattr(llm_client, "get_llm_client", _no_client) + monkeypatch.setattr(code_maintenance, "connect_code_plane", no_connect) + assert await code_maintenance._describe(argparse.Namespace()) == 2 + assert "fake llm" in capsys.readouterr().err From 6b6eb2c4e6c97b0bd426992d8a130bb8865254a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=B0=D1=82-=D0=9E=D1=80=D1=88=D0=B8=D1=85?= <34618353+orshih6@users.noreply.github.com> Date: Sat, 28 Nov 2026 04:53:04 +0000 Subject: [PATCH 2/3] The describe CLI guard test patches llm_is_fake so its injected clients reach the guard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Бат-Орших <34618353+orshih6@users.noreply.github.com> --- tests/unit/test_code_description_provider_guard.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/test_code_description_provider_guard.py b/tests/unit/test_code_description_provider_guard.py index ca754aa6e27..3a83235993c 100644 --- a/tests/unit/test_code_description_provider_guard.py +++ b/tests/unit/test_code_description_provider_guard.py @@ -135,6 +135,7 @@ async def test_cli_rejects_fake_descriptions_before_embedding_or_insert(self) -> patch("server.core.ch.get_client", return_value=object()), patch("server.embedding.embedder.get_embedder", return_value=embedder), patch("server.llm.client.get_llm_client", return_value=client), + patch("server.llm.client.llm_is_fake", return_value=False), patch.object(describe, "_card_for", new_callable=AsyncMock, return_value=""), patch.object(describe, "describe_prompt", return_value=("system", "user", 60)), redirect_stdout(StringIO()), From a17587c828649eafc461380b8b25bd43fe587fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=B0=D1=82-=D0=9E=D1=80=D1=88=D0=B8=D1=85?= <34618353+orshih6@users.noreply.github.com> Date: Sat, 28 Nov 2026 05:23:16 +0000 Subject: [PATCH 3/3] The marked-chunk describe test patches llm_is_fake so its injected client reaches the skip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Бат-Орших <34618353+orshih6@users.noreply.github.com> --- tests/unit/test_code_embed_exclude.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/test_code_embed_exclude.py b/tests/unit/test_code_embed_exclude.py index d4ed6a92455..034fb3931c3 100644 --- a/tests/unit/test_code_embed_exclude.py +++ b/tests/unit/test_code_embed_exclude.py @@ -262,6 +262,7 @@ async def nothing(*_: Any, **__: Any) -> Any: monkeypatch.setattr("server.code.store.index.CodeRepo", _CodeRepo) monkeypatch.setattr("server.embedding.embedder.get_embedder", _Embedder) monkeypatch.setattr("server.llm.client.get_llm_client", _LLM) + monkeypatch.setattr("server.llm.client.llm_is_fake", lambda: False) monkeypatch.setattr("server.code.app.index.describe._describe_chunk", describe_chunk) monkeypatch.setattr("server.code.app.index.describe._card_for", nothing) args = SimpleNamespace(top_pct=100.0, suffix="", concurrency=2, limit=0)