fix(teammate-progress): keep cumulative token+tool counts across prompts (#475)#1402
Open
0xghost42 wants to merge 1 commit into
Open
fix(teammate-progress): keep cumulative token+tool counts across prompts (#475)#14020xghost42 wants to merge 1 commit into
0xghost42 wants to merge 1 commit into
Conversation
…pts (Gitlawb#475) The in-process teammate runner re-created the progress tracker on every prompt iteration, so task.progress.tokenCount and toolUseCount were reset between leader prompts to the same teammate. TeammateSpinnerLine, InProcessTeammateDetailDialog and the Spinner aggregate all read these counters directly, which is why agent-team pills appeared to lose tokens and tool uses partway through a session. The Claude API returns input_tokens as cumulative-per-request (each turn re-sends forkContextMessages history), so latestInputTokens already captures the running context cost. The fix moves createProgressTracker out of the while-loop so cumulativeOutputTokens and toolUseCount also keep their running totals across multiple prompts. Adds src/tasks/LocalAgentTask/progressTracker.test.ts pinning: - output tokens accumulate across multiple assistant messages - cumulative semantic survives a simulated multi-prompt teammate session - fresh-tracker-per-prompt regression repro (prior outputs + tool uses lost) - tool use count accumulates - cache_creation/read input tokens fold into latestInputTokens - recentActivities stays capped while toolUseCount keeps climbing bun test (full): 2998/2998 pass. bun run build clean.
kevincodex1
approved these changes
May 28, 2026
jatmn
approved these changes
May 28, 2026
Collaborator
jatmn
left a comment
There was a problem hiding this comment.
Thanks for the contribution. I do not see any actionable issues from my review.
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.
Closes #475.
What broke
TeammateSpinnerLine,InProcessTeammateDetailDialog, and the leader's spinner aggregate (Spinner.tsx:191-200) all readteammate.progress?.tokenCountandteammate.progress?.toolUseCountstraight fromAppState. Those fields are populated bygetProgressUpdate(tracker)from inside the in-process teammate runner's per-message loop. The runner used to do this:A fresh tracker per prompt iteration meant that whenever the leader sent a second prompt to the same teammate (i.e. any multi-turn agent-team flow), the previous prompts'
cumulativeOutputTokensandtoolUseCountwere dropped on the floor and the pill jumped back to (or near) zero.The Claude API returns
input_tokensas cumulative-per-request —forkContextMessagesalready re-sends the full history each turn — solatestInputTokenswas always large and partially masked the bug. The visible symptom matched the report on #475: output tokens and tool-use counts repeatedly looked low / stale to leaders, even after long sessions.Fix
Hoist
createProgressTracker()(and the resolver) out of thewhileloop so a single tracker spans the whole teammate lifetime.cumulativeOutputTokensandtoolUseCountnow keep running totals across every prompt;latestInputTokenscontinues to track the latest request's cumulative-per-request input (which is what we want for "running context cost").recentActivitiesstays capped atMAX_RECENT_ACTIVITIES = 5so the preview doesn't bloat over long teammate sessions.Behavior on a single-prompt teammate is unchanged.
Tests
New
src/tasks/LocalAgentTask/progressTracker.test.tspins the contract the runner relies on. Six cases:tokenCount).cache_creation_input_tokens+cache_read_input_tokensfold intolatestInputTokens.recentActivitiesstays capped at 5 whiletoolUseCountkeeps climbing.bun test(full): 2998/2998 pass.bun run buildclean (no React/Ink leakage in SDK bundle; external lists valid).Repro for reviewer
/teamwith two agents).