Repository navigation
fix(mini-swe-agent): score SWE-Bench offline - #414
Conversation
# 🐛 Bug Fix - Replace make_test_spec with direct TestSpec construction. - Avoid unused script generation and GitHub dependency downloads during scoring.
|
Thanks for contributing to Relax, @DrRyanHuang! 感谢你为 Relax 做出贡献! Contribution guide / 贡献指南Describe the problem, your changes, and how you validated them. Keep each PR focused and run 请说明问题、改动和验证方式,保持 PR 聚焦,并在提交前运行 CI commands / CI 指令
Put one command on the first line of a new PR comment. Rerun/cancel require PR authorship or repository write access. 在新 PR 评论的首行写一条指令。PR 作者或有仓库写权限的贡献者可以重跑、取消 CI。 |
Nyanpasu 审查看板审查状态: 💬 已完成 · 有补充意见 审查版本: ca322bb 目标分支: main 本轮(head ca322bb)复核新提交:把 TestSpec 构造抽成 make_test_spec_without_deps() 并附上游 4.1.0 源码 permalink。抽取前后构造字段逐项相同,_swebench_reward() 的判定顺序不变,swebench 仍未在模块级导入;ruff check/format 与 CI 的 Pre-commit 检查均通过。范围接收 1 个文件(examples/mini_swe_agent/agent_server.py),无移出/待确认项。唯一新发现为 P3:PR 正文 “How” 仍描述旧实现位置,建议同步。
审查发现待处理
已解决或已取代
提交范围 · 接收 1 · 建议移出 0 · 待确认 0接收 1 个文件 · 建议移出 0 个文件 · 待确认 0 个文件。移出与待确认部分暂停深审,不代表审查通过。
精简审查与验证依据
生产代码的必要性与替代方案
测试的必要性与替代方案
Powered by Nyanpasu with deepseek-v4.1-flash-ali xhigh, please check the suggestions carefully.
|
rai-studio-bot
left a comment
There was a problem hiding this comment.
审查结论
改动经核对为等价替换:直接构造的 TestSpec 与 make_test_spec(row) 在评分路径消费的字段上逐一相同(已在 swebench 4.1.0 上按 py / 非 py 共 6 组 repo·version 对比验证),而 repo_script_list / env_script_list / eval_script_list 在评分路径中不被使用,因此去掉脚本生成确实消除了 raw.githubusercontent.com 的依赖下载,也消除了由此引发的 404 / 超时导致的评分会话失败。
仅一条非阻塞的测试补充建议(P3),不影响合并。
| fail_to_pass = row.get(FAIL_TO_PASS, []) | ||
| pass_to_pass = row.get(PASS_TO_PASS, []) | ||
| # Scoring existing sandbox output does not need environment or test scripts. | ||
| test_spec = TestSpec( |
There was a problem hiding this comment.
本次修复的失败模式目前没有测试锁定:make_test_spec 会经 make_env_script_list_py → get_requirements/get_environment_yml 请求 raw.githubusercontent.com,取不到文件时 get_requirements_by_commit 直接抛 ValueError;异常从 MyAgent.run 传出后在 agent_server.py:1031 被记为会话错误(即 PR 描述的 Eval 失败)。tests/examples/test_mini_swe_agent_server.py 目前只覆盖进程管理 helper,同样的联网依赖可以被后续重构悄悄带回。
可选补充(非阻塞,按该文件既有约定用 importorskip 守卫):
def test_swebench_reward_does_not_fetch_from_github(monkeypatch) -> None:
pytest.importorskip("swebench")
import swebench.harness.test_spec.python as test_spec_python
def _no_network(*args, **kwargs):
raise AssertionError("host-side scoring must not fetch from GitHub")
monkeypatch.setattr(test_spec_python.requests, "get", _no_network)
row = {"instance_id": "django__django-11099", "repo": "django/django",
"version": "3.0", "FAIL_TO_PASS": "[]", "PASS_TO_PASS": "[]"}
assert agent_server._swebench_reward(row, "log output") in (0.0, 1.0)限制说明:swebench 不是 Relax 依赖,该测试在未安装 swebench 的环境(含当前 CI)会被跳过,主要价值在 example venv 内验证,不影响本次合并。
There was a problem hiding this comment.
CPU CI 环境没有,GPU CI 环境没有,喵的这不就是裸奔吗?写这单测 case 有啥意义???
There was a problem hiding this comment.
你说得对,这个建议我撤回。
swebench 只装在 example 自己的 venv 里,CPU/GPU CI 都没有:.github/workflows/ 下没有任何 swebench 安装,unittest.yml 只装 requirements.txt,而 tests/examples/test_mini_swe_agent_server.py 连 flask / minisweagent 都是靠 importorskip 跳过的。再加一条 importorskip("swebench") 的用例,在两个 CI 里都永远不会执行,拦不住任何回归——留在仓库里确实没有意义,撤回。
这不动摇本次改动本身的结论:被消费字段与 make_test_spec(row) 逐一相同,属等价替换,无阻塞问题。
| repo_script_list=[], | ||
| env_script_list=[], | ||
| eval_script_list=[], | ||
| arch="x86_64", |
There was a problem hiding this comment.
为啥假定是 x86_64?GB200/GB300 之类的 ARM 机器怎么办?
There was a problem hiding this comment.
x86_64 不是这次新引入的假定,而是原路径本来就产生的值:swebench 4.1.0 里 make_test_spec(..., arch: str = "x86_64") 的默认值就是 x86_64(swebench/harness/test_spec/test_spec.py:180),原来的 make_test_spec(row) 没有传 arch,构造出的 TestSpec.arch 一直是 "x86_64"。这里只是把该默认值显式写出来(我用 6 组 repo·version 逐字段对比过,arch 与原路径一致)。
而且 arch 在评分路径里完全不被读取:它只被 TestSpec 的镜像 tag 属性(test_spec.py:84-152)和 dockerfile / 脚本生成(dockerfiles/__init__.py:65)使用,而 _swebench_reward 只消费 instance_id / repo / version / FAIL_TO_PASS / PASS_TO_PASS。
关于“旧版本才有的参数”:在 4.1.0 里 arch 既是 make_test_spec 的参数,也是 TestSpec 的必填字段(dataclass 中它没有默认值),所以这里必须显式传一个值,不能省略。
ARM 宿主机(GB200/GB300)是另一个独立问题:改动前后 arch 都是 x86_64,本次改动没有让它变差;example 的 SIF 由 setup_r2e_data_and_sifs.sh 以 apptainer ... docker:// 直接拉取,脚本里没有任何架构选择,所以“能不能在 ARM 上跑”取决于镜像本身与 apptainer,与这段代码无关。
There was a problem hiding this comment.
4.1.0 的源码 permalink 如下,全部固定到 tag v4.1.0(commit 726c5461):
make_test_spec的签名与默认参数 ——arch: str = "x86_64"(L180):
https://github.com/SWE-bench/SWE-bench/blob/726c5461e2ef52d83cf1ea2107870a8bb3328d57/swebench/harness/test_spec/test_spec.py#L174-L181TestSpecdataclass:arch: str(L39)没有默认值,是必填字段:
https://github.com/SWE-bench/SWE-bench/blob/726c5461e2ef52d83cf1ea2107870a8bb3328d57/swebench/harness/test_spec/test_spec.py#L30-L48- 原路径
make_test_spec(row)生成三个脚本列表的位置(L212-L218,本次改为直接构造后不再生成):
https://github.com/SWE-bench/SWE-bench/blob/726c5461e2ef52d83cf1ea2107870a8bb3328d57/swebench/harness/test_spec/test_spec.py#L212-L218 - 缺 key 时
_from_json_or_obj返回[](L195-L205),与row.get(FAIL_TO_PASS, [])的行为一致:
https://github.com/SWE-bench/SWE-bench/blob/726c5461e2ef52d83cf1ea2107870a8bb3328d57/swebench/harness/test_spec/test_spec.py#L195-L205 - 环境脚本会经
requests.get拉raw.githubusercontent.com,取不到即raise ValueError(L141、L145):
https://github.com/SWE-bench/SWE-bench/blob/726c5461e2ef52d83cf1ea2107870a8bb3328d57/swebench/harness/test_spec/python.py#L137-L147
结论不变:x86_64 是 4.1.0 中 make_test_spec 的默认值,不是本次改动新增的假定;arch 在 TestSpec 里没有默认值,直接构造时必须显式传参,所以这里只能写一个值。
| if any(code in output for code in [APPLY_PATCH_FAIL, RESET_FAILED, TESTS_ERROR, TESTS_TIMEOUT]): | ||
| return 0.0 | ||
| test_spec = make_test_spec(row) | ||
| repo, version = row["repo"], row.get("version") |
There was a problem hiding this comment.
这段代码就是对 https://github.com/SWE-bench/SWE-bench/blob/02e7a74ffd0b707aab73d203fe87bdc7c76afc8e/swebench/harness/utils.py#L251-L273 的 copy 和修改是吧,感觉可以抽成一个函数?比如 make_test_spec_without_deps?
There was a problem hiding this comment.
之前看的代码版本有误,那其他问题就不算问题了,只剩这个建议,抽个函数吧(或者说他本来就是个函数)
# ♻️ Refactor - Extract TestSpec construction into make_test_spec_without_deps. - Document the SWE-bench 4.1.0 upstream source.
rai-studio-bot
left a comment
There was a problem hiding this comment.
审查结论:实现与评分语义一致,仅 PR 描述需同步
本轮复核新提交 ca322bbd(把 TestSpec 构造抽成 make_test_spec_without_deps() 并附上游 4.1.0 源码 permalink):抽取前后构造字段逐项相同(repo/version/arch/FAIL_TO_PASS/PASS_TO_PASS/language/docker_specs/namespace 与三个空脚本列表),_swebench_reward() 的判定顺序(错误码短路 → 构造 → 取 test_cmd → 解析 → 报告)不变,swebench 仍未在模块级导入(TYPE_CHECKING 仅用于类型标注),ruff check / ruff format 与 CI 的 Pre-commit 检查均通过。范围:接收 1 个文件(examples/mini_swe_agent/agent_server.py),无移出/待确认项;无阻塞性问题。
非行级:描述在 PR 正文,不在 diff 行。正文 “How” 仍写“仅修改 agent_server.py 中的 _swebench_reward()”,但 ca322bbd 之后构造已移到新增的 make_test_spec_without_deps()。建议改写为:“在 agent_server.py 中新增 make_test_spec_without_deps()(改编自 SWE-bench 4.1.0 make_test_spec,函数内注释附上游 permalink),_swebench_reward() 改为调用它”,以便按描述即可定位实现,并与代码注释中的上游同步依据保持一致。
审查看板:#414 (comment)
…er-profiler Brings in upstream/main 653c43c..dce533b (redai-studio#257, redai-studio#258, redai-studio#285, redai-studio#323, redai-studio#330, redai-studio#335, redai-studio#408, redai-studio#409, redai-studio#412, redai-studio#414, redai-studio#416, redai-studio#417, redai-studio#419-redai-studio#421, redai-studio#424, redai-studio#426, redai-studio#427, redai-studio#430, and 42 commits synced on 10-12 without PR numbers). The only conflict is relax/utils/env.py: cc4b052 adds the DeepSeek-V4 MXFP4 QAT variables at the same spot where this branch adds the straggler profiler variables. Resolved by keeping both blocks, straggler first.

What
移除 Mini SWE Agent 宿主 SWE-Bench 评分阶段不必要的 GitHub 依赖下载。
Why
当前 Eval 分为两个阶段:先在沙盒中执行测试,再由宿主
_swebench_reward(row, output)解析输出、计算 reward。原实现调用官方
make_test_spec(row)获取评分元数据,但该函数还会生成仓库、环境和测试脚本。环境脚本生成过程中可能下载依赖清单,而这些新生成的脚本不会被当前评分流程执行。官方构造逻辑旧调用链如下,以 requirements 分支为例:
实际 GitHub 下载发生在 SWE-bench 4.1.0 的以下位置:
-r引用的文件。environment.yml。访问
raw.githubusercontent.com下载依赖文件较慢,还可能超时,导致该题评分失败。How
新增
make_test_spec_without_deps(),直接构造官方TestSpec,将当前评分不使用的三个脚本列表设为[],跳过完整 builder 的脚本生成及依赖下载。