Skip to content

fix(tool): preserve non-streamed variables in response answers - #345

Open
ZhXZhao wants to merge 1 commit into
langgenius:mainfrom
ZhXZhao:fix/non-stream-tool-variable-answer-public
Open

ZhXZhao wants to merge 1 commit into
langgenius:mainfrom
ZhXZhao:fix/non-stream-tool-variable-answer-public

Conversation

@ZhXZhao

@ZhXZhao ZhXZhao commented Oct 15, 2026 •

Copy link
Copy Markdown

Important

The contribution guidelines and existing open/closed issues and PRs were reviewed. This fixes the upstream cause of the Dify report below rather than adding a host-side workaround.

Related Issue

Fixes langgenius/dify#44141

Summary

Non-streaming custom tool variables are stored in node outputs but were also given empty stream-finalization events. ResponseStreamFilter treated those selectors as closed and skipped its variable-pool fallback, so an Answer node could have correct final graph output while its streamed/persisted reply omitted the variable value.

Track which custom variables actually emitted stream chunks, and emit final markers only for those variables. Keep standard text stream finalization and existing variable assignment/output types unchanged, including repeated assignments and empty streamed values.

Add regression tests covering:

  • real Start -> session Tool -> text Tool -> Answer execution through Engine and ResponseStreamFilter;
  • equality between the filtered answer and final graph output for static/streamed and empty/non-empty session IDs;
  • non-streaming output types and repeated-assignment semantics.

Validation

  • 50 tool-node and response-stream-filter tests passed.
  • The new tests fail against the original ToolNode loaded in memory: 9 expected failures, including correct final graph output but a truncated filtered reply.
  • Full suite: 994 passed on Python 3.12.10 with two workers. An initial EPUB-test NLP-model download failure was resolved by installing the pinned, SHA-256-verified en_core_web_sm model; the complete suite then passed.
  • Full Ruff formatting/lint, ty type checking, lockfile validation, and architectural import checks passed.
  • Independent test, knowledge, and final naming reviews completed; no documentation drift was found.
  • Also verified the focused backport against graphon 0.7.0 with a real in-memory engine. No deployed source, workflow data, or credentials were modified.

Dify PR langgenius/dify#43986 applies the same empty-stream guard to Agent V2, but does not change ToolNode. This PR fixes the corresponding tool-node case described in langgenius/dify#44141.

Checklist

  • This pull request links the issue it resolves or advances
  • This pull request title follows Conventional Commits, and any breaking change is marked with !
  • If CLA Assistant prompted me, I signed CLA.md in the pull request conversation

CLA: not prompted at submission time; no signature is claimed.

Only close custom variable streams that actually emitted chunks so static
values remain available to the response filter's variable-pool fallback.
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

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

@ZhXZhao

ZhXZhao commented Oct 15, 2026

Copy link
Copy Markdown
Author

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

This branch has not been deployed

No deployments
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.

Non-streaming tool variables disappear from streamed and saved Chatflow answers

1 participant