Skip to content

fix(prefill): cap reservation at sliding window - #198

Merged
FluffyAIcode merged 1 commit into
mainfrom
AgentMemory/window-aware-snapshot-estimate-0718
Jul 18, 2026
Merged

fix(prefill): cap reservation at sliding window#198
FluffyAIcode merged 1 commit into
mainfrom
AgentMemory/window-aware-snapshot-estimate-0718

Conversation

@FluffyAIcode

Copy link
Copy Markdown
Owner

Summary

  • estimate retained snapshot bytes with min(prompt_tokens, sink + window)
  • apply the same estimate to upfront capacity validation and active reservation
  • preserve complete prompt processing and full-context Critic semantics
  • prevent long auto-loop histories from falsely exceeding cache capacity after sliding-window saturation

Root cause

The failed 2,731-token turn was estimated as 1,092,400,000 bytes, 18.66 MB over the 1 GiB cache. MLX retains only sink 4 + window 2,048 = 2,052 KV tokens, so the correct conservative estimate is 820,800,000 bytes and fits safely.

Tests

  • exact 2,731-token production regression
  • below-window and no-window estimate behavior
  • upfront validation and reservation paths
  • targeted suite — 32 passed
  • full platform-neutral suite — 881 passed, 1 skipped
  • Python compile and diff checks pass

Made with Cursor

Estimate final snapshot capacity from retained sink and window KV instead of unbounded prompt history so long auto-loop contexts remain admissible.

Co-authored-by: Cursor <cursoragent@cursor.com>
@cursor

cursor Bot commented Jul 18, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@FluffyAIcode
FluffyAIcode merged commit abc8d96 into main Jul 18, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant