Skip to content

Let sandboxes receive files too large for a command - #352

Merged
gregorybchris merged 3 commits into
mainfrom
chrisg/sandbox-file-staging
Sep 3, 2026
Merged

gregorybchris merged 3 commits into
mainfrom
chrisg/sandbox-file-staging

Conversation

@gregorybchris

@gregorybchris gregorybchris commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A scorer reaches a sandbox only through a command string. swe-rex runs that through execve, which caps a single argument at 128KB (MAX_ARG_STRLEN). Fixtures larger than that cannot reach the container at all — the request succeeds and the failure happens inside, at the exec boundary.

That is fine for the code evals we have today, where the test payload is a few hundred bytes of assertions. It rules out any task whose fixtures are megabytes rather than kilobytes.

Approach

swe-rex already serves a POST /write_file endpoint whose payload travels in the request body rather than in argv. It was simply never surfaced: SandboxExecutor keeps its runtime private, and CapabilityExecutionEnvironment published only execute / execute_command / execute_code.

  • SandboxExecutor.write_files() exposes it, going through the same transport retries as every other runtime call.
  • SandboxManager.execute_with_files() stages files and runs a command against them while holding a single lease.

The lease is the crux. execute_command leases an executor from the pool per call, so a separate write and run can land on different containers, and the command would execute somewhere its files were never written. Both steps now happen inside one _execute_with_lease.

StagingExecutionEnvironment is declared separately from ExecutionEnvironment rather than added to it, so environments that cannot stage files still satisfy the base protocol, and a scorer needing the capability fails a type check instead of an attribute lookup at runtime.

Tests

tests/core/harness/test_sandbox_file_staging.py asserts the properties that matter:

  • files are present before the command runs
  • with several executors and concurrent calls, each command runs on the executor that received its files
  • staging respects per-executor concurrency limits

Notes

No existing task changes behavior; this only adds a capability. First caller is the LiveCodeBench task, whose test payloads are 10–20MB at p90 — see #354.

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

A few issues need tightening (test assertion for concurrency limits, capability-defaulting semantics, and file-write retry context) before this is safe and verifiable to merge.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds first-class support for staging large fixture payloads into a sandbox via the request body (instead of argv), then executing a command against those files while holding a single executor lease—preventing “write in one container, run in another” race conditions. This extends the execution-environment surface area with an explicit staging capability and introduces targeted tests for the new behavior.

Changes:

  • Expose SandboxExecutor.write_files() backed by swe-rex /write_file with existing transport-retry behavior.
  • Add SandboxManager.execute_with_files() (and capability-scoped wrapper) that stages files + runs the command under the same lease.
  • Introduce StagingExecutionEnvironment protocol and add a new test module for file staging behavior.
File summaries
File Description
tests/core/harness/test_sandbox_file_staging.py New tests covering file staging before execution and executor selection under concurrency.
src/olmo_eval/harness/sandbox/manager.py Adds execute_with_files() that stages files and executes a command under a single lease.
src/olmo_eval/harness/sandbox/executor.py Adds write_files() to send file contents via swe-rex request bodies with retries.
src/olmo_eval/common/execution/environment.py Adds StagingExecutionEnvironment protocol to represent environments that can stage files.
src/olmo_eval/common/execution/init.py Re-exports StagingExecutionEnvironment.
Review details

Suppressed comments (1)

tests/core/harness/test_sandbox_file_staging.py:102

  • This test currently only asserts that all commands eventually ran; it doesn’t assert the key property (“staging respects per-executor concurrency limits”). Once _StagingExecutor tracks peak concurrent writes, assert that peak_writes never exceeds 1 for max_concurrency=1.
    await asyncio.gather(
        *(manager.execute_with_files(f"cmd {index}", {f"/tmp/{index}": "x"}) for index in range(4))
    )

    assert len(executor.commands) == 4
  • Files reviewed: 5/5 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@gregorybchris

Copy link
Copy Markdown
Collaborator Author

