Skip to content

fix(databricks-langchain): don't repeat streamed Responses text - #465

Open
MarcusKoolaard wants to merge 1 commit into
databricks:mainfrom
MarcusKoolaard:fix/responses-duplicate-final-text
Open

fix(databricks-langchain): don't repeat streamed Responses text#465
MarcusKoolaard wants to merge 1 commit into
databricks:mainfrom
MarcusKoolaard:fix/responses-duplicate-final-text

Conversation

@MarcusKoolaard

Copy link
Copy Markdown

Fixes #464.

Summary

_convert_responses_api_chunk_to_lc_chunk suppressed the terminal full-text block only when the immediately previous chunk was response.output_text.delta. Providers close a message with response.output_text.done and response.content_part.done first, so the check never fired and the completed text was appended on top of the streamed deltas — every reply came back doubled.

Those two terminators now count as "already streamed" when the item_id matches.

Test plan

  • New parametrized unit test covering both terminators before output_item.done; existing tests only covered a delta immediately preceding it, which is why this passed CI.

  • pytest tests/unit_tests/test_chat_models.py — 108 passed, 2 skipped.

  • Offline repro of the documented event order through _stream with a stubbed client:

    before: [{'text': 'hello'}, {'text': ' world'}, {'text': 'hello world', 'annotations': []}] -> 'hello worldhello world'
    after : [{'text': 'hello'}, {'text': ' world'}]                                             -> 'hello world'
    
  • Verified live against Unity AI Gateway (Azure Foundry GPT-5.6 and system.ai.claude-haiku-4-5) through a LangGraph agent with tool calls: streamed deltas and the final message now agree.

The terminal full-text block was only suppressed when the immediately
previous chunk was a text delta. Providers close a message with
output_text.done and content_part.done first, so the check never fired
and the completed text was appended on top of the streamed deltas,
doubling every reply.

Fixes databricks#464
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.

ChatDatabricks Responses API streaming emits the final text twice

1 participant