Skip to content

fix: keep streamed tool names from OpenAI-compatible routers - #351

Merged
Taewan-P merged 2 commits into
mainfrom
cursor/fix-empty-tool-name-9063
Oct 10, 2026
Merged

Taewan-P merged 2 commits into
mainfrom
cursor/fix-empty-tool-name-9063

Conversation

@Taewan-P

@Taewan-P Taewan-P commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Fixes #350

Root cause

Web search on an OpenAI-compatible custom profile (the report used Clouvia Router) failed with Tool '' is not assigned to this profile even though the tool arguments were a valid web_search payload (query, maxResults). The same failure happened with Exa and Firecrawl and across models, so it was not a missing tool binding.

Chat Completions streams from these routers send the function name and call id on the first tool_calls delta, then keep streaming argument fragments with function.name and often id set to "". ChatCompletionsEventAssembler stored every non-null name and id, and an empty string is non-null, so the real name was replaced. The arguments still accumulated, which matches the screenshot: a tool card with a blank name, a real call id when the id was not blanked, and arguments such as {"query":"today's AI news","maxResults":5}.

AgentRunner then looked the tool up by that empty name and returned the assignment error. The follow-up request replayed function.name: "". Gateways commonly drop that connection instead of returning an HTTP error body, which Ktor surfaces as Failed to parse HTTP response: the server prematurely closed the connection. That second error is a consequence of the empty name, not a separate parser bug.

Two related stream shapes drop the name the same way: the delta that carries the name omits index (the chunk used to fail decoding and was skipped), or later argument deltas repeat the same call id under a different index.

Fix

The chat-completions accumulator now:

  • ignores blank ids and names instead of overwriting a value already received
  • appends a function name that arrives in pieces, without duplicating a repeated full name
  • accepts a missing index and still joins argument deltas that share the call id, or that are argument-only fragments of the single open call

A stream that never sends a real name still fails as an incomplete function call, rather than executing Tool ''.

Validation

Reproduced with decoded Chat Completions chunks in the shape those routers emit (name and id on the first delta, "" on the next, full web_search arguments). Before the fix the assembler produced ToolCall(callId=, name=, arguments={"query":"today's AI news","maxResults":5}), and the agent path never invoked web_search. After the fix that stream executes web_search and the next round replays the original call id and name.

Also covered: omitted index, same id under another index, argument fragments on a new index, split and repeated names, and parallel calls whose continuation names are blank.

./gradlew :app:testDebugUnitTest :app:lintDebug passed (730 unit tests, 0 failures). ktlint 1.3.1 is clean on the changed Kotlin files.

Open in Web Open in Cursor 

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of streamed tool calls when updates omit or repeat identifiers, indexes, or names. This helps preserve the correct tool and its accumulated arguments through execution and conversation replay.
    • Tool calls with missing required details continue to report an error.

OpenAI-compatible gateways can send a tool call's name and id only on the first chat-completions delta, then resend both as empty strings while arguments continue. The accumulator treated those empty strings as updates, so web search ran as Tool ''.

Co-authored-by: Taewan Park <Taewan-P@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Review in Change Stack →Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1afe4edb-595e-4b49-a76f-a6f8ca7ae7aa

📥 Commits

Reviewing files that changed from the base of the PR and between ec2a2ba and 7b79560.


📒 Files selected for processing (2)
  • app/src/main/kotlin/dev/chungjungsoo/gptmobile/data/agent/provider/ProviderEventAssemblers.kt
  • app/src/test/kotlin/dev/chungjungsoo/gptmobile/data/agent/provider/ProviderEventAssemblerTest.kt

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.



📝 Walkthrough

Walkthrough

The Chat Completions assembler now resolves tool-call deltas when indexes are omitted or IDs repeat. It preserves accumulated nonblank IDs and names, merges name fragments, and treats blank values as absent. Tests cover assembler behavior and compatible-adapter execution.

Changes

Streamed tool-call assembly

Layer / File(s) Summary
Delta contract, assembly, and validation
app/src/main/kotlin/dev/chungjungsoo/gptmobile/data/dto/openai/response/ChatCompletionChunk.kt, app/src/main/kotlin/dev/chungjungsoo/gptmobile/data/agent/provider/ProviderEventAssemblers.kt, app/src/test/kotlin/dev/chungjungsoo/gptmobile/data/agent/provider/ProviderEventAssemblerTest.kt, app/src/test/kotlin/dev/chungjungsoo/gptmobile/data/agent/provider/ProviderAdaptersTest.kt
The delta index is nullable. The assembler matches pending calls by nonblank ID when possible, then uses index and pending-call state. It retains nonblank IDs and merges nonblank names. Tests cover omitted indexes, repeated IDs, name fragments, separate and parallel calls, incomplete calls, and compatible-adapter execution.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium


Merge Risk: ⚪ Minimal · up to 7b795

No unresolved merge-blocking issue is established in the reviewed streamed tool-call changes.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 4.76% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preserving streamed tool names from OpenAI-compatible routers.
Linked Issues check Passed Issue #350 concerns an empty tool name during OpenAI-compatible web-search calls. ChatCompletionsEventAssembler ignores blank IDs and names, merges streamed names, and joins argument deltas by call …
Out of Scope Changes check Passed The production changes are limited to Chat Completions tool-call decoding and assembly. The DTO change supports omitted indexes. The added tests cover the affected web-search flow and related stream s…

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR


🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

@Taewan-P
Taewan-P marked this pull request as ready for review October 10, 2026 03:18
Copilot AI balanced review requested due to automatic review settings October 10, 2026 03:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ec2a2ba513

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T03:20:40.812131Z ec2a2ba Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

- Append streamed function-name fragments that repeat an earlier prefix, and only drop an exact retransmission or a longer cumulative name.

Co-authored-by: Taewan Park <Taewan-P@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

@Taewan-P
Taewan-P merged commit d99a41f into main Oct 10, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web search fails with "Tool '' is not assigned to this profile" on GPT Mobile 0.9.1

3 participants