feat: make context compaction visible in channels (#5656)
* feat: surface context compaction lifecycle * fix: complete and simplify context compaction notifications
This commit is contained in:
1 parent
455533169d
commit
5229989f28
52 files changed
+1849
-140
No files matched your search
@@ -6,6 +6,7 @@ from unittest.mock import AsyncMock, MagicMock
|
||||
import pytest
|
||||
|
||||
from nanobot.agent.autocompact import AutoCompact
|
||||
from nanobot.bus.outbound_events import ContextCompactionEvent
|
||||
from nanobot.session.manager import Session, SessionManager
|
||||
|
||||
|
||||
@@ -268,6 +269,7 @@ class TestCheckExpired:
|
||||
"cli:old",
|
||||
runtime=admitted,
|
||||
max_suffix=ac._RECENT_SUFFIX_MESSAGES,
|
||||
on_compaction=None,
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize("resolution_error", [KeyError, ValueError])
|
||||
@@ -443,8 +445,39 @@ class TestArchiveDelegates:
|
||||
"cli:test",
|
||||
runtime=runtime,
|
||||
max_suffix=ac._RECENT_SUFFIX_MESSAGES,
|
||||
on_compaction=None,
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_forwards_timeout_compaction_events_with_session_key(self):
|
||||
sessions = MagicMock(spec=SessionManager)
|
||||
consolidator = MagicMock()
|
||||
observed: list[tuple[str, ContextCompactionEvent]] = []
|
||||
|
||||
def bind(key: str):
|
||||
async def publish(event: ContextCompactionEvent) -> None:
|
||||
observed.append((key, event))
|
||||
return publish
|
||||
|
||||
async def compact(key: str, **kwargs):
|
||||
event = ContextCompactionEvent(compaction_id="compact-1", phase="started")
|
||||
await kwargs["on_compaction"](event)
|
||||
return "Summary."
|
||||
|
||||
consolidator.compact_idle_session = AsyncMock(side_effect=compact)
|
||||
ac = AutoCompact(
|
||||
sessions=sessions,
|
||||
consolidator=consolidator,
|
||||
session_ttl_minutes=15,
|
||||
bind_compaction=bind,
|
||||
)
|
||||
|
||||
await ac._archive("cli:test", runtime=_runtime())
|
||||
|
||||
assert len(observed) == 1
|
||||
assert observed[0][0] == "cli:test"
|
||||
assert observed[0][1].phase == "started"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_dream_session_is_ignored(self):
|
||||
ac = _make_autocompact()
|
||||
|
||||
Reference in new issue
Block a user