Skip to content

Conversation

@dfavato
Copy link
Contributor

@dfavato dfavato commented Aug 20, 2025

This PR tries to give users some power to work around AI_RetryError.

Some related issues this is aiming are:

This PR is also related to feat: Add retry mechanism for Anthropic overloaded errors however, in #1027 the retry backoff is re-implemented and I'm not sure this is the right approach.

Exponential backoff, and Retry-After behavior is already implemented at ai.util.retry-with-exponential-backoff and it is used in the streamText function here.

I could not find handles in the ai package where we could expose the backoff parameters (delay, maximumDelay, factor, etc..).

If someone can point me to where I should update the documentation, I can do that.

Here's a log from a session where I changed my config.chatMaxRetries to 5.

ERROR 2025-08-20T14:34:51 +14ms service=tui message=AI_RetryError: Failed after 6 attempts. Last error: Provider returned error name=UnknownError Server error

@thdxr
Copy link
Contributor

thdxr commented Aug 21, 2025

can you put this flag under experimental ? will merge it after

@dfavato
Copy link
Contributor Author

dfavato commented Aug 22, 2025

Changed.

Here's a log from a session where I changed my config experimental.chatMaxRetries to 1.

ERROR 2025-08-22T14:37:07 +4ms service=tui message=AI_RetryError: Failed after 2 attempts. Last error: Provider returned error name=UnknownError Server error

And here's a log from a session where I used the default config.

ERROR 2025-08-22T14:48:18 +2ms service=tui message=AI_RetryError: Failed after 4 attempts. Last error: Provider returned error name=UnknownError Server error

@outp1
Copy link

outp1 commented Sep 17, 2025

Why has this become stale? We cannot use OpenAI models, and we need a solution (

@dfavato
Copy link
Contributor Author

dfavato commented Sep 24, 2025

Seems like the team chose to just increase the maxRetries and not expose the config to the users
https://github.com/sst/opencode/blob/dev/packages/opencode/src/session/compaction.ts#L126
https://github.com/sst/opencode/blob/dev/packages/opencode/src/session/prompt.ts#L266

Let me know if you want me to update this PR with the conflict resolution, if not you can close this.

@Sewer56
Copy link
Contributor

Sewer56 commented Sep 24, 2025

I'd be interested nonetheless, because a part of me is curious to see how things would go if I left the agent overnight.
(I've never tried this sort of thing, but even if the result isn't perfect, having something being done when you're not around sounds like a win)

Caveat is, if I leave it overnight, and it gets rate limited, or servers are overloaded, etc. I wouldn't want it to stop; I'd rather have it keep trying as long as it can.

So I could set the limit to like 999 to never stop trying.

@Sewer56
Copy link
Contributor

Sewer56 commented Sep 24, 2025

Ideally exponential backoff would be perfect with this, but I'm not sure if the dev team is interested on that for the time being.

@dfavato
Copy link
Contributor Author

dfavato commented Sep 24, 2025

Exponential backoff, and Retry-After behavior is already implemented at ai.util.retry-with-exponential-backoff and it is used in the streamText.

So this PR would only let users increase the number of retries tried with exponential backoff.

@Sewer56
Copy link
Contributor

Sewer56 commented Sep 24, 2025

Might be worth closing the issue for exponential backoff then.
I was actually unaware this was already implemented.
Seems it was implemented before I started using OpenCode

I still think it'd be useful nonetheless.
On bad times, I've seen Anthropic servers fail for multiple minutes at a time.

@dfavato
Copy link
Contributor Author

dfavato commented Sep 24, 2025

Solved the conflicts just in case.

@rekram1-node
Copy link
Collaborator

Im gonna resolve the merge conflicts and merge this pr

@rekram1-node rekram1-node changed the title tweak: add chatMaxRetries to config tweak: add experimental chatMaxRetries to config Oct 28, 2025
@rekram1-node rekram1-node merged commit b66e7b6 into anomalyco:dev Oct 28, 2025
3 checks passed
@Sewer56
Copy link
Contributor

Sewer56 commented Oct 29, 2025

Ayo merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants