fix: 修复 OpenAI→Claude 流式转换在并行工具调用下的参数粘连 - #72
Open
housiliao wants to merge 1 commit into
Open
Conversation
修复 issue #5483 场景:带 reasoning 的 OpenAI 模型(如 GPT-5.6)流式
/v1/messages + 多 content block(reasoning+text+并行 tool_use)时,
Claude SDK 报 InputValidationError: Read was called with input that
could not be parsed as JSON。
根因(StreamResponseOpenAI2Claude 为单 block 状态机):
- 上游 tool_calls[].index 从未被读取:同 chunk 内第二个及以后的
tool call 增量直接丢弃
- 第二个 tool call 的参数片段全部并入第一个 tool_use block,
生成 {}{}{} 非法 JSON
- None→tools 切换时对未 start 的 block 发幽灵 content_block_stop
- 首块即 tool_calls 时提前 return,首块增量丢失
- usage-only 尾 chunk 导致收尾序列静默丢失
修复:
- ClaudeConvertInfo 新增 ToolCallBlockIndex(上游 index→block index
映射)与 ActiveBlocks(活跃 block 跟踪)
- tools 分支遍历全部增量并按上游 index 路由到各自 content block
- Done 终结调用提前,所有活跃 block 统一补发 stop 后再收尾
测试:新增 service/convert_test.go(协议状态机校验器 + 6 用例,
含 2 个回归保护),全部通过;go vet / go build 通过。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复 issue #5483 场景:带 reasoning 的 OpenAI 模型(如 GPT-5.6)流式 /v1/messages + 多 content block(reasoning+text+并行 tool_use)时, Claude SDK 报 InputValidationError: Read was called with input that could not be parsed as JSON。
根因(StreamResponseOpenAI2Claude 为单 block 状态机):
修复:
测试:新增 service/convert_test.go(协议状态机校验器 + 6 用例,
含 2 个回归保护),全部通过;go vet / go build 通过。