fix(workflow): guard on_tool_execution stdout traces behind DEBUG#38200
Merged
MRZHUH merged 1 commit intoJun 30, 2026
Merged
Conversation
DifyWorkflowCallbackHandler.on_tool_execution printed tool outputs to stdout on every tool-node execution, unlike every sibling callback in DifyAgentCallbackHandler which guards print_text with dify_config.DEBUG. Besides the unconditional stdout noise (a raw print(), not gated by LOG_LEVEL), it called tool_output.model_dump_json() to fully serialize each output just to print a 1000-char preview. Wrap the prints in the same DEBUG guard so the serialization is skipped when disabled.
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-06-30 07:06:00.034157800 +0000
+++ /tmp/pyrefly_pr.txt 2026-06-30 07:05:45.775067530 +0000
@@ -4238,13 +4238,13 @@
ERROR Argument `None` is not assignable to parameter `dataset_id` with type `str` in function `core.callback_handler.index_tool_callback_handler.DatasetIndexToolCallbackHandler.on_query` [bad-argument-type]
--> tests/unit_tests/core/callback_handler/test_index_tool_callback_handler.py:72:32
ERROR Argument `list[DummyToolInvokeMessage]` is not assignable to parameter `tool_outputs` with type `Iterable[ToolInvokeMessage]` in function `core.callback_handler.workflow_tool_callback_handler.DifyWorkflowCallbackHandler.on_tool_execution` [bad-argument-type]
- --> tests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.py:47:30
+ --> tests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.py:55:30
ERROR Argument `list[DummyToolInvokeMessage]` is not assignable to parameter `tool_outputs` with type `Iterable[ToolInvokeMessage]` in function `core.callback_handler.workflow_tool_callback_handler.DifyWorkflowCallbackHandler.on_tool_execution` [bad-argument-type]
- --> tests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.py:79:30
+ --> tests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.py:89:30
ERROR Argument `list[DummyToolInvokeMessage]` is not assignable to parameter `tool_outputs` with type `Iterable[ToolInvokeMessage]` in function `core.callback_handler.workflow_tool_callback_handler.DifyWorkflowCallbackHandler.on_tool_execution` [bad-argument-type]
- --> tests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.py:139:30
+ --> tests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.py:174:30
ERROR Argument `list[DummyToolInvokeMessage]` is not assignable to parameter `tool_outputs` with type `Iterable[ToolInvokeMessage]` in function `core.callback_handler.workflow_tool_callback_handler.DifyWorkflowCallbackHandler.on_tool_execution` [bad-argument-type]
- --> tests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.py:181:30
+ --> tests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.py:218:30
ERROR Class member `ConcreteDatasourcePlugin.datasource_provider_type` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
--> tests/unit_tests/core/datasource/__base/test_datasource_plugin.py:15:9
ERROR Class member `ConcreteDatasourcePluginProviderController.get_datasource` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
|
Contributor
Pyrefly Type Coverage
|
hjlarry
pushed a commit
to hjlarry/dify
that referenced
this pull request
Jul 1, 2026
…nggenius#38200) (cherry picked from commit 03d59db)
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
DifyWorkflowCallbackHandler.on_tool_executionwas the only callback in theDifyAgentCallbackHandlerfamily that wrote to stdout without theif dify_config.DEBUG:guard that every sibling method uses (on_tool_start,on_tool_end,on_tool_error,on_agent_start,on_agent_finish,on_datasource_start;ignore_agentreturnsnot dify_config.DEBUG). This wraps itsprint_text(...)calls in the same guard.Two improvements when
DEBUGis off (the default):print()that bypassesLOG_LEVEL, so they were emitted in every deployment.tool_output.model_dump_json()is no longer invoked just to build a 1000-char preview, removing avoidable full serialization of large tool outputs on a hot path.Functional behavior is unchanged — outputs are still
yielded; only the debug printing is gated.Local checks:
ruff checkis clean on the changed files andtests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.pypasses (10 passed), with a new case covering theDEBUG-off short-circuit.Fixes #38199
Screenshots
Checklist
make lint && make type-check(backend) andcd web && pnpm exec vp staged(frontend) to appease the lint gods — ranruff check(clean) and the affected unit tests (10 passed); fullmake type-checknot run locally