Muawiya-contact opened a new pull request, #363:
URL: https://github.com/apache/hugegraph-ai/pull/363
## Summary
Fixes a control-flow fall-through in `Scheduler.schedule_stream_flow` that
caused
the flow to be built, run, and streamed **twice** when no reusable pipeline
exists (`manager.fetch()` returns `None`).
Closes #360.
## Root cause
The `if pipeline is None:` branch builds a fresh pipeline, runs it, streams
the
result via `post_deal_stream`, and caches it with `manager.add(pipeline)` —
but
it was missing a `return` at the end. Execution therefore fell straight
through
into the reuse `try` block below, where the just-built (now non-`None`)
pipeline
was prepared and run a second time.
Impact: duplicate pipeline execution, extra LLM calls, and doubled streaming
output on the first call for a given flow.
The synchronous counterpart `schedule_flow` does not have this bug because
its
`if pipeline is None:` branch ends with an explicit `return res`.
## Fix
Add a bare `return` after `manager.add(pipeline)` in the `if pipeline is
None:`
branch, so the build/run/stream path terminates instead of falling through.
A bare `return` is used (not `return res`) because `schedule_stream_flow` is
an
async generator, where `return <value>` is not allowed.
## Tests
Adds `hugegraph-llm/src/tests/flows/test_scheduler.py` (Layer A / `unit`
marker,
no Docker, network, or real LLM):
- `test_stream_flow_runs_once_when_no_reusable_pipeline` — forces
`manager.fetch()` to return `None` and asserts the flow is built,
initialized,
run, and streamed **exactly once**, the stream output is not duplicated,
`manager.add` is called once, and the reuse/release path (`prepare` /
`release`) is never entered. This test fails on the previous code and
passes
with the fix.
- `test_stream_flow_rejects_unknown_flow_name` — covers the `ValueError`
guard
for unsupported flow names.
The `Scheduler` is instantiated via `__new__` with a single mocked pool
entry to
avoid eagerly constructing every real flow/manager in `__init__`.
## How to verify locally
```bash
uv sync --extra llm --extra dev
uv run pytest hugegraph-llm/src/tests/flows/test_scheduler.py -v
uv run ruff format --check .
uv run ruff check .
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]