fix: calculate contextTokens as cumulative sum of all conversation tokens #6007
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
This PR fixes the incorrect token counting in the context window display that was causing users to see unrealistic values like 0 or under 100 tokens.
Problem
The
contextTokenscalculation ingetApiMetricswas only looking at the last API request's tokens instead of calculating the actual cumulative context window usage. This led to:Solution
Changed the
contextTokenscalculation to:condense_contextmessages by resetting to the new context sizeChanges
src/shared/getApiMetrics.tsto calculate cumulative context tokenssrc/shared/__tests__/getApiMetrics.spec.tsto verify correct behaviorTesting
Fixes #6004
Important
Fixes
contextTokenscalculation ingetApiMetricsto sum all conversation tokens and handlecondense_contextmessages correctly.contextTokenscalculation ingetApiMetricsto sum tokens from all API requests.contextTokensaftercondense_contextmessages and continues accumulation.getApiMetrics.tsto track cumulative context tokens and handlecondense_contextmessages.getApiMetrics.spec.tsto verify cumulative token calculation andcondense_contexthandling.condense_contextmessage handling.This description was created by
for efcd3e0. You can customize this summary. It will automatically update as commits are pushed.