fix(grok): seed stream usage so Claude Code's bar is not zero - #154
Merged
Merged
Conversation
Claude Code copies message_delta.usage.input_tokens only when the field is present, and otherwise keeps the message_start value. Grok streams left that start value at 0 and omitted input_tokens from the terminal delta, so the status bar stayed at zero input tokens after every Grok turn.
The Grok stream seeds Claude Code's live input counter with a local request estimate in message_start, then publishes the provider's exact usage in the terminal message_delta. The reducer converted a missing, empty, partial, or non-numeric input_tokens field into 0, and the stream unconditionally wrote that 0 into the terminal usage object. Claude Code treats a present field as authoritative, so an absent provider value erased the estimate and left the status bar at zero, which is the outcome the seeding was meant to avoid. The monitor received the same synthesized 0 and recorded a session with no input tokens. Carry input-token presence through ReducerEvent::Finish as Option<u64>. The stream renderer now omits input_tokens from the terminal usage object when the provider did not report it, so clients keep the seeded estimate, and it passes None to the monitor instead of zero. A provider-reported zero remains Some(0) and is still published, because an explicit zero is real usage. The non-streaming accumulate path still emits zero for a missing field: its single response object always includes input_tokens, and it has no seeded estimate to protect. Regression coverage spans the reducer, the rendered SSE stream, and the monitor for absent, empty, output-only, non-numeric, exact, and explicit-zero input usage.
Merge local main e7eed88 into the grok usage fallback branch so the pull request can be pushed and merged without rewriting history or forcing. The original contributor commit 210c69b and the usage correction 0121054 remain ancestors; this adds only a merge commit on top and does not rebase either of them. The merged main carries the compaction effort cap and Codex transport test isolation changes, which are independent of the grok usage fix.
Owner
|
Thanks for fixing the Grok usage display! Merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Grok streams left
message_start.usage.input_tokensat 0 and omittedinput_tokensfrom the terminalmessage_delta. Claude Code copies that delta field only when it is present, so the status bar stayed at zero input tokens after every Grok turn.The stream now seeds
message_startfrom the local token estimate and writes the provider'sinput_tokenson the finish delta, matching the Codex path. Docs also record that Grok 4.5/4.6 are 500k tokens and that Claude Code needsCLAUDE_CODE_MAX_CONTEXT_TOKENS=500000for those IDs.