Skip to content

fix(mini-swe-agent): score SWE-Bench offline - #414

Merged
SigureMo merged 2 commits into
redai-studio:mainfrom
cattidea:fix/mini-swe-agent-eval-proxy
Oct 5, 2026
Merged

SigureMo merged 2 commits into
redai-studio:mainfrom
cattidea:fix/mini-swe-agent-eval-proxy

Conversation

@DrRyanHuang

@DrRyanHuang DrRyanHuang commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

What

移除 Mini SWE Agent 宿主 SWE-Bench 评分阶段不必要的 GitHub 依赖下载。

Why

当前 Eval 分为两个阶段:先在沙盒中执行测试,再由宿主 _swebench_reward(row, output) 解析输出、计算 reward。

原实现调用官方 make_test_spec(row) 获取评分元数据,但该函数还会生成仓库、环境和测试脚本。环境脚本生成过程中可能下载依赖清单,而这些新生成的脚本不会被当前评分流程执行。官方构造逻辑

旧调用链如下,以 requirements 分支为例:

MyAgent.run()
  ├─ self.env.execute(reward_command)  # 沙盒执行测试
  └─ _swebench_reward(row, output)     # 宿主评分
       └─ make_test_spec(row)
            └─ make_env_script_list(...)
                 └─ make_env_script_list_py(...)
                      └─ get_requirements(...)
                           └─ get_requirements_by_commit(...)
                                └─ requests.get(reqs_url, headers=HEADERS)

实际 GitHub 下载发生在 SWE-bench 4.1.0 的以下位置:

访问 raw.githubusercontent.com 下载依赖文件较慢,还可能超时,导致该题评分失败。

How

新增 make_test_spec_without_deps(),直接构造官方 TestSpec,将当前评分不使用的三个脚本列表设为 [],跳过完整 builder 的脚本生成及依赖下载。

# 🐛 Bug Fix

- Replace make_test_spec with direct TestSpec construction.
- Avoid unused script generation and GitHub dependency downloads during scoring.
@DrRyanHuang
DrRyanHuang requested a review from SigureMo October 5, 2026 14:36
@DrRyanHuang
DrRyanHuang requested a review from yxyOo as a code owner October 5, 2026 14:36
@rai-studio-bot

Copy link
Copy Markdown
Contributor

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 pre-commit run --all-files before submitting.

请说明问题、改动和验证方式,保持 PR 聚焦,并在提交前运行 pre-commit run --all-files。

English contribution guide · 中文贡献指南

CI commands / CI 指令
Command / 指令 Usage / 用途
/rerun Retry failed CI / 重跑失败的 CI
/rerun <target> Rerun a workflow or check / 重跑指定 workflow 或检查
/cancel <workflow> Cancel an entire workflow / 取消整个 workflow
/help Show commands and targets / 查看指令和 target
/review Request a code review / 请求代码 review

Put one command on the first line of a new PR comment. Rerun/cancel require PR authorship or repository write access.

在新 PR 评论的首行写一条指令。PR 作者或有仓库写权限的贡献者可以重跑、取消 CI。

CI usage and targets · CI 用法与 target

@rai-studio-bot

rai-studio-bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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” 仍描述旧实现位置,建议同步。

审查阶段进度范围与结果
常规审查 ✅ 已完成 已核对 ca322bb 的范围与调用链:make_test_spec_without_deps() 与 36b4d98 中的内联构造逐字段相同(repo/version/arch/FAIL_TO_PASS/PASS_TO_PASS/language/docker_specs/namespace 与三个空脚本列表),唯一调用点 _swebench_reward()(同文件:561)逻辑与判定顺序不变;模块级无 swebench 导入(TYPE_CHECKING 仅用于类型标注);ruff check / ruff format 通过,该 head 上 CI 的 Pre-commit 检查已 success。仓库内无其他 make_test_spec 调用点。未发现阻塞性问题;新发现为 PR 描述与实现位置不一致(P3)。
深度审查 ✅ 已完成 改动为窄幅重构(内联构造 → 单调用点 helper),未新增抽象层或协议,故未启动独立设计子任务;由父任务完成生产/测试必要性审计,并以机械字段比对验证等价性。

审查发现

待处理
编号 严重性 问题状态规则来源
F2 Low severity 同步 PR 描述中的实现位置(ca322bbd 后构造已移到 make_test_spec_without_deps) 🚧 未解决 —
已解决或已取代
编号 严重性 问题状态规则来源
F1 Low severity 为“离线评分”补充一个回归测试(已按维护者反馈撤回) ➖ 已被后续变更取代 —
提交范围 · 接收 1 · 建议移出 0 · 待确认 0

接收 1 个文件 · 建议移出 0 个文件 · 待确认 0 个文件。移出与待确认部分暂停深审,不代表审查通过。

