From 4b5de9251f866da116a96cd788dc86c34ad8e57c Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Mon, 26 Oct 2026 11:03:27 +0100 Subject: [PATCH] fix: earlier tool calls vanish from older chats when the conversation continues Chats saved before v0.12.0, or imported from such an instance, where the model gave its tool calls the same ids in every round, lost every tool round but the last once the conversation continued, so the model no longer saw what its earlier calls returned. A tool call still waiting for approval or still running was also sent to the model as finished when a result had been saved next to it. Calls are now matched only with results from their own round and keep the status they were saved with, so the model gets the same history as before. New replies on current versions were not affected, since repeated ids are already renamed while the reply streams. --- backend/open_webui/utils/session_records.py | 29 ++++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/backend/open_webui/utils/session_records.py b/backend/open_webui/utils/session_records.py index 5a7eb106ef..067d9a6480 100644 --- a/backend/open_webui/utils/session_records.py +++ b/backend/open_webui/utils/session_records.py @@ -33,33 +33,36 @@ def normalize_tool_output(output): return output items = [dict(item) for item in output if isinstance(item, dict)] deduped = [] - positions = {} + round_items = {} + previous_kind = None for item in items: kind = item.get('type') + # Some providers restart call ids every round. + if kind != 'function_call_output' and previous_kind == 'function_call_output': + pair_results(round_items) + round_items = {} + previous_kind = kind call_id = item.get('call_id') or item.get('id') if kind in {'function_call', 'function_call_output'} and call_id: key = (kind, call_id) - if key in positions: - deduped[positions[key]] = {**deduped[positions[key]], **item} + if key in round_items: + round_items[key].update(item) continue - positions[key] = len(deduped) + round_items[key] = item deduped.append(item) - return pair_results(deduped) + pair_results(round_items) + return deduped -def pair_results(deduped): - results = {item.get('call_id'): item for item in deduped if item.get('type') == 'function_call_output'} - for item in deduped: - if item.get('type') != 'function_call': +def pair_results(round_items): + for (kind, call_id), item in round_items.items(): + if kind != 'function_call': continue - result = results.get(item.get('call_id')) + result = round_items.get(('function_call_output', call_id)) if result: - if result.get('status'): - item['status'] = result['status'] for key in ('started_at', 'ended_at', 'duration', 'error_type'): if key in result and key not in item: item[key] = result[key] elif item.get('status') == 'completed': item['status'] = 'unknown' - return deduped