ENG-742: Count turns without tools-calls - #262
Merged
Merged
Conversation
StpMax
approved these changes
Jul 22, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Continue of mindsdb/cowork-server#203
Problem
_turn_countis seeded by countingrole == "user"messages in history(
session.py,commands/session.py,memory/history_store.py). Once a hostreplays tool activity into history,
tool_resultmessages — which are alsorole == "user"— get counted as turns. Every tool call inflates the count,and the drift compounds as the session is rebuilt each turn.
Impact: the "every 5 turns" identity extraction misfires, telemetry/episodic
turn IDs are wrong, and resume/list show inflated turn totals.
Fix
Add
is_user_turn(message)inhistory_store.py: auser-role message whosecontent is only
tool_resultblocks is a tool reply, not a turn. Replace allthree naive counts with it.
tool_resultcount unchanged.Fixes https://linear.app/mindsdb/issue/ENG-742/cowork-tool-calls-are-not-stored-in-conversation-history