Thanks — two of the three were right and are fixed in d25b955.

Retry label doesn't name the path — correct, and it mattered: a failed write reported file write whichever file it was, which is useless precisely when the payload is large. The label is now file write to {path}, so it carries into the retry logs and into the SandboxTransportError raised once retries are exhausted.

Capacity test didn't test capacity — correct, and the sharper point is that the assertion (len(commands) == 4) holds for any capacity, so the test's name was a promise it never checked. The stub now counts operations in flight, following test_sandbox_manager_capacity.py, and asserts peak == 1 at max_concurrency=1. I added a second test at max_concurrency=3 asserting 1 < peak <= 3, so neither test can pass on a counter that is stuck at one.

Worth noting what the assertion actually protects: the lease has to bound writing as well as executing, because that is what stops a concurrent caller replacing a file between another caller's write and its command.

capabilities or Capability.DEFAULT conflating frozenset() with None — the reading is right, but I've left it. execute, execute_command and execute_code all contain that line verbatim (manager.py:486, 511, 541), so changing it only in execute_with_files would leave the manager inconsistent with itself and give four sibling methods two different semantics. It belongs in a change that treats all four together, which is a wider behavioral change than this PR should carry.

@abhishekraok abhishekraok left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good.

Only one issue remaining according to Claude:

write_files is the only runtime call with no timeout.**
execute_command wraps its runtime call in asyncio.wait_for(..., timeout + 1.0);
write_files doesn't. swerex's _request posts with no ClientTimeout, so
aiohttp's 5-minute default applies — and the resulting TimeoutError is
classified by _is_transport_error, so it retries: 4 attempts, ~20 minutes,
then a quarantine health check. Separately, execute_with_files(timeout=...)
bounds only the command, so a caller passing timeout=900 can block well past
that in staging.

Naming the path makes the eventual error good; it doesn't bound how long you
wait for it. With #354's payloads as the first real user, this is the stall
you'd actually hit. Suggest an explicit wait_for around the write, and a
docstring note that timeout covers the command only.

Nit: _StagingExecutor now duplicates the active/peak bookkeeping that
_TrackingExecutor in test_sandbox_manager_capacity.py already has, on top of
the duplicated _manager(). A shared fixture would carry both.

Otherwise good to merge.

@gregorybchris

Copy link
Copy Markdown
Collaborator Author

Both addressed in 4404c9a. The timeout point was right, and worse in practice than the description: I confirmed swerex's _request sets no ClientTimeout at all, and _is_transport_error does classify TimeoutError as retryable, so the sequence really was aiohttp's 5-minute default × 4 attempts before _quarantine_if_unresponsive even ran.

Bounding the write. Each write is now wrapped in asyncio.wait_for, mirroring execute_command — per attempt, inside the retry loop — so the worst case is the retry budget × timeout rather than open-ended. The default is config.command_timeout, the same bound commands get.

The docstring. I went one step further than "timeout covers the command only": execute_with_files now passes its timeout through to write_files, so a caller's bound covers every step — each file write and the command, applied separately. The docstring says exactly that. I preferred this to a hidden second default for writes because a caller who passes timeout=900 for a heavy job gets a predictable bound on everything with one knob, and a large payload that legitimately needs longer than 30s to upload can ask for it. A single value applied to each step is a different promise from one applied to the whole, so that distinction is spelled out.

Tests that would have caught this. Two tests run write_files against a runtime whose writes never finish. With an explicit timeout and with the config default, each gives up after the retry budget (4 attempts), within a couple of seconds, with the path in the error. Worth noting how I confirmed they test the real thing: I stashed the fix and ran them — they don't fail, they hang, which is precisely the behavior being fixed. (Retry backoff is patched to zero in that file so the retries themselves don't add wall-clock time.)

