Skip to content

Commit 4fedab2

Browse files
committed
fix(agent): clear last_prompt_tokens after emergency compaction
Addresses review feedback: when emergency compaction succeeds in the ContextOverflow recovery path, the context shrinks but last_prompt_tokens still held the pre-compaction value. If the retried call then returned no usage stats (mock/local provider, transient gap), the end-of-turn check would read that stale huge value through effective_context_tokens and fire a redundant compaction immediately after this one. Reset it to None on successful emergency compaction so the check falls back to the fresh post-compaction estimate.
1 parent 28c9603 commit 4fedab2

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/agent/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,12 @@ impl AgentLogic {
25232523
)
25242524
.with_chat_id(&inbound.chat_id),
25252525
));
2526+
// The context just shrank, so the pre-compaction `prompt_tokens` is
2527+
// now stale. Clear it; otherwise, if the retried call returns no
2528+
// usage stats (mock/local provider, transient gap), the end-of-turn
2529+
// check would read the old huge value via `effective_context_tokens`
2530+
// and immediately fire a redundant compaction right after this one.
2531+
last_prompt_tokens = None;
25262532
// Next iteration refetches context (now smaller due
25272533
// to AddSummary + UpdateThreadMetadata) and re-runs
25282534
// the chat call. No iteration counter refund — the

0 commit comments

Comments
 (0)