fix: drop tool results missing call ids

maintainer edit: treat tool messages without tool_call_id as orphaned during session persistence so malformed results cannot survive into history.
This commit is contained in:
chengyongru
2026-06-13 00:05:03 +08:00
committed by Xubin Ren
parent eb25df9b49
commit 33e6da14d8
2 changed files with 19 additions and 2 deletions
+17
View File
@@ -1406,6 +1406,23 @@ def test_save_turn_drops_orphaned_tool_results() -> None:
assert [m["role"] for m in session.messages] == ["user", "assistant"]
def test_save_turn_drops_tool_results_without_tool_call_id() -> None:
loop = _mk_loop()
session = Session(key="test:missing-tool-call-id")
session.add_message("user", "hi")
loop._save_turn(
session,
[
{"role": "tool", "name": "exec", "content": "missing id"},
{"role": "assistant", "content": "done"},
],
skip=0,
)
assert [m["role"] for m in session.messages] == ["user", "assistant"]
def test_save_turn_keeps_tool_results_declared_in_prior_history() -> None:
# Declarations may live in already-persisted history (e.g. a restored
# runtime checkpoint), not only in the new-turn slice.