Repository navigation
Validate 'done' field in chat() method - #40
Conversation
There was a problem hiding this comment.
The intent (parity between chat() and _stream_chat() on the done field) is reasonable and the one-line change is well scoped, but as written it breaks an existing test that was not updated in this PR.
agent/core/llm.py:207 — self._validate_response(result, ["done"]) now rejects any non-streaming response without a top-level done key. tests/test_llm.py:85-94 (test_chat_accepts_tool_call_only_response) patches _request to return:
response = {"message": {"role": "assistant", "tool_calls": [...]}}with no done field, then asserts client.chat(...) == response. With this change that call raises OllamaError("Malformed API response: missing required fields ['done']") and the test fails. Please add "done": True to that fixture (and any other _request-patched chat fixture) as part of this PR.
Two smaller points while you're in there:
tests/test_llm.py:96-100(test_chat_rejects_non_dict_message) still passes, but only incidentally —{"message": None}now trips thedonecheck before_validate_message_structureever runs, so the test no longer exercises what its name claims. Adding"done": Trueto that fixture too would keep it meaningful.- There is no new test covering the behavior being added. A test asserting that a non-streaming response missing
doneraisesOllamaErrorwould lock in the parity this PR is after; right now the new line is untested.
Happy to approve once the fixtures are updated and the new validation has coverage.
…sing coverage Add "done": True to the _request fixtures in test_chat_accepts_tool_call_only_response and test_chat_rejects_non_dict_message so they reflect a well-formed response again now that chat() validates the 'done' field, and add test_chat_rejects_response_missing_done to cover the new validation itself. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Verified the reviewer's claims directly against the code and they were correct: Fixed:
Checks: |
There was a problem hiding this comment.
Checked agent/core/llm.py:207 against _validate_response and _validate_message_structure: requiring a top-level done on the non-streaming /api/chat response mirrors the existing check in _stream_chat (llm.py:227), and Ollama's non-streaming chat response does include done. The earlier review's concerns are resolved — test_chat_accepts_tool_call_only_response and test_chat_rejects_non_dict_message both carry "done": True so the latter again reaches the message-structure path, and test_chat_rejects_response_missing_done" covers the new behavior; I grepped tests/and found no other_request-patched chat()fixtures (engine tests patch_call_llm`, so they're unaffected). No security surface touched and the change is limited to the one validation call plus its tests.
What
Add validation that Ollama response contains required 'done' field in non-streaming chat() method, matching the validation already present in _stream_chat().
Why
Ensures consistent response validation across both streaming and non-streaming code paths.