mirror of
https://github.com/open-webui/computer.git
synced 2026-11-05 01:17:24 +00:00
[GH-ISSUE #224] bug: Gemini streaming tool calls crash and lose thought signatures #137
Labels
No labels
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
open-webui/computer#137
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @owahltinez on GitHub (Aug 17, 2026).
Original GitHub issue: https://github.com/open-webui/computer/issues/224
Summary
Gemini's OpenAI-compatible Chat Completions stream does not always use the exact chunk shape that
stream_openai_completions()currently assumes.In particular, Gemini can:
tool_calls[].index;finish_reason: "stop"rather than"tool_calls";extra_content.google.thought_signature, including as a standalone metadata-only delta.The current implementation indexes
tc["index"]directly and therefore raisesKeyError: 'index'. If that lookup alone is made optional, the tool call can still be lost atfinish_reason: "stop". If both are fixed, subsequent tool rounds can still fail becauseextra_contentis discarded when the call is normalized, persisted, and reconstructed for history.This breaks Gemini tool use through an OpenAI-compatible connection. A tool can be selected correctly, but Computer aborts before executing it or receives a Gemini 4xx validation error on the follow-up request.
Reproduction
Reproduced against current
mainat9c54711.A minimal representative stream is:
At present, this reaches:
Google's thought-signature rules also require the signature to be returned in the subsequent request exactly where it was received. For parallel function calls, it belongs to the first function call; all calls must precede all function responses. See Google's documentation: https://ai.google.dev/gemini-api/docs/generate-content/thought-signatures
Suggested fix
1. Merge tool-call deltas without assuming an index
Add a small accumulator in
cptr/utils/ai.py. It preserves normal indexed OpenAI streams, matches indexless deltas by call ID, maps parallel indexless fragments by position, attaches a standalone Gemini signature to the first parallel call, and uses the last call only as the final single-call fallback:Use it in the streaming loop and emit accumulated calls for either valid finish reason:
2. Preserve provider metadata through persistence and replay
When converting persisted function calls back to OpenAI messages in
_output_items_to_messages():All four paths that create function-call items—automatic execution, queued approval, rejected/invalid calls, and
ask_user—must retain the metadata. A helper avoids one path silently dropping it:Then replace the repeated inline function-call dictionaries with
_function_call_item(...)in each path.Tests
I reproduced this against the current
mainbranch and have a focused standard-library test suite covering:finish_reason: "stop";extra_contentacross a tool result.All seven tests pass with the changes above, along with Ruff formatting and lint checks. I can provide the complete patch or a branch/PR if external contributions are accepted for this repository.
@owui-terminator[bot] commented on GitHub (Aug 17, 2026):
🔍 Related Issues Found
I found some existing issues that might be related. Please check if any of these are duplicates or contain helpful solutions:
🟣 #96 bug: OpenAI-compatible streaming usage can end responses early
This reports a related OpenAI-compatible streaming bug where the implementation treats an intermediate event as final and ends the response too early. The new issue also centers on incorrect assumptions about streamed chunk shapes and premature termination before tool execution.
by sandrogauci
🟣 #197 bug: every tool call renders as
agent_toolto OpenAI-compatible clientsThis is another OpenAI-compatible tool-call rendering/normalization bug in the gateway path. While the specific symptom differs, it confirms related problems in how function calls are converted for OpenAI-compatible clients and helps triangulate the tool-call handling area.
by penradioGables
💡 If your issue is a duplicate, please close it and add any additional details to the existing issue instead.
This comment was generated automatically. React with 👍 if helpful, 👎 if not.