Skip to content

Conversation

@ozan-s
Copy link

@ozan-s ozan-s commented Jan 25, 2026

Fixes #9416.

Repro

  1. Run /compact in the TUI.
  2. Immediately after the “Context compacted” message, the footer shows:
    0% context left · ? for shortcuts

Expected

After compaction frees space, the footer should show a non-zero context percentage remaining.

Root cause

After remote compaction, the history includes a compaction_summary (ResponseItem::Compaction) with encrypted_content that can be very large. Core recomputes token usage post-compaction via Session::recompute_token_usage, which calls ContextManager::estimate_token_count. The estimator was treating the full encrypted_content length as prompt-sized text, producing an estimated total >= context window; the UI then clamps to 0% remaining.

Fix

Cap the token estimate for ResponseItem::Compaction.encrypted_content to a small, context-window-relative bound (10% of the effective window, capped at 25k tokens). This keeps post-compaction estimates realistic (and avoids transient 0%), without special-casing the UI.

Tests

Add a regression unit test that constructs a compacted history with a huge encrypted_content blob and asserts the estimated total stays below the configured context window.

@etraut-openai
Copy link
Collaborator

@codex review

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. Nice work!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

Context percentage shows zero after compaction

2 participants