Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(channels): drop compaction notices on channels without an in-place affordance (#5799)
AlfredChaos24c41a6af073
diff --git a/docs/configuration.md b/docs/configuration.mdindex 096571518..c5f433fda 100644--- a/docs/configuration.md+++ b/docs/configuration.md@@ -1654,6 +1654,18 @@ Normal tool workspace and media access rules still apply to attachment paths.}```+QQ `showCompactionNotices` defaults to `false`. It controls the context-compaction lifecycle notices ("Compressing context…" / "Context compacted."). Telegram, Discord and WebSocket present that lifecycle as one in-place-updated message or status, but QQ's C2C/group message API has no edit or recall endpoint, so each phase would land as a separate permanent message; the QQ channel therefore drops the notices by default (#5784). Set `channels.qq.showCompactionNotices: true` to post them anyway:++```json+{+ "channels": {+ "qq": {+ "showCompactionNotices": true+ }+ }+}+```+Telegram `richMessages` defaults to `false`. Enable it only to opt in to Bot API 10.1 `sendRichMessage` rendering; leave it disabled for Telegram Web clients that show unsupported-message errors for rich messages.### Retry Behaviordiff --git a/nanobot/channels/qq/manifest.py b/nanobot/channels/qq/manifest.pyindex a3e6cf093..28ada5680 100644--- a/nanobot/channels/qq/manifest.py+++ b/nanobot/channels/qq/manifest.py@@ -11,6 +11,7 @@ SETUP_SPEC = ChannelSetupSpec("allowFrom": field("list"),"msgFormat": field("enum", choices={"plain", "markdown"}, default="plain"),"ackMessage": field(default="⏳ Processing..."),+ "showCompactionNotices": field("bool", default=False),"mediaDir": field(),"downloadChunkSize": field("int", default=1024 * 256),"downloadMaxBytes": field("int", default=1024 * 1024 * 200),diff --git a/nanobot/channels/qq/runtime.py b/nanobot/channels/qq/runtime.pyindex 01af68675..134580d61 100644--- a/nanobot/channels/qq/runtime.py+++ b/nanobot/channels/qq/runtime.py@@ -37,6 +37,7 @@ from loguru import loggerfrom pydantic import Fieldfrom nanobot.bus.events import OutboundMessage+from nanobot.bus.outbound_events import ContextCompactionEventfrom nanobot.bus.queue import MessageBusfrom nanobot.channels.base import BaseChannelfrom nanobot.config.schema import Base@@ -192,6 +193,11 @@ class QQConfig(Base):download_chunk_size: int = 1024 * 256 # 256KBdownload_max_bytes: int = 1024 * 1024 * 200 # 200MB safety limit+ # QQ's C2C/group message API has no edit or recall endpoint, so compaction+ # notices would land as separate permanent messages (#5784). Off by default;+ # set showCompactionNotices: true to post them anyway.+ show_compaction_notices: bool = False+class QQChannel(BaseChannel):"""QQ channel using botpy SDK with WebSocket connection."""@@ -298,6 +304,17 @@ class QQChannel(BaseChannel):async def send(self, msg: OutboundMessage) -> None:"""Send attachments first, then text."""+ # Compaction notices assume the channel can update one message in place+ # (Telegram/Discord edit their notice; WebSocket projects it as status).+ # QQ's C2C/group API has no edit or recall endpoint, so by default the+ # lifecycle is dropped here instead of posting two permanent messages+ # (#5784); showCompactionNotices: true restores them.+ if (+ isinstance(msg.event, ContextCompactionEvent)+ and not self.config.show_compaction_notices+ ):+ return+try:if not self._client:raise RuntimeError("QQ client not initialized")diff --git a/nanobot/channels/qq/webui/locales/en.json b/nanobot/channels/qq/webui/locales/en.jsonindex cb426f104..ecd825144 100644--- a/nanobot/channels/qq/webui/locales/en.json+++ b/nanobot/channels/qq/webui/locales/en.json@@ -33,6 +33,13 @@},"downloadMaxBytes": {"label": "Maximum download size"+ },+ "showCompactionNotices": {+ "label": "Compaction notices",+ "choices": {+ "true": "On",+ "false": "Off"+ }}}}diff --git a/nanobot/channels/qq/webui/locales/es.json b/nanobot/channels/qq/webui/locales/es.jsonindex 0d2f1d528..723bc52e5 100644--- a/nanobot/channels/qq/webui/locales/es.json+++ b/nanobot/channels/qq/webui/locales/es.json@@ -33,6 +33,13 @@},"downloadMaxBytes": {"label": "Tamaño máximo de descarga"+ },+ "showCompactionNotices": {+ "label": "Avisos de compactación de contexto",+ "choices": {+ "true": "Activado",+ "false": "Desactivado"+ }}}}diff --git a/nanobot/channels/qq/webui/locales/fr.json b/nanobot/channels/qq/webui/locales/fr.jsonindex bf9d51b36..97cc8fa4e 100644--- a/nanobot/channels/qq/webui/locales/fr.json+++ b/nanobot/channels/qq/webui/locales/fr.json@@ -33,6 +33,13 @@},"downloadMaxBytes": {"label": "Taille maximale de téléchargement"+ },+ "showCompactionNotices": {+ "label": "Avis de compactage du contexte",+ "choices": {+ "true": "Activé",+ "false": "Désactivé"+ }}}}diff --git a/nanobot/channels/qq/webui/locales/id.json b/nanobot/channels/qq/webui/locales/id.jsonindex 0641dc835..dbf6b84a0 100644--- a/nanobot/channels/qq/webui/locales/id.json+++ b/nanobot/channels/qq/webui/locales/id.json@@ -33,6 +33,13 @@},"downloadMaxBytes": {"label": "Ukuran unduhan maksimum"+ },+ "showCompactionNotices": {+ "label": "Notifikasi pemadatan konteks",+ "choices": {+ "true": "Aktif",+ "false": "Nonaktif"+ }}}}diff --git a/nanobot/channels/qq/webui/locales/ja.json b/nanobot/channels/qq/webui/locales/ja.jsonindex 2efeba43b..66b998481 100644--- a/nanobot/channels/qq/webui/locales/ja.json+++ b/nanobot/channels/qq/webui/locales/ja.json@@ -33,6 +33,13 @@},"downloadMaxBytes": {"label": "最大ダウンロードサイズ"+ },+ "showCompactionNotices": {+ "label": "コンテキスト圧縮通知",+ "choices": {+ "true": "オン",+ "false": "オフ"+ }}}}diff --git a/nanobot/channels/qq/webui/locales/ko.json b/nanobot/channels/qq/webui/locales/ko.jsonindex 228f604d8..1bd6ddafd 100644--- a/nanobot/channels/qq/webui/locales/ko.json+++ b/nanobot/channels/qq/webui/locales/ko.json@@ -33,6 +33,13 @@},"downloadMaxBytes": {"label": "최대 다운로드 크기"+ },+ "showCompactionNotices": {+ "label": "컨텍스트 압축 알림",+ "choices": {+ "true": "켜기",+ "false": "끄기"+ }}}}diff --git a/nanobot/channels/qq/webui/locales/pt-BR.json b/nanobot/channels/qq/webui/locales/pt-BR.jsonindex 442a330c8..d833f10f8 100644--- a/nanobot/channels/qq/webui/locales/pt-BR.json+++ b/nanobot/channels/qq/webui/locales/pt-BR.json@@ -33,6 +33,13 @@},"downloadMaxBytes": {"label": "Tamanho máximo de download"+ },+ "showCompactionNotices": {+ "label": "Avisos de compactação de contexto",+ "choices": {+ "true": "Ativado",+ "false": "Desativado"+ }}}}diff --git a/nanobot/channels/qq/webui/locales/vi.json b/nanobot/channels/qq/webui/locales/vi.jsonindex 18e84e154..d25376076 100644--- a/nanobot/channels/qq/webui/locales/vi.json+++ b/nanobot/channels/qq/webui/locales/vi.json@@ -33,6 +33,13 @@},"downloadMaxBytes": {"label": "Kích thước tải xuống tối đa"+ },+ "showCompactionNotices": {+ "label": "Thông báo nén ngữ cảnh",+ "choices": {+ "true": "Bật",+ "false": "Tắt"+ }}}}diff --git a/nanobot/channels/qq/webui/locales/zh-CN.json b/nanobot/channels/qq/webui/locales/zh-CN.jsonindex a1edc5f37..b2eaf71ab 100644--- a/nanobot/channels/qq/webui/locales/zh-CN.json+++ b/nanobot/channels/qq/webui/locales/zh-CN.json@@ -33,6 +33,13 @@},"downloadMaxBytes": {"label": "下载大小上限"+ },+ "showCompactionNotices": {+ "label": "上下文压缩通知",+ "choices": {+ "true": "开",+ "false": "关"+ }}}}diff --git a/nanobot/channels/qq/webui/locales/zh-TW.json b/nanobot/channels/qq/webui/locales/zh-TW.jsonindex c3f8a698a..ad61aafbc 100644--- a/nanobot/channels/qq/webui/locales/zh-TW.json+++ b/nanobot/channels/qq/webui/locales/zh-TW.json@@ -33,6 +33,13 @@},"downloadMaxBytes": {"label": "下載大小上限"+ },+ "showCompactionNotices": {+ "label": "上下文壓縮通知",+ "choices": {+ "true": "開",+ "false": "關"+ }}}}diff --git a/tests/channels/test_qq_compaction_notices.py b/tests/channels/test_qq_compaction_notices.pynew file mode 100644index 000000000..5262293c8--- /dev/null+++ b/tests/channels/test_qq_compaction_notices.py@@ -0,0 +1,73 @@+"""QQ drops compaction notices it cannot present as one message.++QQ's C2C/group message API has no edit or recall endpoint, so the+compaction lifecycle would land as two separate permanent messages. The+channel drops ``ContextCompactionEvent`` by default; ``showCompactionNotices:+true`` restores the notices for anyone who wants them (#5784).+"""++from __future__ import annotations++from unittest.mock import AsyncMock++import pytest++pytest.importorskip("botpy")++from nanobot.bus.events import OutboundMessage+from nanobot.bus.outbound_events import ContextCompactionEvent, outbound_message_for_event+from nanobot.bus.queue import MessageBus+from nanobot.channels.qq.runtime import QQChannel, QQConfig+++def _make_channel(**config_kwargs) -> QQChannel:+ config = QQConfig(app_id="test_app", secret="test_secret", **config_kwargs)+ channel = QQChannel(config, MessageBus())+ channel._client = object() # truthy: pass the initialized check+ return channel+++async def test_compaction_notices_dropped_by_default(monkeypatch) -> None:+ channel = _make_channel()+ send_text = AsyncMock()+ monkeypatch.setattr(channel, "_send_text_only", send_text)++ for phase in ("started", "succeeded"):+ await channel.send(outbound_message_for_event(+ channel="qq", chat_id="chat",+ event=ContextCompactionEvent(compaction_id="c1", phase=phase),+ ))++ send_text.assert_not_awaited()+++async def test_compaction_notices_sent_when_enabled(monkeypatch) -> None:+ channel = _make_channel(show_compaction_notices=True)+ send_text = AsyncMock()+ monkeypatch.setattr(channel, "_send_text_only", send_text)++ await channel.send(outbound_message_for_event(+ channel="qq", chat_id="chat",+ event=ContextCompactionEvent(compaction_id="c1", phase="started"),+ ))++ send_text.assert_awaited_once()+ assert send_text.await_args.kwargs["content"] == "Compressing context…"+++async def test_ordinary_messages_unaffected(monkeypatch) -> None:+ channel = _make_channel()+ send_text = AsyncMock()+ monkeypatch.setattr(channel, "_send_text_only", send_text)++ await channel.send(OutboundMessage(channel="qq", chat_id="chat", content="hello"))++ send_text.assert_awaited_once()+++def test_config_accepts_camel_case_override() -> None:+ config = QQConfig.model_validate({"appId": "a", "secret": "s", "showCompactionNotices": True})+ assert config.show_compaction_notices is True