Skip to content

Conversation

@plusor
Copy link

@plusor plusor commented Jan 26, 2026

…unction..."

When merging streaming deltas, delta was converted with as_json.deep_symbolize_keys, which left tool_calls[].type as the string "function". hash_merge_delta concatenates when the existing value is a String (hash[key] += value), so each chunk appended "function" and produced "functionfunctionfunction...".

  • Use delta.deep_to_h so the gem returns symbol-keyed hashes with :type => :function. Merges then hit the replace branch and type stays :function.
  • Match when :function in process_function_calls for consistency.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an OpenAI Chat streaming merge issue where tool_calls[].type could become "functionfunctionfunction..." due to string concatenation during delta merges.

Changes:

  • Convert streaming deltas via api_message.delta.deep_to_h to preserve non-string enum values (preventing hash_merge_delta string concatenation on :type).
  • Normalize tool call type handling by switching process_function_calls to compare api_function_call[:type].to_s against "function".

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@plusor plusor force-pushed the main branch 2 times, most recently from 674a691 to 3df2617 Compare January 30, 2026 14:50
…unction..."

When merging streaming deltas, delta was converted with as_json.deep_symbolize_keys, which left tool_calls[].type as the string "function". hash_merge_delta concatenates when the existing value is a String (hash[key] += value), so each chunk appended "function" and produced "functionfunctionfunction...".

- Use delta.deep_to_h so the gem returns symbol-keyed hashes with :type => :function. Merges then hit the replace branch and type stays :function.
- Match when :function in process_function_calls for consistency.
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