mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-06 08:18:39 +00:00
fix: Prevent context token counter from resetting on failed API calls
- Only update context tokens when both input and output tokens are non-zero - Keep previous context token count when API calls fail - Avoid resetting counter on partial or failed responses This makes the context token counter more resilient against edge cases and provides more accurate context size tracking during API failures.
This commit is contained in:
parent
e668169ed9
commit
97fe13dcb1
1 changed files with 4 additions and 1 deletions
|
|
@ -65,7 +65,10 @@ export function getApiMetrics(messages: ClineMessage[]): ApiMetrics {
|
|||
|
||||
// If this is the last api request, use its tokens for context size
|
||||
if (message === lastApiReq) {
|
||||
result.contextTokens = (tokensIn || 0) + (tokensOut || 0)
|
||||
// Only update context tokens if both input and output tokens are non-zero
|
||||
if (tokensIn > 0 && tokensOut > 0) {
|
||||
result.contextTokens = tokensIn + tokensOut
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error parsing JSON:", error)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue