Skip to content

fix: move rate limited queue items off the main queue#2155

Merged
abelanger5 merged 6 commits into
mainfrom
belanger/rate-limiting-requeue
Aug 18, 2025
Merged

fix: move rate limited queue items off the main queue#2155
abelanger5 merged 6 commits into
mainfrom
belanger/rate-limiting-requeue

Conversation

@abelanger5
Copy link
Copy Markdown
Contributor

Description

Currently, items in a queue which are being rate-limited maintain their position in the queue. This means that in cases with heavy use of dynamic rate limits, the head of the queue gets blocked (up to the SERVER_SINGLE_QUEUE_LIMIT, which I believe is 100 by default). This results in many scheduling timeouts, even for items which are not necessarily being rate limited. While this behavior was intended with the v1 refactor, it's undocumented and unexpected thus resembles a bug.

Some other drive-by fixes:

  • Renames the confusingly named package v2 in the v1 scheduler
  • Adds some more traces/spans/attributes to a few components which can be helpful for tracing

Type of change

  • Bug fix (non-breaking change which fixes an issue)

@vercel
Copy link
Copy Markdown

vercel Bot commented Aug 17, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
hatchet-docs Ready Ready Preview Comment Aug 17, 2025 10:09pm
hatchet-v0-docs Ready Ready Preview Comment Aug 17, 2025 10:09pm

@abelanger5 abelanger5 requested review from Copilot and mrkaye97 August 17, 2025 19:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a queue blocking issue with rate-limited items by moving them to a separate table instead of maintaining their position in the main queue. This prevents rate-limited items from blocking the head of the queue and causing scheduling timeouts for non-rate-limited items.

  • Creates a new v1_rate_limited_qis table to store rate-limited queue items separately
  • Adds logic to move rate-limited items with requeue times > 2 seconds to the separate table
  • Fixes package naming inconsistency from v2 to v1 in scheduler components

Reviewed Changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
sql/schema/v1-core.sql Adds new v1_rate_limited_qis table schema
cmd/hatchet-migrate/migrate/migrations/20250817183956_v1_0_37.sql Migration script for the new table
pkg/scheduling/v1/*.go Corrects package name from v2 to v1 across all scheduler files
pkg/repository/v1/sqlcv1/queue.sql* Adds SQL queries for moving and requeuing rate-limited items
pkg/repository/v1/scheduler_queue.go Implements logic to move rate-limited items to separate table
pkg/repository/v1/scheduler_rate_limit.go Updates rate limit repository return type
internal/services/ingestor/ingestor_v1.go Passes context through function calls
internal/services/controllers/v1/task/controller.go Adds telemetry spans

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread pkg/repository/v1/sqlcv1/queue.sql Outdated
Comment thread pkg/repository/v1/scheduler_queue.go Outdated
Copy link
Copy Markdown
Contributor

@mrkaye97 mrkaye97 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, nice idea!

Comment thread cmd/hatchet-migrate/migrate/migrations/20250817183956_v1_0_37.sql Outdated
Comment thread cmd/hatchet-migrate/migrate/migrations/20250817183956_v1_0_37.sql Outdated
Comment thread sql/schema/v1-core.sql Outdated
Comment thread pkg/repository/v1/scheduler_queue.go Outdated
@abelanger5 abelanger5 merged commit 1407594 into main Aug 18, 2025
39 checks passed
@abelanger5 abelanger5 deleted the belanger/rate-limiting-requeue branch August 18, 2025 15:31
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.

3 participants