From 07d93413e5e908859ddf6c4ea4b60c21131c10d3 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Tue, 7 Jul 2026 02:10:43 -0700 Subject: [PATCH] fix: default memory null target to memory store (#46356) Port from nearai/ironclaw#4547: treat a JSON null memory target as omitted so strict providers that fill optional fields with null use the documented default target instead of failing validation. --- tests/tools/test_memory_tool.py | 20 ++++++++++++++++++++ tools/memory_tool.py | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/tests/tools/test_memory_tool.py b/tests/tools/test_memory_tool.py index a7c822cb18d..c2903f375c6 100644 --- a/tests/tools/test_memory_tool.py +++ b/tests/tools/test_memory_tool.py @@ -535,6 +535,26 @@ class TestMemoryToolDispatcher: result = json.loads(memory_tool(action="add", target="invalid", content="x", store=store)) assert result["success"] is False + def test_null_target_defaults_to_memory_store(self, store): + result = json.loads( + memory_tool( + action="add", + target=None, + content="Project uses pytest with xdist.", + store=store, + ) + ) + assert result["success"] is True + assert store.memory_entries == ["Project uses pytest with xdist."] + assert store.user_entries == [] + + def test_invalid_non_string_target_still_rejected(self, store): + result = json.loads( + memory_tool(action="add", target=42, content="via tool", store=store) + ) + assert result["success"] is False + assert "Invalid target" in result["error"] + def test_unknown_action(self, store): result = json.loads(memory_tool(action="unknown", store=store)) assert result["success"] is False diff --git a/tools/memory_tool.py b/tools/memory_tool.py index 02315bd0726..08eeaa470ea 100644 --- a/tools/memory_tool.py +++ b/tools/memory_tool.py @@ -977,6 +977,12 @@ def memory_tool( if store is None: return tool_error("Memory is not available. It may be disabled in config or this environment.", success=False) + # Some strict providers fill optional schema fields with JSON null rather + # than omitting them. Treat ``target: null`` as omitted so memory writes + # still use the documented default store instead of failing validation. + if target is None: + target = "memory" + if target not in {"memory", "user"}: return tool_error(f"Invalid target '{target}'. Use 'memory' or 'user'.", success=False)