Skip to content

Show Grok Build context occupancy on the usage meter - #216

Open
Yy-702 wants to merge 1 commit into
egoist:mainfrom
Yy-702:fix/grok-context-window
Open

Yy-702 wants to merge 1 commit into
egoist:mainfrom
Yy-702:fix/grok-context-window

Conversation

@Yy-702

@Yy-702 Yy-702 commented Sep 7, 2026

Copy link
Copy Markdown

Problem

On Grok Build sessions the usage meter under the composer always showed 0, even after a turn had clearly filled the context window. Plan-limit rows (SuperGrok weekly, etc.) were fine; only the context-window row was empty.

Grok never sends ACP usage_update. Live occupancy is _meta.totalTokens on every session/update (latest-wins snapshot of how full the window is right now). The window size is info.context_window in ~/.grok/models_cache.json. turn_completed.usage.totalTokens is the turn's billed sum across model calls, not occupancy — using it would over-report.

Verified against a live updates.jsonl / signals.json pair: _meta.totalTokens matched contextTokensUsed (e.g. 24095), while turn_completed.usage.totalTokens was the billing total (93005).

Solution

  • Map Grok _meta.totalTokens to UsageUpdated occupancy, deduped so identical snapshots do not wake extra frames.
  • Fill the gauge denominator from Grok's models_cache.json, and from _x.ai/session/update auto_compact_started when a compact starts.
  • Ignore turn_completed.usage.totalTokens so billed totals cannot clobber the meter.

Checks

  • cargo test -p waku-core --lib driver::acp::tests:: (21 passed, 3 ignored)
  • cargo test -p waku-core --lib grok_ (18 passed, including reads_context_window_from_groks_model_cache and the new occupancy tests)
  • Visual check in Waku Debug.app with a Grok Build session after a settled turn

Did not run the full CONTRIBUTING baseline (protocol:check, @waku/client tests). This change is the Grok ACP driver plus docs/providers.md.

Grok never sends ACP usage_update. Occupancy is _meta.totalTokens on
session/update; the window comes from models_cache.json. Do not treat
turn_completed.usage.totalTokens as occupancy — that is billed usage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant