feat(chv): 架构/可维护性/前端只读侧推进——生产实验分离、配置片段化、VM 只读展示
架构:WarmPool 从 cloud/chv/pool.py 移到 experimental_pool.py, 生产残留清理彻底分文件到 cloud/chv/orphans.py(facade 直接读 registry 文件清理,不构造池、不碰 prewarm/acquire/release); cloud/chv 与 cloud/sandbox 不再导出 WarmPool,旧路径一律 ImportError(CHV 未合并、无生产用户,兼容保留已无保留理由); worker 改走 orphans facade,不再持有 _warm_pool;#215 对齐从 接口形状推进到 REPLACEMENT_POINTS 替换清单(R1/R2 可机械替换、 R3 永不替换,#215 模块当前不存在由测试钉住)。 可维护性:build_chv_config 拆成 base/ssh/network/quota/disk/ timeout 六片段(组装只做 dict 合并,键冲突即报错;38 字段集 与取值不变,单项非法报错文案逐字一致);ADR-12 模块职责图 与禁 import 清单(AST 钉住);cloud/chv/ 公开 API 全量类型 标注、无 Any 逃逸,并修正三处旧标注错误;死代码扫一遍 (删实验池已无调用的 _quarantine 委托与未用 _LOGGER)。 前端(只读侧,不做控制按钮):chv.ts 新增纯逻辑谓词与文案 (执行器精确匹配、附件守卫、VM 状态文案、列表徽标);列表 行新增 VM 已报告死亡徽标;详情对全部 CHV 任务显示 VM 行 (已报告死亡/未报告死亡,不猜 live);WorkersSection 与成本 卡沿用已有数据,不新开池管理/成本页;服务端未新增第二个 生命周期字段(持久化事实只有三项,chv_vm_dead 已是完整派生), 只把派生抽成 _chv_vm_dead_from_row 并补 goal 回落形态测试。
This commit is contained in:
1 parent
42de20da68
commit
df8c64bd64
30 files changed
+1263
-331
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { chvAvailability, chvQueueHint, countChvWorkers, isWorkerAlive } from "./chv";
|
||||
import { chvAttachmentBlocked, chvAvailability, chvQueueHint, chvVmBadge, chvVmStatusText, countChvWorkers, isChvExecutor, isWorkerAlive } from "./chv";
|
||||
|
||||
// 纯逻辑测试:只测 chv.ts,不渲染组件、不发请求、不读 localStorage。
|
||||
// alive 规则与 WorkersSection 现有口径一致:alive 字段优先,
|
||||
@@ -50,6 +50,49 @@ describe("chvAvailability", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("isChvExecutor", () => {
|
||||
it("精确值才算 CHV,不做大小写/前缀宽松匹配", () => {
|
||||
expect(isChvExecutor("cloud-hypervisor")).toBe(true);
|
||||
expect(isChvExecutor("Cloud-Hypervisor")).toBe(false);
|
||||
expect(isChvExecutor("cloud-hypervisor-x")).toBe(false);
|
||||
expect(isChvExecutor("docker")).toBe(false);
|
||||
expect(isChvExecutor(undefined)).toBe(false);
|
||||
expect(isChvExecutor(null)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("chvAttachmentBlocked", () => {
|
||||
it("仅 CHV + 带附件时拦(后端 400 的前端提示口径)", () => {
|
||||
expect(chvAttachmentBlocked("cloud-hypervisor", true)).toBe(true);
|
||||
expect(chvAttachmentBlocked("cloud-hypervisor", false)).toBe(false);
|
||||
expect(chvAttachmentBlocked("docker", true)).toBe(false);
|
||||
expect(chvAttachmentBlocked("cloud", true)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("chvVmStatusText", () => {
|
||||
it("已报告死亡时给死亡文案", () => {
|
||||
expect(chvVmStatusText({ executor: "cloud-hypervisor", chv_vm_dead: true })).toContain("VM 中途死亡");
|
||||
});
|
||||
it("CHV 无字段时给未报告文案,绝不写成活着", () => {
|
||||
const text = chvVmStatusText({ executor: "cloud-hypervisor" });
|
||||
expect(text).toContain("未报告 VM 死亡");
|
||||
expect(text).toContain("不代表 VM 活着");
|
||||
});
|
||||
it("非 CHV 任务不显示 VM 行", () => {
|
||||
expect(chvVmStatusText({ executor: "docker" })).toBe("");
|
||||
expect(chvVmStatusText({ executor: "docker", chv_vm_dead: true })).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
describe("chvVmBadge", () => {
|
||||
it("只有 CHV + 已报告死亡时才出徽标", () => {
|
||||
expect(chvVmBadge({ executor: "cloud-hypervisor", chv_vm_dead: true })).toBe("VM 已报告死亡");
|
||||
expect(chvVmBadge({ executor: "cloud-hypervisor" })).toBe("");
|
||||
expect(chvVmBadge({ executor: "docker", chv_vm_dead: true })).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
describe("chvQueueHint", () => {
|
||||
it("仅 CHV + 排队 + 已知零在线时给提示", () => {
|
||||
const knownZero = { state: "known" as const, online: 0, total: 0 };
|
||||
|
||||
@@ -35,6 +35,60 @@ export function chvAvailability(
|
||||
return { state: "unknown", reason: "not-loaded" };
|
||||
}
|
||||
|
||||
// 执行器选择谓词:派发下拉与列表筛选都以字符串相等为准,
|
||||
// 不做大小写/前缀宽松匹配(后端白名单是精确值,见 server
|
||||
// POST /tasks 的 executor 白名单;宽松匹配会把非法值放进
|
||||
// “CHV 任务”分支,造成前端提示与后端拒绝不一致)。
|
||||
export function isChvExecutor(executor: string | undefined | null): boolean {
|
||||
return executor === "cloud-hypervisor";
|
||||
}
|
||||
|
||||
// 附件守卫谓词:CHV + 带附件 → 后端建任务即拒绝(server
|
||||
// POST /tasks 的附件绑定分支,错误文案“附件不支持
|
||||
// cloud-hypervisor 执行器”)。本函数只作前端提示口径,
|
||||
// 绝不代替后端白名单:前端照常提交,后端拒绝为准。
|
||||
export function chvAttachmentBlocked(
|
||||
executor: string | undefined | null,
|
||||
hasAttachments: boolean,
|
||||
): boolean {
|
||||
return isChvExecutor(executor) && hasAttachments;
|
||||
}
|
||||
|
||||
// VM 只读状态文案:输入只有后端已返回的两个字段,输出
|
||||
// 三种情形之一,绝不编造第四种:
|
||||
// - chv_vm_dead 为 true → 已报告死亡(来源:worker 终局
|
||||
// 写回的 interrupted_reason,见 server _chv_vm_dead_from_row);
|
||||
// - CHV 任务但无该字段 → 未报告死亡,且明写“后端无 live
|
||||
// 状态,不代表 VM 活着”(server 没有 VM 登记表);
|
||||
// - 非 CHV 任务 → 空串(不显示 VM 行)。
|
||||
export function chvVmStatusText(task: {
|
||||
executor?: string | null;
|
||||
chv_vm_dead?: boolean;
|
||||
}): string {
|
||||
// 死亡文案同样先过执行器门:后端只对 CHV 任务派生该字段,
|
||||
// 万一某天非 CHV 行误带该字段,前端也不把 docker 任务
|
||||
// 写成“VM 死亡”。
|
||||
if (task.chv_vm_dead && isChvExecutor(task.executor)) {
|
||||
return "VM 中途死亡,任务未完成、断点可续跑(后端只读字段 chv_vm_dead)";
|
||||
}
|
||||
if (isChvExecutor(task.executor)) {
|
||||
return "未报告 VM 死亡(后端无 live 状态字段,不代表 VM 活着)";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// 列表行徽标:只有已报告死亡时才出现短徽标;未报告时
|
||||
// 列表行不写 VM 状态(详情里才写“未报告”长文案,避免
|
||||
// 列表行被未知状态刷屏)。
|
||||
export function chvVmBadge(task: {
|
||||
executor?: string | null;
|
||||
chv_vm_dead?: boolean;
|
||||
}): string {
|
||||
return task.chv_vm_dead && isChvExecutor(task.executor)
|
||||
? "VM 已报告死亡"
|
||||
: "";
|
||||
}
|
||||
|
||||
// 排队原因提示:只在“已知零 CHV worker 在线 + CHV 任务排队”时
|
||||
// 给出,文案明确写“可能原因”,且不编造后端未返回的
|
||||
// VM 状态/IP/快照。未知时返回空串(不提示、不猜测)。
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useRef, useState } from "react";
|
||||
import { useConsole } from "../context";
|
||||
import { Card, Bar } from "../components/ui";
|
||||
import { gatherAttachments } from "../api/client";
|
||||
import { chvAvailability } from "../api/chv";
|
||||
import { chvAttachmentBlocked, chvAvailability, isChvExecutor } from "../api/chv";
|
||||
import { EFFORTS } from "../api/types";
|
||||
|
||||
export default function DispatchSection() {
|
||||
@@ -26,7 +26,7 @@ export default function DispatchSection() {
|
||||
const [hasAttachments, setHasAttachments] = useState(false);
|
||||
const [msg, setMsg] = useState("");
|
||||
const chvAvail = chvAvailability(ctx.workers, ctx.workersSummary, ctx.workersError);
|
||||
const isChv = executor === "cloud-hypervisor";
|
||||
const isChv = isChvExecutor(executor);
|
||||
function refreshAttachments() {
|
||||
setHasAttachments(
|
||||
!!(filesRef.current?.files?.length || dirRef.current?.files?.length || imgRef.current?.files?.length),
|
||||
@@ -69,7 +69,7 @@ export default function DispatchSection() {
|
||||
if (goalMode || goalInvincible || planMode) { setMsg("协调员任务不能与 goal/计划模式同用:协调员任务本身不跑模型回合,请取消 goal/计划勾选,或清空协调员 JSON"); return; }
|
||||
}
|
||||
const atts = gatherAttachments(filesRef.current?.files || null, dirRef.current?.files || null, imgRef.current?.files || null);
|
||||
if (isChv && atts.length) { setMsg("cloud-hypervisor 任务不支持附件:请先清空附件再提交(后端对带附件的 CHV 任务会 400)"); return; }
|
||||
if (chvAttachmentBlocked(executor, atts.length > 0)) { setMsg("cloud-hypervisor 任务不支持附件:请先清空附件再提交(后端对带附件的 CHV 任务会 400)"); return; }
|
||||
try {
|
||||
const result = await ctx.dispatch(body, atts);
|
||||
setMsg(result);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Card } from "../components/ui";
|
||||
import { shortId, fmt } from "../api/client";
|
||||
import { STATUS_EXPLAIN } from "../api/types";
|
||||
import { firstChar, durationOf, tokenOf, fmtCostUsd } from "../api/taskMeta";
|
||||
import { chvAvailability, chvQueueHint } from "../api/chv";
|
||||
import { chvAvailability, chvQueueHint, chvVmStatusText } from "../api/chv";
|
||||
import DetailActions from "./detail/DetailActions";
|
||||
import BrowserPanel from "./detail/BrowserPanel";
|
||||
import ReviewPanel from "./detail/ReviewPanel";
|
||||
@@ -131,7 +131,7 @@ export default function TaskDetailPanel() {
|
||||
<div><dt>turn</dt><dd>{shortId(t.turn_id)}</dd></div>
|
||||
<div><dt>root turn</dt><dd>{shortId(t.root_turn_id)}</dd></div>
|
||||
<div><dt>executor</dt><dd>{t.executor || ""}{t.executor === "cloud-hypervisor" ? "(实验执行器,默认关闭;仅展示,无 VM 控制按钮)" : ""}</dd></div>
|
||||
{t.chv_vm_dead ? <div><dt>VM 状态</dt><dd>VM 中途死亡,任务未完成、断点可续跑(后端只读字段 chv_vm_dead;无该字段时不代表 VM 活着)</dd></div> : null}
|
||||
{t.executor === "cloud-hypervisor" ? <div><dt>VM 状态</dt><dd>{chvVmStatusText(t)}</dd></div> : null}
|
||||
<div><dt>主机</dt><dd>{t.worktree_host || ""}</dd></div>
|
||||
<div><dt>模型</dt><dd>{t.model || "默认"}</dd></div>
|
||||
<div><dt>强度</dt><dd>{t.effort || "默认"}</dd></div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useConsole } from "../context";
|
||||
import { shortId } from "../api/client";
|
||||
import { firstChar, durationOf, tokenOf } from "../api/taskMeta";
|
||||
import { chvAvailability, chvQueueHint } from "../api/chv";
|
||||
import { chvAvailability, chvQueueHint, chvVmBadge } from "../api/chv";
|
||||
|
||||
// 任务列表行 meta:首字 / 总耗时 / token,计算见 api/taskMeta.ts,
|
||||
// 与任务详情共用同一口径。
|
||||
@@ -80,6 +80,9 @@ export default function TaskListSection({ onNew }: { onNew: () => void }) {
|
||||
{chvQueueHint(t.executor, t.status, chvAvail) ? (
|
||||
<div className="issue-meta" title={chvQueueHint(t.executor, t.status, chvAvail)}>{chvQueueHint(t.executor, t.status, chvAvail)}</div>
|
||||
) : null}
|
||||
{chvVmBadge(t) ? (
|
||||
<div className="issue-meta" title="后端只读字段 chv_vm_dead(worker 终局写回的 VM 死亡原因派生);无徽标时不代表 VM 活着">{chvVmBadge(t)}</div>
|
||||
) : null}
|
||||
</span>
|
||||
</li>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user