Skip to content

[Bug] SWEBench Verified mini测试时发现模型未运行在正确的环境中 #304

Closed

Description

@SJTUyh

操作系统及版本

ubuntu 20.04

安装工具的python环境

在anaconda/miniconda创建的python虚拟环境

python版本

3.10

AISBench工具版本

3.1.20260415

AISBench执行命令

ais_bench mini_swe_agent_swe_bench_verified_mini.py

模型配置文件或自定义配置文件内容

与配置文件内容无关

预期行为

mini-swe-agent在容器执行过程中执行在指定的conda环境下。

实际行为

mini-swe-agent在容器执行过程中似乎不是执行在容器中指定的conda环境下。
证据如下:

  1. 执行环境中缺失docutils库,但是这个库在 容器中指定的conda环境内是有的
    {
      "content": "<returncode>1</returncode>\n<output>\nTraceback (most recent call last):\n  File \"<string>\", line 5, in <module>\n  File \"/testbed/sphinx/ext/autodoc/__init__.py\", line 20, in <module>\n    from docutils.statemachine import StringList\nModuleNotFoundError: No module named 'docutils'\n</output>",
      "extra": {
        "raw_output": "Traceback (most recent call last):\n  File \"<string>\", line 5, in <module>\n  File \"/testbed/sphinx/ext/autodoc/__init__.py\", line 20, in <module>\n    from docutils.statemachine import StringList\nModuleNotFoundError: No module named 'docutils'\n",
        "returncode": 1,
        "timestamp": 1777302400.3996165,
        "exception_info": ""
      },
      "tool_call_id": "chatcmpl-tool-a6b00b6448b119a1",
      "role": "tool"
    },
    {
      "content": "Let me install the dependencies.</think>",
      "role": "assistant",
      "tool_calls": [
        {
          "function": {
            "arguments": "{\"command\": \"pip install docutils -q\"}",
            "name": "bash"
          },
          "id": "chatcmpl-tool-bf8350a013476e7f",
          "type": "function"
        }
      ],
  1. 部分用例中模型有完整执行pip3 list的记录,这些记录显示的pip3 package与容器中非conda环境下一致:
{
      "content": "<returncode>0</returncode>\n<output>\nPackage                 Version\n----------------------- ----------\narchspec                0.2.1\nboltons                 23.0.0\nBrotli                  1.0.9\ncertifi                 2023.11.17\ncffi                    1.16.0\ncharset-normalizer      2.0.4\nconda                   23.11.0\nconda-content-trust     0.2.0\nconda-libmamba-solver   23.12.0\nconda-package-handling  2.2.0\nconda_package_streaming 0.9.0\ncryptography            41.0.7\ndistro                  1.8.0\nidna                    3.4\njsonpatch               1.32\njsonpointer             2.1\nlibmambapy              1.5.3\nmenuinst                2.0.1\npackaging               23.1\npip                     23.3.1\nplatformdirs            3.10.0\npluggy                  1.0.0\npycosat                 0.6.6\npycparser               2.21\npyOpenSSL               23.2.0\nPySocks                 1.7.1\nrequests                2.31.0\nruamel.yaml             0.17.21\nsetuptools              68.2.2\ntqdm                    4.65.0\ntruststore              0.8.0\nurllib3                 1.26.18\nwheel                   0.41.2\nzstandard               0.19.0\n</output>",
      "extra": {
        "raw_output": "Package                 Version\n----------------------- ----------\narchspec                0.2.1\nboltons                 23.0.0\nBrotli                  1.0.9\ncertifi                 2023.11.17\ncffi                    1.16.0\ncharset-normalizer      2.0.4\nconda                   23.11.0\nconda-content-trust     0.2.0\nconda-libmamba-solver   23.12.0\nconda-package-handling  2.2.0\nconda_package_streaming 0.9.0\ncryptography            41.0.7\ndistro                  1.8.0\nidna                    3.4\njsonpatch               1.32\njsonpointer             2.1\nlibmambapy              1.5.3\nmenuinst                2.0.1\npackaging               23.1\npip                     23.3.1\nplatformdirs            3.10.0\npluggy                  1.0.0\npycosat                 0.6.6\npycparser               2.21\npyOpenSSL               23.2.0\nPySocks                 1.7.1\nrequests                2.31.0\nruamel.yaml             0.17.21\nsetuptools              68.2.2\ntqdm                    4.65.0\ntruststore              0.8.0\nurllib3                 1.26.18\nwheel                   0.41.2\nzstandard               0.19.0\n",
        "returncode": 0,
        "timestamp": 1775764867.9952104,
        "exception_info": ""
      },
      "tool_call_id": "chatcmpl-tool-97be5297181e9e9f",
      "role": "tool"
    },

影响面机会所有的case都会受到影响,被迫让被测模型在一个不恰当的执行环境中解决问题,会影响精度

前置检查

  • 我已读懂主页文档的快速入门,无法解决问题
  • 我已检索过FAQ,无重复问题
  • 我已搜索过现有Issue,无重复问题
  • 我已更新到最新版本,问题仍存在

Activity

  1. added
    bug
    on May 19, 2026
  2. pinned this issue on May 19, 2026
  3. github-actions commented on May 19, 2026

    @github-actions

    🌟欢迎给AISBench benchmark测评工具提issue,您可以先尝试以下途径寻求issue的解决方法:

    1. 【强烈推荐❤️‍🔥】确保issue描述完整后,可以试着将issue交给Ask DeepWiki回答,deepwiki包含了和工具相关的所有知识库
    2. 在 工具历史issue 中通过问题的关键日志片段或关键词检索相似issue
    3. 在 官方文档 的搜索栏中通过问题的关键日志片段或关键词检索
    4. 寻求仓库维护者的帮助(issue评论区中 @SJTUyh)
  4. github-actions commented on May 19, 2026

    @github-actions

    🤖 基于AI机器人的issue内容完整性检查结果:

    问题内容检查结果

    检查状态

    PASS

    详细检查

    • 操作系统及版本: COMPLETE
    • 安装工具的python环境: COMPLETE
    • python版本: COMPLETE
    • AISBench工具版本: COMPLETE
    • AISBench执行命令: COMPLETE
    • 模型配置文件或自定义配置文件内容: COMPLETE
    • 实际行为: COMPLETE

    改进建议

    所有内容已完备!

    补充说明

    Issue内容非常详细和完整,提供了清晰的操作系统、环境信息、工具版本、执行命令,以及详细的预期行为和实际行为描述,并附带了充分的证据(错误日志和pip list输出)。“影响面”的补充也很有价值。整体信息量充足,有助于问题的排查。

    👉 如果想重新检查,在评论区@issue_checker即可。

    【强烈推荐❤️‍🔥】确保issue描述完整后,可以试着将issue交给Ask DeepWiki回答,deepwiki包含了和工具相关的所有知识库

  5. added
    content_check_passed
    on May 19, 2026
  6. SJTUyh commented on May 19, 2026

    @SJTUyh
    CollaboratorAuthor

    这个问题在aarch64的环境出现,因为官方本身不支持aarch64,AISBench是通过docker模拟x86_64环境跑的,不确定是不是这个原因造成的。但是大概率单纯是python中通过subprocess.run执行docker exec 命令进容器没有自动执行bashrc等操作

  7. SJTUyh commented on May 19, 2026

    @SJTUyh
    CollaboratorAuthor

    目前可尝试的解决方法,需要修改mini-swe-agent中的代码:https://github.com/SWE-agent/mini-swe-agent/blob/60f566bd/src/minisweagent/environments/docker.py#L101

    import os
    from typing import Any
    
    def execute(self, action: dict, cwd: str = "", *, timeout: int | None = None) -> dict[str, Any]:
        """Execute a command in the Docker container and return the result as a dict."""
        command = action.get("command", "", str)
        cwd = cwd or self.config.cwd
        assert self.container_id, "Container not started"
    
        cmd = [self.config.executable, "exec", "-w", cwd]
        for key in self.config.forward_env:
            if (value := os.getenv(key)) is not None:
                cmd.extend(["-e", f"{key}={value}"])
        for key, value in self.config.env.items():
            cmd.extend(["-e", f"{key}={value}"])
    
        # 特殊命令:保持原逻辑,不主动加载 .bashrc
        special_flag = "COMPLETE_TASK_AND_SUBMIT_FINAL_OUTPUT"
        if special_flag in command:
            final_command = command
        else:
            # ✅ 标准写法:登录式shell,自动加载 ~/.bashrc, /etc/profile, ~/.bash_profile
            # 完全模拟手动 docker exec -it 进入容器的环境
            final_command = f"bash -lc '{command}'"
    
        # 拼接最终执行命令
        cmd.extend([self.container_id, *self.config.interpreter, final_command])
    
        # 以下保留你原有执行逻辑不变
        result = {}
        return result
  8. SJTUyh commented on May 20, 2026

    @SJTUyh
    CollaboratorAuthor

    或者采用如下修改:

    def execute(self, action: dict, cwd: str = "", *, timeout: int | None = None) -> dict[str, Any]:
            """Execute a command in the Docker container and return the result as a dict."""
            command = action.get("command", "")
            cwd = cwd or self.config.cwd
            assert self.container_id, "Container not started"
    
            cmd = [self.config.executable, "exec", "-w", cwd]
            for key in self.config.forward_env:
                if (value := os.getenv(key)) is not None:
                    cmd.extend(["-e", f"{key}={value}"])
            for key, value in self.config.env.items():
                cmd.extend(["-e", f"{key}={value}"])
            # ===================== 核心修改开始 =====================
            # 新增条件判断:包含指定关键词则走旧逻辑,否则走新逻辑
            if "COMPLETE_TASK_AND_SUBMIT_FINAL_OUTPUT" in command:
                # 旧逻辑:直接执行原解释器+命令
                cmd.extend([self.container_id, *self.config.interpreter, command])
            else:
                # 1. 拼接:先加载bashrc,再执行原解释器+命令
                interpreter_cmd = " ".join(self.config.interpreter)  # 把解释器列表转成字符串
                full_command = f"source ~/.bashrc && {interpreter_cmd} {command}"
                # 2. 用 bash -c 执行完整命令(强制加载bashrc)
                cmd.extend([self.container_id, "bash", "-c", full_command])
            # ===================== 核心修改结束 =====================
            #cmd.extend([self.container_id, *self.config.interpreter, command])
  9. unpinned this issue on Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcontent_check_passed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions