feat(chv-muse-round11): 执行器接 nspawn 单元(P2 差距表 §4)
客内 host.py 调用改为 chv-cell run -- python3 /app/host.py --state /home/chv/.codex/host-state.json --codex-home /home/chv/.codex --sandbox danger-full-access …,其余原参数 原样保留。--sandbox 放全局参数最后(argparse 后胜出), 单元内恒为 danger-full-access,调用方 read-only 不得盖回 bwrap;非单元路径(本地/Docker/冷启动回落)不动。 开关 CHV_CELL_ENABLED:只认 0/1,默认 1 开;非法值 ValueError(_to_switch 同款口径)。关时走原命令,给 lite10 及更早无单元的旧镜像留逃生口。 测试:新 test_chv_muse_round11_cell.py 7 项(开/关 argv、 原参数保留、sandbox 只在单元路径、非法值报错、SSH 层 接线);test_host_command_options_identical_across_executors 显式关单元测三执行器参数全等,断言本身未动。 全量 cloud 套件 2011 OK(skipped=8)。
This commit is contained in:
1 parent
304707b372
commit
73176e135c
3 files changed
+231
-3
No files matched your search
+46
-2
@@ -38,7 +38,8 @@ from collections.abc import Callable
|
||||
|
||||
from cloud.chv.api_client import _unix_socket_api, normalize_api_result
|
||||
from cloud.chv.atomic_file import atomic_write_text
|
||||
from cloud.chv.config import _parse_memory_bytes, build_chv_config
|
||||
from cloud.chv.config import _parse_memory_bytes, _to_switch
|
||||
from cloud.chv.config import build_chv_config
|
||||
from cloud.chv.disk import (
|
||||
check_disk_quota,
|
||||
check_snapshot_limits,
|
||||
@@ -76,6 +77,13 @@ def _default_popen_launcher(cmd):
|
||||
stderr=subprocess.DEVNULL, start_new_session=True)
|
||||
|
||||
|
||||
# round-11 集成补洞(P2 差距表 §4):单元内 host.py 的显式路径。
|
||||
# 单元内 /app 只读,host.py 默认 state(/app/host-state.json)
|
||||
# 写不进;~/.codex 是单元内 bind 的可写路径。
|
||||
_CELL_STATE_PATH = "/home/chv/.codex/host-state.json"
|
||||
_CELL_CODEX_HOME = "/home/chv/.codex"
|
||||
|
||||
|
||||
class CloudHypervisorExecutor(Executor):
|
||||
"""Cloud Hypervisor 执行器 v1(命名:cloud-hypervisor,绝不用
|
||||
cloud/ch 缩写——cloud 已是通用 HTTP runner 占位,撞名会让
|
||||
@@ -240,6 +248,10 @@ class CloudHypervisorExecutor(Executor):
|
||||
0/1,非法值 ValueError)
|
||||
- CHV_VSOCK_CID:客机 vsock CID(默认 3;须在
|
||||
3-4294967295 内,0/1/2 为保留 CID)
|
||||
- CHV_CELL_ENABLED:nspawn 单元开关(默认 1 开;只认
|
||||
0/1,非法值 ValueError)。开时客内 host.py 改走
|
||||
chv-cell run(P2 差距表 §4);关时走原命令,给
|
||||
lite10 及更早无单元的旧镜像留逃生口
|
||||
|
||||
前置校验(preflight,执行入口必调,缺一即 fail-fast):
|
||||
收集全部缺失项一次报出具体缺哪一项,绝不笼统报错:
|
||||
@@ -1411,13 +1423,31 @@ class CloudHypervisorExecutor(Executor):
|
||||
子命令之前,共享 helper 在 cloud/sandbox.py)。
|
||||
guest_host_py 默认 /app/host.py:客机镜像须把 host.py
|
||||
放在该路径(与 Docker 的 /app:ro 同款约定,只是载体
|
||||
从容器换成 VM 镜像)。"""
|
||||
从容器换成 VM 镜像)。
|
||||
round-11 集成补洞(P2 差距表 §4):单元开时(默认)
|
||||
命令改为 chv-cell run -- python3 /app/host.py --state
|
||||
/home/chv/.codex/host-state.json --codex-home
|
||||
/home/chv/.codex … --sandbox danger-full-access [子命令
|
||||
...]。--state/--codex-home 须显式给(见模块顶 _CELL_*
|
||||
注释);--sandbox 放全局参数最后(argparse 后胜出),
|
||||
确保单元内恒为 danger-full-access:单元即沙箱,调用
|
||||
方传的 read-only(plan 任务)与 approval=full 自带的
|
||||
值都不得把它盖回 bwrap。单元关时
|
||||
(CHV_CELL_ENABLED=0)走原命令,给无单元的旧镜像留
|
||||
逃生口。"""
|
||||
from cloud.sandbox import _host_command_options
|
||||
cell = self._cell_enabled()
|
||||
cmd = ["python3", self.guest_host_py]
|
||||
if cell:
|
||||
cmd = ["chv-cell", "run", "--"] + cmd
|
||||
cmd += ["--state", _CELL_STATE_PATH,
|
||||
"--codex-home", _CELL_CODEX_HOME]
|
||||
cmd += _host_command_options(
|
||||
model=model, effective_model=self.model,
|
||||
model_provider=model_provider, effort=effort,
|
||||
approval=approval, sandbox=sandbox)
|
||||
if cell:
|
||||
cmd += ["--sandbox", "danger-full-access"]
|
||||
cmd += list(args)
|
||||
return cmd
|
||||
|
||||
@@ -2519,6 +2549,20 @@ class CloudHypervisorExecutor(Executor):
|
||||
"interrupted_reason": reason,
|
||||
}
|
||||
|
||||
def _cell_enabled(self):
|
||||
"""nspawn 单元开关(round-11 集成补洞,P2 差距表 §4):
|
||||
CHV_CELL_ENABLED 默认 1(开)。只认 "1"/"0",其它值
|
||||
ValueError(_to_switch 的 CHV_BALLOON/CHV_VSOCK 同款
|
||||
口径,绝不静默 fallback)。关时 _guest_host_command
|
||||
走原命令,给 lite10 及更早无单元的旧镜像留逃生口;
|
||||
开时走 chv-cell run -- python3 /app/host.py …。读
|
||||
self._env(与 _resident_enabled 同款惰性读法),不
|
||||
经 config:开关只影响命令构造,不影响建池/起 VM。"""
|
||||
flag = _to_switch(
|
||||
self._env.get("CHV_CELL_ENABLED", "1"),
|
||||
"CHV_CELL_ENABLED")
|
||||
return True if flag is None else flag
|
||||
|
||||
def _resident_enabled(self):
|
||||
"""常驻默认开;CHV_RESIDENT_ENABLED=0/false/no/off 关。
|
||||
优先认执行器上已有的 resident_enabled 属性(P1-B 若
|
||||
|
||||
Reference in new issue
Block a user