Repository navigation
fix(cua-bench): raise when the sandbox does not answer in file_exists/directory_exists - #5194
Merged
injaneity merged 1 commit intoOct 14, 2026
Conversation
…/directory_exists On a cua-sandbox session both methods caught every exception and returned False, so a sandbox that froze or crashed read as "the file is missing". A task that scores a missing answer file as 0 (the starter template, example_tasks/hello_file_env) then recorded a reward of 0 for an episode it never scored, and the variant completed. Errors that mean the sandbox did not answer (TimeoutError, ConnectionError, cua_sandbox.SpacesdNotAvailable, and the native SDK's Transport, Timeout, Closed, SpacesdNotAvailable and DaemonNotRunning) now propagate; a path that does not exist still returns False, and other errors still read as missing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Thanks for the quick review and merge! If you have a moment, #4898 is the companion fix on the worker-pool side (the timeout-checker deadlock), and it's still waiting on first-time-contributor CI approval. |
Collaborator
|
Thanks, @TanishGudise. #4898 is on our list; we'll reply there. |
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.
Summary
file_exists()anddirectory_exists()caught every exception and returned False, so a sandbox that froze or crashed read as "the file is missing". A task that scores a missing answer file as 0 (thecb task createstarter template,example_tasks/hello_file_env) then recorded a reward of 0 for an episode it never scored, and the variant was markedcompleted. In RL use that reward reaches the trainer as a genuine failure. Reproduced on a real local container:docker pauseon the sandbox as evaluation started; the agent had solved the task, the evaluation recorded[0.0], the variant completed, and the Tinker loop'straces.load_runsdelivered it as reward 0.SandboxInterface.file_exists/directory_exists(compat/legacy_interface.py) let errors that mean the sandbox did not answer propagate:TimeoutError,ConnectionError,cua_sandbox.SpacesdNotAvailable, and the native SDK'sCuaError.Transport,Timeout,Closed,SpacesdNotAvailableandDaemonNotRunning(looked up lazily, skipped if not installed). A path that does not exist still returns False (cua-sandbox's env transport already answersNotFoundwith False), and other errors still read as missing. TheRemoteDesktopSessiondocstrings say so.Related work
Refs #4929 (fail-closed benchmark scoring, draft) and #5163 (fail closed on missing/invalid evaluator rewards in
run_single_task): same direction, different code path. I found no issue or PR aboutfile_existsswallowing errors.RFC (required for a public SDK, CLI, MCP, protocol, compatibility, permission, or cross-component contract change): not needed in my view: no new API; the methods keep their signatures and still return booleans whenever the sandbox answers.
Compatibility and risk
file_exists/directory_existsnow raise instead of returning False. The variant then fails (and is retryable under--retries) instead of completing with a 0. Two callers change with it:write_bytes(append=True)raisesRuntimeError("Failed to write file: ...")instead of overwriting the file when the existence check fails, and the legacy_send_command("file_exists")dispatch returns{"success": False, "error": ...}instead of{"success": True, "exists": False}. Nothing changes when the sandbox answers.Validation
cua_bench/tests/test_sandbox_exists_errors.py:cua_sandbox.SpacesdNotAvailable) raises from both methods: all 3 fail on main (they read as missing);CuaError.Transport/Timeoutraise throughfile_existsandCuaError.NotFoundreads as missing: fails on main; skipped where the native library is not built (it passes under cua 0.4.1);pytest -q cua_bench/tests --ignore=cua_bench/tests/live: 370 passed, 3 skipped, also with-W error::RuntimeWarning -W error::pytest.PytestUnhandledThreadExceptionWarning(main: 365 passed, 2 skipped). Run with cua-bench-rl's locked environment, which installs this checkout's cua-bench; cua-bench's own lock needscua-fleetfrom wheels.cua.ai, which I could not fetch offline.ghcr.io/trycua/linux:24.04, runc on Colima, cua 0.4.1), the container paused at the start of evaluation of a solved task, 3 seeds each:The same with cua-bench's in-memory test sandbox (a freeze that times out after 20 s): main 1 per run (3/3), this PR 0 (3/3). Both "this PR" rows also included a separate per-variant deadline fix (proposed in #5193;
variant_timeout=90/30), which does not touch evaluation scoring.example_tasks/test_notepad_env(its ownexcept Exception: return [0.0]), the WinArena adapter (controller_adapter.py,evaluator.py,getters_async/file.py), and legacy computer-server sessions (LegacyInterface.file_existsreads.get("exists", False)from a failed command). A Fleet gateway answering Unavailable/DeadlineExceeded surfaces asCuaError.Env("rpc failed: ... (Unavailable)"), which is not matched (that would need message matching). CI:cua-benchtests.Contributor and release checks
no-releaselabel is applied. (Not applicable: this is a releasing fix to cua-bench.)AI assistance
AI tools helped with tracing and tests; I reviewed the diff and can explain every change.