Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(vibey): remember a 1-hour cache TTL rejection per Source, not per gateway URL (#2585)
Call White70880f5c9f85
diff --git a/core/agent_core/ai/anthropic.py b/core/agent_core/ai/anthropic.pyindex f7da4535b..63fce1c67 100644--- a/core/agent_core/ai/anthropic.py+++ b/core/agent_core/ai/anthropic.py@@ -65,7 +65,7 @@ _MAX_CACHE_BREAKPOINTS = 4# and requires every longer lifetime to come before every shorter one, which this placement satisfies._PREFIX_TTL = "1h"# Routes whose endpoint rejected the field. They keep the default lifetime for the rest of the process.-_TTL_REJECTED_ROUTES: set[tuple[str, str, str]] = set()+_TTL_REJECTED_ROUTES: set[tuple[str, str | None, str, str]] = set()_TTL_REJECTION = re.compile(r"cache_control|\bttl\b", re.IGNORECASE)_LEGACY_THINKING_BUDGETS = {"minimal": 1024,@@ -1025,8 +1025,10 @@ def _prefix_ttl(request: ModelRequest) -> str | None:return _PREFIX_TTL-def _ttl_route(endpoint: ModelEndpoint) -> tuple[str, str, str]:- return (endpoint.base_url, endpoint.provider, endpoint.model_id)+def _ttl_route(endpoint: ModelEndpoint) -> tuple[str, str | None, str, str]:+ """The route a TTL rejection is remembered for. Every Vibey hop shares the one gateway URL, so the Source behind+ it is part of the route: one relay's rejection never changes what another Source is sent."""+ return (endpoint.base_url, endpoint.source_id, endpoint.provider, endpoint.model_id)def _rejects_ttl(event: Any) -> bool:diff --git a/tests/agent_core/ai/test_anthropic_prompt_cache.py b/tests/agent_core/ai/test_anthropic_prompt_cache.pyindex 33f7051ef..b366b28a8 100644--- a/tests/agent_core/ai/test_anthropic_prompt_cache.py+++ b/tests/agent_core/ai/test_anthropic_prompt_cache.py@@ -73,11 +73,17 @@ def _request(tools: tuple[ToolSpec, ...] = TOOLS,messages: tuple[Any, ...] = CONVERSATION,base_url: str | None = None,+ source_id: str | None = None,) -> ModelRequest:# A fresh endpoint per request unless one is given: a route's TTL memory lasts the process.return ModelRequest(endpoint=ModelEndpoint(- "anthropic", base_url or f"https://{uuid.uuid4().hex}.test/v1", model_id, "token", provider=provider+ "anthropic",+ base_url or f"https://{uuid.uuid4().hex}.test/v1",+ model_id,+ "token",+ provider=provider,+ source_id=source_id,),system=system,messages=messages,@@ -207,17 +213,21 @@ async def test_a_rejected_ttl_is_retried_once_without_it_and_remembered_for_the_return httpx.Response(200, headers={"content-type": "text/event-stream"}, text=SUCCESS)caplog.set_level(logging.WARNING, logger="core.agent_core.ai.anthropic")- request = _request()+ # Two Sources behind one gateway URL, as every Vibey hop is.+ gateway = f"https://{uuid.uuid4().hex}.test/vibey/v1"+ request = _request(base_url=gateway, source_id="src_relayaaaa01")async with httpx.AsyncClient(transport=httpx.MockTransport(handler)) as client:runs = [await _run(client, request),# A later run builds its own adapter; the route keeps the default for the process.await _run(client, request),- # The memory is the route's: another model on the same endpoint still asks for the hour.- await _run(client, _request(model_id="claude-sonnet-5", base_url=request.endpoint.base_url)),+ # The memory is the route's: another model on the same endpoint still asks for the hour,+ await _run(client, _request(model_id="claude-sonnet-5", base_url=gateway, source_id="src_relayaaaa01")),+ # and so does another Source of the same model behind the same gateway URL.+ await _run(client, _request(base_url=gateway, source_id="src_directbbb02")),]- rejected, retried, remembered, other_rejected, other_retried = sent+ rejected, retried, remembered, other_rejected, other_retried, source_rejected, source_retried = sentassert _breakpoints(rejected)[:2] == [("tools.1", HOUR), ("system.0", HOUR)]# Exactly one retry: the same request with the default lifetime.assert retried == _without_ttl(rejected)@@ -225,13 +235,15 @@ async def test_a_rejected_ttl_is_retried_once_without_it_and_remembered_for_the_assert not _carries_ttl(remembered)assert _carries_ttl(other_rejected)assert other_retried == _without_ttl(other_rejected)+ assert _carries_ttl(source_rejected)+ assert source_retried == _without_ttl(source_rejected)for events in runs:# One terminal per run: a rejected attempt never reaches the consumer.terminals = [event for event in events if isinstance(event, (Done, ProviderError))]assert [type(event) for event in terminals] == [Done if retry_accepted else ProviderError]assert retry_accepted or terminals[0].status == 400# Logged once per route, not once per request.- assert len([record for record in caplog.records if record.name == "core.agent_core.ai.anthropic"]) == 2+ assert len([record for record in caplog.records if record.name == "core.agent_core.ai.anthropic"]) == 3@pytest.mark.parametrize(