Skip to content

fix(response-stream): render non-streamed variables from the pool - #391

Closed
Luckyou-d wants to merge 1 commit into
langgenius:mainfrom
Luckyou-d:fix/response-stream-non-streamed-variable-main
Closed

Luckyou-d wants to merge 1 commit into
langgenius:mainfrom
Luckyou-d:fix/response-stream-non-streamed-variable-main

Conversation

@Luckyou-d

Copy link
Copy Markdown
Contributor

Fixes #389 (root cause of langgenius/dify#46034)

Problem

When a variable's source node runs with streaming disabled, the stream buffer receives only an empty final marker (chunk="", is_final=True) and is closed. TemplateStream._read_variable_chunks pops the marker, sees is_closed, marks the segment complete — and skips the variable-pool fallback, because that branch requires not has_stream_events while the buffer does have events (the empty marker).

The response node therefore renders nothing for non-streamed variables, even though the workflow run record contains the text. Reported from dify as langgenius/dify#46034 (the 0.8.0 rev dify pins has the same logic in filter.py; main carries it in template_stream.py).

Fix

Track the text actually emitted for the segment; if the closed buffer carried no non-empty content, fall back to the variable-pool value as before.

Streamed variables are unaffected: meaningful chunks suppress the fallback (test_response_stream_filter_no_pool_fallback_when_streamed pins this). Genuinely empty values render nothing, as before.

Tests

  • test_response_stream_filter_falls_back_to_pool_for_non_streamed_variable — fails before the fix (rendered ""), passes after ("saved").
  • test_response_stream_filter_no_pool_fallback_when_streamed — guards against double-emission for streamed variables.

pytest tests/engine/: 166 passed.

Note for the dify side

dify pins graphon at rev 4fa2214; after this merges, a rev bump in dify's pyproject.toml picks the fix up.

A variable whose source ran with streaming disabled produces no
incremental chunks - only an empty final marker in the stream buffer.
_read_variable_chunks popped that marker, treated the closed buffer as a
complete stream, and skipped the variable-pool fallback (which only ran
when the buffer had no events at all). The response node therefore
rendered nothing for non-streamed variables, even though the workflow
run record contained the text. Reported from dify (langgenius/dify#46034).

Fall back to the variable pool when the buffer closed without emitting
any non-empty text. Streamed variables are unaffected: meaningful chunks
suppress the fallback.
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

All contributors on this pull request have signed the CLA.
Posted by the CLA Assistant Lite bot.

@Luckyou-d

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@WH-2099 WH-2099 self-assigned this Nov 12, 2026
@WH-2099

WH-2099 commented Nov 12, 2026

Copy link
Copy Markdown
Member

Thanks for looking into this!
#345 already fixes the reported Workflow-as-Tool issue.
This fallback can replay earlier text when the empty final marker arrives (Hello becomes HelloHello), so I'm closing this as superseded.
The remaining blocking/polling LLM issue needs a separate fix in the node's event handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Complete LLM results disappear from streamed answers

2 participants