code_puppy icon indicating copy to clipboard operation
code_puppy copied to clipboard

Synthetic API Premature Disconnection Causes `APIConnectionError`

Open diegonix opened this issue 3 months ago • 1 comments

Synthetic API Premature Disconnection Causes APIConnectionError

Version: code_puppy 0.252 Environment: Linux / Python 3.13


Description

Occasionally, the Synthetic API (https://api.synthetic.new) aborts requests prematurely. When this happens, the code_puppy agent crashes with an unhandled APIConnectionError propagated from httpx and openai layers.

The error trace shows a RemoteProtocolError from httpcore, indicating that the server disconnected without sending a response.


Example Traceback

httpcore.RemoteProtocolError: Server disconnected without sending a response.

The above exception was the direct cause of the following exception:
...
openai.APIConnectionError: Connection error.

Triggered during:

Error invoking agent 'code-puppy'
...
File ".../code_puppy/tools/agent_tools.py", line 432, in invoke_agent
    result = await task

Analysis

This appears to occur when the Synthetic API backend closes the connection early — possibly due to transient network issues, API-side throttling, or partial response timeouts.

While code_puppy has built-in retry/backoff handling for other HTTP statuses (e.g., 502 Bad Gateway), these connection-level exceptions are not currently retried, causing the agent to fail abruptly.

Example of existing retry handling:

HTTP retry: Retrying request due to status code 502
HTTP retry: Retrying request due to status code 502
HTTP retry: Retrying request due to status code 502

Suggested Fix

Add graceful handling and retry with exponential backoff for connection-related exceptions such as:

  • httpx.RemoteProtocolError
  • httpx.ReadTimeout
  • openai.APIConnectionError
  • httpcore.RemoteProtocolError

diegonix avatar Nov 06 '25 17:11 diegonix

Need linear backoff on 502/503 and actually Anthropic's 529 (which is a fake HTTP code that they invented)

mpfaffenberger avatar Nov 09 '25 12:11 mpfaffenberger