test(learn): pin the digest budget with many tiny sessions

Each kept session closes with a blank line whose newline the budget
counts (chars_used += 1 since df75e3fa). No test covered that count: the
long-session case keeps 5 sessions, which the 100-char marker reserve
absorbs. This case keeps hundreds to thousands of one-call sessions at 80k
and 10k, as tool calls and as events. With that count removed it fails
(324,858 chars against 320,000, 40,590 against 40,000).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Garm
2026-10-19 23:38:17 +02:00
co-authored by Claude Opus 5.5
parent df75e3faf4
commit c95f5fe853
+26
View File
@@ -239,6 +239,32 @@ class TestDigestSurfacesLoops:
assert len(digest) <= max_tokens * 4
assert "remaining" in digest and "sessions truncated" in digest
@pytest.mark.parametrize("with_events", [False, True], ids=["tool-calls", "events"])
@pytest.mark.parametrize("max_tokens", [80_000, 10_000])
def test_many_tiny_sessions_stay_inside_the_budget(self, max_tokens, with_events):
# Thousands of kept sessions, each closed by a blank line whose newline
# counts too; the marker reserve alone would absorb only ~100 of them.
sessions = []
for s in range(20_000):
call = ToolCall(
name="Bash",
tool_call_id=str(s),
input_data={"command": "ls"},
output="ok",
is_error=False,
msg_index=0,
)
events = [SessionEvent(type="tool_call", msg_index=0, tool_call=call)]
sessions.append(
SessionData(
session_id=f"s{s}", tool_calls=[call], events=events if with_events else []
)
)
digest = _build_digest(_project(), sessions, loops=[], max_tokens=max_tokens)
assert len(digest) <= max_tokens * 4
assert digest.count("=== Session ") > 500
assert "sessions truncated" in digest
# =============================================================================
# apply_loop_weighting