Repository navigation
Description
Summary
When the body of a streamed response ends before the protocol's terminal event, OpenAICodexProvider and OpenAICompatibleProvider finish with AssistantDoneEvent(reason="stop"). The message holds whatever text arrived and zero usage, and no error is raised.
canonicalize_provider_stream already turns a stream without a terminal event into AssistantErrorEvent ("Provider stream ended without a terminal event"). That check never applies here, because the parsers always emit ProviderResponseEndEvent once the body ends.
Versions
tau-ai 0.4.2 (httpx 0.28.1) and 0.4.12 (httpx 0.29.0), Python 3.13.
Reproduction
An httpx.MockTransport serves a 200 text/event-stream body, and the last event stream_response yields is printed:
- Codex Responses:
response.created, then oneresponse.output_text.delta, with noresponse.completed. - Chat Completions: one chunk with
delta.content, with no chunk carrying afinish_reasonand nodata: [DONE].
Each case is also run once with the terminal event in place, as a control.
import asyncio, json, httpx
from tau_agent.messages import UserMessage
from tau_ai.env import OpenAICompatibleConfig
from tau_ai.openai_codex import OpenAICodexConfig, OpenAICodexCredentials, OpenAICodexProvider
from tau_ai.openai_compatible import OpenAICompatibleProvider
def sse(*events):
return "".join(f"data: {json.dumps(e)}\n\n" for e in events).encode()
def client(body):
return httpx.AsyncClient(transport=httpx.MockTransport(lambda request: httpx.Response(
200, headers={"content-type": "text/event-stream"}, content=body)))
async def credentials():
return OpenAICodexCredentials(access_token="test-token", account_id="test-account")
async def last(provider):
events = [e async for e in provider.stream_response(
model="test-model", system="", messages=[UserMessage(content="hi")], tools=[])]
m = getattr(events[-1], "message", None) or events[-1].error
return type(events[-1]).__name__, events[-1].reason, m.text, m.usage.input, m.usage.output
async def main():
codex = sse({"type": "response.created", "response": {"id": "r1", "status": "in_progress"}},
{"type": "response.output_text.delta", "item_id": "m1", "output_index": 0,
"content_index": 0, "delta": "Hel"})
print(await last(OpenAICodexProvider(
OpenAICodexConfig(credential_resolver=credentials, max_retries=0), client=client(codex))))
chat = sse({"id": "c1", "choices": [{"index": 0, "delta": {"role": "assistant", "content": "Hel"}}]})
print(await last(OpenAICompatibleProvider(
OpenAICompatibleConfig(api_key="test-key", base_url="http://chat.test/v1", max_retries=0),
client=client(chat))))
asyncio.run(main())Result
The same on 0.4.2 and 0.4.12 (the usage figures are the test bodies' own):
| Body | Last event | Text | Usage in / out | Error |
|---|---|---|---|---|
Codex, with response.completed |
AssistantDoneEvent, stop |
Hel |
5 / 2 | none |
Codex, without response.completed |
AssistantDoneEvent, stop |
Hel |
0 / 0 | none |
Chat, with finish_reason and [DONE] |
AssistantDoneEvent, stop |
Hel |
5 / 2 | none |
| Chat, without either | AssistantDoneEvent, stop |
Hel |
0 / 0 | none |
Where it happens
openai_codex._codex_provider_eventsyieldsProviderResponseEndEvent(finish_reason=None)after its SSE loop, whether or not it sawresponse.completed,response.doneorresponse.incomplete.- In
openai_compatible, the stream parsers'finalize()always appends aProviderResponseEndEvent. stream._finish_reason(None)returns"stop".
The other providers were not checked.
Expected
A body that ends before its terminal event should end in AssistantErrorEvent, as canonicalize_provider_stream already does for a stream with no end event. The terminal event is response.completed, response.incomplete or response.done for Responses, and a finish_reason or [DONE] for Chat Completions. Ideally the error would also say what did arrive, such as the number of events parsed, so that a truncated stream can be told apart from an empty answer.
How this showed up
A proxy between the client and the provider truncated streams to their first chunk. The answers were recorded as successful turns with partial or no text and zero usage, with no error at the model-call level.
Activity
Log only a model's reply as a model call
four1er commentedon Nov 27, 2026
Hi, I am reproducing this with the MockTransport cases from the report and preparing a fix so a stream that ends before its terminal event surfaces as an error instead of a normal
stop. Will open a PR shortly.