Commits
Click on a commit to change the comparison rangefix(langchain): prevent index desync causing invalid_tool_calls (#32562)
This fixes issue #32562 where response.output_text.annotation.added events
were advancing the sub-index, causing function_call_arguments.delta chunks
to get different indices and leading to invalid_tool_calls in OpenAI responses.
**Root Cause:**
The annotation event handler called _advance(output_index, content_index)
with sub_idx, while function call argument deltas called _advance(output_index)
without sub_idx. This caused current_index to increment mid-tool-call when
annotations were interleaved with function arguments.
**Fix:**
Change annotation event to call _advance(output_index) without sub_idx,
treating annotations as metadata on existing content rather than new blocks.
**Tests:**
- Added regression test test_tool_call_args_with_annotation_index_consistency
- Verifies tool call chunks maintain consistent indices
- Confirms invalid_tool_calls remains empty
- Ensures complete tool call argument reconstruction
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com> Merge branch 'master' into fix/responses-stream-invalid_tool_calls-32562