Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#4,022 20 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
api

Hướng nghiên cứu

Bắt đầu tại openai/lib/streaming/_deltas.py, ở accumulate_delta, và tái hiện trường hợp được báo cáo trong đó chỉ mục 1 đến trước chỉ mục 0. Kiểm tra các bài kiểm thử hiện có về việc tích lũy delta và bổ sung kiểm thử cho các chỉ mục thưa, đến không theo thứ tự. Hoàn thành khi mỗi lệnh gọi công cụ vẫn ở chỉ mục dự định, không có trường từ các lệnh gọi riêng biệt bị nối với nhau.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
31.8k
Fork
8k
Merge trung bình
1 ngày 1 giờ
Pull request đã merge (30 ngày)
137

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của openai/openai-python

Tất cả issue của openai/openai-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.