Bug: google.ts input double-counts cached tokens (inconsistent with google-gemini-cli.ts) #1487
reverendrewind
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Bug
In
packages/ai/src/providers/google.ts, usage metadata mapspromptTokenCountdirectly toinput:Per Google's documentation,
promptTokenCountincludescachedContentTokenCountas a subset. So when a downstream consumer computesinput + cacheRead, cached tokens are counted twice.Real data from a cached request:
promptTokenCount = 21675,cachedContentTokenCount = 16289input = 21675, cacheRead = 16289input + cacheRead = 37964— nearly double the actualtotalTokenCountof21680This causes false context overflow detection in OpenClaw (openclaw/openclaw#15265).
Fix
The correct implementation already exists in
google-gemini-cli.ts(line 660):Apply the same subtraction to
google.ts. One-line change, I have a branch ready to go once approved.Beta Was this translation helpful? Give feedback.
All reactions