Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion run_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11908,8 +11908,18 @@ def _stop_spinner():
self._vprint(f"{self.log_prefix}⚠️ Injecting recovery tool results for invalid JSON...")
self._invalid_json_retries = 0 # Reset for next attempt

# Append the assistant message with its (broken) tool_calls
# Append the assistant message, repairing broken tool_call
# arguments at write time so corrupted JSON never enters

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current main extracted the live run_conversation loop into agent/conversation_loop.py; the active recovery branch is now at agent/conversation_loop.py:4571 (commit 053025238). Salvage this write-site repair there, before the assistant message is appended.

# the persistent message history.
recovery_assistant = self._build_assistant_message(assistant_message, finish_reason)
for tc_dict in recovery_assistant.get("tool_calls") or []:
raw = tc_dict.get("function", {}).get("arguments", "")
try:
json.loads(raw)
except (json.JSONDecodeError, TypeError):
tc_dict["function"]["arguments"] = _repair_tool_call_arguments(
raw, tc_dict.get("function", {}).get("name", "?"),
)
messages.append(recovery_assistant)

# Respond with tool error results for each tool call
Expand Down