Skip to content

fix(compaction): make sliding-window eviction token-aware - #4099

Closed
Ricky-7-Yan wants to merge 1 commit into
letta-ai:mainfrom
Ricky-7-Yan:fix/sliding-window-token-budget
Closed

Ricky-7-Yan wants to merge 1 commit into
letta-ai:mainfrom
Ricky-7-Yan:fix/sliding-window-token-budget

Conversation

@Ricky-7-Yan

@Ricky-7-Yan Ricky-7-Yan commented Aug 28, 2026

Copy link
Copy Markdown

Summary

Fixes #3956.

planLocalSlidingWindowCompaction previously had no token budget when no persisted context-window limit existed, so it stopped at the first valid record-count cutoff. Tool-heavy tails could therefore retain most estimated tokens and trigger compaction again almost immediately.

The planner now falls back to a proportional budget from the transcript estimate, while automatic pressure-driven compaction passes the provider-resolved context window when available. Explicitly configured limits retain precedence. The implementation also preserves the current 1014-line source-size baseline.

This draft revives the voluntarily closed #3980 on current main; the earlier commits and investigation by @feiiiiii5 were reviewed and adapted, with the tightened file-size baseline handled here.

Test plan

  • bun test src/backend/local/compaction.test.ts: 6 passed, 0 failed.
  • bun run check: all 12 checks passed, including cycles, file-size, Biome, and TypeScript.

AI Disclosure

  • This pull request was written entirely by a human
  • This pull request was written with AI assistance and reviewed and edited by a human
  • I have read the AI Policy and agree to its terms

AI Tool(s) Used

OpenAI Codex was used to inspect the issue and prior closed work, adapt the implementation to current main, and run the focused and repository-wide validation.

Human Verification

Pending the submitting human's review. This draft must not be marked ready until the human has read the diff, checked the AI Policy box above, and can truthfully add the repository's required verification statement.

@Ricky-7-Yan
Ricky-7-Yan marked this pull request as ready for review August 31, 2026 15:34
@github-actions

Copy link
Copy Markdown
Contributor

This pull request was automatically closed because it does not meet our submission requirements.

What failed:

  • Missing exact Human Verification phrase

Please use the repository template and provide the required AI disclosure, AI tool list, policy acknowledgment, and exact Human Verification phrase.

@github-actions github-actions Bot added the invalid This doesn't seem right label Aug 31, 2026
@github-actions github-actions Bot closed this Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid This doesn't seem right

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool-heavy turns can rapidly refill context after sliding_window compaction

1 participant