Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions agent/model_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,13 @@ def get_model_context_length(
except Exception:
pass # fall through to probing

if not str(model or "").strip():
logger.info(
"No model id provided for context length resolution — defaulting to %s tokens.",
f"{DEFAULT_FALLBACK_CONTEXT:,}",
)
return DEFAULT_FALLBACK_CONTEXT

# Normalise provider-prefixed model names (e.g. "local:model-name" →
# "model-name") so cache lookups and server queries use the bare ID that
# local servers actually know about. Ollama "model:tag" colons are preserved.
Expand Down
4 changes: 4 additions & 0 deletions tests/agent/test_model_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ def test_tools_cache_is_bounded(self):
# =========================================================================

class TestDefaultContextLengths:
def test_empty_model_uses_fallback_context(self):
assert get_model_context_length("") == DEFAULT_FALLBACK_CONTEXT

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This verifies the final value but not the stated early-return guarantee: on current main, "" can reach fetch_model_metadata() and still eventually return the same fallback. Please assert that a downstream resolver/probe is not called (and include whitespace input).

assert get_model_context_length(None) == DEFAULT_FALLBACK_CONTEXT # type: ignore[arg-type]

def test_grok_substring_matching(self):
# Longest-first substring matching must resolve the real xAI model
# IDs to the correct fallback entries without 128k probe-down.
Expand Down