CountTokensRequest.contents[2].parts[0].data: required oneof field 'data' must have one initialized field\n","status":"INVALID_ARGUMENT"
What happened?
See the screenshot:
Note that this happened after I cancelled an ongoing operation above, so this might have to do something with what happens when user cancels the request in between, and not really a compress command.
What did you expect to happen?
No Error
Client information
- CLI Version: 0.1.17
- Git Commit: 99ba2f64 (local modifications)
- Operating System: darwin v24.3.0
- Sandbox Environment: no sandbox
- Model Version: gemini-2.5-pro
- Memory Usage: 352.4 MB
Login information
No response
Anything else we need to know?
No response
After scrutinizing the countTokens 400 Bad Request error, I've narrowed down the root cause. The problem originates in src/core/client.js with this line:
const { text: summary } = await this.getChat().sendMessage(/* ... */);
The failure unfolds through several interlocked steps:
-
Malformed Request: An inspection with Proxyman confirms the
/countTokensAPI request is malformed. The payload contains an empty object in thepartsarray forcontents[2]:{ "role": "user", "parts": [{}] }Manually correcting this part to include a
textfield results in a successful API response. -
Immediate Cause: The empty part object is created because the
summaryvariable becomesundefined. This is due to the destructuring assignmentconst { text: summary } = ...failing to find atextproperty on the object returned bysendMessage. -
Root Cause: The fundamental issue lies in the response from the preceding
generateContentAPI call. The prompt'First, reason in your scratchpad. Then, generate the <state_snapshot>.'is only yielding a singlethoughtpart, not a standard text part. The response is structured as follows:"content": { "parts": [ { "text": "...", "thought": true } ], "role": "model" }This triggers a failure where the model doesn't correctly follow the second part of the instruction (
'Then, generate the <state_snapshot>').
Conclusion:
The /compress command in the Gemini CLI is failing to generate the expected summary text. This leads to the undefined variable, the malformed request, and triggers the final INVALID_ARGUMENT error.
After scrutinizing the
countTokens400 Bad Request error, I've narrowed down the root cause. The problem originates insrc/core/client.jswith this line:const { text: summary } = await this.getChat().sendMessage(/* ... */);
The failure unfolds through several interlocked steps:
1. **Malformed Request:** An inspection with Proxyman confirms the `/countTokens` API request is malformed. The payload contains an empty object in the `parts` array for `contents[2]`: { "role": "user", "parts": [{}] } Manually correcting this part to include a `text` field results in a successful API response. 2. **Immediate Cause:** The empty part object is created because the `summary` variable becomes `undefined`. This is due to the destructuring assignment `const { text: summary } = ...` failing to find a `text` property on the object returned by `sendMessage`. 3. **Root Cause:** The fundamental issue lies in the response from the preceding `generateContent` API call. The prompt `'First, reason in your scratchpad. Then, generate the <state_snapshot>.'` is only yielding a single `thought` part, not a standard text part. The response is structured as follows: "content": { "parts": [ { "text": "...", "thought": true } ], "role": "model" } This triggers a failure where the model doesn't correctly follow the second part of the instruction (`'Then, generate the <state_snapshot>'`).Conclusion:
The /compress command in the Gemini CLI is failing to generate the expected summary text. This leads to the
undefinedvariable, the malformed request, and triggers the finalINVALID_ARGUMENTerror.
Thanks a ton for the input, it's a life-saver. I edited ~/.gemini/tmp/<64-char-string>/checkpoint-<name-of-checkpoint>.json to remove the erroneous entry per your suggestion and it works now.
Hopefully future releases will have better internal handling for such issues that won't require this type of manual workaround.