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
@@ -17,7 +17,7 @@ from nanobot.bus.events import InboundMessage
|
||||
from nanobot.bus.queue import MessageBus
|
||||
from nanobot.command import CommandContext
|
||||
from nanobot.config.schema import AgentDefaults, Config
|
||||
from nanobot.events import NO_EVENTS
|
||||
from nanobot.events import NO_EVENTS, ContextCompactionEvent
|
||||
from nanobot.providers.base import LLMResponse
|
||||
from nanobot.runtime_context import public_history_message
|
||||
from nanobot.sdk.clients import RuntimeClient
|
||||
@@ -99,6 +99,7 @@ def _make_fake_compact(
|
||||
max_suffix: int = 8,
|
||||
trigger: str = "policy",
|
||||
events=NO_EVENTS,
|
||||
reason=None,
|
||||
) -> str:
|
||||
state["count"] += 1
|
||||
session = await loop.sessions.state.get(key)
|
||||
@@ -150,6 +151,37 @@ async def test_heartbeat_idle_compaction_persists_summary_without_channel_notice
|
||||
assert loop.bus.outbound.empty()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("outcome", ["succeeded", "failed", "cancelled"])
|
||||
async def test_idle_compaction_emits_its_real_trigger_for_each_phase(tmp_path, monkeypatch, outcome):
|
||||
loop = _make_loop(tmp_path)
|
||||
try:
|
||||
key = "websocket:idle-reason"
|
||||
session = await loop.sessions.state.get(key)
|
||||
_add_turns(session, 1)
|
||||
await loop.sessions.state.finish_turn(session)
|
||||
clock = MagicMock(wraps=datetime)
|
||||
clock.now.return_value = datetime.now() + timedelta(minutes=20)
|
||||
monkeypatch.setattr("nanobot.agent.autocompact.datetime", clock)
|
||||
if outcome == "succeeded":
|
||||
loop.consolidator.archive_session = AsyncMock(return_value="Idle summary.")
|
||||
else:
|
||||
error = asyncio.CancelledError() if outcome == "cancelled" else RuntimeError("summary failed")
|
||||
loop.consolidator.archive_session = AsyncMock(side_effect=error)
|
||||
|
||||
await loop.auto_compact.check_expired(loop.schedule_background, loop.runtime_for_session)
|
||||
await _drain_background_tasks(loop)
|
||||
|
||||
events = [loop.bus.outbound.get_nowait().event for _ in range(loop.bus.outbound_size)]
|
||||
assert len(events) == 2
|
||||
assert all(isinstance(event, ContextCompactionEvent) for event in events)
|
||||
assert [event.phase for event in events] == ["started", outcome]
|
||||
assert [event.reason for event in events] == ["idle", "idle"]
|
||||
assert events[0].compaction_id == events[1].compaction_id
|
||||
assert all(event.notify is False for event in events)
|
||||
finally:
|
||||
await loop.aclose()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("reopen", [False, True])
|
||||
async def test_idle_compaction_skips_subagent_sessions(tmp_path, monkeypatch, reopen):
|
||||
loop = _make_loop(tmp_path)
|
||||
|
||||
@@ -265,6 +265,7 @@ class TestCheckExpired:
|
||||
"cli:old",
|
||||
runtime=admitted,
|
||||
events=NO_EVENTS,
|
||||
reason="idle",
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize("resolution_error", [KeyError, ValueError])
|
||||
@@ -443,6 +444,7 @@ class TestArchiveDelegates:
|
||||
"cli:test",
|
||||
runtime=runtime,
|
||||
events=NO_EVENTS,
|
||||
reason="idle",
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -402,6 +402,7 @@ async def test_native_compaction_uses_provider_request_boundary(
|
||||
assert any(message.get("content") == "inspect the project" for message in result.messages)
|
||||
assert any(message.get("content") == "complete tool result" for message in result.messages)
|
||||
assert [event.phase for event in compaction_events] == ([] if scope == "prior_context" else ["succeeded"])
|
||||
assert all(event.reason == "provider_native" for event in compaction_events)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("error", [RuntimeError("checkpoint failed"), asyncio.CancelledError()])
|
||||
@@ -439,6 +440,7 @@ async def test_native_checkpoint_failure_does_not_relabel_completed_compaction(m
|
||||
events=EventSink(observe),
|
||||
))
|
||||
assert [notice.phase for notice in notices] == ["succeeded"]
|
||||
assert all(notice.reason == "provider_native" for notice in notices)
|
||||
|
||||
|
||||
async def test_runner_keeps_current_tool_exchange_outside_summary(monkeypatch):
|
||||
@@ -576,6 +578,7 @@ async def test_repeated_pressure_advances_summary_boundary(monkeypatch):
|
||||
assert [event.phase for event in compaction_events] == [
|
||||
"started", "succeeded", "started", "succeeded",
|
||||
]
|
||||
assert all(event.reason == "context_pressure" for event in compaction_events)
|
||||
first_id, second_id = compaction_events[0].compaction_id, compaction_events[2].compaction_id
|
||||
assert first_id == compaction_events[1].compaction_id
|
||||
assert second_id == compaction_events[3].compaction_id
|
||||
|
||||
Reference in new issue
Block a user