Skip to content

fix: infer missing streaming tool call indexes#3246

Open
pragnyanramtha wants to merge 1 commit into
openai:mainfrom
pragnyanramtha:pragnyan/infer-missing-stream-tool-call-index-2806
Open

fix: infer missing streaming tool call indexes#3246
pragnyanramtha wants to merge 1 commit into
openai:mainfrom
pragnyanramtha:pragnyan/infer-missing-stream-tool-call-index-2806

Conversation

@pragnyanramtha
Copy link
Copy Markdown

Summary

  • infer a missing streaming tool-call delta index when there is only one unambiguous target tool call
  • cover the first tool-call delta omitting index, matching Gemini OpenAI-compatible streaming responses
  • cover follow-up argument deltas omitting index while continuing the sole active tool call

Fixes #2806.

Context

Some OpenAI-compatible streaming providers omit delta.tool_calls[].index. The streaming chat state later indexes into accumulated tool calls with that value, which can raise TypeError: list indices must be integers or slices, not NoneType before user code sees the stream.

This patch only infers an index when the stream is unambiguous: a single incoming tool call with no prior tool call becomes index 0, and a single follow-up delta reuses the sole prior tool-call index. Multi-tool or ambiguous streams remain strict.

Validation

  • uv run --with pytest --with pytest-asyncio --with respx --with inline-snapshot --with rich pytest tests/lib/chat/test_completions_streaming.py -k 'tool_call_delta_without_index' -p no:xdist -o addopts='' -> 2 passed, 15 deselected
  • uv run --with pytest --with pytest-asyncio --with respx --with inline-snapshot --with rich pytest tests/lib/chat/test_completions_streaming.py -p no:xdist -o addopts='' -> 17 passed
  • uv run --with ruff ruff check src/openai/lib/streaming/chat/_completions.py tests/lib/chat/test_completions_streaming.py -> passed
  • uv run --with ruff ruff format src/openai/lib/streaming/chat/_completions.py tests/lib/chat/test_completions_streaming.py -> 2 files left unchanged
  • git diff --check -> passed

Copilot AI review requested due to automatic review settings May 16, 2026 16:40
@pragnyanramtha pragnyanramtha requested a review from a team as a code owner May 16, 2026 16:40
Copy link
Copy Markdown

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

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: 22b6c83817

ℹ️ 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".

Comment thread src/openai/lib/streaming/chat/_completions.py
Copy link
Copy Markdown

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@pragnyanramtha pragnyanramtha force-pushed the pragnyan/infer-missing-stream-tool-call-index-2806 branch from 22b6c83 to 45f4923 Compare May 16, 2026 17:14
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.

gemini-3-flash-preview openai compatible tool call error

2 participants