Skip to content

fix: report context occupancy state and track guessed budgets (#69) - #110

Merged
bbondy merged 5 commits into
brave:mainfrom
winshaurya:fix/context-hint-lifecycle
Sep 8, 2026
Merged

bbondy merged 5 commits into
brave:mainfrom
winshaurya:fix/context-hint-lifecycle

Conversation

@winshaurya

@winshaurya winshaurya commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Closes #69, where the context percentage disappears or leaves ambiguous states on the hint line.

Changes Made

  1. Added budget_is_guessed() and advertised window tracking in crates/config.
  2. Introduced an Occupancy enum (Unmeasured, Compacted, Measured) in crates/tui::state to distinguish empty sessions, post-compaction state, and active measurements.
  3. Updated the TUI hint line in crates/tui::render to display context compacted, context ~N% for guessed budgets, or context N% for verified budgets, while keeping unmeasured sessions clean to preserve the shortcuts hint on 80-column terminals.
  4. Restored context measurement on session resume when conversation history has tokens on disk.
  5. Measured context on the turn failure path when requests were dispatched prior to error.
  6. Added saturating arithmetic for fullness calculations and comprehensive unit tests

Please let me know if anything further is needed or if you would like any adjustments. Thank you for your time and review!

The one part of #69 not answered here is the empty case: a session that has measured nothing still draws as a blank. That is #113.

@winshaurya
winshaurya force-pushed the fix/context-hint-lifecycle branch from ca1e6e9 to 719eeb7 Compare September 6, 2026 21:30
@winshaurya

Copy link
Copy Markdown
Contributor Author

Squashed the commits for easier review.

@winshaurya
winshaurya force-pushed the fix/context-hint-lifecycle branch 2 times, most recently from 42e2c6b to 48f4862 Compare September 7, 2026 02:05
winshaurya and others added 5 commits September 7, 2026 22:01
- Distinguish unmeasured, compacted, and active context states via Occupancy enum.

- Keep unmeasured context empty to preserve shortcut hint line on 80-column terminals.

- Display context compacted and context ~N% for guessed budgets on the hint line.

- Restore context measurement on session resume when conversation history has tokens on disk.

- Measure context on turn failure when requests were sent prior to error.

- Update context occupancy budget immediately when model window is adopted.

- Use saturating arithmetic for context fullness calculation.
Nine arguments is one past what clippy allows, so `-D warnings` fails the build, and the
three added here belong together anyway: a token count without the budget it is against is
not a percentage, and a budget without knowing whether anyone advertised it is not one the
hint line may state flatly.
…ands

Marking a budget as advertised is a question about where the figure came from, not a reason
to move it. Reverting to the default whenever the next model reports nothing raises the
budget above a cramped window that is still in force, and a budget above the window does
not delay compaction, it removes it: every round asks, no round qualifies, and the session
runs to exhaustion looking exactly like one with nothing to summarise.

What stands is a figure taken for a model no longer in force, which is exactly what
`budget_is_guessed` reports, so the hint line marks it rather than stating it flatly.
Adopting a window answers two questions and only one of them is whether the number changed.
A model the listing does not describe leaves the budget standing and stops it being one the
endpoint advertised, and a model advertising exactly the budget already in force does the
reverse, so a marker carried only when the figure moved is wrong in both directions.
The reading is what a person uses to decide whether to compact, and nothing said which of
the three things it knows it is saying, so a blank line meant an empty session, a shortened
one, or a turn that had not ended yet.

The resume half needed a test of its own: what the last request came to is the server's
figure and cannot be recomputed here, so a snapshot that dropped it would leave a resumed
session no way back to the number but to spend a turn.

@bbondy bbondy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@bbondy
bbondy merged commit 83dd128 into brave:main Sep 8, 2026
3 checks passed
@winshaurya
winshaurya deleted the fix/context-hint-lifecycle branch October 10, 2026 20:12
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.

the context figure comes and goes, and the hint line gives a person no way to tell why

2 participants