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): let the gateway bound the wait before model output (#2802)
Call White70f3cb1107c9
diff --git a/core/agent_core/ai/_common.py b/core/agent_core/ai/_common.pyindex 69674d1c1..819edc24a 100644--- a/core/agent_core/ai/_common.py+++ b/core/agent_core/ai/_common.py@@ -9,6 +9,7 @@ import ioimport inspectimport jsonimport re+import timefrom collections.abc import AsyncIterator, Awaitable, Callable, Hashable, Mappingfrom dataclasses import asdict, dataclass, field, fields, is_dataclass, replacefrom typing import Any, TypeVar@@ -111,15 +112,19 @@ class WireField:# call's arguments. One bound covers every wait on the provider: response# headers, the first chunk, and each next chunk. Codex, Claude Code, Pi, and# OpenCode allow 300s of silence; Avibe allows 600s (owner decision,-# 2026-10-10), because Model Hub withholds even the response headers until the-# first model output, so a high-effort reasoning model's thinking time is all-# silence and can exceed five minutes. For the Sources whose streams keep-# sending, the gateway bounds the engine's silence at 120s first and retries a-# stall before output itself (docs/plans/model-hub-inference-deadlines.md), so-# this bound is the outer guard. Connecting stays separately short, so an-# unreachable provider still fails fast. Both bounds are shared by every native-# adapter; the loop may retry the resulting error only when no model output has-# been emitted.+# 2026-10-10). Connecting stays separately short, so an unreachable provider+# still fails fast. Both bounds are shared by every native adapter; the loop+# may retry the resulting error only when no model output has been emitted.+#+# Through the Model Hub gateway the wait for response headers is not this+# bound's: the gateway withholds the headers, and every upstream byte with them+# (Anthropic's pings included), until the first model output, so a model that+# thinks without streaming its thinking is silent here however healthy it is.+# Only the gateway sees the upstream until then, so the gateway bounds that+# wait on every attempt: 120 s of byte silence for the Sources whose streams+# keep sending, this bound for the rest (docs/plans/model-hub-inference-+# deadlines.md, "Vibey's wait before output"). Once headers arrive the gateway+# forwards every byte, and this bound covers each next chunk again.CONNECT_TIMEOUT_S = 10.0PROVIDER_SILENCE_TIMEOUT_S = 600.0CLEANUP_TIMEOUT_S = 10.0@@ -1836,6 +1841,7 @@ async def drive_sse_stream(response: httpx.Response | None = Noneopening: asyncio.Task[httpx.Response] | None = Nonecandidate: Done | ProviderError | None = None+ sent_at: float | None = Noneassembler.begin_driver()try:try:@@ -1843,7 +1849,8 @@ async def drive_sse_stream(candidate = assembler.aborted(cancel.reason)else:# The transport bounds only connecting; the wait for response- # headers is the provider's silence, bounded below.+ # headers is the provider's silence, bounded below, or the+ # gateway's to bound (``PROVIDER_SILENCE_TIMEOUT_S``).request = client.build_request(method,url,@@ -1853,11 +1860,12 @@ async def drive_sse_stream()# Retain the opening task even if cancellation wins the await:# its successful result still belongs to this driver's finally.+ sent_at = time.monotonic()opening = asyncio.create_task(client.send(request, stream=True))response = await _await_network(opening,cancel,- timeout_s=PROVIDER_SILENCE_TIMEOUT_S,+ timeout_s=None if gateway else PROVIDER_SILENCE_TIMEOUT_S,)if response is None:candidate = assembler.aborted(cancel.reason)@@ -1947,6 +1955,17 @@ async def drive_sse_stream(candidate = assembler.exception(exc)if candidate is not None:+ if (+ isinstance(candidate, ProviderError)+ and sent_at is not None+ and not assembler.streamed+ and time.monotonic() - sent_at >= PROVIDER_SILENCE_TIMEOUT_S+ ):+ # Whatever ended it, the request went at least the whole silence+ # bound without output. Sent again it would most likely wait as+ # long again, so the failure ends the turn: neither replayed nor+ # continued.+ candidate = replace(candidate, retryable=False, continuable=False)# Translator terminals are candidates, not public errors. Commit# and sanitize exactly once at the shared driver boundary.assembler.end_driver()diff --git a/docs/plans/agent-core-contracts/conversion-tables.md b/docs/plans/agent-core-contracts/conversion-tables.mdindex d6e0aee10..6f5cc88fc 100644--- a/docs/plans/agent-core-contracts/conversion-tables.md+++ b/docs/plans/agent-core-contracts/conversion-tables.md@@ -19,7 +19,7 @@ rules on top of those mappings.| Missing tool results | The transform inserts `[tool call interrupted; no result recorded]` with `is_error=true`. || Origin | Direct requests use the endpoint origin. Gateway requests parse only `x-avibe-served-hop`, whose JSON object must contain exactly `provider`, `api`, `model`, and `source` (Model Hub contract v12); `origin` takes `provider`, `api`, `model`, and `source` is the serving Source id matching `^src_[a-z0-9]{8,}$`. A missing or invalid report makes the response unverified: thinking and tool-call signatures are nulled, and redacted thinking is dropped before allocating a canonical slot, so later event indexes still identify their final message blocks. || Cancellation | `CancelToken` ends the HTTP stream and yields one non-retryable `ProviderError(kind="aborted")`. Opening, stream reads, error-body reads, media loads, and served-hop resolution all use the shared cancellation-aware await owner. |-| Network timeouts | The shared lifecycle driver bounds connecting at 10 seconds; a connect failure or timeout is `ProviderError(kind="network")`. Every wait on a connected provider (response headers, the first chunk, and each next chunk) is bounded by the same 600-second silence bound: reasoning models and relays that buffer tool-call arguments stay silent far longer than a connect window. Codex (`stream_idle_timeout_ms`), Claude Code, Pi, and OpenCode use 300 seconds; Avibe doubles it (owner decision, 2026-10-10) because through Model Hub the response headers wait for the first model output, so a high-effort reasoning model's thinking time is all silence and can exceed five minutes. Running out of the silence bound is `ProviderError(kind="stalled")`, never a connection failure. Both kinds are retryable only when no model output was emitted; a provider that never sends response headers cannot hang a turn. A bounded 10-second cancellation join detaches a non-cooperative transport task instead of extending the timeout indefinitely. |+| Network timeouts | The shared lifecycle driver bounds connecting at 10 seconds; a connect failure or timeout is `ProviderError(kind="network")`. Every wait on a connected provider (response headers, the first chunk, and each next chunk) is bounded by the same 600-second silence bound: reasoning models and relays that buffer tool-call arguments stay silent far longer than a connect window. Codex (`stream_idle_timeout_ms`), Claude Code, Pi, and OpenCode use 300 seconds; Avibe doubles it (owner decision, 2026-10-10). Through the Model Hub gateway the wait for response headers is the gateway's to bound, not the driver's: the headers wait for the first model output, so a model that thinks without streaming its thinking is silent here for as long as it thinks, while only the gateway sees the upstream's bytes. The gateway's engine read applies its 120-second idle bound on the measured Sources and this 600-second bound on every other Vibey stream (`model-hub-inference-deadlines.md`, "Vibey's wait before output"). Running out of the silence bound is `ProviderError(kind="stalled")`, never a connection failure. Both kinds are retryable only when no model output was emitted, and no failure that arrives without output at least the silence bound after its request was sent is retryable or continuable. A provider that never sends response headers cannot hang a turn without a gateway; behind one, the gateway's bounds end the wait. A bounded 10-second cancellation join detaches a non-cooperative transport task instead of extending the timeout indefinitely. || HTTP response status | Only 2xx responses enter an SSE translator. Redirects (3xx) are terminal `invalid_request` errors and are never followed implicitly; 4xx/5xx bodies use the shared status-aware classifier. || SSE memory and scan bounds | `SSEParser` caps an unfinished line at 8 MiB of decoded characters and an unfinished event's combined `data:` fields at 32 MiB of decoded characters. It scans each buffer with a cursor and compacts once per feed, so many short fields remain linear rather than repeatedly copying the suffix. Exceeding either bound is one terminal `invalid_request` provider error, with any assembled partial preserved. || Cumulative assembled-output bound | `StreamAssembler._account_output` is the only byte-accounting function. It covers text, thinking, signatures, opaque/reasoning details, tool arguments, serialized initial tool inputs, tool-call identities and aliases. Each content slot, tool state, or Anthropic block-kind entry adds a conservative 2048-byte structure allowance; each alias adds 512 bytes, plus its string payload. The cumulative accounting budget is 32 MiB across the stream, not an exact process-RSS promise (transport/parser buffers and transient materialization have separate costs). An over-budget mutation raises one terminal `invalid_request` error, preserving the assembled partial. |diff --git a/docs/plans/agent-core-contracts/provider.md b/docs/plans/agent-core-contracts/provider.mdindex 1bcc05a08..5ed230048 100644--- a/docs/plans/agent-core-contracts/provider.md+++ b/docs/plans/agent-core-contracts/provider.md@@ -131,7 +131,9 @@ continuation runs, which cannot replay the original input or committed tools. Rafuture causes, explicit pin/opaque refusals, permanent/protocol errors, unclassified failures, and local preparationerrors grant no continuation. Neither the terminal sanitizer nor a downstream consumer may infer permission from`kind` alone. A recovery-exhausted error after thinking remains non-continuable, because the partial response is not-safe to replay or continue implicitly.+safe to replay or continue implicitly. A failure of any kind that arrives before any output, at least the silence bound+after its request was sent, is neither retryable nor continuable: sent again, the request would most likely wait as+long again (`conversion-tables.md`, network timeouts).The loop carries both permissions and `retry_after_s` into the terminal `AgentError` unchanged. These fields donot grant permission to replay committed tools or manufacture user input; Vibey uses `Agent.resume` under itsdiff --git a/docs/plans/model-hub-inference-deadlines.md b/docs/plans/model-hub-inference-deadlines.mdindex 1694dee03..ff96f0665 100644--- a/docs/plans/model-hub-inference-deadlines.md+++ b/docs/plans/model-hub-inference-deadlines.md@@ -344,8 +344,9 @@ which agrees with the `openai` row.started. With the bound at 120 s that does not happen, because the errorcomes at least 120 s after the last byte. After text or a tool call the erroris terminal (C-2). It now comes 120 s after the last byte instead of 600 s.-- **Vibey's 600 s silence bound** stays as the outer guard. It now fires only- for the unbounded Sources above, or if the gateway itself stops.+- **Vibey's 600 s silence bound** covers each chunk after the response+ headers. The wait for the headers belongs to the engine read; see+ [Vibey's wait before output](#vibeys-wait-before-output-2026-10-18).- **Native callers.** Their own bounds (Codex 300 s between events, ClaudeCode's first-byte and idle watchdogs) are longer and remain unchanged.- **Engine patches 4 and 5 stay.** They bound a dead path in about 45 s on@@ -365,3 +366,49 @@ which agrees with the `openai` row.- The vendor is the Source's declared vendor. A relay declared `openai` thatserves a model which buffers tool calls, as xAI does, would be cut at 120 son a tool call longer than that.++## Vibey's wait before output (2026-10-18)++### Problem++On 2026-10-17 a Vibey turn on Claude Opus 5.5 at `xhigh` effort, asked for a+long piece of writing through an `anthropic` API-key relay, failed after+20 minutes as `stalled`: two engine requests, each cut by Vibey at 600 s. The+gateway's 120 s bound never fired, so the engine kept receiving bytes, the+Anthropic pings. From Claude Opus 4.7 on, `thinking.display` defaults to+`omitted`, so a thinking phase streams no thinking deltas. The gateway withholds+the response headers and every byte until the first content block, and Vibey's+own bound also covered the wait for those headers, so it counted the model's+whole thinking time as silence. Claude Code is not affected: its streams commit+early and carry keepalives (`_EARLY_STREAM_COMMIT_SECONDS`).++Two alternatives were rejected. Requesting `display: "summarized"` would make+thinking count as output, but would move the upstream request away from Claude+Code's default shape (owner decision, 2026-10-18). Committing Vibey's streams+early, as Claude Code's are, would drop the `x-avibe-served-hop` header Vibey+reads with the headers to verify the origin of replayed signatures, and the+HTTP status its error handling keys on.++### Contract++- Through the gateway, Vibey does not bound the wait for response headers.+ Once they arrive, its 600 s bound covers each next chunk as before.+- The engine read holds the bound for every attempt of a Vibey stream: the+ 120 s idle bound on the measured Sources above, and Vibey's 600 s silence+ bound on every other stream. Every byte restarts either one, so a model that+ thinks behind a pinging upstream is never cut, and a silent stream on an+ unmeasured Source is cut at 600 s and recovered like any other timeout.+- A failure that reaches Vibey before any model output, at least 600 s after+ its request was sent, ends the turn: it is neither replayed nor continued.+ Sent again, the request would most likely wait as long again, and Model Hub+ has already retried what its recovery window allows.++### Residuals++- A stuck upstream behind a relay that keeps pinging holds a Vibey turn until+ Stop, as it holds a Claude Code turn. Elapsed time alone is not failure.+- On an unmeasured Source, after output, the engine read's 600 s bound and+ Vibey's own coincide, and the engine read usually ends first, so such a stall+ reaches Vibey as `interrupted` rather than `stalled`.+- A persistently silent unmeasured Source still costs about two 600 s attempts+ (Model Hub recovery), as before (Vibey's own stall and one continuation).diff --git a/tests/agent_core/ai/test_provider_adapters.py b/tests/agent_core/ai/test_provider_adapters.pyindex ddbfd8e6b..98773e74d 100644--- a/tests/agent_core/ai/test_provider_adapters.py+++ b/tests/agent_core/ai/test_provider_adapters.py@@ -3350,13 +3350,15 @@ async def test_shared_driver_bounds_each_wait_on_a_silent_provider(error = events[-1]assert isinstance(error, ProviderError)assert error.kind == "stalled"+ assert error.retryable is Falseif phase == "after_output":# Output already reached the user: the stall ends the request with what streamed.- assert error.retryable is False+ assert error.continuable is Trueassert error.partial is not Noneassert [block.text for block in error.partial.content] == ["partial"]else:- assert error.retryable is True+ # The whole bound passed without output: sent again, it would wait as long again.+ assert error.continuable is Falseassert error.partial is Noneif phase == "first_byte":assert first_byte_stream.closed.is_set()@@ -3407,6 +3409,66 @@ async def test_slow_but_alive_provider_is_bounded_per_silence_not_per_stream(assert done.message.content[0].text == "".join(words)+_RECOVERY_EXHAUSTED_BY_NETWORK = {+ "type": "error",+ "error": {"type": "model_hub_recovery_exhausted", "code": "model_hub_recovery_exhausted", "cause": "network"},+}+_ANSWERED = {+ "anthropic": (+ 'data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":"ok"}}\n\n'+ 'data: {"type":"message_delta","delta":{"stop_reason":"end_turn"}}\n\n'+ 'data: {"type":"message_stop"}\n\n'+ ),+ "openai_chat": (+ 'data: {"choices":[{"delta":{"content":"ok"},"finish_reason":null}]}\n\n'+ 'data: {"choices":[{"delta":{},"finish_reason":"stop"}]}\n\n'+ "data: [DONE]\n\n"+ ),+ "openai_responses": (+ 'data: {"type":"response.output_text.delta","delta":"ok"}\n\n'+ 'data: {"type":"response.completed","response":{"status":"completed"}}\n\n'+ ),+}+++ ("adapter_type", "protocol"),+ [(OpenAIResponsesAdapter, "openai_responses"), (OpenAIChatAdapter, "openai_chat"), (AnthropicAdapter, "anthropic")],+)+ ("answer", "bounds_waited", "continuable"),+ [("served", 4, None), ("exhausted", 4, False), ("exhausted", 0, True)],+)+async def test_the_gateway_bounds_the_wait_for_headers_and_a_failure_that_outwaited_the_bound_is_final(+ monkeypatch: pytest.MonkeyPatch, adapter_type, protocol: str, answer: str, bounds_waited: int, continuable: bool | None,+) -> None:+ """Model Hub sends response headers at the first model output, so a model thinking without streaming its thinking+ holds them back for as long as it thinks. The gateway sees the upstream's bytes meanwhile and bounds that wait+ itself; the driver does not. A failure that comes back only after the whole silence bound without output is not+ sent again: it would most likely take as long again."""+ import core.agent_core.ai._common as common++ bound = 0.05+ monkeypatch.setattr(common, "PROVIDER_SILENCE_TIMEOUT_S", bound)++ async def handler(_: httpx.Request) -> httpx.Response:+ await asyncio.sleep(bound * bounds_waited)+ if answer == "exhausted":+ return httpx.Response(424, json=_RECOVERY_EXHAUSTED_BY_NETWORK)+ return httpx.Response(200, headers={"content-type": "text/event-stream"}, text=_ANSWERED[protocol])++ async with httpx.AsyncClient(transport=httpx.MockTransport(handler)) as client:+ events = await asyncio.wait_for(_events(adapter_type(client, gateway=True), _request(protocol)), timeout=5)++ terminal = events[-1]+ if answer == "served":+ assert isinstance(terminal, Done)+ return+ assert isinstance(terminal, ProviderError)+ assert (terminal.kind, terminal.retryable, terminal.continuable) == ("network", False, continuable)++@pytest.mark.asyncio@pytest.mark.parametrize("failure", [httpx.ConnectError, httpx.ConnectTimeout])async def test_only_connecting_is_bounded_by_the_transport_and_its_failure_is_network(@@ -3456,7 +3518,6 @@ async def test_non_cooperative_stream_cancellation_join_does_not_block_driver(error = events[-1]assert isinstance(error, ProviderError)assert error.kind == "stalled"- assert error.retryable is Trueassert stream.cancel_seen.is_set()assert stream.cancel_count == 1assert stream.closed.is_set()diff --git a/tests/test_model_hub_retry_lifecycle.py b/tests/test_model_hub_retry_lifecycle.pyindex 681102ec3..98ccb734d 100644--- a/tests/test_model_hub_retry_lifecycle.py+++ b/tests/test_model_hub_retry_lifecycle.py@@ -26,6 +26,7 @@ from core.run_settlement import SETTLED_BY_TERMINAL_RESULTfrom modules.agents.model_hub import ModelHubRuntimeRouter, bind_launchfrom tests.test_model_hub_l3 import _assert_valid, _canonicalize_fixed_test_routes, _outcome, _sourcefrom tests.test_model_hub_retry_policy import WIRE, clock_service, fail+from vibe.model_hub_runtime import adapter as engine_adapter_modulefrom vibe.model_hub_runtime import client as engine_client_modulefrom vibe.model_hub_runtime.adapter import CLIProxyEngineAdapterfrom vibe.model_hub_runtime.client import EngineClient, EngineConnection@@ -1133,3 +1134,72 @@ def test_a_silent_engine_stream_is_cancelled_and_retried_at_its_idle_bound(assert clock.delays == [1]asyncio.run(run())+++ "origin,vendor,source_protocol,bound",+ [+ # Vibey's own bound, which Vibey no longer applies to the wait for response headers.+ ("vibey", "xai", "openai_responses", "caller"),+ # A measured Source keeps its shorter bound for every caller.+ ("vibey", "anthropic", "anthropic", "idle"),+ # A native caller keeps its own bound, and an unmeasured Source stays unbounded here.+ ("codex", "xai", "openai_responses", None),+ ],+)+def test_vibey_hands_its_silence_bound_to_the_engine_read(+ monkeypatch, tmp_path, origin, vendor, source_protocol, bound,+):+ """MH-RUNTIME-013: before model output only the engine read sees the upstream, so it holds Vibey's bound.++ The gateway withholds the response, heartbeats included, until the first+ model output, and a model that thinks without streaming its thinking sends+ nothing else for as long as it thinks. Vibey therefore bounds no wait for+ response headers itself; the engine read applies Vibey's silence bound to+ every stream the measured Source table leaves unbounded.+ """+ idle, caller = 0.3, 0.8+ monkeypatch.setattr(engine_client_module, "_STREAM_IDLE_TIMEOUT_SECONDS", idle)+ monkeypatch.setattr(engine_adapter_module, "PROVIDER_SILENCE_TIMEOUT_S", caller)++ async def run() -> None:+ source = _source("src_silent01", "Silent", vendor=vendor, protocol=source_protocol)+ service, _clock, _models = configured_service(tmp_path, sources=[source])+ metadata, output, terminal, _buffered = WIRE[source_protocol]+ stalled_for: list[float] = []++ async def respond(request: web.Request) -> web.StreamResponse:+ await request.json()+ response = web.StreamResponse(headers={"Content-Type": "text/event-stream"})+ await response.prepare(request)+ await response.write(metadata)+ started = time.monotonic()+ try:+ await asyncio.sleep(caller * 2)+ except asyncio.CancelledError:+ stalled_for.append(time.monotonic() - started)+ raise+ await response.write(output)+ await response.write(terminal)+ await response.write_eof()+ return response++ async with loopback_engine(tmp_path, service, respond) as (adapter, _engine_client):+ handle = await asyncio.wait_for(+ adapter.invoke(source.id, "shared-model", {"stream": True}, True, origin), timeout=5,+ )+ body = b"".join([chunk async for chunk in handle.stream]) if handle.stream is not None else b""+ outcome = await asyncio.wait_for(handle.outcome(), timeout=5)+ await asyncio.sleep(0.05)++ if bound is None:+ assert outcome.kind == RawOutcomeKind.SUCCESS+ assert body == metadata + output + terminal+ assert stalled_for == []+ return+ assert outcome.kind == RawOutcomeKind.TIMEOUT+ assert body == b""+ expected = caller if bound == "caller" else idle+ assert len(stalled_for) == 1 and expected * 0.9 <= stalled_for[0] < min(expected + 0.4, caller * 2)++ asyncio.run(run())diff --git a/tests/test_model_hub_runtime.py b/tests/test_model_hub_runtime.pyindex 34f765a1d..7b16c849e 100644--- a/tests/test_model_hub_runtime.py+++ b/tests/test_model_hub_runtime.py@@ -4864,6 +4864,7 @@ def test_adapter_uses_origin_protocol_for_engine_translation(request_headers=None,on_transport_done=None,on_request_sent=None,+ silence_bound_s=None,):self.request_protocol = request_protocolself.request_headers = request_headers@@ -5032,6 +5033,7 @@ def test_adapter_serializes_source_sync_with_new_invocations(tmp_path: Path) ->request_headers=None,on_transport_done=None,on_request_sent=None,+ silence_bound_s=None,):invoked_refs.append(source.credential_ref)on_transport_done()diff --git a/vibe/model_hub_runtime/adapter.py b/vibe/model_hub_runtime/adapter.pyindex 90656736c..2e0e0da41 100644--- a/vibe/model_hub_runtime/adapter.py+++ b/vibe/model_hub_runtime/adapter.py@@ -18,6 +18,7 @@ from typing import Any, Callable, Literal, Mapping, Sequence, TypeVarimport aiohttpfrom config.v2_config import normalize_model_hub_base_url+from core.agent_core.ai._common import PROVIDER_SILENCE_TIMEOUT_Sfrom core.handlers.model_hub.adapter import (DiscoveredModel,EngineEnsureResult,@@ -2907,6 +2908,9 @@ class CLIProxyEngineAdapter:request_headers=getattr(request, "headers", None),on_transport_done=release,on_request_sent=request_sent,+ # Vibey waits on the gateway without a bound of its own until the+ # response headers, which the gateway sends at the first model output.+ silence_bound_s=PROVIDER_SILENCE_TIMEOUT_S if origin == "vibey" else None,)if handle.outcome_available and engine_disowned_call(await handle.outcome()):# The engine's last health check vouches for it no longer: thediff --git a/vibe/model_hub_runtime/client.py b/vibe/model_hub_runtime/client.pyindex 2fa1c8e19..db2f4a86a 100644--- a/vibe/model_hub_runtime/client.py+++ b/vibe/model_hub_runtime/client.py@@ -472,7 +472,14 @@ class EngineClient:request_headers: Mapping[str, str] | None = None,on_transport_done: Callable[[], None] | None = None,on_request_sent: Callable[[], None] | None = None,+ silence_bound_s: float | None = None,) -> EngineInvokeHandle:+ """Send one request to the engine.++ ``silence_bound_s`` is the byte-silence bound a caller hands over for a+ stream the measured Source table leaves unbounded; ``None`` leaves it so.+ """+request_protocol = request_protocol or source.protocolbody = dict(request)routed_model = f"{source.prefix}/{model_id}"@@ -509,16 +516,21 @@ class EngineClient:if request_protocol == "anthropic":headers.setdefault("anthropic-version", "2023-06-01")+ idle_bound: float | None = None+ if stream:+ measured = (+ request_protocol == source.protocol+ and (source.vendor, source.protocol) in _STREAM_IDLE_BOUNDED_SOURCES+ )+ # A caller that holds no bound of its own before model output hands+ # it over: until then the gateway withholds the whole response,+ # heartbeats included, so only this read sees the upstream's bytes.+ idle_bound = _STREAM_IDLE_TIMEOUT_SECONDS if measured else silence_bound_stimeout = aiohttp.ClientTimeout(total=None,connect=self.timeout,sock_connect=self.timeout,- sock_read=(- _STREAM_IDLE_TIMEOUT_SECONDS- if stream and request_protocol == source.protocol- and (source.vendor, source.protocol) in _STREAM_IDLE_BOUNDED_SOURCES- else None- ),+ sock_read=idle_bound,)# Connecting to the local engine is bounded. Once connected, inference# can take any duration; completion, transport failure, or owner