Skip to content

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

Merged
WH-2099 merged 1 commit into
langgenius:mainfrom
ZhXZhao:fix/non-stream-tool-variable-answer-public
Nov 12, 2026
Merged

WH-2099 merged 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
Contributor

Important

Reviewed the contribution guidelines and related issues and pull requests.

Related Issue

Fixes langgenius/dify#44141

Summary

A tool can return a non-streaming custom variable such as session_id that appears in the final workflow output but disappears from the streamed and saved Chatflow answer.
ToolNode emits an empty final stream marker for that variable, causing ResponseStreamFilter to finish the selector before reading its value from the variable pool.

Track custom variables that emitted stream chunks and send final markers only for those variables.
Static variables then use the existing variable-pool fallback.
Preserve standard text finalization, empty streamed values, original output types, and repeated-assignment behavior.

Regression tests exercise the real Start → session Tool → text Tool → Answer chain through Engine and ResponseStreamFilter, checking that the assembled reply matches the final graph output.
They also cover static and streamed session IDs, empty values, and typed repeated assignments.

Validation on the rebased branch:

  • 60 focused tool-node, tool-adapter, and response-filter tests passed.
  • Loading the original ToolNode from current main produces 9 expected failures in the 56-test tool/filter set: eight detect the spurious variable events, and one reproduces the missing session ID while final graph output stays correct.
  • Full suite: 1,262 passed on Python 3.12 with two workers.
  • just check passed: lockfile, formatting, lint, types, and architectural imports.

The engine tests use an in-memory tool runtime.
Live Dify/plugin-daemon execution and database persistence were not exercised; the Dify adapter and answer-persistence paths were inspected.

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

@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
Contributor Author

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

Only close custom variable streams that actually emitted chunks so static
values remain available to the response filter's variable-pool fallback.
@WH-2099
WH-2099 force-pushed the fix/non-stream-tool-variable-answer-public branch from b5625e0 to b10f463 Compare November 12, 2026 11:29

@WH-2099 WH-2099 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed b10f463. The regression tests, full local suite, and required CI checks passed.

@WH-2099
WH-2099 merged commit c2e4165 into langgenius:main Nov 12, 2026
6 checks passed
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

2 participants