Repository navigation
feat(anyswe_agent): add opt-in sanitize_git_history - #4017
Open
linj-glitch wants to merge 5 commits into
Open
linj-glitch wants to merge 5 commits into
linj-glitch wants to merge 5 commits into
Conversation
4 tasks done
linj-glitch
marked this pull request as draft
October 5, 2026 06:11
linj-glitch
force-pushed
the
linj/anyswe-sanitize-git-history
branch
from
October 8, 2026 00:15
5c41010 to
b05637e
Compare
linj-glitch
added a commit
to linj-glitch/Gym
that referenced
this pull request
Oct 8, 2026
Some task images ship the upstream clone with history past the base commit: the fix sits on origin/* refs, on a release branch it was backported to, on a later tag, or in the reflog of a clone that was reset to the base commit. `git log --all --grep=<issue words>` plus `git show <sha>` then recovers the reference solution, and an RL policy learns to do that instead of solving the task. The OpenHands harness's own reset only drops refs that descend from the base commit, so a backport onto an older branch stays reachable. With `sanitize_git_history: true`, both harness paths (OpenHands, opencode) run a short script in the image's repository before the agent starts: remove remotes, delete every ref that is not an ancestor of HEAD (or of the instance's base_commit, which the OpenHands harness resets to), delete refs to non-commit objects, expire reflogs and `git gc --prune=now`. Ancestor tags stay, so `git describe` / setuptools-scm versions inside the agent container are unchanged; HEAD and the working tree are untouched, so patch capture and grading are unaffected. Output goes to git_sanitize.log in the rollout's trajectory directory; a failure never blocks the rollout. Off by default. Same flag name as the anyswe_agent option (NVIDIA-NeMo#4017). Signed-off-by: Lin Jia <linj@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Some task images (R2E-Gym, SWE-Gym and SWE-rebench among them) ship the full upstream clone checked out at the base commit, so the fix commit is still reachable through other refs: `git log --all --grep=<issue words>` plus `git show` recovers it. An RL policy learns to mine the history instead of solving the task, and the skill does not transfer to images without future refs. With `sanitize_git_history: true`, the agent's sandbox keeps only the history reachable from HEAD before the agent starts. Every other ref, reflog and remote is deleted, and unreachable objects are pruned with `git gc --prune=now`, bounded by `sanitize_git_history_timeout_s`. If gc exceeds the budget, the history is replaced by a single commit of the current tree. The working tree is untouched. Grading runs in a fresh sandbox and is unaffected. The option defaults to off. Signed-off-by: Lin Jia <linj@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
linj-glitch
force-pushed
the
linj/anyswe-sanitize-git-history
branch
from
October 8, 2026 00:20
b05637e to
095312f
Compare
linj-glitch
added a commit
to linj-glitch/Gym
that referenced
this pull request
Oct 8, 2026
Some task images ship the upstream clone with history past the base commit: the fix sits on origin/* refs, on a release branch it was backported to, on a later tag, or in the reflog of a clone that was reset to the base commit. `git log --all --grep=<issue words>` plus `git show <sha>` then recovers the reference solution, and an RL policy learns to do that instead of solving the task. The OpenHands harness's own reset only drops refs that descend from the base commit, so a backport onto an older branch stays reachable. With `sanitize_git_history: true`, both harness paths (OpenHands, opencode) run a short script in the image's repository before the agent starts: remove remotes, delete every ref that is not an ancestor of HEAD (or of the instance's base_commit, which the OpenHands harness resets to), delete refs to non-commit objects, expire reflogs and `git gc --prune=now`. Ancestor tags stay, so `git describe` / setuptools-scm versions inside the agent container are unchanged; HEAD and the working tree are untouched, so patch capture and grading are unaffected. Output goes to git_sanitize.log in the rollout's trajectory directory; a failure never blocks the rollout. Off by default. Same flag name as the anyswe_agent option (NVIDIA-NeMo#4017). Signed-off-by: Lin Jia <linj@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lin Jia <linj@nvidia.com>
linj-glitch
marked this pull request as ready for review
October 13, 2026 23:08
This was referenced Oct 22, 2026
Signed-off-by: Lin Jia <linj@nvidia.com>
Compare retained refs literally and reject linked/shared Git metadata or alternate object stores before mutation. Check repository access and HEAD, propagate setup/fallback failures, and verify unreachable objects are gone. Document strict setup behavior and cover real Git layouts and failure paths. Signed-off-by: Lin Jia <linj@nvidia.com> (cherry picked from commit 5e41f05218731ef9e669fd9b2134501f3918620e) Signed-off-by: Lin Jia <linj@nvidia.com>
Collaborator
Author
|
/ok to test 5d0ccb3 |
…back Signed-off-by: Lin Jia <linj@nvidia.com>
Collaborator
Author
|
/ok to test 79a310f |
This branch was previously deployed
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.
What and why
Some SWE images contain future branches, tags, remote refs, or reflogs that expose the reference fix. In observed GRPO training, policies learned to mine that history: training reward rose while performance on SWE-bench Verified regressed.
This adds opt-in
sanitize_git_historytoanyswe_agent, disabled by default. Before the agent starts, it keeps the checked-out history, deletes other refs/remotes/reflogs, and prunes unreachable objects. A detached HEAD receives a branch. If garbage collection fails or exceedssanitize_git_history_timeout_s(default 300 seconds, enforced whentimeoutis available), it falls back to one commit of the current working tree. Grading still uses a fresh sandbox. Output is saved asgit_sanitize.txt.The sanitizer compares retained refs literally, rejects linked/shared Git metadata and alternate object stores before mutation, propagates Git and fallback failures, and checks that unreachable objects are actually gone. Unsupported shared layouts or incomplete cleanup fail setup instead of reporting success or allowing the agent to read retained future commits. The fallback also preserves previously tracked files that match ignore rules, using NUL-delimited literal paths, so subsequent fixes remain visible to patch capture. A missing repository remains a no-op. No separate issue is needed for these reproduced in-PR defects.
Validation
Validated head:
79a310f0ab0c569913796d6cd04f93a69ad7066a, including an additive merge of mainf36e126547866601bee9c0671c9b59484ef83723. Python 3.13.14; before running pytest, the runner asserted thatnemo_gym,responses_api_agents.anyswe_agent.app, andagent_runnerwere imported from the reviewed checkout.pytest -q -o addopts= --disable-warnings responses_api_agents/anyswe_agent/tests: 80 passed.pre-commit run --all-files: passed; final PR diff whitespace checks passed and the worktree was clean.Nine real-Git safety regressions failed before the correction and now pass: linked and shared repositories, alternate object stores, separate/symlinked Git directories, kept packs retaining future objects, branch names containing regex metacharacters, ownership errors, and failed fallback initialization. An additional independently identified regression failed before the follow-up fix and now passes: forced garbage-collection failure followed by the real runner snapshot and patch extraction, including ignored tracked filenames containing a newline and brackets. The existing real-repository tests still verify that future commits become unreadable and working files are preserved; sandbox wiring tests cover the opt-in flag.
Rollouts and compatibility
Historical author-reported use of the flag spans several thousand Claude Code GRPO rollouts on R2E-Gym. No fresh model or sandbox rollout was run for this revision; the new failure paths were validated using real temporary Git repositories.
The default remains unchanged. When enabled, setup may reject unsupported Git layouts or cleanup failures; the fallback intentionally discards historical commits while preserving working-tree contents. Current-head CI and maintainer review remain merge gates.