The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(gateway): single StreamingConfig.enabled_for gate for both streaming sites (#53697)
kshitijk4poor20fb7556090c
diff --git a/gateway/config.py b/gateway/config.pyindex e484102a9a1..276009ac6bd 100644--- a/gateway/config.py+++ b/gateway/config.py@@ -508,6 +508,19 @@ class StreamingConfig:# fresh-message replacement path; set >0 to opt in.fresh_final_after_seconds: float = 0.0+ @property+ def globally_enabled(self) -> bool:+ """The ``streaming.enabled`` master switch (``transport: off`` also disables)."""+ return bool(self.enabled) and self.transport != "off"++ def enabled_for(self, platform_override: Any) -> bool:+ """Effective streaming for one platform.++ ``platform_override`` is ``display.platforms.<plat>.streaming`` (``None`` = follow global).+ A per-platform value can only narrow the global switch, never enable streaming on its own.+ """+ return self.globally_enabled and (platform_override is None or bool(platform_override))+def to_dict(self) -> Dict[str, Any]:return asdict(self)diff --git a/gateway/run_turn.py b/gateway/run_turn.pyindex b49e52aefab..40e3b6e65b2 100644--- a/gateway/run_turn.py+++ b/gateway/run_turn.py@@ -2722,13 +2722,12 @@ class GatewayTurnMixin:if _scfg is None:from gateway.config import StreamingConfig_scfg = StreamingConfig()+ # Global master switch first: skips the config.yaml re-read on the default (off) path.+ if not _scfg.globally_enabled:+ return Nonefrom gateway.display_config import resolve_display_setting_plat_streaming = resolve_display_setting(_load_gateway_config(), _platform_config_key(source.platform), "streaming")- _global_streaming_enabled = bool(_scfg.enabled) and _scfg.transport != "off"- _streaming_enabled = _global_streaming_enabled and (- True if _plat_streaming is None else bool(_plat_streaming)- )- if not _streaming_enabled:+ if not _scfg.enabled_for(_plat_streaming):return Nonetry:from gateway.stream_consumer import GatewayStreamConsumerdiff --git a/gateway/run_turn_runner.py b/gateway/run_turn_runner.pyindex 80c265f9b1d..76d8e5ec56c 100644--- a/gateway/run_turn_runner.py+++ b/gateway/run_turn_runner.py@@ -921,10 +921,7 @@ class TurnRunner:scfg = StreamingConfig()# display.platforms.<plat>.streaming may disable streaming per platform; None = follow global.plat_streaming = ctx.resolve_display_setting(ctx.user_config, platform_key, "streaming")- global_streaming_enabled = bool(scfg.enabled) and scfg.transport != "off"- want_stream_deltas = not ctx.scheduled_heartbeat and global_streaming_enabled and (- True if plat_streaming is None else bool(plat_streaming)- )+ want_stream_deltas = not ctx.scheduled_heartbeat and scfg.enabled_for(plat_streaming)want_interim_messages = bool(ctx.interim_assistant_messages_enabled) and not ctx.scheduled_heartbeatif want_stream_deltas or want_interim_messages:try: