caoqianming
|
b6faeda83d
|
fix(deploy): APP_USER 默认取部署目录属主,不写死 zcbot
与 APP_DIR 同思路:服务用户默认 = 部署目录属主(bootstrap chown 后即服务
用户),仍可 env 覆盖。加两道前置:推成 root 时 warn(服务/沙箱不该跑 root,
HOST_UID 要对齐 bind mount 属主),用户不存在直接 fail。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
2026-06-01 15:28:16 +08:00 |
caoqianming
|
e8aeef19de
|
fix(deploy): update.sh 的 APP_DIR 从脚本位置推导,不写死 /opt/zcbot
部署目录 = 脚本所在 deploy/ 的上一级,用 readlink -f 解析(兼容相对路径 /
软链调用),仍可 APP_DIR env 覆盖。换部署路径不必再改脚本字面量。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
2026-06-01 15:18:58 +08:00 |
caoqianming
|
f66d55cc3b
|
feat(deploy): 加一键部署脚本 deploy/update.sh(pull/pip/migration/build/restart/healthz)
固化日常部署:git pull --ff-only → pip install → db upgrade head →
docker build sandbox → systemctl restart → curl /healthz 验活。
两处钉死:① migration 不能漏,env.py 直读 os.environ 不读 .env,脚本从
.env 抠 ZCBOT_DB_URL 显式喂进去;② build 必先于 restart —— 容器复用 +
tools/ 烤进镜像,restart 时 shutdown_all 清旧容器,下次 ensure() 才用
新镜像重建。sandbox 每次 build 无所谓(重活在 COPY tools/ 之上,cache
让改代码部署秒过)。镜像源默认阿里,可置空回落官方。前置守卫 + healthz
失败 dump journalctl 非零退出。bootstrap 不进脚本,留 RUN.md。
RUN.md §部署 SOP 重写为指向脚本 + 手动 fallback;PROGRESS 加一条。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
2026-06-01 14:52:44 +08:00 |
caoqianming
|
fb5e68d9e7
|
fix(sandbox): 装 CJK 字体修 matplotlib / mermaid 出图中文方块
sandbox 镜像基于 python:3.12-slim 一个中文字体都没装,matplotlib /
mermaid(chromium)/ render_icon 出的 PNG 中文全是豆腐块。
- Dockerfile: apt 装 fonts-noto-cjk + fonts-wqy-microhei + fontconfig,fc-cache 刷索引
- style.py: 候选首位加 "Noto Sans CJK SC",matplotlib 优先用 Noto
- PROGRESS / RUN 故障表同步
改了 Dockerfile 必须重 build 镜像 + 清旧容器才生效。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
2026-06-01 13:47:04 +08:00 |
caoqianming
|
85415470d2
|
sandbox+infra: Python 3.10→3.12(host+Dockerfile)+ docker PYTHONPATH 加 /sandbox
为通过 3 个科学 skill 的 smoke 解决两件基础设施问题。
1. emmet-core 0.86.0rc1 用了 typing.NotRequired(3.11+),host .venv 是 3.10
→ mp_rester ImportError。选 3.12(当下 ML 生态默认稳定版,比 3.11 多一年
优化,比 3.13 wheel 覆盖更全 Windows 不踩坑)。Dockerfile python:3.11
→ 3.12 同步升,部署机 rebuild image 时生效。
2. executor_docker.py:172 PYTHONPATH 由 /workspace 改 /sandbox:/workspace,
修历史 bug —— skills/ bind mount 到容器 /sandbox/skills:ro,SKILL.md 教
LLM `from skills.xxx import yyy`,docker backend 之前根本 import 不到
(research/paper 同款受影响,只是 dogfood 一直跑 host backend 没暴露)。
test_executor_docker.py:243 regression 测试改为 assertIn 含 /sandbox,
15/15 PASS。
smoke 验证:pymatgen XRD / sklearn / statsmodels / plot_pub 全通,
mp_rester 联网遇 MP 服务侧 IP/ASN 403(LBNL 对国内 IP 临时封,非代码问题)。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-28 11:35:02 +08:00 |
caoqianming
|
8743449711
|
init.sh: apply_resolv_conf 失败 robust,不让容器整体退出
docker 在某些 kernel / version 组合下 /etc/resolv.conf 可能是 ro mount,
> redirect 失败 → set -e 触发 → 容器立即退出 → docker exec 报
"cannot exec in a stopped container"。
修法:tmp file 中转 + cat > 失败 || warn,resolv.conf 写不动也继续跑 iptables
等其他启动逻辑;此时容器仍能跑 shell/run_python,只是 DNS 解析跪 ── 比容器
直接退出可调试。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-27 12:15:36 +08:00 |
caoqianming
|
ae15a36e58
|
init.sh: 覆写 /etc/resolv.conf 绕过 docker embedded DNS
发现 user-defined bridge network 上 docker run --dns 是改 daemon 给 embedded
DNS(127.0.0.11)的上游 forward 目标,容器 /etc/resolv.conf 不变(仍是
nameserver 127.0.0.11)。腾讯云轻量等场景 daemon 探测 systemd-resolved 上游
失败 → embedded DNS 自身 forward 也跪 → --dns 8.8.8.8 救不了。
正确解:init.sh 启动时直接覆写 /etc/resolv.conf,完全绕过 embedded DNS。
- pool.py 把 --dns flag 换成 -e ZCBOT_DNS=8.8.8.8,114.114.114.114
- init.sh apply_resolv_conf 函数循环 echo "nameserver $ip" > /etc/resolv.conf
- /etc/resolv.conf 是 docker bind mount file(非 rootfs),--read-only 不挡,
root 跑 init.sh 可写;--restart=no 容器生命周期内不被 docker 覆盖
iptables 127.0.0.11 ACCEPT 例外保留不动(无副作用,以备未来需要 service
discovery 等场景)。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-27 12:03:24 +08:00 |
caoqianming
|
bbe79ce36d
|
init.sh: 127.0.0.11:53 ACCEPT 例外(docker embedded DNS,不然全跪)
容器内 /etc/resolv.conf 默 `nameserver 127.0.0.11`(docker daemon 注入的
embedded DNS),iptables `127.0.0.0/8 DROP` 把它也挡了 → 所有域名解析失败,
模型在容器里跑 curl/pip 等全 NameResolutionError。
精准 ACCEPT 127.0.0.11/32 udp/tcp 53 在 DROP 127.0.0.0/8 之前(iptables -A
按 append 顺序生效),不破坏 loopback 基线 ── 其他 127.x 仍挡。
RUN.md 故障兜底加一行。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-27 11:11:53 +08:00 |
caoqianming
|
eaf7f3ea1e
|
Stage C 收尾包:资源 yaml + 磁盘配额 + 网络放开 + 容器内源持久化
dogfood + 信任同事白名单阶段 Step 4 完整 egress proxy 暂不做(沉淀为升级触发
信号:任一陌生用户注册 / 模型异常 outbound / 信任白名单出现非密切相识者 → 必上)。
本批 3 件:
(A) 容器资源 yaml 化(可调不重 build):
- agent.yaml 加 sandbox 段(memory/cpus/pids_limit)
- SandboxPool ctor 加三字段,优先级 env > yaml > 默(2g/1.0/256)
- setup_pool/init_pool 透传 sandbox_cfg
- sandbox check 输出加 [info] 4 行给运维一眼对账
(B) 应用层磁盘配额(§7.5 #4 软配额):
- migration 0008 user_disk_usage 单行 per user
- core/storage/disk_quota.py:parse_bytes("5gb"/int)+ scan_user_dir
(os.scandir 跳顶层 .zcbot_tmp / .memory)+ upsert ON CONFLICT
+ check_disk_quota + scan_all_users 串行
- lifespan _disk_scanner 后台 task(启动跑一次 + 默 15min 周期)
- DockerExecutor write/edit 起手 gate 超额 [Error] 不调容器
- /v1/files/upload 同款 gate 超额 HTTP 413
- yaml `quotas.disk_bytes_per_user: 5gb` + `disk_scan_interval_seconds: 900`
- race 接受:扫描间隙写入轻微突破(image/video 配额同款 race-tolerant);
外部用户开放前 OS 层 xfs prjquota 兜底
- 11 测试 covered parse_bytes / scan / 跳 dotfile
(C) 网络放开 + 容器内源持久化:
- network.py 去 --internal flag,容器走 docker bridge default 有 NAT outbound
- 已存在 internal network 不自动 rm 仅 warn,RUN.md 给迁移命令(避免破现有容器)
- iptables 红线段不动(169.254/127/10/172.16/192.168/100.64/PG_IP DROP),
挡 cloud metadata + 内网扫描 + loopback,基线不依赖 proxy
- Dockerfile 加 /etc/pip.conf(global index-url + timeout 60) + /etc/npmrc
(global registry),让运行时模型 `pip install foo` / `npm install bar`
也走 mirror(此前 --build-arg 只 build 时生效)
unittest discover 46/46 PASS(原 35 + 新 11)。
DESIGN 不动(延后决策仍在 §7.7 Stage C 阶段语义内,触发信号沉淀进
PROGRESS / RUN);RUN.md 加 env 列表 + 网络迁移 + 配额 + 故障兜底 3 行。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-27 08:35:53 +08:00 |
caoqianming
|
792366d9fc
|
deploy/sandbox: apt retry + 推 http mirror(腾讯云 https 偶发 SSL EOF)
腾讯云内网 apt mirror (169.254.0.3) HTTPS 端偶发不发 close_notify 直接断,
OpenSSL 3 严格 fail (error:0A000126: unexpected eof while reading),OpenSSL
1.1.1 容忍。python:3.11-slim 自带 OpenSSL 3,撞这条。
修两层:
- Dockerfile 加 Acquire::Retries "5" + Pipeline-Depth "0" + No-Cache "true"
- RUN.md 推 APT_MIRROR=http:// 而非 https://(apt 包 GPG 签名校验,无 HTTPS
安全收益,顺手绕开 SSL 兼容问题)
故障兜底加 OpenSSL EOF 一行。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-26 22:16:05 +08:00 |
caoqianming
|
29557cad45
|
deploy/sandbox: apt 源 build-arg APT_MIRROR(chromium 装得慢)
跟 PIP_INDEX_URL / NPM_REGISTRY 同款:Dockerfile 加 ARG APT_MIRROR,空默
Debian 官方;非空则 sed 替 sources.list[.d/*.sources] 里 deb.debian.org +
security.debian.org 的 host 前缀。
腾讯云轻量 / CVM 上跑:
--build-arg APT_MIRROR=https://mirrors.cloud.tencent.com
RUN.md 镜像构建段加 APT_MIRROR 行,跟 pip/npm 排一起。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-26 22:01:33 +08:00 |
caoqianming
|
23ff996d38
|
Stage C Step 3d: fs 工具进容器 + DESIGN §7.5 #6 重写(物理边界替代代码护栏)
Ubuntu dogfood 暴露 host 工具漏底:base_dir=Path.cwd() 无 user_root 校验,
模型 glob "*" 列出 host /home/lighthouse/zcbot/.git/.venv/... zcbot 源码自身。
DESIGN §7.5 #6 原写"host 工具走 paths.py::resolve_user_path 校验"是假命题
(代码里没那函数),绝对路径完全不挡。
修法:fs 工具(read/write/edit/glob/grep)也走 docker exec,物理边界替代
代码护栏(Phase B path validator 那条不做 ── 脆弱)。
- core/sandbox/tool_runner.py 新增:容器内 helper,stdin 接 JSON args,
调 tools/fs.py 的 Tool 子类;base_dir=cwd,user_root=/workspace
- DockerExecutor 加 FS_TOOLS 信任域 + _exec_fs_tool:docker exec -i ...
python /sandbox/tool_runner.py <name>,stdin 喂 JSON args(CJK / 引号
透明传不被 shell metachar 切)
- _run_subprocess 加 stdin 参数 + is_fs_tool 分支返 stdout 直透(原 Tool
返回串语义保持),exit≠0 stderr 当 ToolResult content
- SandboxPool 加 repo_root 字段 + <repo>/skills:/sandbox/skills:ro mount
让容器内 read SKILL references 能解析
- Dockerfile COPY tools/ /sandbox/tools/ + tool_runner.py(build-time COPY
而非 mount ── 容器内代码不应跟随 host repo 改动)
- web/app.py 透传 ROOT 给 init_pool
- 留 host 的工具:load_skill(SkillRegistry 内存查找)/ web_search /
web_fetch / seedream / seedance(持 Bocha/ARK key 不入容器)
- DESIGN §7.5 #6 重写:"几乎所有工具进容器,host 只留持 key + 跨 user 的",
原假命题溯源标注 2026-05-26 修正
代价:每 fs tool call +~200ms docker exec overhead,对话级 N≤15 总 1-3s,
LLM 推理 5-30s 下噪声。升级触发(§7.9 升级表)docker exec → unix socket RPC
仍按原信号(overhead/total > 30% 持续 / 长驻服务工作流)。
测试:test_executor_docker 加 4 fs 路径测试(argv 形态 / CJK stdin JSON /
exit≠0 stderr 透传 / timeout);改原 read 直通测试 → load_skill 直通
(read 现在进容器)。unittest discover 35/35 PASS。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-26 21:56:41 +08:00 |
caoqianming
|
d93cc1a949
|
Stage C Step 3 hotfix: exec_user 跟随 build_arg + 镜像装 mermaid-cli
Ubuntu dogfood 暴露两个真问题:
(1) uid 错配:DockerExecutor 写死 --user 1000:1000,但镜像 build 时
--build-arg HOST_UID=$(id -u) 跟随 host 实际 uid(腾讯云轻量 lighthouse
uid=1001),docker exec 进容器 uid=1000 → bind mount owner 1001 错配 →
写 /workspace/<wd>/ 全 EACCES,文件落 /tmp。
改 DEFAULT_EXEC_USER = "zcbot"(username,docker 自动查容器 /etc/passwd
拿 uid),无论 HOST_UID build 成 1000/1001/其他都跟 bind mount owner 对齐。
(2) proposal/patent skill 渲 mermaid 缺 Node:render_diagrams.py 调
shutil.which("mmdc") 容器没装 → 退 mermaid.ink → sandbox --internal
默 deny outbound API 也不通 → ASCII fallback 出 docx 没图。
Dockerfile 加 chromium + nodejs + npm + @mermaid-js/mermaid-cli,
+~400MB 接受成本(ASCII 不能用)。容器 chromium 缺 setuid sandbox +
/dev/shm 不够大会跪,镜像落 /sandbox/puppeteer-config.json
(--no-sandbox --disable-setuid-sandbox --disable-dev-shm-usage) +
ENV MERMAID_PUPPETEER_CONFIG;render_via_mmdc 改读 env 拼 -p 注入,
host 上跑 env 没设行为零变化。
PUPPETEER_SKIP_DOWNLOAD + PUPPETEER_EXECUTABLE_PATH 让 puppeteer 用
容器内 chromium 不下载自带 Chrome(省 ~300MB)。
NPM_REGISTRY build-arg 同 pip 同款(腾讯云内网 / 阿里 npmmirror)。
RUN.md 加 NPM_REGISTRY 段 + 故障兜底 3 行(EACCES uid 错配 / mmdc 报
launch chromium / npm 慢)。DESIGN 不动(纯 bug fix + skill 依赖)。
unittest discover 31/31 PASS。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-26 21:47:33 +08:00 |
caoqianming
|
55adfa17b4
|
deploy/sandbox: pip 镜像源可配 + timeout 60s 兜底 ReadTimeout
- Dockerfile 加 ARG PIP_INDEX_URL/PIP_TRUSTED_HOST,默 PyPI 官方;
build 时 --build-arg PIP_INDEX_URL=... 切换腾讯云/阿里云/清华源
- pip install --timeout 60s(默 15s 太短,境内抖动易撞)
- RUN.md 镜像构建段加 3 个常用源命令 + 故障兜底加 ReadTimeoutError 行
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-26 21:10:50 +08:00 |
caoqianming
|
160e801ab0
|
Stage C Step 2: Docker per-user 容器池 + iptables blocklist 基底
- deploy/sandbox/Dockerfile: python:3.11-slim + tini + iptables + non-root uid via HOST_UID build-arg + 全套 requirements
- deploy/sandbox/init.sh: 6 段红线 IPv4 + ::1 + ZCBOT_PG_IPS 环境注入,任一规则失败 fail-fast
- core/sandbox/network.py: ensure_network() 创 --internal zcbot-sandbox-net
- core/sandbox/pool.py: SandboxPool 容器命名 zcbot-sandbox-<user_id>,per-user asyncio.Lock,
in-memory _last_active dict(Docker 23+ 移除 docker update --label-add),hardening flags
全套(read-only / tmpfs / cap-drop ALL + NET_ADMIN / no-new-privileges / pids/mem/cpu limit /
bind mount user_root → /workspace)
- core/sandbox/__init__.py: 公开 SandboxPool / container_name / setup_pool / NETWORK_NAME
Step 2 范围明确不含 AgentLoop 集成 / shell-run_python 切容器 / egress proxy / reaper task ——
pool 孤立 commit,Step 3 接入。本地 Windows 无 docker 走不动,Ubuntu 上 5 条 smoke 命令
(build / iptables 段 / non-root uid / read-only / 销毁)写进 RUN.md "Sandbox(Stage C,Ubuntu)" 段。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-26 10:44:34 +08:00 |