Skip to content

fix(orchestrator): annotate ResourceExhausted refusals with the metric that varies - #3584

Open
AdaAibaby wants to merge 1 commit into
e2b-dev:mainfrom
AdaAibaby:fix/orchestrator-resource-exhausted-error-context
Open

AdaAibaby wants to merge 1 commit into
e2b-dev:mainfrom
AdaAibaby:fix/orchestrator-resource-exhausted-error-context

Conversation

@AdaAibaby

@AdaAibaby AdaAibaby commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3583

Problem

When the orchestrator returns a ResourceExhausted gRPC error and the API logs "Node exhausted, trying another node", the attached error string carried no useful numbers. Two of the three sites had no counts at all, and the running-sandboxes one had only the cap:

"max number of running sandboxes on node reached (%d), please retry"   // only max
"too many sandboxes starting on this node, please retry"               // nothing
"too many sandboxes resuming on this node, please retry"               // nothing

Approach: annotate with the value that actually varies at refusal time

A naive fix adds current=N, max=M everywhere. But for the gate sites, current is tautological: the branch only runs because the gate is full, so current always equals max. So each site gets the value that carries real information:

  • running sandboxes — max= (the reserve-within cap). current is definitionally == max here, so only the cap is informative.
  • starting sandboxes (instant TryAcquire) — max=, via a new AdjustableSemaphore.Limit() accessor. A refusal means the gate is full; the cap is the new information.
  • resuming sandboxes (blocking Acquire up to acquireTimeout) — waited= and max=. waited is the differentiating value: it separates a hard timeout (the gate stayed saturated the whole window) from a fast context cancellation — something current/max cannot show.

Only Limit() is added to AdjustableSemaphore; a Current() accessor was intentionally dropped because it carries no information a refusal does not already imply.

After this change

"max number of running sandboxes on node reached: max=50, please retry"
"too many sandboxes starting on this node: max=10, please retry"
"too many sandboxes resuming on this node: waited=15s, max=10, please retry"

Changes

  • packages/shared/pkg/utils/resizable_semaphore.go — add Limit() int64
  • packages/orchestrator/pkg/server/sandboxes.go — max= on the running and starting refusals
  • packages/orchestrator/pkg/server/utils.go — waited= + max= on the resuming refusal

Testing

  • resizable_semaphore_limit_test.go — Limit() tracks the initial cap and SetLimit, independent of held slots.
  • resource_exhausted_message_test.go — the resuming refusal carries waited= and max= via the real waitForAcquire path.
  • sandbox_limit_metric_test.go — updated to the new message formats.
  • go build / go vet clean for packages/shared and packages/orchestrator/pkg/server.

/cc @ryan-sana @jakubno @dobrac @ValentaTomas @arkamar @tvi Looking forward to your code review.

@cla-bot cla-bot Bot added the cla-signed label Aug 18, 2026
@AdaAibaby
AdaAibaby force-pushed the fix/orchestrator-resource-exhausted-error-context branch from 999c1f7 to 8de62ee Compare August 18, 2026 03:17
…c that varies

Fixes e2b-dev#3583

When a node refuses a sandbox with ResourceExhausted and the API logs
"Node exhausted, trying another node", the error string carried no numbers
for two of the three sites, and the running-sandboxes one carried only the
cap. Operators could not tell a saturated node from a throttled start gate.

Add context, choosing per site the value that actually varies at refusal time
rather than a tautological "current" (which always equals the cap the moment
the gate rejects):

- running sandboxes: include max= (the reserve-within cap). current is
  definitionally == max here, so only the cap is informative.
- starting sandboxes (instant TryAcquire): include max= via a new
  AdjustableSemaphore.Limit() accessor. Same reasoning — a refusal means the
  gate is full, so the cap is the new information.
- resuming sandboxes (blocking Acquire up to acquireTimeout): include
  waited= and max=. waited is the differentiating value: it separates a hard
  timeout (gate saturated the whole window) from a fast context cancellation,
  which current/max cannot show.

Only Limit() is added to AdjustableSemaphore; a Current() accessor was
dropped because it carries no information a refusal does not already imply.

Tests:
- resizable_semaphore_limit_test.go: Limit() tracks the initial cap and
  SetLimit, independent of held slots.
- resource_exhausted_message_test.go: the resuming refusal message carries
  waited= and max= via the real waitForAcquire path.
- sandbox_limit_metric_test.go: updated to the new message formats.
@AdaAibaby
AdaAibaby force-pushed the fix/orchestrator-resource-exhausted-error-context branch from 8de62ee to 7b80447 Compare November 10, 2026 12:14
@AdaAibaby AdaAibaby changed the title orchestrator: include current/max counts in ResourceExhausted error messages fix(orchestrator): annotate ResourceExhausted refusals with the metric that varies Nov 10, 2026
@AdaAibaby
AdaAibaby force-pushed the fix/orchestrator-resource-exhausted-error-context branch from 7b80447 to 395969e Compare November 25, 2026 14:03

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

orchestrator: ResourceExhausted error messages don't include current vs max counts

2 participants