fix(channels): make automatic compaction notices follow send_progress

Idle auto-compaction emitted "Compressing context…" / "Context compacted."
as standalone messages even when the channel had sendProgress: false, so
routine maintenance kept interrupting Discord chats after scheduled turns.

Gate ContextCompactionEvent notices in the outbound dispatch loop on the
channel's send_progress like other progress text. Two cases stay visible
regardless of the setting: a user-requested /compact (the event now
carries manual=True, set by cmd_compact through compact_idle_session)
and a failed compaction.

Fixes #5719
This commit is contained in:
L4XB authored and chengyongru committed 2026-09-11 11:15:57 +08:00
1 parent d7de5d5344
commit 92f151ae67
6 files changed
+135 -2

No files matched your search

+5 -2
View File
@@ -1165,6 +1165,7 @@ class Consolidator:
runtime: LLMRuntime,
max_suffix: int = 0,
events: EventSink = NO_EVENTS,
manual: bool = False,
) -> str | None:
"""Replace archived history with a summary checkpoint.
@@ -1187,7 +1188,7 @@ class Consolidator:
compaction_id = uuid4().hex
await events.emit(
ContextCompactionEvent(compaction_id=compaction_id, phase="started"),
ContextCompactionEvent(compaction_id=compaction_id, phase="started", manual=manual),
)
last_active = session.updated_at
archive_end = archive_start + len(messages_to_archive)
@@ -1207,19 +1208,21 @@ class Consolidator:
await events.emit(
ContextCompactionEvent(
compaction_id=compaction_id,
manual=manual,
phase="cancelled" if isinstance(exc, asyncio.CancelledError) else "failed",
),
)
raise
if not summary:
await events.emit(
ContextCompactionEvent(compaction_id=compaction_id, phase="failed"),
ContextCompactionEvent(compaction_id=compaction_id, phase="failed", manual=manual),
)
return None
await events.emit(
ContextCompactionEvent(
compaction_id=compaction_id,
manual=manual,
phase="succeeded",
),
)
+13
View File
@@ -15,6 +15,7 @@ from loguru import logger
from nanobot.bus.events import OutboundMessage
from nanobot.bus.outbound_events import (
ContextCompactionEvent,
ProgressEvent,
RetryWaitEvent,
RuntimeModelUpdatedEvent,
@@ -810,6 +811,18 @@ class ChannelManager:
):
continue
# Automatic compaction notices are maintenance chatter, so they
# follow the channel's progress setting like other progress
# text. A user-requested ``/compact`` and a failed compaction
# are still reported.
if (
isinstance(event, ContextCompactionEvent)
and not event.manual
and event.phase != "failed"
and not self._should_send_progress(msg.channel)
):
continue
if isinstance(event, RetryWaitEvent):
continue
+1
View File
@@ -357,6 +357,7 @@ async def cmd_compact(ctx: CommandContext) -> None:
ctx.key,
runtime=runtime,
events=delivery.events,
manual=True,
)
except Exception:
logger.exception("Manual context compaction failed for {}", ctx.key)
+3
View File
@@ -17,6 +17,9 @@ class AgentEvent:
class ContextCompactionEvent(AgentEvent):
compaction_id: str
phase: Literal["started", "succeeded", "failed", "cancelled"]
# True when the user asked for the compaction (``/compact``). Automatic
# compaction is routine maintenance and its notices follow ``send_progress``.
manual: bool = False
@dataclass(frozen=True)