feat(webui): distinguish context compaction reasons (NAN-324) (#6389)
* feat(webui): distinguish context compaction reasons (NAN-324) * fix(webui): describe idle compaction cancellation as interruption * docs: omit compaction notice details from configuration guide * fix(i18n): make compaction notices read naturally * fix(i18n): keep CJK compaction notices concise * fix(i18n): describe idle compaction as unfinished
This commit is contained in:
1 parent
084b6bb394
commit
bc5c58d239
38 files changed
+540
-23
No files matched your search
@@ -101,6 +101,7 @@ class AutoCompact:
|
||||
key,
|
||||
runtime=runtime,
|
||||
events=self._bind_events(key) if self._bind_events else NO_EVENTS,
|
||||
reason="idle",
|
||||
)
|
||||
if summary:
|
||||
session = await self.sessions.state.get(key)
|
||||
|
||||
@@ -533,7 +533,7 @@ class ContextGovernor:
|
||||
if response.provider_compaction_event_id is None:
|
||||
response.provider_compaction_event_id = uuid4().hex
|
||||
await shield_and_drain(state.events.emit(ContextCompactionEvent(
|
||||
response.provider_compaction_event_id, "succeeded",
|
||||
response.provider_compaction_event_id, "succeeded", reason="provider_native",
|
||||
)))
|
||||
if (
|
||||
not response.provider_compaction_applied
|
||||
@@ -585,7 +585,7 @@ class ContextGovernor:
|
||||
measured, _source = pressure
|
||||
compaction_id = uuid4().hex
|
||||
await state.events.emit(
|
||||
ContextCompactionEvent(compaction_id=compaction_id, phase="started"),
|
||||
ContextCompactionEvent(compaction_id=compaction_id, phase="started", reason="context_pressure"),
|
||||
)
|
||||
try:
|
||||
delta_messages = await self.prepare_in_background(
|
||||
@@ -645,6 +645,7 @@ class ContextGovernor:
|
||||
ContextCompactionEvent(
|
||||
compaction_id=compaction_id,
|
||||
phase="cancelled" if isinstance(exc, asyncio.CancelledError) else "failed",
|
||||
reason="context_pressure",
|
||||
),
|
||||
)
|
||||
raise
|
||||
@@ -652,6 +653,7 @@ class ContextGovernor:
|
||||
ContextCompactionEvent(
|
||||
compaction_id=compaction_id,
|
||||
phase="succeeded",
|
||||
reason="context_pressure",
|
||||
),
|
||||
)
|
||||
return prepared
|
||||
|
||||
@@ -20,7 +20,7 @@ from uuid import uuid4
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from nanobot.events import NO_EVENTS, ContextCompactionEvent, EventSink
|
||||
from nanobot.events import NO_EVENTS, CompactionReason, ContextCompactionEvent, EventSink
|
||||
from nanobot.llm_usage.context import llm_usage_source
|
||||
from nanobot.providers.base import LLMResponse, ProviderConversationState
|
||||
from nanobot.providers.conversation_state import ProviderConversationStateController
|
||||
@@ -1222,6 +1222,7 @@ class Consolidator:
|
||||
max_suffix: int = 0,
|
||||
events: EventSink = NO_EVENTS,
|
||||
notify: bool = False,
|
||||
reason: CompactionReason | None = None,
|
||||
) -> str | None:
|
||||
"""Replace archived history with a summary checkpoint.
|
||||
|
||||
@@ -1244,7 +1245,7 @@ class Consolidator:
|
||||
|
||||
compaction_id = uuid4().hex
|
||||
await events.emit(
|
||||
ContextCompactionEvent(compaction_id=compaction_id, phase="started", notify=notify),
|
||||
ContextCompactionEvent(compaction_id=compaction_id, phase="started", notify=notify, reason=reason),
|
||||
)
|
||||
archive_end = archive_start + len(messages_to_archive)
|
||||
try:
|
||||
@@ -1261,12 +1262,13 @@ class Consolidator:
|
||||
compaction_id=compaction_id,
|
||||
phase="cancelled" if isinstance(exc, asyncio.CancelledError) else "failed",
|
||||
notify=notify,
|
||||
reason=reason,
|
||||
),
|
||||
)
|
||||
raise
|
||||
if not summary:
|
||||
await events.emit(
|
||||
ContextCompactionEvent(compaction_id=compaction_id, phase="failed", notify=notify),
|
||||
ContextCompactionEvent(compaction_id=compaction_id, phase="failed", notify=notify, reason=reason),
|
||||
)
|
||||
return None
|
||||
|
||||
@@ -1275,6 +1277,7 @@ class Consolidator:
|
||||
compaction_id=compaction_id,
|
||||
phase="succeeded",
|
||||
notify=notify,
|
||||
reason=reason,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user