-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Fix(workflow): Prevent token overcount caused by loop/iteration #28406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @anobaka, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where token usage was being overcounted in workflow processes involving loop and iteration nodes. By refactoring the token accumulation logic, it ensures that token usage is accurately tracked through the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively resolves the token overcounting issue within loop and iteration nodes. The changes correctly eliminate the redundant token accumulation logic, ensuring that usage is calculated accurately through the LLMUsage object. The fix is well-targeted, consistent across both node types, and improves the reliability of workflow cost tracking. The changes are sound and I have no further suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a token overcounting bug in workflow loop and iteration nodes (issue #28405). The fix removes redundant direct manipulation of graph_runtime_state.total_tokens, relying instead on the proper usage tracking mechanism via _accumulate_usage() which updates llm_usage.
Key Changes:
- Removed
cost_tokensvariable and its accumulation in loop nodes - Removed
tokens_usedfrom parallel iteration return values - Removed direct
total_tokensupdates that caused double-counting
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| api/core/workflow/nodes/loop/loop_node.py | Removed redundant cost_tokens tracking and direct total_tokens manipulation; relies on _accumulate_usage() to properly track tokens via llm_usage |
| api/core/workflow/nodes/iteration/iteration_node.py | Removed tokens_used from parallel iteration return tuple and direct total_tokens updates; usage is now tracked consistently via _merge_usage() and the llm_usage field |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…odes
Important
Fixes #<issue number>.Summary
Total tokens overcount in workflow caused by loop/iteration nodes
fix: #28405
Screenshots
Checklist
dev/reformat(backend) andcd web && npx lint-staged(frontend) to appease the lint gods