mirror of
https://github.com/usestrix/strix.git
synced 2026-08-24 11:52:38 +02:00
fix(context): never floor summary input above the model's remaining room
The 1,000-token floor on summary-input room could exceed the space actually left after instructions, the reserved summary output, and any existing checkpoint. On a small window the summary request then overflowed and returned nothing, leaving the oversized session uncompacted. Clamp to the real room instead so the request always fits.
This commit is contained in:
@@ -202,6 +202,29 @@ async def test_maybe_compact_bounds_summary_prompt(monkeypatch: pytest.MonkeyPat
|
||||
assert len(captured["prompt"]) <= 4_000
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_summary_request_fits_when_room_is_below_old_floor(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
# When the window leaves less head-input room than the old fixed floor, the
|
||||
# budget must shrink to the real room so the request still fits the window
|
||||
# (a fixed floor above the room would overflow and silently fail).
|
||||
instructions = len(compaction._SUMMARY_INSTRUCTIONS)
|
||||
window = instructions + 64 + 256 + 300 # summary_max(64)+slack(256)+room(300)
|
||||
_patch_budget(monkeypatch, keep_tokens=30, window=window)
|
||||
captured: dict[str, str] = {}
|
||||
|
||||
async def fake_acompletion(**kwargs: Any) -> Any:
|
||||
captured["prompt"] = kwargs["messages"][0]["content"]
|
||||
return SimpleNamespace(choices=[SimpleNamespace(message=SimpleNamespace(content="S"))])
|
||||
|
||||
monkeypatch.setattr("strix.llm.compaction.litellm.acompletion", fake_acompletion)
|
||||
session = FakeSession([{"role": "user", "content": "y" * 5_000} for _ in range(20)])
|
||||
|
||||
assert await compaction.maybe_compact(session, model="m") is True
|
||||
assert len(captured["prompt"]) <= window
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_maybe_compact_skips_when_summary_fails(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
_patch_budget(monkeypatch, keep_tokens=30, window=50)
|
||||
|
||||
Reference in New Issue
Block a user