The nit. Agreed. Both files now import a single TrackingExecutor and make_manager from tests/core/harness/sandbox_stubs.py. The stub records every kind of operation (execute_code, execute_command, write_files) through one _run() that does the active/peak bookkeeping, so either test file can assert on capacity, routing or staging without a second copy. I used a plain module rather than a pytest fixture because the tests construct executors with different arguments (max_concurrency, failure modes) per test — a class import carries that more naturally than a fixture would. The capacity tests are unchanged in behavior; only the helper moved.

#354 is rebuilt on this commit and re-verified, including the integration tests against real containers.

gregorybchris and others added 3 commits September 3, 2026 16:49
Scorers reach a sandbox only through a command string, and swe-rex runs that
through execve, which caps a single argument at 128KB. Anything larger than
that has to arrive some other way, which today means it cannot arrive at all:
a task whose fixtures are megabytes rather than kilobytes has no way to get
them into the container.

swe-rex already serves a /write_file endpoint whose payload travels in the
request body rather than in argv. SandboxExecutor.write_files exposes it, and
SandboxManager.execute_with_files stages files and runs a command against
them while holding a single lease. The lease is the point: execute_command
picks an executor from the pool per call, so a separate write and run can
land on different containers and the command would execute somewhere its
files were never written.

StagingExecutionEnvironment is declared separately from ExecutionEnvironment
so that environments which cannot stage files still satisfy the base
protocol, and so a scorer needing this capability fails a type check rather
than an attribute lookup at runtime.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Review feedback on file staging.

A failed write reported "file write" whichever file it was, so a large
fixture failing gave no way to tell which path the transport gave up on. The
retry label now names the path, which carries into the retry logs and into
the error raised once retries are exhausted.

test_staging_respects_executor_capacity asserted only that all four commands
eventually ran, which holds whatever the capacity is. The stub executor now
counts operations in flight, so the test can assert what its name claims: one
slot means writing and running never overlap, which is what stops a
concurrent caller replacing a file between another caller's write and its
command. A second test at three slots asserts the peak rises above one, so
neither test passes on a counter that is always one.

Left alone: `capabilities or Capability.DEFAULT` treats an explicitly empty
frozenset as unset. That reading is real, but execute, execute_command and
execute_code all share the line verbatim, so changing it here alone would
leave the manager inconsistent with itself. It belongs in a change that
treats all four together.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Review feedback on file staging.

write_files was the one runtime call with no timeout. execute_command wraps
its call in asyncio.wait_for; write_files did not, and swe-rex's _request
posts with no client timeout, so a stalled upload waited on aiohttp's default
of five minutes. That timeout is classified as a transport failure and
retried, so a single stuck write could hold a lease for four attempts, some
twenty minutes, before a quarantine health check even began. With
LiveCodeBench's payloads as the first caller, that is the stall a run would
actually hit.

Each write is now bounded by asyncio.wait_for, mirroring execute_command:
per attempt, inside the retry loop, so the worst case is the retry budget
times the timeout rather than open-ended. The default is the config's command
timeout, the same bound commands get. execute_with_files passes its timeout
through, so a caller's bound covers every step rather than the command alone;
the docstring says so, since a single value applied to each step is a
different promise from one applied to the whole.

The staging tests had grown a copy of the active/peak bookkeeping and the
manager factory that test_sandbox_manager_capacity already carried. Both now
use one TrackingExecutor in sandbox_stubs, which records every kind of
operation, so a test of either file can assert on capacity, routing or
staging without a second stub.

Two tests check the bound directly against a runtime whose writes never
finish: an explicit timeout and the config default each give up after the
retry budget, within a couple of seconds, naming the path. Without the bound
those tests do not fail -- they hang, which is the behavior being fixed.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@gregorybchris
gregorybchris force-pushed the chrisg/sandbox-file-staging branch from 4404c9a to 1df3bf9 Compare September 3, 2026 23:49
@gregorybchris
gregorybchris merged commit 254e2c2 into main Sep 3, 2026
10 checks passed
@gregorybchris
gregorybchris deleted the chrisg/sandbox-file-staging branch September 23, 2026 22:57
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.

3 participants