-
Notifications
You must be signed in to change notification settings - Fork 10.7k
fix(tasker): make task claiming atomic with PostgreSQL SKIP LOCKED to prevent race conditions #24277
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
base: main
Are you sure you want to change the base?
Conversation
@Nirvik30 is attempting to deploy a commit to the cal Team on Vercel. A member of the Team first needs to authorize it. |
Hey there and thank you for opening this pull request! 👋🏼 We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted. Details:
|
Walkthrough
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/features/tasker/repository.ts (1)
116-116
: Keep in-memoryclaimedAt
consistent with the DB writeWe lock, claim, and persist
claimedAt = now
, but the array we return still reflects the pre-update rows (oftennull
). Any downstream logging/metrics that inspect the returned payload will seeclaimedAt
unset even though the DB row is already claimed. Map the results before returning so the in-memory view matches what we just wrote, without another query.- return tasks; + return tasks.map((task) => ({ + ...task, + claimedAt: now, + }));
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/features/tasker/repository.ts
(3 hunks)packages/prisma/schema.prisma
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
**/*.ts
: For Prisma queries, only select data you need; never useinclude
, always useselect
Ensure thecredential.key
field is never returned from tRPC endpoints or APIs
Files:
packages/features/tasker/repository.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js
.utc()
in hot paths like loops
Files:
packages/features/tasker/repository.ts
**/*.{ts,tsx,js,jsx}
⚙️ CodeRabbit configuration file
Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.
Files:
packages/features/tasker/repository.ts
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Tests / Unit
- GitHub Check: Linters / lint
- GitHub Check: Type check / check-types
- GitHub Check: Codacy Static Code Analysis
This PR fixes a race condition in task claiming by making the process atomic.
Summary of Changes
claimedAt
field to the Task model (with a composite index on[claimedAt, scheduledAt, succeededAt]
).findMany()
with transaction-based claiming using PostgreSQLSELECT FOR UPDATE SKIP LOCKED
.retry()
to clearclaimedAt
, allowing tasks to be picked up again.Benefits
Notes
claimedAt
column before deploying.Fixes #24186