Subagent crashes in retry loop when API returns 400 on image processing
Bug Description
When a subagent attempts to read a PNG image file and sends it to the API, the API returns a 400 error (Could not process image). Instead of gracefully handling the error and moving on, the agent gets stuck in an infinite retry loop.
Steps to Reproduce
- Have a PNG image file accessible to the agent (in this case, an emulator screenshot copied to
/tmp/) - Agent reads the image via the
Readtool (succeeds — displays asimage.png 387×533) - API responds with:
400 {"type":"error","error":{"type":"invalid_request_error","message":"Could not process image"},"request_id":"req_011CZG7DkVYBqPQ5iACEk6Fw"} - Agent retries the same operation in a loop indefinitely
Expected Behavior
The agent should catch the API error, inform the user that the image could not be processed, and continue with the conversation (or offer an alternative approach).
Actual Behavior
The agent enters an infinite retry loop, repeatedly attempting to process the image and receiving the same 400 error.
Environment
- Platform: Linux (WSL2)
- Image: PNG, 387×533 pixels (Android emulator screenshot)
- Reproduced across multiple fresh agent shells
Additional Context
The image was a standard Android emulator screenshot. The crash was consistent — deleting the image and starting new agent shells did not help once the loop began. The issue appears to be missing error handling for invalid_request_error responses during image processing in subagents.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