Skip to content

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

Merged
charlesvien merged 2 commits intomainfrom
04-07-token_usage_fix
Apr 9, 2026
Merged

fix: Fix stale context usage after compaction + usage calculation#1548
charlesvien merged 2 commits intomainfrom
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
@charlesvien charlesvien force-pushed the 04-07-token_usage_fix branch from 9e310fa to 4a5c188 Compare April 8, 2026 22:50
@charlesvien charlesvien force-pushed the 04-07-show_both_local_and_remote_repo_name_when_they_differ branch 2 times, most recently from 299b4d5 to ca54136 Compare April 8, 2026 22:55
@charlesvien charlesvien force-pushed the 04-07-token_usage_fix branch from 4a5c188 to f8e77ea Compare April 8, 2026 22:55
Copy link
Copy Markdown
Member Author

charlesvien commented Apr 8, 2026

Merge activity

  • Apr 8, 11:25 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Apr 9, 12:19 AM UTC: Graphite rebased this pull request as part of a merge.
  • Apr 9, 12:30 AM UTC: @charlesvien merged this pull request with Graphite.

@charlesvien charlesvien changed the base branch from 04-07-show_both_local_and_remote_repo_name_when_they_differ to graphite-base/1548 April 9, 2026 00:08
@charlesvien charlesvien changed the base branch from graphite-base/1548 to main April 9, 2026 00:18
@charlesvien charlesvien force-pushed the 04-07-token_usage_fix branch from f8e77ea to e24c214 Compare April 9, 2026 00:19
@charlesvien charlesvien merged commit 416ccef into main Apr 9, 2026
16 checks passed
@charlesvien charlesvien deleted the 04-07-token_usage_fix branch April 9, 2026 00:30
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.

2 participants