Bug: accumulate_delta corrupts tool call items on out-of-order delta indexes
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 openai/lib/streaming/_deltas.py 中的 accumulate_delta 开始,复现报告的索引 1 先于索引 0 到达的情况。检查现有的 delta 累积测试,并添加对稀疏、乱序索引的测试覆盖。完成标准是每个工具调用都保留在其预期索引处,且不同调用中的字段不会被拼接在一起。
由索引模型根据 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 小时
- 30 天内合并 PR
- 128
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
openai/openai-python 的其他 Issue
-
fix(auth): SubjectTokenProviderError drops response and duplicates error message in workload identity providers可能已有人在做 @mohmedmm 于 6 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
openai/openai-python#4017 · 3 条评论 ·
维护者通常 1 天内回复
-
Querystring drops explicit empty-string scalar values可能已有人在做 @sylvesterkaczmarek 于 28 天前认领。 未关闭sdk-breaking-change v4
难度 2/5 1-3 小时 新手友好度 86/100
openai/openai-python#3837 ·
维护者通常 1 天内回复
-
Define + export `ServiceTiers` string literal可能已有人在做 @SparshGarg999 于 54 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
openai/openai-python#3556 · 3 条评论 ·
维护者通常 1 天内回复
-
Empty OPENAI_BASE_URL prevents fallback to default API endpoint可能已有人在做 @Sehastrajit-S 于 21 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 68/100
openai/openai-python#2927 · 7 条评论 ·
维护者通常 1 天内回复
-
Realtime API Pydantic Models incomplete for RealtimeResponseStatus type可能已有人在做 @LuminaX-alt 于 434 天前认领。 未关闭bug openapi
难度 2/5 1-3 小时 新手友好度 78/100
openai/openai-python#2502 · 7 条评论 ·
维护者通常 1 天内回复
查看 openai/openai-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
rpm-software-management/mock#1824 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
jpata/particleflow#520 ·
维护者通常 1 天内回复
-
bug good first issue hacktoberfest
难度 1/5 1 小时以内 新手友好度 78/100
gridhead/gi-loadouts#699 ·
维护者通常 13 天内回复
-
难度 1/5 1 小时以内 新手友好度 86/100
FinanceFlash/unvibecode#206 ·
维护者通常 1 天内回复