Skip to content

[fix][ap] Tell agent sandboxes what their actual CPU limit is - #394

Open
jamie-retool wants to merge 1 commit into
mainfrom
jd/sandbox-cpu-aware-threads
Open

jamie-retool wants to merge 1 commit into
mainfrom
jd/sandbox-cpu-aware-threads

Conversation

@jamie-retool

@jamie-retool jamie-retool commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR

Adds CPU-aware thread pool sizing for sandbox build tools by exposing the container's CPU limit as an environment variable.

What changed?

A new cpuAwareThreads option (defaulting to true) has been added to the sandbox configuration. When enabled, the SANDBOX_CPU_LIMIT environment variable is injected into the sandbox container using a resourceFieldRef pointing to limits.cpu. This allows build tools such as tsc, esbuild, Rolldown, and pnpm to size their thread pools based on the container's actual CPU limit rather than the host node's total CPU count. The chart version has been bumped to 6.12.2.

How to test?

  1. Deploy the Helm chart with the default values and confirm the sandbox container has the SANDBOX_CPU_LIMIT environment variable set to the configured CPU limit (e.g., 2).
  2. Set cpuAwareThreads: false and verify that SANDBOX_CPU_LIMIT is not injected into the container.

Why make this change?

Without this change, build tools inside the sandbox container detect the host node's CPU count when sizing their thread pools, which can far exceed the container's actual CPU limit. This leads to over-provisioned thread pools, resource contention, and degraded performance. By passing the container's CPU limit directly, build tools can right-size their concurrency to match available resources.

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@jamie-retool
jamie-retool marked this pull request as ready for review October 4, 2026 04:30
@greptile-apps

greptile-apps Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium risk] Agent sandbox configuration passes CPU limit to build tools.

The PR appears safe to merge, though fractional sandbox CPU limits will be reported too high.

Findings

  1. P2 Fractional CPU limits round up ▶

Reviews (1) · Last reviewed commit: "[fix][ap] Tell agent sandboxes what thei..."

,{"name": "SANDBOX_GLOBAL_LIFETIME_MS", "value": "{{ $as.sandbox.sandboxGlobalLifetimeMs }}"}
,{"name": "SANDBOX_READY_TIMEOUT_MS", "value": "{{ $as.sandbox.sandboxReadyTimeoutMs }}"}
{{- if $as.sandbox.cpuAwareThreads }}
,{"name": "SANDBOX_CPU_LIMIT", "valueFrom": {"resourceFieldRef": {"resource": "limits.cpu", "divisor": "1"}}}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Fractional CPU limits round up

When a user sets rr.agentSandbox.sandbox.resources.limits.cpu to a fractional value, divisor: "1" rounds SANDBOX_CPU_LIMIT up to a whole core. For example, a 1.5-core limit is reported as 2. Build tools using that value may start too many threads for the sandbox's limit. Pass a value that preserves the fraction in a unit the consumer expects.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants