fix: retry sandbox capacity 429 before surfacing to caller#1431
Merged
Conversation
The sandbox sheds load with 429 + Retry-After when its per-pod concurrency cap is reached, but the client treated any non-200 as terminal, so a momentary overshoot surfaced as a hard error on the Code node. Honor the Retry-After with bounded, jittered, abort-aware retries (default 3, via SANDBOX_MAX_RETRIES). Only capacity 429s are retried since the run never started; all other failures stay terminal. Also adds a scaling notes spec for the separate pod-sizing discussion.
Retry-After is read off an HTTP response, so feeding it straight into setTimeout let a buggy or hostile value pin a workflow step on a long timer (CodeQL: resource exhaustion). Clamp the backoff to a 5s ceiling at both the parse site and the timer sink.
CodeQL flagged feeding the Retry-After header into setTimeout as a resource-exhaustion sink, and a Math.min clamp did not break the taint. Drop the header-derived duration entirely and use a fixed, capped, exponential backoff schedule. The 429 is still the retry trigger; only the wait magnitude changes (the sandbox always signals a 1s backoff anyway).
🧹 PR Environment Cleaned UpThe PR environment has been successfully deleted. Deleted Resources:
All resources have been cleaned up and will no longer incur costs. |
ℹ️ No PR Environment to Clean UpNo PR environment was found for this PR. This is expected if:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The code sandbox sheds load with
429 sandbox at capacityplusRetry-After: 1once a pod hits its per-pod concurrency cap. The main-app client treated any non-200 as terminal, so a momentary overshoot above the cluster ceiling surfaced directly to the customer as a failed Code node, even though the server explicitly signals "back off and retry." Paid and enterprise workloads hit this on brief bursts.Change
runRemotenow honors theRetry-Afterthe sandbox already sends:SANDBOX_MAX_RETRIES) with jitter so concurrent callers do not resynchronize into a thundering herd.A
SandboxHttpErrorcarries the status and parsedRetry-Afterso the retry decision does not string-match the message.This absorbs sub-second micro-bursts at zero infra cost. It does not add capacity; that is the separate pod-sizing work captured in
specs/sandbox-scaling.md, included here for the infra discussion.Tests
Added coverage in
tests/unit/sandbox-client.test.ts: retry-then-succeed honoring Retry-After, give-up after the bounded retries on sustained 429, and no-retry on a non-429 error. Full unit suite green, type-check passes.