← Back to PRs

#15196: fix: clear stale token totals after compaction

by bufordtjustice2918 open 2026-02-13 04:42 View on GitHub →
stale size: XS
Fixes #15101. Clears stale session token totals when compaction does not provide a valid post-compaction estimate, preventing false memory flush triggers. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR updates `incrementCompactionCount` to clear cached token totals when compaction doesn’t provide a valid `tokensAfter` estimate, aiming to avoid false memory-flush triggers from stale counts. The key behavioral change is that `tokensAfter` being omitted now also triggers clearing `totalTokens`/`inputTokens`/`outputTokens`. In the current codebase there are call sites (notably the memory-flush compaction path) that call `incrementCompactionCount` without a post-compaction estimate, and downstream logic (`shouldRunMemoryFlush`) depends on `entry.totalTokens` being present. As written, this can clear totals in those flows and prevent future memory flushes from triggering until totals are repopulated elsewhere. <h3>Confidence Score: 2/5</h3> - This PR introduces a behavior change that can break memory-flush triggering when compaction counts are incremented without a post-compaction token estimate. - Although the intent is to prevent stale totals from causing false triggers, the implementation treats an omitted `tokensAfter` the same as an invalid estimate and clears cached totals. Verified call sites omit `tokensAfter`, and the memory flush decision path requires `totalTokens`, so this can cause real functional regressions and also appears to break an existing test expectation. - src/auto-reply/reply/session-updates.ts <sub>Last reviewed commit: ca944c5</sub> <!-- greptile_other_comments_section --> <sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub> <!-- /greptile_comment -->

Most Similar PRs