Repository navigation
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP
LGTM. No concerns found.
I reviewed all three changed files and traced cleanup through verification masking and session teardown retries. The cancellation handling and normal grading contract are consistent with the added and existing tests.
Static review only. I did not execute tests.
Note: formal approval is not available for this request, so this review is posted as a comment only.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
| # The verifier session then stops the sandbox again. | ||
| try: | ||
| await self._inner_container.stop() | ||
| with anyio.fail_after(STOP_TIMEOUT_S, shield=True): |
There was a problem hiding this comment.
With #6410 adding cancellation protection for AsyncSandbox.stop() plus a timeout, do we still need the extra cancellation shield and timeout here?
There was a problem hiding this comment.
No, it's not needed. I dropped the shield and the time limit from cleanup, since #6410 covers both, and rebased onto main in 2544d7e. cleanup is back to main's version.
The run_instance change stays, and #6410 makes it matter more. Before #6410, the unshielded stop raised the middleware's cancellation again, and that escaped the finally before the return. Now the stop finishes inside its shield, so the return in finally swallows the cancellation. The verify then returns a masked result, and an episode session saves it and replays it on retry. The description has the details.
run_instance returned its result from inside its `finally`, which swallowed a cancellation. Since AsyncSandbox.stop is shielded, the stop now finishes under a cancelled request, so nothing after it raises the cancellation again, and a verify cut short by a client disconnect returned a masked "did not complete" result that an episode session saved. The result is now returned after the `finally`, and the logger is closed in an inner `finally`, so a second task cancel during the stop still closes the log file. Signed-off-by: Ananth Subramaniam <[email protected]>
3f4dee7 to
2544d7e
Compare
What does this PR do?
When a swebench verify is cancelled, this PR makes the cancellation reach the caller. Today the verify returns a masked "did not complete" result instead, and an episode session saves that result and replays it on retry.
The swebench resources server grades a patch by calling
run_instanceinresources_servers/swebench/swebench_patches.py. That function stops the verification sandbox and closes its log file in afinallyblock, and it returned its result from inside that block. Areturninsidefinallydiscards whatever exception was propagating, which includesasyncio.CancelledError. The return dates from #2421.#6410 made
AsyncSandbox.stopshielded and bounded in time, so the stop now finishes while the request is being cancelled. That made the swallowed cancellation reachable under the server middleware:finallyblock then raisedCancelledErroragain, which escaped before thereturn. So the cancellation reached the caller, by accident.returnswallows it.run_instancereturnscompleted: False, and_verify, which has noawaitafter it, builds a masked response from that result.verify_task_sandbox_sessionstores the response as the session's verification. A client that disconnects during evaluation and retries gets that masked result replayed instead of a grade, so the sample is lost.A plain
task.cancel()was swallowed the same way, before and after #6410.This PR makes two changes in
run_instance:finallyblock, so a cancellation propagates to the caller. When nothing is cancelled, it returns the same result as before.finally. The shield inAsyncSandbox.stopholds off an anyio cancel scope, not a secondtask.cancel()of the same task, as its docstring says. A second cancel during the stop makescleanupraise, and the innerfinallystill closes the log file.DockerContainer.cleanupalready catchesException, so a failed sandbox stop, including one that runs out of time, still does not escaperun_instance. The only exceptions that now propagate areBaseExceptionsubclasses such asCancelledError.No issue was filed: a reviewer found the bug while reviewing #6230, which moves the harness logs of each verify into a temporary folder. That PR touches the top of
run_instanceand this one touches the end, so they overlap only in context.Validation
resources_servers/swebench/tests/test_app.pyrunrun_instanceon a realAsyncSandboxover the fake provider fromnemo_gym.sandbox.testing, so the stop is shielded and bounded as in production. The provider's evaluation script runs until it is cancelled, and its close awaits before it finishes. The tests check that:task.cancel()makes awaiting it raiseCancelledError, after the sandbox is stopped.run_instanceraise instead of returning a result, after the sandbox is stopped.task.cancel()that arrives while the sandbox stop is running still closes the log file.swebench_patches.py. Removing only the innerfinallyaroundclose_loggerfails only the second-cancel test.pytest resources_servers/swebench/tests/in a venv withswebench==4.1.0.pre-commit run --fileson the changed files.Rollouts
N/A. The change affects only what
run_instancedoes when cancelled. On the normal path the function returns the same dictionary from the same values, and the existing failure-only grading tests runrun_instanceend to end on that path.Compatibility and benchmark impact
None for verifies that are not cancelled. A cancelled verify now ends with
CancelledErrorinstead of returning a masked result, so an episode session no longer saves that result, and a retry grades the patch.