Repository navigation
fix(swe_rebench): pin the upstream log parsers to a commit - #6172
Conversation
UPSTREAM_COMMIT was "main" despite the comment saying it is pinned, so each fresh cache cloned whatever upstream head was current and scores could move between runs with no change on our side. Pin it to c71902a8 (2026-03-12), the tree the swe_agents harness graded with. Upstream main has since moved past it (SWE-rebench V2.1, 2026-11-13), but lib/agent/log_parsers.py is unchanged between the pin and that head, so grading is unchanged. Key the clone directory by commit: the clone step returns early when any parser file exists, so a cache filled from main (or an older pin) would otherwise be reused under a new pin. Remove the tree when the fetch or checkout of the pin fails, for the same reason. Co-authored-by: Jiaqi Zeng <[email protected]> Signed-off-by: Ananth Subramaniam <[email protected]>
|
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. |
Workers waiting on the clone lock return as soon as a parser file exists under the destination. Cloning main into the destination and only then fetching the pin let a waiting worker import main's parsers and cache them for the life of the process. Build the tree in a private staging directory (git init, fetch the pinned commit, check out FETCH_HEAD) and rename it into place, so a parser file under the destination always belongs to a complete pinned checkout. A failure removes only the staging directory. This also skips downloading main's tree. Mark the pinned SHA as an allowlisted string for the secrets detector, and assert the pin is a full commit instead of repeating the literal. Signed-off-by: Ananth Subramaniam <[email protected]>
A worker killed during the fetch leaves its .<name>.tmp-<pid> staging tree behind, and the next lock holder has a different pid, so it never removed it. The lock holder has exclusive access, so remove every staging tree for this destination before building a new one. Signed-off-by: Ananth Subramaniam <[email protected]>
Reformat the comments and docstrings added for the parser pin so each sentence sits on its own line. No behavior change. Signed-off-by: Ananth Subramaniam <[email protected]>
yaoyu-33
left a comment
There was a problem hiding this comment.
Thanks for this. It fixes a real gap: UPSTREAM_COMMIT = "main" contradicted the "pinned" comment, and upstream has just moved to V2.1. Fetching by full SHA into a staging dir and publishing with one rename is the right minimal design.
What we checked and found sound, at 665d118:
- Pin and integrity.
git fetch --depth 1 <url> <40-hex sha>followed bycheckout FETCH_HEADproduced HEAD ==c71902a8…against GitHub under both protocol v0 and v2. An unknown SHA fails loudly ("not our ref"). Git names objects by their content hash, so the checked-out tree is bound to the pinned commit. - Upstream parsers.
lib/agent/is identical atc71902a8and3beb41a4, andlib/agent/log_parsers.pylast changed upstream on 2026-02-24. Grading is unchanged and no re-baseline is owed. - Concurrent first fetch. We ran 8 real processes against a local
file://upstream. There was exactly one fetch, every caller loaded a complete tree at the pin, and nothing was left beside the destination. - Failure cleanup. A failed fetch or a non-empty destination leaves no staging dir, lock or tree behind, and the error reaches
verify(), which masks the row asverifier_errorrather than scoring it 0. - Tests and CI. The new tests pass (79 passed in
resources_servers/swe_rebench/tests), and each fails withmain'slog_parsers.py. CI is green on this head and DCO is fine.
The inline comments cover the remaining asks: one weakness in the new visibility test, plus the killed-worker claim and error reporting.
Non-blocking context, no inline comment needed:
- swe_agents'
setup_scripts/swe_rebench.shstill clones upstreammainunpinned. The two graders agree today but could drift on the next upstream parser change, which makes this a good follow-up. - The PR has no labels yet. A
fixtype label and the resources-server area label would help.
| # The lock holder has exclusive access, so any staging tree found here belongs to a killed worker. | ||
| for orphan in destination.parent.glob(f".{destination.name}.tmp-*"): | ||
| shutil.rmtree(orphan, ignore_errors=True) |
There was a problem hiding this comment.
A worker killed by SIGKILL or the OOM killer mid-fetch skips both finally blocks. It therefore leaves the .clone.lockdir behind, not only its .tmp-<pid> dir. The mkdir lock has no owner or age check, so every later caller waits timeout_s (600 s) and raises TimeoutError. Each verify masks the row and the wait repeats on the next verify, until someone deletes the lock by hand. That means this sweep never runs in the killed-worker case the comment and the PR body describe. We reproduced it by SIGKILLing the holder during a slow fetch. test_staging_trees_from_killed_workers_are_removed passes only because it creates the orphan without the lockdir.
The lock itself predates this PR, so a full fix can be a follow-up. For this PR, could you make the TimeoutError say to remove {lock_path} if no clone is running, and reword this comment and the body to match? For the follow-up, write pid/host/time into the lockdir and break the lock when it is stale, once the git calls have a timeout=. Moving to nemo_gym/utils/install_lock.py would not be enough on its own: it runs unlocked where flock is refused (NFS/Lustre), and this sweep would then delete a live holder's staging dir.
There was a problem hiding this comment.
Fixed in e0302d7: the TimeoutError now names the lock and says to remove it if no other worker is fetching (log_parsers.py:73-78). The comment above the sweep now says it runs once that lock is cleared. The test now starts from a lock plus an orphan, the state a killed worker leaves. Automatic stale-lock recovery is left for a follow-up, together with git timeouts.
There was a problem hiding this comment.
Thanks for pushing e0302d7. It is kept as is. The TimeoutError now names the lock and says to remove it when no other worker is fetching. The cleanup comment says the staging sweep runs only once that lock is removed, and the killed-worker test leaves the lock in place, checks the timeout, then removes the lock and checks the sweep.
Breaking a stale lock automatically, with the owner's PID, host and start time written into the lock directory, is left for a follow-up. It depends on adding timeout= to the git calls, as you point out in the event-loop comment.
| on_call = lambda command: seen.append((command, log_parsers._parser_path(destination))) # noqa: E731 | ||
| monkeypatch.setattr(log_parsers.subprocess, "run", self._fake_git([], on_call=on_call)) | ||
| log_parsers._clone_locked(destination) | ||
| assert seen and all(path is None for _, path in seen), seen |
There was a problem hiding this comment.
on_call samples the destination before each git command and never after checkout, so this test cannot see a checkout that writes into the destination. We checked two non-atomic variants: (1) init/fetch/checkout straight into the destination, and (2) rename after fetch, then checkout in place. Both pass all five new tests. Sampling after each command closes the gap: it passes on this PR and fails on both variants. A fail_on="checkout" twin of test_a_failed_fetch_leaves_no_tree_behind would also catch variant (2).
| on_call = lambda command: seen.append((command, log_parsers._parser_path(destination))) # noqa: E731 | |
| monkeypatch.setattr(log_parsers.subprocess, "run", self._fake_git([], on_call=on_call)) | |
| log_parsers._clone_locked(destination) | |
| assert seen and all(path is None for _, path in seen), seen | |
| fake = self._fake_git([]) | |
| def run(args, **kwargs): | |
| fake(args, **kwargs) | |
| seen.append((args[1], log_parsers._parser_path(destination))) | |
| monkeypatch.setattr(log_parsers.subprocess, "run", run) | |
| log_parsers._clone_locked(destination) | |
| assert [command for command, _ in seen] == ["init", "fetch", "checkout"] | |
| assert all(path is None for _, path in seen), seen |
There was a problem hiding this comment.
Fixed in e0302d7: the test now samples after each git command and asserts the command order. A checkout straight into the destination now fails it, and fail_on is parametrized over fetch and checkout.
There was a problem hiding this comment.
Taken in e0302d7. The test now samples the destination after each git command and asserts the order init, fetch, checkout. A clone straight into the destination, and a rename after fetch followed by checkout in place, both fail it now. The failure test is parametrized over fetch and checkout, so a failed checkout also has to leave nothing behind.
| subprocess.run( | ||
| ["git", "fetch", "--depth", "1", UPSTREAM_REPO, UPSTREAM_COMMIT], | ||
| cwd=staging, | ||
| check=True, | ||
| capture_output=True, | ||
| ) | ||
| subprocess.run(["git", "checkout", "-q", "FETCH_HEAD"], cwd=staging, check=True, capture_output=True) |
There was a problem hiding this comment.
All three git calls capture output, but str(CalledProcessError) leaves out stderr. verify() puts str(exc) into failure_reason, so a masked row only says Command [...] returned non-zero exit status 128. The actual cause (not our ref, Could not resolve host, a proxy or auth error) is dropped and logged nowhere. main's clone already had this problem; with the pin, fetch is now the path that fails on offline clusters. Could you catch CalledProcessError around these calls and re-raise, e.g. RuntimeError(f"git {exc.cmd[1]} of {UPSTREAM_COMMIT} failed: {exc.stderr.decode(errors='replace').strip()}") from exc?
There was a problem hiding this comment.
Fixed in 4739c92. Each git command now runs through _git(), which catches CalledProcessError and raises RuntimeError(f"git {args[0]} of {UPSTREAM_REPO} at {UPSTREAM_COMMIT} failed: {stderr}"). failure_reason therefore carries git's own message. A real fetch of an unknown commit now reports fatal: remote error: upload-pack: not our ref .... The failure test's fake git sets stderr and checks that it reaches the exception for both a failed fetch and a failed checkout.
| staging = destination.with_name(f".{destination.name}.tmp-{os.getpid()}") | ||
| try: | ||
| subprocess.run(["git", "init", "-q", str(staging)], check=True, capture_output=True) | ||
| subprocess.run( |
There was a problem hiding this comment.
This one is not introduced here and fits a follow-up. _verify calls resolve_parser synchronously, so this git fetch (no timeout=) and the time.sleep(2.0) wait loop run on the event loop. We measured an 8 s loop stall with timeout_s=6; with the defaults a waiting worker freezes every session for up to 600 s, and a hung fetch has no bound. Loading the parsers once in model_post_init (best effort) or through asyncio.to_thread, and adding timeout= and GIT_TERMINAL_PROMPT=0 to the git calls, would fix it. The timeout is also what makes the stale-lock break above safe.
There was a problem hiding this comment.
Agreed that this belongs in a follow-up, since resolve_parser blocked the event loop on main before this PR as well. The follow-up will load the parsers off the event loop, add timeout= and GIT_TERMINAL_PROMPT=0 to the git calls, and then break a stale lock automatically. Those three go together, because the stale-lock break is only safe once a hung fetch has a bound.
…ublish after each git step A worker killed while it holds the clone lock leaves the lock behind, so the staging sweep only runs once that lock is removed. Say so in the comment and make the TimeoutError name the lock and how to clear it. The visibility test sampled the destination only before each git command, so a checkout straight into the destination passed it. Sample after each command, assert the command order, and cover a failed checkout as well as a failed fetch. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test e0302d7 |
yaoyu-33
left a comment
There was a problem hiding this comment.
Approving at e0302d7. I pushed one commit on top of your branch to address the two RISK comments:
- Killed-worker lock. The
TimeoutErrornow names the lock and says to remove it if no other worker is fetching, and the comment above the staging sweep now says the sweep runs once that lock is cleared. The killed-worker test now starts from what a killed worker actually leaves: the lock plus a staging tree. It checks that the error names the lock, then that the sweep runs after the lock is removed. - Visibility test. It now samples after each git command and asserts the
init,fetch,checkoutorder. The failed-fetch test is parametrized overfetchandcheckout.
Validation:
resources_servers/swe_rebench/tests: 80 passed.- A mutant that checks out straight into the destination now fails the visibility test and both failed-step cases. Before this commit it passed all five tests.
- Scoped
pre-commit run --fileson both files passes. - CI started with
/ok to test.
The two NOTE comments (git stderr in failure_reason, and the git fetch plus lock wait on the event loop) stay open as non-blocking follow-ups, along with stale-lock recovery and pinning swe_agents' setup_scripts/swe_rebench.sh to the same commit.
The PR description still says "the next lock holder removes" staging left by killed workers. With this commit, that holds once the stale lock has been removed.
verify() reports str(exc) as the failure reason, and CalledProcessError leaves stderr out of that string. A masked row therefore said only that git exited with status 128, not whether the fetch hit an unknown commit, a DNS failure or a proxy error. Run each git command through _git(), which re-raises as RuntimeError with git's stderr. Signed-off-by: Ananth Subramaniam <[email protected]>
|
/ok to test 4739c92 |
|
This PR keeps the grading rules fixed between evaluation runs and I was not able to kind any major things to address. It was also accepted by yaoyu-33 before adding fixes to it. |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/43936759552 |
What changed
The SWE-rebench resources server grades rollouts with the log parsers from the upstream
SWE-rebench/SWE-rebench-V2repository, which it clones on first use.UPSTREAM_COMMITinresources_servers/swe_rebench/log_parsers.pywas"main", even though the comment above it says the parsers are pinned. Each fresh cache therefore cloned whatever upstream head was current, so scores could move between runs with no change in Gym.This PR makes five changes to
log_parsers.py:UPSTREAM_COMMITis nowc71902a8cf8d2b725f63d51f199f4d3e56f68d2d(2026-03-12), the tree theswe_agentsharness graded with.main, or from an older pin, stand in for a new pin. The clone now lives inSWE-rebench-V2-<first 12 characters of the commit>.maincheckout or a half-written tree. The staging directory is created withgit init, filled by fetching only the pinned commit, and checked out atFETCH_HEAD, which also avoids downloading themaintree first. A failed fetch or checkout removes only the staging directory.timeout_s, and theTimeoutErrornow names the lock and says to remove it when no other worker is fetching. Once the lock is removed, the next lock holder has exclusive access, so it removes every leftover staging directory for the destination before it builds its own.verify()reportsstr(exc)as the failure reason, andCalledProcessErrorleaves stderr out of that string. Each git command now runs through_git(), which raisesRuntimeErrorwith git's stderr, so a masked row says whether the fetch hit an unknown commit, a DNS failure or a proxy error.Why the pin keeps grading unchanged
Upstream
mainmoved to SWE-rebench V2.1 (3beb41a4) on 2026-11-13, which is the kind of change this pin guards against. The pinned commitc71902a8still exists upstream and is an ancestor of that head.lib/agent/log_parsers.py, the file this server imports, is identical at both commits, and nothing else underlib/agent/changed.Grading with the pin therefore matches grading with the current upstream head. Later upstream changes no longer reach graded results until someone bumps the pin and re-baselines.
Issue
No linked issue. This restores behavior that existing training recipes rely on: graded results that do not depend on when the parser cache was filled.
Tests
The new tests in
resources_servers/swe_rebench/tests/test_app.pyreplacegitwith a fake and check that:mainis ignored, and the parsers load from a fresh fetch and checkout of the pinned commit;init,fetchorcheckoutin the staging directory;Each new test fails on
mainwithout the change tolog_parsers.py. The visibility test also fails for code that clonesmaininto the destination before it fetches the pin, for code that checks out straight into the destination, and for code that renames the staging directory before the checkout.Commands:
PYTHONPATH=$PWD .venv/bin/python -m pytest resources_servers/swe_rebench/tests -q pre-commit run --files resources_servers/swe_rebench/log_parsers.py resources_servers/swe_rebench/tests/test_app.py uvx --from detect-secrets detect-secrets scan resources_servers/swe_rebench/log_parsers.py resources_servers/swe_rebench/tests/test_app.pyRollout evidence
N/A for a model rollout. The pinned commit's parser file is identical to the current upstream head, so a model rollout would grade the same as before.
The clone path was checked against GitHub with a real
load_parsers()call into an empty cache. The cache afterwards held onlySWE-rebench-V2-c71902a8cf8d, checked out atc71902a8cf8d2b725f63d51f199f4d3e56f68d2d, and the parsers loaded from it:Follow-up
verify()callsresolve_parsersynchronously, so the first fetch and the lock wait block the event loop, and the git calls have no timeout. This predates the PR. A follow-up will load the parsers off the event loop, addtimeout=andGIT_TERMINAL_PROMPT=0to the git calls, and then break a stale lock automatically, which is only safe once a hung fetch has a bound.Compatibility
Existing caches under
<cache dir>/SWE-rebench-V2are no longer used, so the first run after this change clones the pinned tree into the new directory. The old directory stays on disk and can be deleted.