Skip to content

Commit a31c91a

Browse files
author
Saad ur Rehman
committed
refactor(api): give the timeout sentinel its own type
The default marker was a bare object(), so execution_timeout typed as float | None | object collapsed to object and the value reaching asyncio.wait_for was never narrowed. Use a private sentinel class and an isinstance check instead, leaving float | None afterwards. No behaviour change.
1 parent 7dc1cb1 commit a31c91a

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/backend/base/langflow/api/v2/workflow_execution.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,18 @@ def _resolve_execution_timeout() -> int:
7070
# letting frames accumulate without bound when the network is slow.
7171
_EVENT_QUEUE_MAX_SIZE = 256
7272

73-
# Default for ``_stream_event_frames(execution_timeout=...)``: resolve the ceiling
74-
# from settings. Distinct from ``None`` so a caller can ask for "unbounded" without
75-
# it collapsing into "use the default".
76-
_CEILING_FROM_SETTINGS: Final = object()
73+
74+
class _CeilingFromSettings:
75+
"""Sentinel type for ``_stream_event_frames(execution_timeout=...)``.
76+
77+
Its own class rather than a bare ``object()`` so the parameter carries a real
78+
static type and an ``isinstance`` check narrows the remaining value to
79+
``float | None`` for ``asyncio.wait_for``. Distinct from ``None`` so a caller
80+
can ask for "unbounded" without it collapsing into "use the default".
81+
"""
82+
83+
84+
_CEILING_FROM_SETTINGS: Final = _CeilingFromSettings()
7785

7886

7987
async def generate_flow_events(*args, **kwargs) -> None:
@@ -191,7 +199,7 @@ async def _stream_event_frames(
191199
job_id: UUID | None = None,
192200
resume: dict | None = None,
193201
track_job_status: bool = True,
194-
execution_timeout: float | None | object = _CEILING_FROM_SETTINGS,
202+
execution_timeout: float | None | _CeilingFromSettings = _CEILING_FROM_SETTINGS,
195203
) -> AsyncIterator[tuple[bytes, str]]:
196204
"""Run a flow via the v1 build-vertex loop, dispatch its events through ``adapter``.
197205
@@ -228,7 +236,7 @@ async def _stream_event_frames(
228236
# Ceiling for the modes whose caller is waiting on a socket (stream, public).
229237
# Sync uses its own asyncio.wait_for upstream; background passes None and is
230238
# bounded by JobRunner instead. wait_for(timeout=None) simply awaits.
231-
if execution_timeout is _CEILING_FROM_SETTINGS:
239+
if isinstance(execution_timeout, _CeilingFromSettings):
232240
execution_timeout = _resolve_execution_timeout()
233241

234242
# Captured from drive()'s exception path so the consumer can yield a

0 commit comments

Comments
 (0)