Skip to content

The agent that grows with you

fix(model_metadata): guard _localhost_to_ipv4 against non-string urls

kshitij733e7d26c089
diff --git a/agent/model_metadata.py b/agent/model_metadata.py
index be1efb163ed..7acf3868c57 100644
--- a/agent/model_metadata.py
+++ b/agent/model_metadata.py
@@ -836,7 +836,10 @@ def _localhost_to_ipv4(url: str) -> str:
``http://localhost...`` (e.g. ``?upstream=http://localhost:11434``)
passes through untouched.
"""
- if not url:
+ if not url or not isinstance(url, str):
+ # Non-string values (test doubles, lazily-resolved config objects)
+ # previously flowed through these call sites untouched — keep that
+ # contract; re.sub would raise TypeError.
return url
return re.sub(
r"^(https?://)localhost(?=[:/]|$)",