Repository navigation
Let sandboxes receive files too large for a command - #352
Conversation
There was a problem hiding this comment.
🟡 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_filewith existing transport-retry behavior. - Add
SandboxManager.execute_with_files()(and capability-scoped wrapper) that stages files + runs the command under the same lease. - Introduce
StagingExecutionEnvironmentprotocol 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
_StagingExecutortracks peak concurrent writes, assert thatpeak_writesnever exceeds 1 formax_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.
|
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 Capacity test didn't test capacity — correct, and the sharper point is that the assertion ( 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.
|
abhishekraok
left a comment
There was a problem hiding this comment.
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.
|
Both addressed in 4404c9a. The timeout point was right, and worse in practice than the description: I confirmed swerex's Bounding the write. Each write is now wrapped in The docstring. I went one step further than "timeout covers the command only": Tests that would have caught this. Two tests run The nit. Agreed. Both files now import a single #354 is rebuilt on this commit and re-verified, including the integration tests against real containers. |
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]>
4404c9a to
1df3bf9
Compare
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_fileendpoint whose payload travels in the request body rather than in argv. It was simply never surfaced:SandboxExecutorkeeps its runtime private, andCapabilityExecutionEnvironmentpublished onlyexecute/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_commandleases 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.StagingExecutionEnvironmentis declared separately fromExecutionEnvironmentrather 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.pyasserts the properties that matter: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