mpfaffenberger / mpfaffenberger/code_puppy
Synthetic API Premature Disconnection Causes `APIConnectionError`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 814
- Forks
- 278
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 76
Description
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.RemoteProtocolErrorhttpx.ReadTimeoutopenai.APIConnectionErrorhttpcore.RemoteProtocolError
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at code_puppy/tools/agent_tools.py around line 432, then trace the existing HTTP retry handling described in the issue. Check how connection-level exceptions from the Synthetic API propagate through httpx and openai. Done means the listed connection exceptions receive graceful exponential-backoff retries instead of crashing the agent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100