Phase2 dry-run: pending A, probe, build-config client, gated task/add

Still default dry-run; ALLOW_LIVE_SUBMIT=0. Live gates closed.
This commit is contained in:
Victor Cao
2026-10-16 19:00:15 +08:00
parent 0d0f3b611a
commit bed3bc11ca
25 changed files with 952 additions and 110 deletions

View File

@@ -1,12 +1,5 @@
#!/usr/bin/env python3
"""Generate a dry-run adaptation report (no platform side effects).
Reads config/candidates.example.json (or DRY_RUN_CANDIDATES path).
Writes reports/dry-run-<Asia/Shanghai-timestamp>.md
"""
from __future__ import annotations
"""Read-only Phase2 pending draft report. Offline by default; opt-in configuration generation only."""
import json
import os
import sys
@@ -15,93 +8,78 @@ from pathlib import Path
from zoneinfo import ZoneInfo
ROOT = Path(__file__).resolve().parents[1]
TZ = ZoneInfo("Asia/Shanghai")
sys.path.insert(0, str(ROOT))
from src.pending_pool import build_ordered_candidates, input_path, experience_order
from src.config_params import build_config_params, config_params_source, SOURCE, GAP
from src.queue_depth import queue_depth
from src.task_add_client import build_payload
TZ = ZoneInfo('Asia/Shanghai')
def _load_candidates(path: Path) -> list[dict]:
data = json.loads(path.read_text(encoding="utf-8"))
if isinstance(data, list):
return data
if isinstance(data, dict) and "candidates" in data:
return list(data["candidates"])
raise SystemExit(f"unexpected candidates schema in {path}")
def _load_candidates(path):
data = json.loads(path.read_text())
return data if isinstance(data, list) else list(data['candidates'])
def _render(candidates: list[dict], ts: str, src: Path) -> str:
lines = [
f"# Dry-run 适配建议报告 — {ts} (Asia/Shanghai)",
"",
"> **模式:dry-run** — 本报告不产生平台侧真实提交。",
"> **需 Victor 人工提交**:请登录模盒控制台按草稿确认后手工提交。",
"> **积分:待平台核实**(发布智能体本身不得分;成功适配按账本计)。",
"",
"## 闸门状态",
"",
f"- ALLOW_LIVE_SUBMIT is 1: {os.environ.get('ALLOW_LIVE_SUBMIT', '0').strip() == '1'}",
f"- LIVE_CONFIRM set: {'yes' if os.environ.get('LIVE_CONFIRM', '').strip() else 'no'}",
f"- STRATEGY_ID present: {'yes' if os.environ.get('STRATEGY_ID', '').strip() else 'no'}",
"",
"## 输入",
"",
f"- 候选文件:`{src}`",
f"- 候选条数:{len(candidates)}",
"",
"## 建议草稿(字段示意,非真实 POST)",
"",
]
def _render(candidates, ts, src):
candidates = [c for c in candidates if not os.environ.get('PENDING_SECTION') or
c.get('section', 'B') == os.environ['PENDING_SECTION'].strip().upper()]
depth = queue_depth()
lines = [f'# 代提候选 / 需 Victor 确认 — Dry-run — {ts} (Asia/Shanghai)', '',
'> 模式:dry-run;零网络写;需 Victor 人工提交/确认',
'> 积分:待平台核实', '> perf_order=unset;order_source=experience(经验序 / 待平台核实)',
f'> configParams source: {SOURCE}', f'> configParams_source={config_params_source()}', f'> {GAP}', '',
'## A→B 顺序草稿', '', f'输入:{src};候选条数:{len(candidates)}',
f'队列深度:{depth if depth is not None else "未知,需人工确认"}',
'队列≥95:禁 live;适配 W1 优先,不抢空位。', '']
if depth is not None and depth >= 95:
lines.extend(['> **禁 live / 队列≥95**', ''])
for i, c in enumerate(candidates, 1):
model = c.get("modelAddress") or c.get("model_id") or "(missing model_id)"
lines.append(f"### {i}. `{model}`")
lines.append("")
lines.append("```json")
draft = {
"modelAddress": model,
"taskType": c.get("taskType", "text-generation"),
"targetGpu": c.get("targetGpu", "(unset)"),
"framework": c.get("framework", "(unset)"),
"strategyId": "<PLATFORM_INJECTED_STRATEGY_ID>",
"configParams": "<from build-config — not fetched in Phase1 dry-run>",
"notes": c.get("notes", ""),
}
lines.append(json.dumps(draft, ensure_ascii=False, indent=2))
lines.append("```")
lines.append("")
lines.append("- 风险:Phase1 未做唯一性/硬门预检;提交前请对照 do-not-resubmit 与队列空位。")
lines.append("- **需 Victor 人工提交**(或经双重闸门的受控 live;本骨架默认拒绝 live)。")
lines.append("- **积分:待平台核实**")
lines.append("")
lines.extend(
[
"## 后续对接(Phase2)",
"",
"- **待对接 pending-submit**:尚未读取 `/workspace/modelhub-adapt/pending-submit.md`,未验证 A→B、PASS、硬门与 do-not-resubmit;本报告仅保留输入顺序。",
"- 适配 W1 优先;同一 100 队列,≥95 全体停交;空位先 A 再 B,人工核验后决定,不凭示例报告提交。",
"- 禁止 Makefile / 脚本调用 `/api/adapt/task/add` 或 `/agent_platform/strategies*` 写接口。",
"",
]
)
return "\n".join(lines)
model = c.get('model_address') or c.get('modelAddress') or c.get('model_id') or '<MODEL>'
gpus = experience_order(c.get('try_next_gpus', []))
target = gpus[0] if gpus else c.get('targetGpu', '<TARGET_GPU:需人工确认>')
status = c.get('status', 'needs_human')
lines.extend([f'### {i}. Section {c.get("section", "B")} — `{model}`', '',
f'状态:{status};needs_human={c.get("needs_human", True)}',
f'过滤:{c.get("skip_reason") or "名称硬门未命中;元数据/唯一性待人工核实"}', ''])
lines.extend([f'未适配卡(仅 pending 缺口):{", ".join(gpus) or "未提供,需确认"}',
'perf_order=unset;order_source=experience;天垓100 一般不扇出', ''])
draft = build_payload(model, target, 'vllm', strategy_id='<STRATEGY_ID>',
config_params=build_config_params(target))
# Display only; this truncated draft must never be submitted.
draft['configParams'] = draft['configParams'][:400] + '\n… [truncated; dry-run only]'
lines.extend(['build-config query: gpuType=<targetGpu>&framework=vllm&taskType=text-generation; POST empty body', 'POST 字段草稿(skipped 行禁止提交):', '```json', json.dumps(draft, ensure_ascii=False, indent=2), '```',
'需 Victor 人工提交/确认;积分:待平台核实', ''])
report = '\n'.join(lines)
# Defensive redaction even if an input happens to contain an injected credential.
secrets = [os.environ.get(k, '') for k in ('XC_TOKEN', 'MODELHUB_XC_TOKEN', 'EXTERNAL_SERVICE_TOKEN', 'Xc-Token')]
if os.environ.get('XC_TOKEN_FILE'):
try:
secrets.append(Path(os.environ['XC_TOKEN_FILE']).read_text().strip())
except OSError:
pass
for secret in secrets:
if secret:
report = report.replace(secret, '[REDACTED]')
return report
def main() -> None:
src = Path(
os.environ.get(
"DRY_RUN_CANDIDATES",
str(ROOT / "config" / "candidates.example.json"),
)
)
if not src.is_file():
raise SystemExit(f"candidates file not found: {src}")
candidates = _load_candidates(src)
def main():
md = input_path('PENDING_SUBMIT_MD', 'pending-submit.md')
txt = input_path('PENDING_SUBMIT_TXT', 'pending-submit.txt')
if md.is_file() or txt.is_file():
src = md if md.is_file() else txt
candidates = build_ordered_candidates(md, txt)
else:
src = Path(os.environ.get('DRY_RUN_CANDIDATES', ROOT / 'config/candidates.example.json'))
candidates = _load_candidates(src)
now = datetime.now(TZ)
ts = now.strftime("%Y%m%d-%H%M%S")
out_dir = ROOT / "reports"
out_dir.mkdir(parents=True, exist_ok=True)
out_path = out_dir / f"dry-run-{ts}.md"
out_path.write_text(_render(candidates, now.strftime("%Y-%m-%d %H:%M:%S"), src), encoding="utf-8")
print(f"Wrote {out_path}")
out = ROOT / 'reports' / f'dry-run-{now:%Y%m%d-%H%M%S}.md'
out.parent.mkdir(exist_ok=True)
out.write_text(_render(candidates, now.strftime('%Y-%m-%d %H:%M:%S'), src), encoding='utf-8')
print(f'Wrote {out}')
if __name__ == "__main__":
if __name__ == '__main__':
main()