fix: correct context token calculation to only include input tokens #6669
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 context token calculation in
getApiMetrics.tsthat was causing premature context condensing.Problem
The
contextTokenscalculation was incorrectly summing all token types:tokensIn(input tokens)tokensOut(output tokens)cacheWrites(cache write tokens)cacheReads(cache read tokens)This inflated context size was causing the context to be condensed prematurely, even when the actual input context was well within limits.
Solution
Changed the calculation to only count
tokensIn, which represents the actual context size being sent to the API. Output tokens and cache tokens are not part of the context that determines whether condensing should happen.Changes
contextTokenscalculation insrc/shared/getApiMetrics.tsto only count input tokensTesting
src/shared/__tests__/getApiMetrics.spec.tssrc/shared/src/core/sliding-window/Fixes #6668
Important
Fixes
contextTokenscalculation ingetApiMetrics.tsto only include input tokens, preventing premature context condensing.contextTokenscalculation ingetApiMetrics.tsto only includetokensIn.tokensOut,cacheWrites, andcacheReadsfrom context size.getApiMetrics.spec.tsto validate new behavior.src/shared/andsrc/core/sliding-window/pass with updated logic.This description was created by
for c66b76e. You can customize this summary. It will automatically update as commits are pushed.