fix(llm): avoid double execution in schedule_stream_flow#363
Merged
imbajin merged 2 commits intoJun 21, 2026
Merged
Conversation
Contributor
Author
|
@imbajin Could you please review that one? |
imbajin
approved these changes
Jun 21, 2026
imbajin
left a comment
Member
There was a problem hiding this comment.
Blocking: no. Summary: No obvious issues found in the current head. Evidence: GitHub checks passed; git diff --check refs/remotes/apache/main...HEAD; uv run --extra llm --extra dev pytest hugegraph-llm/src/tests/flows/test_scheduler.py -q; ruff format/check on touched files.
haohao0103
pushed a commit
to haohao0103/incubator-hugegraph-ai
that referenced
this pull request
Jun 30, 2026
## 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 apache#360
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a control-flow fall-through in
Scheduler.schedule_stream_flowthat causedthe flow to be built, run, and streamed twice when no reusable pipeline
exists (
manager.fetch()returnsNone).Closes #360.
Root cause
The
if pipeline is None:branch builds a fresh pipeline, runs it, streams theresult via
post_deal_stream, and caches it withmanager.add(pipeline)— butit was missing a
returnat the end. Execution therefore fell straight throughinto the reuse
tryblock below, where the just-built (now non-None) pipelinewas 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_flowdoes not have this bug because itsif pipeline is None:branch ends with an explicitreturn res.Fix
Add a bare
returnaftermanager.add(pipeline)in theif pipeline is None:branch, so the build/run/stream path terminates instead of falling through.
A bare
returnis used (notreturn res) becauseschedule_stream_flowis anasync generator, where
return <value>is not allowed.Tests
Adds
hugegraph-llm/src/tests/flows/test_scheduler.py(Layer A /unitmarker,no Docker, network, or real LLM):
test_stream_flow_runs_once_when_no_reusable_pipeline— forcesmanager.fetch()to returnNoneand asserts the flow is built, initialized,run, and streamed exactly once, the stream output is not duplicated,
manager.addis called once, and the reuse/release path (prepare/release) is never entered. This test fails on the previous code and passeswith the fix.
test_stream_flow_rejects_unknown_flow_name— covers theValueErrorguardfor unsupported flow names.
The
Scheduleris instantiated via__new__with a single mocked pool entry toavoid eagerly constructing every real flow/manager in
__init__.How to verify locally