Skip to content

fix(swe_rebench): pin the upstream log parsers to a commit - #6172

Merged
yaoyu-33 merged 6 commits into
mainfrom
ananthsub/swe-rebench-pin-log-parsers
Nov 16, 2026
Merged

yaoyu-33 merged 6 commits into
mainfrom
ananthsub/swe-rebench-pin-log-parsers

Conversation

@ananthsub

@ananthsub ananthsub commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What changed

The SWE-rebench resources server grades rollouts with the log parsers from the upstream SWE-rebench/SWE-rebench-V2 repository, which it clones on first use. UPSTREAM_COMMIT in resources_servers/swe_rebench/log_parsers.py was "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:

  • Pin the commit. UPSTREAM_COMMIT is now c71902a8cf8d2b725f63d51f199f4d3e56f68d2d (2026-03-12), the tree the swe_agents harness graded with.
  • Key the clone directory by commit. The clone step returns early when any parser file already exists, so a shared directory would let a cache filled from main, or from an older pin, stand in for a new pin. The clone now lives in SWE-rebench-V2-<first 12 characters of the commit>.
  • Publish the tree with one rename. Several server workers can start at once, and a worker waiting on the clone lock returns as soon as a parser file exists. The lock holder now builds the tree in a private staging directory and renames it into place once the pinned commit is checked out, so a waiting worker never loads a main checkout or a half-written tree. The staging directory is created with git init, filled by fetching only the pinned commit, and checked out at FETCH_HEAD, which also avoids downloading the main tree first. A failed fetch or checkout removes only the staging directory.
  • Name a lock left by a killed worker, and remove its staging directory. A worker killed mid-fetch skips its cleanup, so it leaves both its staging directory and the clone lock behind. Later callers time out after timeout_s, and the TimeoutError now 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.
  • Report git's stderr when a git command fails. verify() reports str(exc) as the failure reason, and CalledProcessError leaves stderr out of that string. Each git command now runs through _git(), which raises RuntimeError with 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 main moved to SWE-rebench V2.1 (3beb41a4) on 2026-11-13, which is the kind of change this pin guards against. The pinned commit c71902a8 still 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 under lib/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.py replace git with a fake and check that:

  • the parsers are pinned to a full 40-character commit, and the clone directory name includes that commit;
  • an existing cached clone of main is ignored, and the parsers load from a fresh fetch and checkout of the pinned commit;
  • no parser file appears under the clone directory after init, fetch or checkout in the staging directory;
  • a lock left by a killed worker makes later callers time out with an error that names the lock, and once the lock is removed the next clone removes the leftover staging directory;
  • when the fetch or the checkout fails, the error carries git's stderr and no clone directory, staging directory or lock is left behind.

Each new test fails on main without the change to log_parsers.py. The visibility test also fails for code that clones main into 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.py

Rollout 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 only SWE-rebench-V2-c71902a8cf8d, checked out at c71902a8cf8d2b725f63d51f199f4d3e56f68d2d, and the parsers loaded from it:

PYTHONPATH=$PWD .venv/bin/python -c "from pathlib import Path; from resources_servers.swe_rebench import log_parsers as lp; lp.load_parsers(Path('/tmp/swe-rebench-cache'))"
git -C /tmp/swe-rebench-cache/SWE-rebench-V2-c71902a8cf8d rev-parse HEAD

Follow-up

verify() calls resolve_parser synchronously, 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, add timeout= and GIT_TERMINAL_PROMPT=0 to 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-V2 are 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.

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]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

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]>
@ananthsub
ananthsub marked this pull request as ready for review November 13, 2026 23:36
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 13, 2026 23:37
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 yaoyu-33 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 by checkout FETCH_HEAD produced 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 at c71902a8 and 3beb41a4, and lib/agent/log_parsers.py last 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 as verifier_error rather than scoring it 0.
  • Tests and CI. The new tests pass (79 passed in resources_servers/swe_rebench/tests), and each fails with main's log_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.sh still clones upstream main unpinned. 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 fix type label and the resources-server area label would help.

Comment on lines +80 to +82
# 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

log_parsers.py:80-82

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment on lines +648 to +651
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

test_app.py:648-651

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).

Suggested change
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment on lines +86 to +92
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

log_parsers.py:86-92

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

log_parsers.py:86

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 14, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@yaoyu-33

Copy link
Copy Markdown
Contributor

/ok to test e0302d7

yaoyu-33
yaoyu-33 previously approved these changes Nov 14, 2026

@yaoyu-33 yaoyu-33 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving at e0302d7. I pushed one commit on top of your branch to address the two RISK comments:

  • Killed-worker lock. The TimeoutError now 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, checkout order. The failed-fetch test is parametrized over fetch and checkout.

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 --files on 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.

@yaoyu-33 yaoyu-33 added the ready-to-merge PR is approved, current, and waiting for final CI or merge label Nov 14, 2026
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]>
@ananthsub ananthsub added bug Something isn't working area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers labels Nov 14, 2026
@yaoyu-33

Copy link
Copy Markdown
Contributor

/ok to test 4739c92

@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 16, 2026
@mpatel31415

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot removed the sla:review-overdue Review response is over the one-business-day SLA label Nov 16, 2026
@ananthsub
ananthsub requested review from yaoyu-33 and yfw November 16, 2026 17:09
@yaoyu-33
yaoyu-33 added this pull request to the merge queue Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/43936759552

Merged via the queue into main with commit 59d0b04 Nov 16, 2026
62 checks passed
@yaoyu-33
yaoyu-33 deleted the ananthsub/swe-rebench-pin-log-parsers branch November 16, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers bug Something isn't working ready-to-merge PR is approved, current, and waiting for final CI or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants