[Bug]: Python SDK silently accepts non-JSON 2xx responses
Issue Origin
Observed or reproduced in a real environment
Bug Description
The Python HTTP SDK silently accepts a non-empty, non-JSON response when its HTTP status is successful. For example, a 200 text/html login page makes rm() return normally and add_message() return {}, even though neither response confirms that the operation reached OpenViking.
The same happens with malformed JSON, and affects both synchronous and asynchronous clients.
Steps to Reproduce
- Install
sdk/pythonfrom upstreammainat21a3ca15cc64e54cdaa8f7bdee645e675e41b748. - Have the endpoint respond with HTTP 200 and
<html>Please sign in</html>, or the incomplete JSON{"status":. - Call
rm("viking://resources/demo")oradd_message("demo", "user", "hello"). - Observe a normal return instead of an error.
Expected Behavior
Raise an OpenVikingError when a JSON API returns a non-empty body that cannot be decoded. Preserve existing handling of valid JSON envelopes and empty successful responses, including HTTP 204.
Actual Behavior
rm -> _handle_response -> _handle_response_data and add_message -> _handle_response_data both reach the same exception branch. When response.json() fails, _handle_response_data() raises only for unsuccessful HTTP status codes; a 2xx response falls through to return {}.
Minimal Reproducible Example
This transport fixture makes the invalid response deterministic:
import asyncio
import httpx
from openviking_sdk import AsyncHTTPClient
async def main():
client = AsyncHTTPClient(url="http://localhost:1933")
client._http = httpx.AsyncClient(
base_url="http://localhost:1933",
transport=httpx.MockTransport(
lambda request: httpx.Response(
200,
text="<html>Please sign in</html>",
headers={"Content-Type": "text/html"},
)
),
)
try:
print("rm:", await client.rm("viking://resources/demo"))
print("add_message:", await client.add_message("demo", "user", "hello"))
finally:
await client.close()
asyncio.run(main())
Error Logs
No exception is raised:
rm: None
add_message: {}
OpenViking Version
Upstream main at 21a3ca15cc64e54cdaa8f7bdee645e675e41b748; editable standalone openviking-sdk reports 0.1.15.dev169.
Python Version
3.12.14, with HTTPX 0.28.1
Operating System
macOS
Model Backend
Not applicable; no model calls.
Additional Context
In addition to the transport fixture, I reproduced this through initialized public sync/async clients against a local loopback HTTP recording server. Both operations silently accepted both invalid bodies. Empty HTTP 204 responses also return normally today and should retain that behavior. This is a controlled SDK/HTTP reproduction, not a claim about a live OpenViking deployment.
All 187 existing standalone SDK tests pass on this base, with three pre-existing unawaited-mock warnings.
#5988 fixed the same symptom class in the JavaScript memory-plugin transport after a reported authenticating-gateway deployment returned a login page with status 200. It does not change the Python SDK. Searches of existing issues/PRs for non-JSON, malformed responses, invalid JSON and the Python SDK found no matching Python fix.
Proposed scope: reuse the existing OpenVikingError(code="INTERNAL") path for non-empty JSON-decoding failures even on 2xx statuses. Keep empty successful responses, structured server errors, and successful binary operations unchanged. This affects the SDK's shared JSON error handling, with no additional requests, retries, or server-side changes.
This report was investigated and reproduced by an AI coding agent.