| 1 | # Responses tool-stream validation |
| 2 | |
| 3 | Responses-compatible endpoints may omit individual tool-call completion events. |
| 4 | Reasonix can recover a complete `function_call` from the terminal response's |
| 5 | `output`, using `call_id` to avoid dispatching the same recovered call twice. |
| 6 | |
| 7 | A clean completion must not silently lose a tool call: |
| 8 | |
| 9 | - An announced call that remains unfinished at `response.completed` or `[DONE]` |
| 10 | is a protocol error. |
| 11 | - A `function_call` in a completed response must have a call ID, name, string |
| 12 | arguments, and an absent or `completed` status. A malformed call invalidates |
| 13 | that sampling attempt, including any other speculative calls in it. |
| 14 | - Malformed unrelated output items remain independently skippable. String |
| 15 | arguments are still interpreted by the existing tool-validation layer; the |
| 16 | stream guard does not repair or parse their JSON contents. |
| 17 | |
| 18 | The two causes have stable Go identities: `responses.ErrInvalidFunctionCall` |
| 19 | and `responses.ErrUnfinishedFunctionCall`; callers can use `errors.Is` through |
| 20 | wrapping rather than matching message text. This intentionally rejects a |
| 21 | no-argument tool whose terminal item omits `arguments` (the accepted test |
| 22 | control supplies the string `"{}"`) |
| 23 | and a terminal call still marked `in_progress` in `response.completed`. |
| 24 | |
| 25 | These protocol errors are not automatic retry signals. The Agent keeps the |
| 26 | failed attempt out of committed model history and does not execute its client |
| 27 | function calls. Already completed work from earlier attempts is unaffected. |
| 28 | The returned error exposes its cause to the user-facing caller, not the model. |
| 29 | Errors contain no tool arguments or provider payloads. |
| 30 | |
| 31 | Explicit `response.incomplete` output limits retain their truncation warning |
| 32 | and existing recovery behavior. Connection EOF before a terminal remains a |
| 33 | stream interruption. A text-only final answer, even one describing a future |
| 34 | step, remains a valid final; Reasonix does not infer tool calls from prose. |
| 35 | |
| 36 | The regression suite uses local HTTP SSE fixtures through the real Responses |
| 37 | adapter and Agent. It establishes backend behavior, not that a particular |
| 38 | provider emitted those malformed streams. A provider-specific incident still |
| 39 | needs a sanitized event trace before its cause can be attributed. |
| 40 |