feat(tools): queue hosted-key tool calls instead of failing with 429#4416
feat(tools): queue hosted-key tool calls instead of failing with 429#4416TheodoreSpeaks wants to merge 2 commits intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Replace the per-call distributed lock with a Redis-backed FIFO queue so callers within a workspace get strict ordering instead of racing the bucket. Adds heartbeat-based crash recovery and dead-head reaping in a single Lua script. Bumps Exa search hosted RPM from 5 to 60.
|
@BugBot review |
PR SummaryMedium Risk Overview Adds a new Redis-backed Tool execution now optionally re-acquires a hosted key and retries once after upstream 429 backoff is exhausted, and Exa search hosted RPM is increased from 5 to 60; tests are expanded to cover queue ordering, heartbeat, cap timeouts, and wait-then-succeed flows. Reviewed by Cursor Bugbot for commit 0b80ed3. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0b80ed3. Configure here.
| } | ||
|
|
||
| const sleepMs = Math.max(MIN_QUEUE_RETRY_DELAY_MS, result.retryAfterMs) | ||
| await sleep(sleepMs) |
There was a problem hiding this comment.
Sleep duration can exceed heartbeat TTL, breaking FIFO
Medium Severity
In waitForActorCapacity and waitForDimensionCapacity, the sleep duration is Math.max(MIN_QUEUE_RETRY_DELAY_MS, result.retryAfterMs). The token bucket's retryAfterMs can be up to ~60 seconds (equal to refillIntervalMs), but TICKET_HEARTBEAT_TTL_SECONDS is only 30 seconds. The heartbeat is refreshed before the sleep, so during a 60-second sleep the heartbeat expires at the 30-second mark. Another caller's checkHead Lua script then reaps the "dead" ticket, allowing a second caller to simultaneously act as queue head — breaking the strict FIFO ordering guarantee that the queue is designed to provide.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 0b80ed3. Configure here.


Summary
platform.hosted_key.queue_waited(withqueuePositionfield) andplatform.hosted_key.queue_wait_exceeded.Type of Change
Testing
bun run lintcleanbun run check:api-validation:strictpassesChecklist