Skip to content
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

feat: add rate limiting and more error handling to Cal.ai #11898

Merged
merged 13 commits into from
Oct 17, 2023

Conversation

DexterStorey
Copy link
Contributor

@DexterStorey DexterStorey commented Oct 15, 2023

What does this PR do?

This PR adds:

  • Rate Limiting (20 emails / day / user)
Screenshot 2023-10-14 at 10 07 19 PM
  • A catch all error for OpenAI rate limit and any other funky action in agent loop that tells user to try again later
Screenshot 2023-10-14 at 10 06 39 PM

Fixes #11916

Requirement/Documentation

Type of change

  • New feature (non-breaking change which adds functionality)

How should this be tested?

To test rate limit: send more than 20 emails / day
To test agent loop 500 catch: overspend OpenAI tokens or use a bad OpenAI API key

  • Tested rate limiting by sending too many requests
  • Confirmed everything else still works with standard tests "Create a booking with...", "What meetings do I have...", etc.

Mandatory Tasks

  • Make sure you have self-reviewed the code. A decent size PR without self-review might be rejected.

Checklist

  • I haven't read the contributing guide
  • My code doesn't follow the style guidelines of this project
  • I haven't commented my code, particularly in hard-to-understand areas
  • I haven't checked if my PR needs changes to the documentation
  • I haven't checked if my changes generate no new warnings
  • I haven't added tests that prove my fix is effective or that my feature works
  • I haven't checked if new and existing unit tests pass locally with my changes

@vercel
Copy link

vercel bot commented Oct 15, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 17, 2023 5:28pm

@vercel
Copy link

vercel bot commented Oct 15, 2023

@DexterStorey is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 15, 2023

Thank you for following the naming conventions! 🙏 Feel free to join our discord and post your PR link to collect XP and win prizes!

@@ -1,4 +1,4 @@
import { TRPCError } from "@calcom/trpc";
import { TRPCError } from "@calcom/trpc/server";
Copy link
Contributor Author

@DexterStorey DexterStorey Oct 15, 2023

Choose a reason for hiding this comment

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

!!!IMPORTANT!!!

We needed to swap this TRPC import from client side to server side because the AI app uses it server side.
Rate limiting in our use case Does not work without this.

We need a senior engineer on Cal team to verify that this change is okay.

We don't know if this has upstream repercussions or if it's no prob.

Please don't merge this without checking this out. 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zomars @emrysal @PeerRich

Flagging this, otherwise, this PR should be good to 🚀

Copy link
Member

Choose a reason for hiding this comment

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

This looks safe to me <3

This is only ever ran on the server in all of use cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah this looks like an ideal change actually

@github-actions
Copy link
Contributor

github-actions bot commented Oct 15, 2023

📦 Next.js Bundle Analysis for @calcom/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@DexterStorey DexterStorey changed the title feat: add rate limiting and more error handling feat: add rate limiting and more error handling to Cal.ai Oct 15, 2023
@DexterStorey DexterStorey marked this pull request as ready for review October 15, 2023 02:30
@PeerRich PeerRich requested a review from sean-brydon October 15, 2023 14:39
@sean-brydon sean-brydon enabled auto-merge (squash) October 15, 2023 17:20
Copy link
Member

@sean-brydon sean-brydon left a comment

Choose a reason for hiding this comment

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

LGTM - always called on server side so that change is fine

NIT: we should move this to a HTTP error in future as now its not always called within trpc

@DexterStorey
Copy link
Contributor Author

Fixes: #11916

@Udit-takkar Udit-takkar disabled auto-merge October 17, 2023 10:08
@Udit-takkar Udit-takkar enabled auto-merge (squash) October 17, 2023 10:10
@PeerRich PeerRich added the High priority Created by Linear-GitHub Sync label Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
High priority Created by Linear-GitHub Sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: "Undefined" Email Subject if left empty
5 participants