Skip to content

fix: Fix stale context usage after compaction + usage calculation#1548

Open
charlesvien wants to merge 2 commits into04-07-show_both_local_and_remote_repo_name_when_they_differfrom
04-07-token_usage_fix
Open

fix: Fix stale context usage after compaction + usage calculation#1548
charlesvien wants to merge 2 commits into04-07-show_both_local_and_remote_repo_name_when_they_differfrom
04-07-token_usage_fix

Conversation

@charlesvien
Copy link
Copy Markdown
Member

@charlesvien charlesvien commented Apr 8, 2026

Problem

  1. Context usage calculation omitted output_tokens, under-reporting total token occupancy.
  2. Context usage bar shows stale pre-compaction values until the next agent turn, making it look like context is still full after compaction.

Changes

  1. Include output_tokens in context usage calculation (they become input on the next turn)
  2. Emit a usage_update with used:0 immediately on compact_boundary
  3. Reset local usage counter on compaction so subsequent turns start fresh

How did you test this?

Manually

@charlesvien charlesvien marked this pull request as ready for review April 8, 2026 04:44
@charlesvien charlesvien changed the title fix: Include output_tokens in context usage calculation fix: Fix stale context usage after compaction + usage calculation Apr 8, 2026
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