GitHub Repo
Dify Community Reports Audio Tool Usage Misclassification After Deferred Generator Execution Loses Source Context
A Dify community report on October 29 says built-in speech recognition and speech synthesis tools may record model usage as UNKNOWN instead of audio. The issue involves Python generators and the lifecycle of usage tracking; it remained open at the time of review, and the actual billing impact has yet to be confirmed.

On October 29, the Dify community reported a usage-tracking defect: the built-in automatic speech recognition (ASR) and text-to-speech (TTS) tools use generator functions, but the decorator responsible for marking the usage source may leave scope before the tools actually run. The report concerns commit e5acabc3d on that day’s main branch and was labeled “1.18.0 Bugs” the following day. The issue remained open at the time of review. Issue and reproduction details
The key is that “obtaining a generator” and “executing a generator” happen at different times. The official Python documentation explains that calling a generator function only returns an iterator; the function body does not run until an operation such as next() is performed. Therefore, if a decorator calls the function inside a with block and immediately returns, the block exits first, and subsequent iteration cannot access the context that was set earlier. Python generator semantics
According to the ASR test output provided by the reporter, the usage metadata retrieved by the model manager was None. Only after keeping the context active during iteration did the source show as audio. The report says this difference in the snapshot causes the usage source to be recorded as UNKNOWN. The public evidence currently consists mainly of the author’s code analysis and test output; an independent reproduction is still lacking, and incorrect billing amounts have not been demonstrated. Report details
For operators, the concern is the traceability of audio costs. If source classification is inaccurate, usage analytics broken down by feature may understate the share attributable to audio. This risk is inferred from the reported mechanism; its actual scope still needs to be checked against deployed versions and usage records. From an engineering perspective, validation must consume the iterator to completion: merely creating a generator object will not reach the model call.
The author recommends extending the decorator over the iteration process or moving the context into the execution bodies of the two tools. A follow-up fix should check that the context is restored correctly on normal completion, exceptions, and early closure. Python’s generator-closing mechanism can execute pending finally blocks, so cleanup paths also need validation. Suggested fix, Python closing behavior