The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): canonicalize todo history pairing
JoaoMarcos44031e3296a5cd
diff --git a/run_agent.py b/run_agent.pyindex afd8150c402..d146217c988 100644--- a/run_agent.py+++ b/run_agent.py@@ -1107,10 +1107,14 @@ class AIAgent(@classmethoddef _assistant_has_todo_tool_call(cls, assistant_msg: Dict[str, Any], tool_call_id: str) -> bool:- """True when the assistant message issued a ``todo`` call with this id."""+ """True when the paired call resolves to the registered Todo tool."""+ from agent.tool_executor import _canonical_tool_name+ from tools.todo_tool import TODO_SCHEMA+tool_calls = assistant_msg.get("tool_calls")return isinstance(tool_calls, list) and any(- cls._get_tool_call_id_static(tc) == tool_call_id and cls._get_tool_call_name_static(tc) == "todo"+ cls._get_tool_call_id_static(tc) == tool_call_id+ and _canonical_tool_name(cls._get_tool_call_name_static(tc)) == TODO_SCHEMA["name"]for tc in tool_calls)diff --git a/tests/agent/test_todo_history_canonicalization_124960.py b/tests/agent/test_todo_history_canonicalization_124960.pynew file mode 100644index 00000000000..54840b93ad6--- /dev/null+++ b/tests/agent/test_todo_history_canonicalization_124960.py@@ -0,0 +1,68 @@+"""Regression for #124960: Todo history pairing follows dispatch canonicalization."""++import json+from unittest.mock import patch++from model_tools import _LEGACY_TOOL_ALIASES+from run_agent import AIAgent+from tools.todo_tool import TODO_SCHEMA, TodoStore+++def _agent() -> AIAgent:+ agent = object.__new__(AIAgent)+ agent.quiet_mode = True+ agent._todo_store = TodoStore()+ return agent+++def _assistant_call(name: str, call_id: str = "todo-call") -> dict:+ return {+ "role": "assistant",+ "content": None,+ "tool_calls": [{+ "id": call_id,+ "type": "function",+ "function": {"name": name, "arguments": "{}"},+ }],+ }+++def test_current_todo_list_name_hydrates_eleven_items_across_turns():+ todos = [+ {"id": str(index), "content": f"Task {index}", "status": "pending"}+ for index in range(11)+ ]+ history = [+ _assistant_call(TODO_SCHEMA["name"]),+ {+ "role": "tool",+ "tool_call_id": "todo-call",+ "content": json.dumps({"todos": todos, "revision": 7}),+ },+ ]+ agent = _agent()++ with patch("run_agent._set_interrupt"):+ agent._hydrate_todo_store(history)++ assert agent._todo_store.snapshot() == {"todos": todos, "revision": 7}+++def test_history_pairing_uses_the_same_alias_table_as_dispatch(monkeypatch):+ synthetic_alias = "legacy_todo_probe"+ monkeypatch.setitem(_LEGACY_TOOL_ALIASES, synthetic_alias, TODO_SCHEMA["name"])++ assert AIAgent._assistant_has_todo_tool_call(+ _assistant_call(synthetic_alias), "todo-call"+ )+++def test_unrelated_alias_and_wrong_call_id_remain_rejected(monkeypatch):+ monkeypatch.setitem(_LEGACY_TOOL_ALIASES, "legacy_reader_probe", "read_file")++ assert not AIAgent._assistant_has_todo_tool_call(+ _assistant_call("legacy_reader_probe"), "todo-call"+ )+ assert not AIAgent._assistant_has_todo_tool_call(+ _assistant_call(TODO_SCHEMA["name"]), "different-call"+ )