Skip to content

fix(tui): derive context gauge fill from cumulative report deltas - #25

Merged
jkyberneees merged 1 commit into
mainfrom
fix/ctx-gauge-cumulative-delta
Aug 9, 2026
Merged

fix(tui): derive context gauge fill from cumulative report deltas#25
jkyberneees merged 1 commit into
mainfrom
fix/ctx-gauge-cumulative-delta

Conversation

@jkyberneees

Copy link
Copy Markdown
Contributor

Problem

The header context-window gauge overflowed on any long multi-iteration session, e.g.:

● 100% 2.3M/1.0M · ∑ ⌂ 2.3M

while the backend context window was actually within budget.

Root cause

odek serve reports contextTokens — on both usage and done events — cumulative per run: the sum of prompt tokens across all LLM calls (agent.TotalInputTokens()). bodek treated it as the live window fill, so the gauge pinned at 100% once the cumulative total exceeded the model's context window. The ∑ ⌂ session total was correct all along.

Fix

Recover the live window fill client-side as the delta between consecutive cumulative reports — exactly the last request's prompt size, which drops again after odek trims history:

  • new runCtxCum baseline on the model, updated on usage, consumed and reset on done (each run's cumulative restarts), and reset on session resume/clear
  • winCtxTok is now only ever the per-request prompt size, never a cumulative figure
  • comment corrections in internal/client and internal/tui/view.go documenting the real wire semantics

Tests

  • New regression test TestGaugeDerivesFillFromCumulativeDeltas replaying the reported scenario (cumulative 600k → 1.4M → 2.3M against a 1.0M window): gauge shows 90%, and drops after a trim
  • make fmt / vet / lint (0 issues) / test (full race suite) all green

Known limitation: mid-run the fill lags by one request's output tokens (the delta is prompt tokens only); it self-corrects on the next usage event. Exact per-request fill on the wire would require an odek-side change.

odek serve reports contextTokens (usage and done events) cumulative per
run — the sum of prompt tokens across all LLM calls — not the live
window fill. Treating it as the fill made the header gauge overflow on
any long multi-iteration session (e.g. 100% 2.3M/1.0M) while the
backend context window was actually within budget.
Track the last cumulative report per run and use the delta between
consecutive reports as the window fill: that delta is exactly the last
request's prompt size, which drops again after odek trims history. The
baseline resets on done (each run's cumulative restarts) and on session
resume/clear.
@jkyberneees
jkyberneees merged commit 2237f13 into mainAug 9, 2026
5 checks passed
@jkyberneees
jkyberneees deleted the fix/ctx-gauge-cumulative-delta branch August 9, 2026 12:13
Sign up for freeto 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

@jkyberneees