From 3fa7389ba952efd619c8ff7924948f39288d99f1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 15:49:25 +0000 Subject: [PATCH] Add defensive checks for thought_signature modification Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> --- .../pkg/provider/modelmgr/requesters/geminichatcmpl.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/langbot/pkg/provider/modelmgr/requesters/geminichatcmpl.py b/src/langbot/pkg/provider/modelmgr/requesters/geminichatcmpl.py index e0800c9d..7fe70e1d 100644 --- a/src/langbot/pkg/provider/modelmgr/requesters/geminichatcmpl.py +++ b/src/langbot/pkg/provider/modelmgr/requesters/geminichatcmpl.py @@ -28,8 +28,11 @@ class GeminiChatCompletions(chatcmpl.OpenAIChatCompletions): """ for msg in messages: if 'tool_calls' in msg and msg['tool_calls']: + # Ensure we're working with a mutable copy of tool_calls + if not isinstance(msg['tool_calls'], list): + continue for tool_call in msg['tool_calls']: - if 'thought_signature' not in tool_call: + if isinstance(tool_call, dict) and 'thought_signature' not in tool_call: tool_call['thought_signature'] = '' return messages @@ -168,6 +171,7 @@ class GeminiChatCompletions(chatcmpl.OpenAIChatCompletions): ) -> tuple[provider_message.Message, dict]: """Override _closure to add thought_signature to messages""" # Add thought_signature to tool_calls for Gemini compatibility + # Note: modifying in place is safe here as parent _closure will make a copy req_messages = self._add_thought_signature_to_messages(req_messages) # Call parent implementation