You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] chunk_with_boundary returns more than budget chunks whenever overlap_ratio > 0 #2111
chunk_with_boundary() documents a hard upper bound — Cut ``text`` into ≤ ``budget`` chunks aligned to natural boundaries (deeptutor/services/memory/consolidator/chunker.py:52, also repeated in the module docstring at line 4, in modes/update.py:7 and modes/audit.py:7) — but it sizes the window as ceil(len(text) / budget) while advancing the cursor by target - overlap. The overlap is lost at every cut, so budget chunks only reach target + (budget - 1) * (target - overlap) characters and the function needs about budget / (1 - overlap_ratio) chunks to cover the text.
This is on the default configuration: services/memory/settings.py:23 uses l2_budget = 20 and :50 uses overlap_ratio = 0.10, i.e. 21 chunks for a 20-chunk budget (see update.py:207 / audit.py:159, which emit {"stage": "chunked", "chunks": 21, "budget": 20}).
The existing tests/services/memory/test_chunker.py::test_budget_caps_chunk_count asserts len(chunks) <= 5, but only passes because that particular text's paragraph-boundary expansion happens to add enough characters; the same assertion fails on other equally valid inputs.
Expected behavior
len(chunk_with_boundary(...)) <= budget for every overlap_ratio that keeps the stride positive, with the last chunk still covering the end of the text. Because each chunk is one LLM call (modes/update.py:254 and :485), an extra chunk is an extra paid call.
Fixed on dev by commit e1c05b852 (“size chunk windows by the stride that overlap leaves”, integrated via #2126). The chunker now sizes the target from span = budget - (budget - 1) * overlap_ratio, so chunk_with_boundary stays within budget when overlap_ratio > 0. #2148 was the competing PR and is now superseded. This can be closed.
Activity
Antonio-Faure commentedon Oct 31, 2026
Fixed on
devby commite1c05b852(“size chunk windows by the stride that overlap leaves”, integrated via #2126). The chunker now sizes the target fromspan = budget - (budget - 1) * overlap_ratio, sochunk_with_boundarystays withinbudgetwhenoverlap_ratio > 0. #2148 was the competing PR and is now superseded. This can be closed.Eapp1e commentedon Nov 1, 2026
Fixed in #2112, which is merged. Closing.