fix(memory): reject tool-call-only consolidation

This commit is contained in:
chengyongru
2026-08-19 18:40:20 +08:00
committed by chengyongru
parent 12a4a8c04c
commit 93f71b61a0
2 changed files with 36 additions and 0 deletions
+4
View File
@@ -1060,6 +1060,10 @@ class Consolidator:
logger.warning("Consolidation provider returned an error, raw-dumping to history")
self.store.raw_archive(fallback_messages, session_key=session_key)
return None
if response.has_tool_calls is True:
logger.warning("Consolidation provider returned tool calls, raw-dumping to history")
self.store.raw_archive(fallback_messages, session_key=session_key)
return None
summary = response.content or "[no summary]"
self.store.append_history(
summary,
+32
View File
@@ -14,6 +14,7 @@ from nanobot.providers.base import (
GenerationSettings,
LLMResponse,
ProviderConversationState,
ToolCallRequest,
)
from nanobot.runtime_context import (
RUNTIME_CONTEXT_HISTORY_META,
@@ -1069,6 +1070,37 @@ class TestCompactIdleSession:
"Overview from the temporary turn."
]
@pytest.mark.asyncio
async def test_tool_call_response_uses_raw_fallback(
self,
real_consolidator,
mock_provider,
store,
runtime,
):
mock_provider.chat_with_retry.return_value = LLMResponse(
content=None,
tool_calls=[ToolCallRequest(id="call-1", name="lookup", arguments={})],
finish_reason="tool_calls",
)
sessions = real_consolidator.sessions
session = sessions.get_or_create("cli:unexpected-tool")
session.add_message("user", "remember this")
session.add_message("assistant", "important answer")
sessions.save(session)
result = await real_consolidator.compact_idle_session(
"cli:unexpected-tool",
runtime=runtime,
)
assert result is None
entries = store.read_unprocessed_history(since_cursor=0)
assert len(entries) == 1
assert entries[0]["content"].startswith("[RAW] ")
assert "important answer" in entries[0]["content"]
assert sessions.get_or_create("cli:unexpected-tool").last_consolidated == 2
@pytest.mark.asyncio
async def test_oversized_prefix_falls_back_to_bounded_archive(
self,