feat(api): singleflight per sandbox, 256-concurrency cap, in-flight gauge#2625
Conversation
…flight gauge Dedupe overlapping eviction attempts for the same sandbox via singleflight, cap concurrent evictions at 256 using errgroup.TryGo so the ticker loop never blocks, and expose an observable gauge (api.evictor.evictions.running) for the in-flight count.
PR SummaryMedium Risk Overview Reviewed by Cursor Bugbot for commit f56fd8b. Bugbot is set up for automated code reviews on this repo. Configure here. |
❌ 6 Tests Failed:
View the full list of 9 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
There was a problem hiding this comment.
Code Review
The use of singleflight.Do inside the errgroup goroutine can lead to starvation because it blocks while waiting for the same sandbox ID, potentially filling all 256 slots with redundant goroutines and preventing the evictor from processing other sandboxes. Replacing singleflight with a sync.Map to track active sandbox IDs and skipping the TryGo call if an eviction is already in progress avoids this blocking and ensures slots remain available for other tasks.
…arvation singleflight.Do blocked inside the errgroup goroutine, so duplicate ticks for the same slow-evicting sandbox piled up as waiters and could exhaust the 256 concurrency cap. Switch to a sync.Map LoadOrStore check before TryGo so duplicates short-circuit without consuming a slot, and derive the in-flight gauge from the map directly.
There was a problem hiding this comment.
An organization admin can view or raise the cap at claude.ai/admin-settings/claude-code. The cap resets at the start of the next billing period.
Once the cap resets or is raised, reopen this pull request to trigger a review.
…auge (#2625) Dedupe overlapping eviction attempts for the same sandbox via `singleflight`, cap concurrent evictions at **256** using `errgroup.TryGo` so the ticker loop never blocks, and expose an observable gauge (api.evictor.evictions.running) for the in-flight count.
…auge (e2b-dev#2625) Dedupe overlapping eviction attempts for the same sandbox via `singleflight`, cap concurrent evictions at **256** using `errgroup.TryGo` so the ticker loop never blocks, and expose an observable gauge (api.evictor.evictions.running) for the in-flight count.
Dedupe overlapping eviction attempts for the same sandbox via
singleflight, cap concurrent evictions at 256 usingerrgroup.TryGoso the ticker loop never blocks, and expose an observable gauge (api.evictor.evictions.running) for the in-flight count.