Skip to content

feat: retry failed aichat requests #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 8, 2025
Merged

feat: retry failed aichat requests #110

merged 2 commits into from
May 8, 2025

Conversation

ChristopherChudzicki
Copy link
Collaborator

What are the relevant tickets?

Closes https://github.com/mitodl/hq/issues/7238

Description (What does it do?)

This PR enables retries on failed AiChat requests. Requests are retried 3 times with exponential backoff, 1s, 2s, 4s.

Screenshots (if appropriate):

Screenshot 2025-05-08 at 11 52 03 AM

How can this be tested?

The easiest way to test this is illustrated in the screenshot above:

  1. yarn start and navigate to http://localhost:6006/?path=/docs/smoot-design-ai-aichat--docs
  2. Open network tab.
  3. Pick an AiChat story and chat with it.
  4. In network tab, block the chat requests—this will force them to fail and is an easy way to cause network errors.
  5. Send another message. You should see it fail, then see it retried 3 times.

@ChristopherChudzicki ChristopherChudzicki added the Needs Review An open Pull Request that is ready for review label May 8, 2025
@ChristopherChudzicki ChristopherChudzicki changed the title retry failed aichat requests feat: retry failed aichat requests May 8, 2025
Comment on lines +103 to +107
/**
* If true, the chat input will be autofocused on load.
* Defaults to true.
*/
autofocus?: boolean
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This slipped in from our other issue.

return false
}
if (response) {
if (response.status < 400) return false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just for good measure? I wouldn't expect any status < 400 to produce an error to retry on.

Copy link
Collaborator Author

@ChristopherChudzicki ChristopherChudzicki May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually necessary: If you implement retryOn as a function, then that is what determines retry, period.

And for fetch:

  • promise resolve = network response (possibly an error response, based on status code)
  • promise reject = network error

So we really do need to check the status code and explicitly say "Do not retry if < 400".


Alternatively, we could specify retryOn: <array of whitelisted status codes to retry>.

But if we want to retry everything except a specific list, then we need to do it this way.

Copy link
Contributor

@jonkafton jonkafton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, works great!

@ChristopherChudzicki ChristopherChudzicki merged commit c9a51ee into main May 8, 2025
8 checks passed
Copy link

github-actions bot commented May 9, 2025

🎉 This PR is included in version 6.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review An open Pull Request that is ready for review released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants