Skip to content

Feature/en 352/google api rate limits#222

Open
chen7david wants to merge 2 commits into
stagingfrom
feature/EN-352/google-api-rate-limits
Open

Feature/en 352/google api rate limits#222
chen7david wants to merge 2 commits into
stagingfrom
feature/EN-352/google-api-rate-limits

Conversation

@chen7david

Copy link
Copy Markdown
Owner

Summary

Ticket Link

Type of Change

  • ✨ Feature
  • 🐛 Bug Fix
  • 🛠 Refactor
  • 📚 Documentation
  • 🧪 Testing
  • 🚀 Hotfix

Changes Made

  • 💎 Architecture: (e.g., Migrated auth logic to Service layer)
  • 📡 Routes: (e.g., Added GET /api/v1/playlists)
  • 🗄️ Database: (e.g., New columns added to playlists table)
  • 🎨 UI: (e.g., Updated sidebar UI for mobile responsive)

How to Test

  1. 🌐 Navigate to /org/:slug/dashboard
  2. 🖱️ Click "Add Playlist"
  3. ✅ Confirm the playlist appears in the database and list

Risks / Rollback Notes

  • New environment variables added
  • Database migration required
  • High impact to existing functionality

Screenshots (If UI changed)


🏗 Checklist

  • Typecheck: npm run typecheck:api passes.
  • Tests: npm run test:api (or relevant unit tests) passes.
  • Patterns: No direct repository access from handlers. All DB logic is in Services.
  • Boundaries: No external clients (Better Auth, Stripe, etc.) in Repositories.
  • Resilience: get* methods have corresponding NotFoundError test cases.
  • Documentation: docs/ updated if new architecture patterns were introduced.
  • AI Context: docs/AI.md updated if canonical rules changed.

- Added a global cap for Gemini API requests, limiting to 10 requests per minute.
- Integrated a rate limiter into the AiService to manage API call frequency.
- Updated the EntixQueueHandler to defer processing when the rate limit is exceeded.
- Enhanced tests to verify behavior under rate limit conditions.
@chen7david chen7david self-assigned this Jun 10, 2026
@cloudflare-workers-and-pages

Copy link
Copy Markdown
Contributor

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
entix-app-staging af44ad0 Commit Preview URL

Branch Preview URL
Jun 10 2026, 11:27 PM

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: af44ad0a1d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +83 to +84
timestamps.push(now);
await this.kv.set(key, JSON.stringify(timestamps), KV_TTL_SECONDS);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Use an atomic reservation for RPM slots

When multiple queue batches or HTTP requests call acquire() concurrently, they can all read the same timestamp list before any of them writes it back, see capacity, and then each append a slot. Because this KV read/modify/write is not atomic, the new limiter can admit far more than 10 Gemini calls per minute exactly during the bursty queue scenarios it is meant to protect; use a serialization point/atomic primitive for the reservation instead of a plain KV get then set.

Useful? React with 👍 / 👎.

Comment on lines +153 to +155
if (this.rateLimiter) {
await this.rateLimiter.acquire();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid logging planned throttles as pipeline failures

When a vocabulary.process-text job is throttled here, acquire() throws before the Gemini fetch; that exception is caught by VocabularyProcessingService.processText, which invokes the queue's logPipelineFailure hook and inserts a vocabulary.pipeline_failed audit row before the queue handler recognizes the rate-limit error and retries. As a result, normal limiter deferrals create false pipeline-failure audit records for every delayed vocabulary item.

Useful? React with 👍 / 👎.

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.

1 participant