Fix Claude context usage normalization for UI meter, Fixes #2034 #2551
Closedamitbet(GitHub profile, opens in a new tab)wants to merge 3 commits into
main fromrefs/pull/2551/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
- apps/server/src/provider/Layers/ClaudeAdapter.ts line 379OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -347,11 +363,17 @@347363 : undefined;348- const usedTokens =349- maxTokens !== undefined ? Math.min(totalProcessedTokens, maxTokens) : totalProcessedTokens;364+ const usedTokens = (() => {365+ if (directUsedTokens !== undefined && directUsedTokens > 0) {366+ return maxTokens !== undefined ? Math.min(directUsedTokens, maxTokens) : directUsedTokens;367+ }368+ return totalProcessedTokens ?? 0;369+ })();350370351371 return {352372 usedTokens,353373 lastUsedTokens: usedTokens,354- ...(totalProcessedTokens > usedTokens ? { totalProcessedTokens } : {}),374+ ...(totalProcessedTokens !== undefined && totalProcessedTokens > usedTokens375+ ? { totalProcessedTokens }376+ : {}),355377 ...(inputTokens > 0 ? { inputTokens } : {}),356378 ...(outputTokens > 0 ? { outputTokens } : {}),357- ...(maxTokens !== undefined ? { maxTokens } : {}),379+ ...(maxTokens !== undefined && directUsedTokens !== undefined ? { maxTokens } : {}),
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
amitbet(GitHub profile, opens in a new tab) changed the title
- @@ -348,10 +364,17 @@348- const usedTokens =349- maxTokens !== undefined ? Math.min(totalProcessedTokens, maxTokens) : totalProcessedTokens;364+ const hasDirectContextUsedTokens = directUsedTokens !== undefined && directUsedTokens > 0;365+ const usedTokens = (() => {366+ if (hasDirectContextUsedTokens) {367+ return maxTokens !== undefined ? Math.min(directUsedTokens, maxTokens) : directUsedTokens;368+ }369+ return totalProcessedTokens ?? 0;370+ })();350371351372 return {352373 usedTokens,353374 lastUsedTokens: usedTokens,354- ...(totalProcessedTokens > usedTokens ? { totalProcessedTokens } : {}),375+ ...(totalProcessedTokens !== undefined && totalProcessedTokens > usedTokens376+ ? { totalProcessedTokens }377+ : {}),355378 ...(inputTokens > 0 ? { inputTokens } : {}),356379 ...(outputTokens > 0 ? { outputTokens } : {}),357- ...(maxTokens !== undefined ? { maxTokens } : {}),380+ ...(maxTokens !== undefined && hasDirectContextUsedTokens ? { maxTokens } : {}),
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
72468eb2-5dc9-485c-8e56-2104ef3b8ab0You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip
💬 Introducing Slack Agent: The best way for teams to turn conversations into code.
Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack.
👉 Get started
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share