Skip to content

The agent that grows with you

fix(agent): title pin spelled as the main custom route still waits for the turn

kshitijk4poore1f70474e4c7
diff --git a/agent/title_generator.py b/agent/title_generator.py
index a41701974b2..9385a562817 100644
--- a/agent/title_generator.py
+++ b/agent/title_generator.py
@@ -180,9 +180,10 @@ def _model_title_upgrade_enabled() -> bool:
def title_upgrade_must_wait_for_turn(main_runtime: Optional[dict]) -> bool:
"""True when the model title call would hit the SAME self-hosted endpoint as the turn's own request.
- A ``custom`` (including ``custom:<name>``) main route (llama.cpp, Ollama, vLLM, LM Studio…)
- whose ``auxiliary.title_generation``
- is not pinned elsewhere shares one local server between the streaming main request and the
+ A ``custom`` / ``custom:<name>`` / ``lmstudio`` main route (llama.cpp, Ollama, vLLM, LM Studio…)
+ whose ``auxiliary.title_generation`` is not pinned elsewhere (a pin naming the same custom route —
+ ``custom:<name>``, bare ``<name>`` or its display name — is not "elsewhere", #120558)
+ shares one local server between the streaming main request and the
concurrent ``response_format: json_schema`` title request. Single-slot servers then serve the
title grammar/completion into the main turn: the user's reply arrives as ``{"title": ...}``, is
persisted as a genuine assistant row and replayed, and the model adopts the format (#117296).
@@ -190,7 +191,7 @@ def title_upgrade_must_wait_for_turn(main_runtime: Optional[dict]) -> bool:
Hosted providers multiplex requests independently and keep the turn-start timing.
"""
provider = str((main_runtime or {}).get("provider") or "").strip().lower()
- if provider not in {"custom", "lmstudio"} and not provider.startswith("custom:"):
+ if not _is_self_hosted_provider(provider):
return False
try:
cfg = _title_config()
@@ -199,11 +200,34 @@ def title_upgrade_must_wait_for_turn(main_runtime: Optional[dict]) -> bool:
pinned_provider = str(cfg.get("provider") or "").strip().lower()
pinned_base_url = str(cfg.get("base_url") or "").strip().rstrip("/")
main_base_url = str((main_runtime or {}).get("base_url") or "").strip().rstrip("/")
- if pinned_provider and pinned_provider not in ("", "auto", "custom"):
+ if pinned_provider not in ("", "auto") and not _title_pin_may_share_endpoint(pinned_provider, provider):
return False
return not pinned_base_url or pinned_base_url == main_base_url
+def _is_self_hosted_provider(provider: str) -> bool:
+ """``custom``, a named ``custom:<name>`` route, or first-class LM Studio: one local server per route."""
+ return provider in ("custom", "lmstudio") or provider.startswith("custom:")
+
+
+def _title_pin_may_share_endpoint(pinned_provider: str, main_provider: str) -> bool:
+ """A title pin that can land on the turn's own self-hosted server (only its ``base_url`` can prove otherwise).
+
+ Hosted pins (``openrouter``…) multiplex and never share the slot. A pin to ``custom``/``lmstudio``/any
+ ``custom:<name>`` is assumed to share until the caller compares ``base_url``, and a bare ``<name>`` /
+ display-name pin is the same endpoint when it aliases the main ``custom:<name>`` route
+ (``hermes_cli.providers.custom_provider_aliases`` — the resolver's own identity set).
+ """
+ try:
+ from hermes_cli.providers import custom_provider_aliases, normalize_provider
+ except Exception:
+ return True
+ pinned = normalize_provider(pinned_provider)
+ if _is_self_hosted_provider(pinned):
+ return True
+ return bool(custom_provider_aliases(pinned_provider) & custom_provider_aliases(main_provider))
+
+
def start_title_upgrade(upgrade: Optional[threading.Thread]) -> None:
"""Start a (deferred) title upgrade thread; joinable via ``wait_for_title_upgrades`` only once started."""
if upgrade is None or upgrade.ident is not None:
diff --git a/tests/agent/test_title_generator.py b/tests/agent/test_title_generator.py
index dd415d35696..c61714f7526 100644
--- a/tests/agent/test_title_generator.py
+++ b/tests/agent/test_title_generator.py
@@ -419,6 +419,35 @@ class TestMaybeAutoTitle:
assert started.wait(timeout=10), "auto_title thread never ran"
assert upgrade in tg._UPGRADE_THREADS
+ @pytest.mark.parametrize(
+ "main_provider, title_cfg, deferred",
+ [
+ ("Custom:GPTOSS-Local", {}, True), # /model stores the id as typed; the gate lowercases
+ ("custom:gptoss-local", {"provider": "custom:gptoss-local"}, True),
+ ("custom:gptoss-local", {"provider": "gptoss-local"}, True), # bare config name
+ ("custom:gptoss-local", {"provider": "GPTOSS Local"}, True), # display name
+ ("custom:gptoss-local", {"provider": "custom"}, True),
+ ("custom:gptoss-local", {"provider": "custom:gptoss-local", "base_url": "http://127.0.0.1:8080/v1/"}, True),
+ ("custom:gptoss-local", {"provider": "custom:other", "base_url": "http://10.0.0.2:8080/v1"}, False),
+ ("custom:gptoss-local", {"provider": "gptoss-local", "base_url": "http://10.0.0.2:8080/v1"}, False),
+ ("custom:gptoss-local", {"provider": "openrouter"}, False),
+ ("custom:gptoss-local", {"provider": "nous"}, False),
+ ("custom", {"provider": "ollama"}, True), # alias of custom
+ ("lmstudio", {"provider": "lm-studio"}, True),
+ ("lmstudio", {"provider": "lmstudio", "base_url": "http://10.0.0.2:1234/v1"}, False),
+ ("lmstudio", {"provider": "openrouter"}, False),
+ ],
+ )
+ def test_title_pin_naming_the_same_self_hosted_route_still_waits_for_the_turn(self, main_provider, title_cfg, deferred):
+ """#120558: a ``/model`` switch to a named custom provider runs the turn as ``custom:<name>``. A title pin
+ spelled as that route (``custom:<name>``, the bare config name or its display name) is the same single-slot
+ server, so the gate must still defer; only a differing pinned base_url or a hosted pin fires at turn start."""
+ from agent import title_generator as tg
+
+ main_runtime = {"provider": main_provider, "base_url": "http://127.0.0.1:8080/v1"}
+ with patch.object(tg, "_title_config", return_value=title_cfg):
+ assert tg.title_upgrade_must_wait_for_turn(main_runtime) is deferred
+
def test_kanban_worker_is_named_after_its_card_without_the_llm_thread(self, tmp_path, monkeypatch):
"""A worker's session takes the board card's title synchronously; no auxiliary model call (#111166)."""
from hermes_cli import kanban_db, kanban_db_connect