文件结论仓库维护必要性依据替代去向或方案
examples/mini_swe_agent/agent_server.py
接收 该文件是 README 记录的既有用户示例;其评分入口 MyAgent.run(同文件:770)在 eval 模式调用 _swebench_reward,本次改动(内联构造 TestSpec → 提取 make_test_spec_without_deps 并附上游 4.1.0 源码 permalink)是该入口在宿主评分阶段保持离线可用的必要修复,且不新增仓库级抽象或依赖。 PR 描述(宿主评分阶段去掉 GitHub 依赖下载)+ 现有调用点 examples/mini_swe_agent/agent_server.py:770 与 README 的“Prepare data and SIF images / Launch training”流程 仅作为外部实验/PR 证据保留不会修复仓库中已发布示例的评分路径;改动 37 行、单文件,无需外部替代机制,也不适合拆到新目录。
精简审查与验证依据
审查范围进度结论
生产代码 ✅ 已完成 对新增的 make_test_spec_without_deps() 做了必要性审计:保留,未发现可删除的多余生产逻辑。
测试 ✅ 已完成 现有 tests/examples/test_mini_swe_agent_server.py 只覆盖进程管理 helper;本轮未新增评分路径测试,理由与上一轮一致并已由维护者确认。

生产代码的必要性与替代方案

范围必须保留的契约更简单的方案结论依据与限制
examples/mini_swe_agent/agent_server.py:511-539 的 make_test_spec_without_deps() 宿主评分只需 instance_id / repo / version / FAIL_TO_PASS / PASS_TO_PASS 以及由 repo·version 派生的 language / docker_specs;调用方为 _swebench_reward()(同文件:561)。 保持 36b4d98 的内联写法(少一个函数);或继续调用 make_test_spec 并对其网络请求打桩。 保留 抽取前后构造语句逐字段机械比对相同(仅 test_spec = TestSpec( 变为 return TestSpec( );三个空脚本列表在评分路径上与 4.1.0 make_test_spec 的生成结果等价(log_parsers 只读 instance_id,脚本列表仅被镜像构建/run_evaluation/modal 使用)。保留理由:把改编自上游的代码与出处注释(固定到 v4.1.0 tag commit 的 permalink)集中一处,便于按上游变化同步。ruff check / format 与 CI Pre-commit 通过。限制:未在真实 R2E 数据行上端到端跑一次 eval。

测试的必要性与替代方案

范围必须保留的契约更简单的方案结论依据与限制
tests/examples/test_mini_swe_agent_server.py 与本次未新增的评分路径测试 该文件是 agent_server 的回归测试(孤儿回收与退出码竞态、Apptainer 实例命名),既有约定用 importorskip 守卫可选依赖。 在同一文件内新增 monkeypatch swebench.harness.test_spec.python.requests.get 的离线评分测试(原 P3 建议,已撤回)。 保留 保留现有测试,不新增。swebench 不是 Relax 依赖,.github/workflows/ 下无任何 swebench 安装(unittest.yml 只装 requirements.txt),该文件连 flask/minisweagent 都靠 importorskip 跳过,因此新增用例在 CPU 与 GPU CI 中都不会执行;维护者在 discussion_r4185396658 中据此否决该建议,撤回记录见 discussion_r4185283937。限制:该离线属性因此没有自动化回归保护,仅由本轮人工验证覆盖。
Powered by Nyanpasu with deepseek-v4.1-flash-ali xhigh, please check the suggestions carefully.

@rai-studio-bot rai-studio-bot 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.

审查结论

改动经核对为等价替换:直接构造的 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),不影响合并。

看板:#414 (comment)

Powered by Nyanpasu with deepseek-v4.1-flash-ali xhigh, please check the suggestions carefully.

Comment thread examples/mini_swe_agent/agent_server.py Outdated
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(

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.

Low severity P3 · 为“离线评分”补充一个回归测试

本次修复的失败模式目前没有测试锁定: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 内验证,不影响本次合并。

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

CPU CI 环境没有,GPU CI 环境没有,喵的这不就是裸奔吗?写这单测 case 有啥意义???

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.

你说得对,这个建议我撤回。

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",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

为啥假定是 x86_64?GB200/GB300 之类的 ARM 机器怎么办?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

SWE-bench/SWE-bench#523 看起来是一个旧版本才有的参数

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.

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,与这段代码无关。

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

给我 4.1.0 版本的源码 permalink @rai-studio-bot

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.

4.1.0 的源码 permalink 如下,全部固定到 tag v4.1.0(commit 726c5461):

结论不变:x86_64 是 4.1.0 中 make_test_spec 的默认值,不是本次改动新增的假定;arch 在 TestSpec 里没有默认值,直接构造时必须显式传参,所以这里只能写一个值。

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

函数里加个注释说明出处,就算将来上游行为修改了也知道怎么同步

@SigureMo SigureMo Oct 5, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

之前看的代码版本有误,那其他问题就不算问题了,只剩这个建议,抽个函数吧(或者说他本来就是个函数)

Comment thread examples/mini_swe_agent/agent_server.py Resolved
Comment thread examples/mini_swe_agent/agent_server.py Resolved
# ♻️ Refactor

- Extract TestSpec construction into make_test_spec_without_deps.
- Document the SWE-bench 4.1.0 upstream source.

@rai-studio-bot rai-studio-bot 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.

审查结论:实现与评分语义一致,仅 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),无移出/待确认项;无阻塞性问题。

Low severity P3 · 同步 PR 描述中的实现位置

非行级:描述在 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)

Powered by Nyanpasu with deepseek-v4.1-flash-ali xhigh, please check the suggestions carefully.

@SigureMo
SigureMo merged commit b81c6cc into redai-studio:main Oct 5, 2026
12 checks passed
@SigureMo
SigureMo deleted the fix/mini-swe-agent-eval-proxy branch October 5, 2026 16:25
Mukayi added a commit to Mukayi/Relax that referenced this pull request Oct 12, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants