mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user