You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Auto compaction happens much earlier than expected when caching is enabled #4416
As per this code the total tokens count = input + cache.read + output. As per OpenAI the input tokens is the total size of the prompt and cache.read is the tokens that had cache hit from input. With this logic we are double counting the cache.read tokens and when in long running sessions when the cache is bigger it ends up compaction even though we have a lot of room left.
Below is when I was logging the usage object from OpenAI responses. Opencode ended up compacting even though input tokens were less than 200K ( out of 400K size )
Activity
github-actions commentedon Nov 17, 2025
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if none of these address your specific case.
shantur commentedon Nov 18, 2025
Fixed with #4256