Repository navigation
Commit ab02eb6
fix(chat): buffer streamed tool call until name arrives (#577)
Some OpenAI-compatible upstreams (e.g. DeepSeek / Kimi) stream a tool
call whose FIRST `tool_calls` delta carries only `id` + partial
`arguments`, delivering `function.name` in a later delta. The Chat
Completions stream encoder forwarded each delta verbatim, so the first
chunk a client saw had no `function.name`. Strict clients — the Vercel
AI SDK `@ai-sdk/openai-compatible`, and thus opencode — reject the first
streamed chunk for a new tool-call index unless `function.name` is a
string, aborting with:
AI_InvalidResponseDataError: Expected 'function.name' to be a string.
Plain (non-tool) generation was unaffected. PR #552 hardened the
Responses / Messages / Generate Content encoders and the chat decoder
against the same upstream quirk but left the chat encoder naive.
`ChatStreamEncoder` now holds a tool call's opening chunk back —
buffering argument fragments per call — until a non-empty name arrives,
then emits one named opening chunk and streams the remaining arguments.
A call whose name never arrives is dropped, consistent with the
server-tool loop's handling of nameless calls. Encoder-only; the decoder
and the other encoders are untouched.
Adds a regression test that replays the captured wire shape through the
chat decode -> encode round trip and asserts the first emitted chunk
names the function.
Ref: anomalyco/opencode#24137
Co-authored-by: Claude Opus 4.8 <[email protected]>1 parent 5ffe7b1 commit ab02eb6
2 files changed
Lines changed: 145 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
724 | 724 | | |
725 | 725 | | |
726 | 726 | | |
727 | | - | |
| 727 | + | |
728 | 728 | | |
729 | 729 | | |
730 | 730 | | |
| |||
1533 | 1533 | | |
1534 | 1534 | | |
1535 | 1535 | | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
1536 | 1549 | | |
1537 | 1550 | | |
1538 | 1551 | | |
1539 | 1552 | | |
1540 | 1553 | | |
1541 | | - | |
1542 | | - | |
1543 | | - | |
| 1554 | + | |
| 1555 | + | |
1544 | 1556 | | |
1545 | 1557 | | |
1546 | 1558 | | |
1547 | | - | |
| 1559 | + | |
| 1560 | + | |
1548 | 1561 | | |
1549 | | - | |
| 1562 | + | |
1550 | 1563 | | |
1551 | 1564 | | |
1552 | | - | |
1553 | | - | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
1554 | 1571 | | |
1555 | 1572 | | |
1556 | 1573 | | |
| |||
1609 | 1626 | | |
1610 | 1627 | | |
1611 | 1628 | | |
1612 | | - | |
1613 | | - | |
1614 | | - | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
1615 | 1678 | | |
1616 | | - | |
1617 | | - | |
1618 | | - | |
1619 | | - | |
1620 | | - | |
1621 | | - | |
1622 | | - | |
1623 | | - | |
1624 | | - | |
1625 | | - | |
1626 | | - | |
1627 | | - | |
1628 | 1679 | | |
1629 | 1680 | | |
1630 | 1681 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9630 | 9630 | | |
9631 | 9631 | | |
9632 | 9632 | | |
| 9633 | + | |
| 9634 | + | |
| 9635 | + | |
| 9636 | + | |
| 9637 | + | |
| 9638 | + | |
| 9639 | + | |
| 9640 | + | |
| 9641 | + | |
| 9642 | + | |
| 9643 | + | |
| 9644 | + | |
| 9645 | + | |
| 9646 | + | |
| 9647 | + | |
| 9648 | + | |
| 9649 | + | |
| 9650 | + | |
| 9651 | + | |
| 9652 | + | |
| 9653 | + | |
| 9654 | + | |
| 9655 | + | |
| 9656 | + | |
| 9657 | + | |
| 9658 | + | |
| 9659 | + | |
| 9660 | + | |
| 9661 | + | |
| 9662 | + | |
| 9663 | + | |
| 9664 | + | |
| 9665 | + | |
| 9666 | + | |
| 9667 | + | |
| 9668 | + | |
| 9669 | + | |
| 9670 | + | |
| 9671 | + | |
| 9672 | + | |
| 9673 | + | |
| 9674 | + | |
| 9675 | + | |
| 9676 | + | |
| 9677 | + | |
| 9678 | + | |
| 9679 | + | |
| 9680 | + | |
| 9681 | + | |
| 9682 | + | |
| 9683 | + | |
| 9684 | + | |
| 9685 | + | |
| 9686 | + | |
| 9687 | + | |
| 9688 | + | |
| 9689 | + | |
| 9690 | + | |
| 9691 | + | |
| 9692 | + | |
| 9693 | + | |
| 9694 | + | |
| 9695 | + | |
| 9696 | + | |
| 9697 | + | |
| 9698 | + | |
| 9699 | + | |
| 9700 | + | |
| 9701 | + | |
| 9702 | + | |
| 9703 | + | |
9633 | 9704 | | |
9634 | 9705 | | |
9635 | 9706 | | |
| |||
0 commit comments