fix: retry on Gemini API errors and handle equip error while a window is open#794
Open
Austin-Lee02 wants to merge 2 commits into
Open
Conversation
Add error handling when equipping items while a window is open. If it still errors, then gracefully fail and log failure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains two small bug fixes:
1. Gemini API retry logic (src/models/gemini.js)
The Gemini API occasionally returns 503 (service unavailable), 429 (rate limited), or an empty response, especially under load with multiple agents running. Previously this caused the agent to crash or silently fail. This adds a retry loop of up to 5 attempts with a 5 second delay between each. The number 5 is rather arbitrary, but I found that the agents usually never exceeded even 3 calls, so 5 calls was just a number I thought was safe, but not ridiculously large as to cause the agent to wait forever.
Edit: I am running with Gemini 2.5 Flash-Lite (for context)
2. Equip crash with open window (src/agent/library/skills.js)
Calling bot.equip(item, 'hand') throws when the bot has a container window open (e.g. a chest). This closes any open window before equipping to hand, and wraps the call in a try/ catch so the agent can recover gracefully instead of crashing. I stumbled into this bug while just having a single agent attempting to progress in a world. This didn't happen often, but it did happen. The most common case I found was with a crafting table and attempting to equip a tool.
P.S. My apologies if this isn't super well written. This is my first PR and doing something like this to be honest! I would love any feedback!! :D