fix: stop sending context compaction notifications
This commit is contained in:
1 parent
fbe9b4fd72
commit
0b402d0414
31 files changed
+157
-38
No files matched your search
@@ -1,11 +1,4 @@
|
||||
"""Context-compaction lifecycle notices are delivered regardless of ``send_progress``.
|
||||
|
||||
Compaction changes the context of every later turn, so both the start and
|
||||
the outcome of a compaction are information for the user, not progress
|
||||
chatter: a channel with ``send_progress`` off still receives them. Reducing
|
||||
the noise (one message updated in place) is the adapter's job; see the
|
||||
Discord channel (#5719).
|
||||
"""
|
||||
"""Channel transports decide whether to render compaction lifecycle events."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -40,6 +33,8 @@ class _MockChannel(BaseChannel):
|
||||
pass
|
||||
|
||||
async def send(self, msg):
|
||||
if isinstance(msg.event, ContextCompactionEvent) and not msg.event.notify:
|
||||
return
|
||||
return await self._send_mock(msg)
|
||||
|
||||
|
||||
@@ -71,12 +66,18 @@ def _sent_contents(manager: ChannelManager) -> list[str]:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_compaction_lifecycle_is_delivered_with_progress_off(manager: ChannelManager) -> None:
|
||||
async def test_channel_receives_automatic_compaction_but_does_not_render_it(
|
||||
manager: ChannelManager,
|
||||
) -> None:
|
||||
manager.channels["mock"].send_progress = False
|
||||
for event in (
|
||||
ProgressEvent(content="ordinary progress"),
|
||||
ContextCompactionEvent(compaction_id="c1", phase="started"),
|
||||
ContextCompactionEvent(compaction_id="c1", phase="succeeded"),
|
||||
ContextCompactionEvent(compaction_id="auto", phase="started"),
|
||||
ContextCompactionEvent(compaction_id="auto", phase="succeeded"),
|
||||
ContextCompactionEvent(compaction_id="auto-failed", phase="failed"),
|
||||
ContextCompactionEvent(compaction_id="auto-cancelled", phase="cancelled"),
|
||||
ContextCompactionEvent(compaction_id="c1", phase="started", notify=True),
|
||||
ContextCompactionEvent(compaction_id="c1", phase="succeeded", notify=True),
|
||||
):
|
||||
await manager.bus.publish_outbound(
|
||||
outbound_message_for_event(channel="mock", chat_id="chat", event=event)
|
||||
@@ -86,4 +87,4 @@ async def test_compaction_lifecycle_is_delivered_with_progress_off(manager: Chan
|
||||
|
||||
contents = _sent_contents(manager)
|
||||
assert "ordinary progress" not in contents
|
||||
assert len(contents) == 2
|
||||
assert contents == ["Compressing context…", "Context compacted."]
|
||||
@@ -50,7 +50,7 @@ async def test_compaction_notices_sent_when_enabled(monkeypatch) -> None:
|
||||
|
||||
await channel.send(outbound_message_for_event(
|
||||
channel="qq", chat_id="chat",
|
||||
event=ContextCompactionEvent(compaction_id="c1", phase="started"),
|
||||
event=ContextCompactionEvent(compaction_id="c1", phase="started", notify=True),
|
||||
))
|
||||
|
||||
send_text.assert_awaited_once()
|
||||
|
||||
Reference in new issue
Block a user