mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 04:11:10 -05: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:
@@ -65,7 +65,10 @@ export function getApiMetrics(messages: ClineMessage[]): ApiMetrics {
|
|||||||
|
|
||||||
// If this is the last api request, use its tokens for context size
|
// If this is the last api request, use its tokens for context size
|
||||||
if (message === lastApiReq) {
|
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) {
|
} catch (error) {
|
||||||
console.error("Error parsing JSON:", error)
|
console.error("Error parsing JSON:", error)
|
||||||
|
|||||||
Reference in New Issue
Block a user