Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(concurrency-limit): add staggering to the setTimeout

Gergő Móricza9c3e7ac35c6
diff --git a/apps/api/src/lib/concurrency-limit.ts b/apps/api/src/lib/concurrency-limit.ts
index 132c7356c..52fc2fbdb 100644
--- a/apps/api/src/lib/concurrency-limit.ts
+++ b/apps/api/src/lib/concurrency-limit.ts
@@ -228,7 +228,7 @@ async function getNextConcurrentJob(teamId: string, i = 0): Promise<{
return await new Promise((resolve, reject) => setTimeout(() => {
getNextConcurrentJob(teamId, i + 1).then(resolve).catch(reject);
- }, 250));
+ }, Math.floor(Math.random() * 300))); // Stagger the workers off to break up the clump that causes the race condition
} else {
logger.debug("Removed job from concurrency limit queue", {
teamId,