fix(grok): surface context window usage in the composer #5405
Closedahmed-besic(GitHub profile, opens in a new tab)wants to merge 5 commits into
main fromrefs/pull/5405/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/provider/acp/GrokAcpSupport.ts lines 192 to 199OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -108,0 +179,21 @@179+ maxTokens: number | undefined,180+): ThreadTokenUsageSnapshot | undefined {181+ if (!isRecord(meta)) {182+ return undefined;183+ }184+185+ const usageRecord = isRecord(meta.usage) ? meta.usage : undefined;186+ const usedTokens =187+ finitePositiveInt(meta.totalTokens) ?? finitePositiveInt(usageRecord?.totalTokens);188+ if (usedTokens === undefined) {189+ return undefined;190+ }191+192+ const inputTokens =193+ finitePositiveInt(meta.inputTokens) ?? finitePositiveInt(usageRecord?.inputTokens);194+ const outputTokens =195+ finitePositiveInt(meta.outputTokens) ?? finitePositiveInt(usageRecord?.outputTokens);196+ const cachedInputTokens =197+ finitePositiveInt(meta.cachedReadTokens) ?? finitePositiveInt(usageRecord?.cachedReadTokens);198+ const reasoningOutputTokens =199+ finitePositiveInt(meta.reasoningTokens) ?? finitePositiveInt(usageRecord?.reasoningTokens);
- apps/server/src/provider/acp/GrokAcpSupport.ts lines 183 to 183OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -108,0 +163,21 @@163+ if (direct !== undefined) {164+ return direct;165+ }166+ }167+ // Prefer the sole known window when the active model id does not match.168+ if (windows.size === 1) {169+ return windows.values().next().value;170+ }171+ return undefined;172+}173+174+/** Best-effort window for a new session: bound model, then setup current, then sole entry. */175+export function resolveInitialGrokContextWindow(input: {176+ readonly windows: ReadonlyMap<string, number>;177+ readonly boundModelId: string | undefined;178+ readonly setupModelId: string | undefined;179+}): number | undefined {180+ return (181+ contextWindowForModelId(input.windows, input.boundModelId) ??182+ contextWindowForModelId(input.windows, input.setupModelId) ??183+ (input.windows.size > 0 ? input.windows.values().next().value : undefined)
t3dotgg(GitHub profile, opens in a new tab) 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 Plus
Run ID:
943c338f-0f2a-40ce-9163-8bef728f6237You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
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