Skip to content

fix: should omit empty name for function call, close #1587#1639

Merged
looplj merged 1 commit into
unstablefrom
dev-tmp
May 11, 2026
Merged

fix: should omit empty name for function call, close #1587#1639
looplj merged 1 commit into
unstablefrom
dev-tmp

Conversation

@looplj

@looplj looplj commented May 11, 2026

Copy link
Copy Markdown
Owner

No description provided.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the FunctionCall struct in llm/transformer/openai/model.go by adding the omitempty tag to the Name field's JSON definition. This change allows the field to be excluded from JSON serialization when it is empty. There are no review comments to address, and I have no further feedback to provide.

@greptile-apps

greptile-apps Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a serialization issue where an empty name field in a FunctionCall struct was being included in JSON output as \"name\": \"\", which causes some LLM providers to reject the request. The fix adds omitempty to the JSON tag so an empty name is silently omitted from the payload.

  • FunctionCall.Name is now tagged json:\"name,omitempty\", preventing \"name\": \"\" from appearing in serialized function call payloads — which is relevant during streaming aggregation where the function name arrives in a later delta chunk.
  • No test is added to assert the new serialization behavior, leaving the fix without direct regression coverage.

Confidence Score: 4/5

The change is isolated to one JSON struct tag, only affects marshaling (not unmarshaling), and corrects a real compatibility problem with providers that reject "name":"". Safe to merge.

The one-line tag addition correctly eliminates an empty name field from serialized function call payloads, which is the right behavior for both streaming aggregation and pass-through scenarios. The only gap is the absence of a direct unit test asserting the new serialization behavior, leaving the fix unguarded against future regressions.

llm/transformer/openai/model.go — the only changed file; no new test accompanies the fix.

Important Files Changed

Filename Overview
llm/transformer/openai/model.go Adds omitempty to FunctionCall.Name JSON tag so an empty name is not serialized; fix is correct but lacks a dedicated test.

Sequence Diagram

sequenceDiagram
    participant Stream as Streaming Provider
    participant Agg as aggregator.go
    participant Conv as outbound_convert.go (ToolCallFromLLM)
    participant JSON as JSON Serializer
    participant Downstream as Downstream LLM Provider

    Stream->>Agg: "delta chunk (name="", arguments="")"
    Note over Agg: Initialize ToolCall with empty Name
    Agg->>Agg: "delta chunk (name="get_weather", arguments="{}")"
    Note over Agg: Update Name to "get_weather"
    Agg->>Conv: "llm.ToolCall{Name: ""}  [partial/forwarded]"
    Conv->>JSON: "FunctionCall{Name: "", Arguments: "..."}"
    Note over JSON: Before fix: emits name:""<br/>After fix (omitempty): name key omitted
    JSON->>Downstream: "{"function": {"arguments": "..."}}"
    Note over Downstream: Accepts payload without empty name field
Loading

Reviews (1): Last reviewed commit: "fix: should omit empty name for function..." | Re-trigger Greptile

Comment on lines +372 to 373
Name string `json:"name,omitempty"`
Arguments string `json:"arguments"`

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.

P2 Missing test for the new serialization behavior. The fix is correct, but no test verifies that marshaling a FunctionCall with an empty Name omits the name key from JSON output. Without it, a future refactor that reverts or misapplies the tag (e.g., moving to a custom marshaler) would silently reintroduce the bug. A small table-driven test in model_test.go marshaling FunctionCall{Name: "", Arguments: "{}"} and asserting the key is absent would be sufficient.

@looplj looplj merged commit 8ddb62a into unstable May 11, 2026
4 checks passed
yoke233 pushed a commit to yoke233/axonhub that referenced this pull request May 26, 2026
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.

1 participant