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(api): honor skip-user persist through save boundary
Xubin Ren7bec0f6e019d
diff --git a/nanobot/session/turn_continuation.py b/nanobot/session/turn_continuation.pyindex 2cb5e8686..2d63bdf42 100644--- a/nanobot/session/turn_continuation.py+++ b/nanobot/session/turn_continuation.py@@ -183,6 +183,8 @@ def _save_skip_for_turn(user_persisted_early: bool,) -> int:"""Return the persisted-message append boundary for this turn."""+ if message_metadata and message_metadata.get(SKIP_USER_PERSIST_META) is True:+ return initial_message_countif internal_continuation_inbound(message_metadata):return initial_message_count# build_messages may merge the current message into a same-role history tail.diff --git a/tests/agent/test_loop_save_turn.py b/tests/agent/test_loop_save_turn.pyindex dfd530c91..d64eb13cb 100644--- a/tests/agent/test_loop_save_turn.py+++ b/tests/agent/test_loop_save_turn.py@@ -1,5 +1,6 @@import asynciofrom pathlib import Path+from types import SimpleNamespacefrom unittest.mock import AsyncMock, MagicMockimport pytest@@ -39,6 +40,7 @@ def _mk_loop() -> AgentLoop:def _make_full_loop(tmp_path: Path) -> AgentLoop:provider = MagicMock()provider.get_default_model.return_value = "test-model"+ provider.generation = SimpleNamespace(max_tokens=4096)provider.chat_with_retry = AsyncMock(return_value=LLMResponse(content="Test title"))loop = AgentLoop(bus=MessageBus(), provider=provider, workspace=tmp_path, model="test-model")WebuiTurnCoordinator(@@ -988,6 +990,33 @@ async def test_run_agent_loop_goal_continue_message_reads_latest_metadata(assert "Goal created during this runner call." in (seen["goal_continue"] or "")+async def test_process_direct_skip_user_persist_does_not_save_retry_user(+ tmp_path: Path,+) -> None:+ loop = _make_full_loop(tmp_path)+ loop._connect_mcp = AsyncMock()+ session = loop.sessions.get_or_create("api:default")+ session.add_message("user", "hello")+ session.add_message("assistant", "previous empty-response attempt")+ loop.sessions.save(session)++ await loop.process_direct(+ "hello",+ session_key=session.key,+ channel="api",+ chat_id="default",+ persist_user_message=False,+ )++ session = loop.sessions.get_or_create("api:default")+ assert [(m["role"], m["content"]) for m in session.messages] == [+ ("user", "hello"),+ ("assistant", "previous empty-response attempt"),+ ("assistant", "Test title"),+ ]++def test_set_tool_context_uses_effective_key_for_spawn_tool(tmp_path: Path) -> None:loop = _make_full_loop(tmp_path)spawn_tool = loop.tools.get("spawn")