)]}'
{
  "commit": "a3e28fb8e570ab7e43f84d2f5c5fcecb81d00618",
  "tree": "5469d620466a368eae9f342bd240178e0e0cf57b",
  "parents": [
    "15cc2e75ed6dc840c78bc7f2b2075d40d5f22470"
  ],
  "author": {
    "name": "Josh Bleecher Snyder",
    "email": "josharian@gmail.com",
    "time": "Fri May 30 15:53:23 2025 +0000"
  },
  "committer": {
    "name": "Josh Bleecher Snyder",
    "email": "josharian@gmail.com",
    "time": "Fri May 30 12:34:24 2025 -0700"
  },
  "message": "llm/conversation: fix duplicate tool results in insertMissingToolResults\n\nFix critical bug in insertMissingToolResults function that created duplicate\ntool_result blocks when multiple tool uses were missing results, causing\nClaude API 400 errors with message \"each tool_use must have a single result\".\n\nProblem Analysis:\nThe function was designed to add error tool results for tool uses that\nwere requested but had no corresponding tool_result in the user message\n(e.g., when hitting budget limits). However, when multiple tool uses\nwere missing results, the function incorrectly duplicated results:\n\n1. First iteration: adds tool1 result to prefix, sets msg.Content \u003d [tool1] + original\n2. Second iteration: adds tool2 to prefix, sets msg.Content \u003d [tool1, tool2] + [tool1] + original\n\nThis created duplicate tool_result blocks with the same tool_use_id, violating\nClaude\u0027s API requirements and causing 400 Bad Request errors.\n\nRoot Cause:\nThe msg.Content assignment was inside the loop that builds the prefix:\n\nSolution:\nMove the msg.Content assignment outside the loop, after all missing\ntool results have been collected:\n\nTesting:\nAdded comprehensive test coverage for insertMissingToolResults with scenarios:\n- Single missing tool result\n- Multiple missing tool results (the problematic case)\n- No missing results when results already present\n- No tool uses in previous message\n\nThe test specifically verifies no duplicate tool_use_ids are created\nand that all expected tool results are present exactly once.\n\nThis fix resolves the \"multiple tool_result blocks with id\" error\nthat was occurring in deep conversations with tool usage.\n\nFixes #121\n\nCo-Authored-By: sketch \u003chello@sketch.dev\u003e\nChange-ID: s07f278af38b745aak",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "d85515cad9c8fbac7ccc275fc0a3c8d819e9bf0a",
      "old_mode": 33188,
      "old_path": "llm/conversation/convo.go",
      "new_id": "12c334f5edbcfcef3e4fb6aa52ab98af17d3cf48",
      "new_mode": 33188,
      "new_path": "llm/conversation/convo.go"
    },
    {
      "type": "modify",
      "old_id": "cf4f1c26360dfbbab20597677e6cdbe49ebc95f8",
      "old_mode": 33188,
      "old_path": "llm/conversation/convo_test.go",
      "new_id": "879446891f87a25506358040a58bf6601af07e68",
      "new_mode": 33188,
      "new_path": "llm/conversation/convo_test.go"
    }
  ]
}
