Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Bug: accumulate_delta corrupts tool call items on out-of-order delta indexes

オープン 初心者向け
#4,022 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
api

調査の方向性

openai/lib/streaming/_deltas.py の accumulate_delta から始め、インデックス 1 がインデックス 0 より先に届くという報告されたケースを再現してください。デルタの蓄積に関する既存のテストを確認し、疎で順不同のインデックスを対象とするテストを追加してください。各ツール呼び出しが意図されたインデックスにとどまり、別々の呼び出しのフィールドが連結されない状態になれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Describe the bug

In openai.lib.streaming._deltas.accumulate_delta, list delta entries with index attributes are inserted into acc_value via acc_value.insert(index, delta_entry) when IndexError occurs:

try:
    acc_entry = acc_value[index]
except IndexError:
    acc_value.insert(index, delta_entry)

In Python, list.insert(index, obj) on a list shorter than index inserts the element at the end of the list (len(list)). When an out-of-order or sparse stream chunk arrives where index > len(acc_value) (for example, index = 1 arrives when acc_value is empty []), acc_value.insert(1, delta_entry) places the item at index 0.

When a subsequent chunk for index = 0 arrives, acc_value[0] matches the entry intended for index 1, causing accumulate_delta(acc_entry, delta_entry) to concatenate strings across distinct tool calls:

  • id: "call_1" + "call_0" -> "call_1call_0"
  • function.name: "func_1" + "func_0" -> "func_1func_0"
  • function.arguments: '{"b": 2}{"a": 1}' (invalid JSON syntax)
To Reproduce
from openai.lib.streaming._deltas import accumulate_delta

acc = {}
# Chunk for index 1 arrives first
accumulate_delta(
    acc,
    {
        "tool_calls": [
            {"index": 1, "id": "call_1", "type": "function", "function": {"name": "func_1", "arguments": '{"b": 2}'}}
        ]
    },
)

# Chunk for index 0 arrives second
accumulate_delta(
    acc,
    {
        "tool_calls": [
            {"index": 0, "id": "call_0", "type": "function", "function": {"name": "func_0", "arguments": '{"a": 1}'}}
        ]
    },
)

print(acc["tool_calls"])
# Corrupted Output: [{'index': 0, 'id': 'call_1call_0', 'type': 'function', 'function': {'name': 'func_1func_0', 'arguments': '{"b": 2}{"a": 1}'}}]
Expected Behavior

List items should occupy their exact numerical index without collisions or string concatenations between different tool calls.

主要言語
Python
スター
31.8k
フォーク
7.3k
平均マージ
1日 3時間
マージ済み PR(30日)
128

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

openai/openai-python のほかの issue

openai/openai-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。