Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/republic/formats/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ def feed(self, event: str, data: str) -> Iterable[Delta]:
payload = json.loads(data)
if payload.get("type") in {"response.completed", "response.incomplete"}:
self.completed = True
if (
payload.get("type") in {"response.output_item.added", "response.output_item.done"}
Comment thread
PsiACE marked this conversation as resolved.
Resolved
Comment thread
PsiACE marked this conversation as resolved.
Resolved
and payload.get("item") is None
):
return
yield from self._feed_payload(payload)

def _feed_payload(self, payload: Mapping[str, Any]) -> Iterable[Delta]:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_provider_golden.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,3 +738,13 @@ async def test_azure_uses_api_key_header_and_deployment_name(service: FakeServic
assert "40" in second.text
assert service.requests[1].headers["api-key"] == "test-key"
assert_tool_exchange(service, "chat", [call], {"weather": "40 C"})


async def test_responses_null_items_preserve_text_and_tools(service: FakeService) -> None:
load_case(service, "responses_null_output_items_streaming")

response, _ = await respond(make_model(service, "responses"), [republic.user("Hi")], streaming=True)

assert response.text == '{"answer":4}'
assert response.tool_calls == [republic.ToolCall("call_test", "lookup", '{"answer":4}')]
assert response.finish_reason == "tool_calls"
12 changes: 12 additions & 0 deletions tests/test_provider_golden/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,15 @@ OpenRouter tool identity and streaming reasoning, and Azure authentication/routi
same golden runner and numbered response format. `PROVIDER-SAMPLES.md` pins their Fantasy cassette
sources, transformations and response hashes. Recorded provenance describes the inputs; it does not
make Republic's own request conventions evidence of the recorded service's requirements.


## Responses null-item regression

`cases/responses_null_output_items_streaming/0.sse` adapts the synthetic input in
[openai-python@59738a2](https://github.com/openai/openai-python/blob/59738a289ee82c7b86bf1e10230cceb6daa9716d/tests/lib/responses/test_null_output_items.py)
(Apache-2.0; `LICENSE.openai`). Its SHA-256 is
`609c654ee2aa50d590995e15d2515009e868651c02e65c7321d177834ffb8302`.
The upstream construction is serialized as SSE, retaining event order and sequence numbers.
It is not a production recording and does not establish that null items mean keepalives.
The input is replayed through the OpenAI Responses provider. Valid text and calls following
empty output-item events survive. This case does not establish non-streaming or Copilot behavior.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
data: {"type": "response.created", "response": {"id": "resp_test", "output": []}, "sequence_number": 0}

data: {"type": "response.output_item.added", "output_index": 0, "item": null, "sequence_number": 1}

data: {"type": "response.output_item.added", "output_index": 0, "item": {"id": "msg_test", "type": "message", "role": "assistant", "status": "in_progress", "content": []}, "sequence_number": 2}

data: {"type": "response.output_item.added", "output_index": 0, "item": null, "sequence_number": 3}

data: {"type": "response.output_item.added", "output_index": 1, "item": {"id": "fc_test", "type": "function_call", "call_id": "call_test", "name": "lookup", "arguments": "", "status": "in_progress"}, "sequence_number": 4}

data: {"type": "response.content_part.added", "output_index": 0, "content_index": 0, "part": {"type": "output_text", "text": "", "annotations": [], "logprobs": []}, "sequence_number": 5}

data: {"type": "response.output_text.delta", "output_index": 0, "content_index": 0, "item_id": "msg_test", "delta": "{\"answer\":", "logprobs": [], "sequence_number": 6}

data: {"type": "response.function_call_arguments.delta", "output_index": 1, "item_id": "fc_test", "delta": "{\"answer\":", "sequence_number": 7}

data: {"type": "response.output_text.delta", "output_index": 0, "content_index": 0, "item_id": "msg_test", "delta": "4}", "logprobs": [], "sequence_number": 8}

data: {"type": "response.function_call_arguments.delta", "output_index": 1, "item_id": "fc_test", "delta": "4}", "sequence_number": 9}

data: {"type": "response.output_text.done", "output_index": 0, "content_index": 0, "item_id": "msg_test", "text": "{\"answer\":4}", "logprobs": [], "sequence_number": 10}

data: {"type": "response.output_item.done", "output_index": 1, "item": {"id": "fc_test", "type": "function_call", "call_id": "call_test", "name": "lookup", "arguments": "{\"answer\":4}", "status": "completed"}, "sequence_number": 11}

data: {"type": "response.output_item.done", "output_index": 0, "item": {"id": "msg_test", "type": "message", "role": "assistant", "status": "completed", "content": [{"type": "output_text", "text": "{\"answer\":4}", "annotations": [], "logprobs": []}]}, "sequence_number": 12}

data: {"type": "response.completed", "response": {"id": "resp_test", "status": "completed", "output": null}, "sequence_number": 13}

Loading