Repository navigation
Description
Summary
Auto-compaction fires far too early and then re-fires on every turn until one summary succeeds, because the trigger estimate is roughly 2.4x the provider's own prompt_tokens and a failed compaction leaves no trace that it was tried.
Seen on an infer-action v0.58.0 run with CLI v0.233.0 and ollama_cloud/glm-5.3-flash (context window 1,000,000, compact-auto-at: 50): https://github.com/edenreich/das-ist-berlin/actions/runs/39459666409
Steps to Reproduce
- Run
infer agentwith a reasoning model that returnsreasoning_contenton every turn (glm-5.3-flash) andINFER_COMPACT_AUTO_AT=50on a 1M-window model. - Let it read a few large files and call ~100 tools, so the real prompt reaches about 200k tokens.
- Watch the
compaction_started/compaction_completeddebug events against thetoken_usage.prompt_tokensthe gateway reports.
Expected Behavior
current_tokensincompaction_startedis close to the provider's lastprompt_tokens, so a 50 percent threshold on a 1M window trips near 500k real tokens.- One compaction per crossing. If the summary call fails, the failure is logged as an event and the next turn does not immediately try again with the same context.
Actual Behavior
The gateway reported at most 265,907 prompt_tokens (median 177,887 over 114 requests), but the CLI's trigger estimate went 497k, 528k, 535k, 599k, 621k, 633k and fired six compaction_started events in six minutes before one compaction_completed (153 messages to 12):
{"auto_at_pct":50,"context_window":1000000,"current_tokens":497420,"force":true,"messages_before":139,"threshold":500000,"timestamp":"2026-10-20T17:04:57Z","type":"compaction_started"}
{"auto_at_pct":50,"context_window":1000000,"current_tokens":528097,"force":true,"messages_before":143,"threshold":500000,"timestamp":"2026-10-20T17:05:52Z","type":"compaction_started"}
{"auto_at_pct":50,"context_window":1000000,"current_tokens":535362,"force":true,"messages_before":146,"threshold":500000,"timestamp":"2026-10-20T17:07:37Z","type":"compaction_started"}
{"auto_at_pct":50,"context_window":1000000,"current_tokens":599009,"force":true,"messages_before":149,"threshold":500000,"timestamp":"2026-10-20T17:07:49Z","type":"compaction_started"}
{"auto_at_pct":50,"context_window":1000000,"current_tokens":621851,"force":true,"messages_before":151,"threshold":500000,"timestamp":"2026-10-20T17:08:50Z","type":"compaction_started"}
{"auto_at_pct":50,"context_window":1000000,"current_tokens":633329,"force":true,"messages_before":153,"threshold":500000,"timestamp":"2026-10-20T17:10:18Z","type":"compaction_started"}
{"messages_after":12,"messages_before":153,"timestamp":"2026-10-20T17:10:25Z","type":"compaction_completed"}
{"auto_at_pct":50,"context_window":1000000,"current_tokens":502734,"force":true,"messages_before":112,"timestamp":"2026-10-20T17:22:04Z","type":"compaction_started"}
The last one never completed either. Twelve minutes after the big compaction the agent was back over the (mis-estimated) threshold with 112 messages. Each attempt is a full summarisation request to the model, and after the one that succeeded the agent spent several turns re-orienting ("I've been context-compacted again. Let me re-establish state").
What the code does (internal/conversation):
- When
smartOptimizefails (summary request error, empty summary)OptimizeMessageslogs and returns the messages unchanged. Nothing is emitted, so the stream showscompaction_startedwith no end, and the next turn crosses the same threshold and tries again. Fixed in fix(compaction): emit a failure event and back off after a failed summary #1584. - The trigger estimate (
estimateTriggerTokens, the max of the gateway'sLastInputTokensandTokenizerService.EstimateMessagesTokens) reported 497k to 633k while the provider reported at most 266kprompt_tokenson the same turns. Why the two diverge this much is not established. To find out: log both numbers per turn on a reasoning-heavy run and compare which messages the estimate charges that the provider does not. - The events above say
force: true. Session rollover (session_rollover.go) gates on the same estimate and compacts with force, so it is the likely caller. To be confirmed from the logger output of a run.
Activity
inference-gateway-releaser commentedon Oct 20, 2026
🎉 This issue has been resolved in version 0.233.2 🎉
The release is available on:
Your semantic-release bot 📦🚀