Skip to content

fix(sdk): add runtime config type validation in PythonRuntimeEnv#652

Open
KunWuLuan wants to merge 1 commit intoalibaba:masterfrom
KunWuLuan:typeerr
Open

fix(sdk): add runtime config type validation in PythonRuntimeEnv#652
KunWuLuan wants to merge 1 commit intoalibaba:masterfrom
KunWuLuan:typeerr

Conversation

@KunWuLuan
Copy link

(EnvironmentWorker(train_env-0) pid=746905) 2026-03-19T17:41:53.502+08:00 INFO:rock_agent.py:382 [rock.sdk.sandbox.agent.rock_agent] [] [] -- [240498b70e464981a6cfc7165776dc31] Start to Initializing ModelService
(EnvironmentWorker(train_env-0) pid=746905) 2026-03-19T17:41:53.503+08:00 ERROR:rock_agent.py:224 [rock.sdk.sandbox.agent.rock_agent] [] [] -- [240498b70e464981a6cfc7165776dc31] Agent initialization failed - 'RuntimeEnvConfig' object has no attribute 'pip' (elapsed: 0.50s),

I asked LLM, it gives me the following reason:

问题分析
在 RuntimeEnv.create() 方法(第 64 行)中:
python
runtime_env = runtime_class(sandbox=sandbox, runtime_env_config=runtime_env_config)
这里 runtime_class 是 PythonRuntimeEnv,但它的构造函数签名是:
python
def init(self, sandbox: Sandbox, runtime_env_config: PythonRuntimeEnvConfig) -> None:
而传入的 runtime_env_config 实际上是 RuntimeEnvConfig 基类对象(不是 PythonRuntimeEnvConfig)。
根本原因
当 RockAgentConfig 被创建时,runtime_env_config 字段的默认值是:
python
runtime_env_config: RuntimeEnvConfigType | None = Field(default_factory=PythonRuntimeEnvConfig)
但如果配置是从 YAML/字典加载的,Pydantic 可能会将字典解析为基类 RuntimeEnvConfig 而不是 PythonRuntimeEnvConfig。

And the solution:

def __init__(self, sandbox: Sandbox, runtime_env_config: PythonRuntimeEnvConfig) -> None:
    # 确保是 PythonRuntimeEnvConfig 类型
    if not isinstance(runtime_env_config, PythonRuntimeEnvConfig):
        runtime_env_config = PythonRuntimeEnvConfig.model_validate(runtime_env_config.model_dump())
    ...

The problem is solved with the solution.

fix #651

Add explicit type check and conversion for runtime_env_config to ensure
it is properly validated as PythonRuntimeEnvConfig before processing.
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

[Bug] swe agent sandbox init failed

2 participants