Repository navigation
fix(sandbox): scratch 预检本机能力,启动失败时说清原因和修法 - #2545
Merged
Merged
Conversation
- 新增只读能力探测(uid、bwrap / fuse-overlayfs / fusermount3、/dev/fuse、 内核 overlay、user namespace sysctl、NoNewPrivs),不挂载、不起沙盒; Dashboard 选 scratch 时提示「这台机器不能用 scratch」或「只能用磁盘存储」, 只提示、不阻止保存,默认值不变 - prepareScratchSandbox / prepareMacScratchSandbox 增加 Detailed 版本返回失败 原因枚举,worker 翻成中文原因和修法;只有 tmpfs 在机器重启后丢失才建议新开会话 - docs/file-sandbox.md 修正非 root 的说法,补前置条件表与日志对照修法表 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 29, 2026 18:55
…待验证项 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…pability precheck
…ratch capability precheck
deepcoldy
pushed a commit
that referenced
this pull request
Oct 30, 2026
This was referenced Oct 30, 2026
|
@deepcoldy 合入 master 后的 Midscene E2E 失败:Feishu live Midscene 失败。 这次运行覆盖 89a9cea…22d1c8d0b(20 个提交),同批合入的还有 #2546 #2556 #2589 #2591 #2538 #2595 #2596 #2597 #2581 #2539 #2598 #2515 #2536 #2575 #2366 #2606 #2544 #2593 #2603,失败不一定由本 PR 引起。
|
This was referenced Oct 30, 2026
This was referenced Oct 30, 2026
deepcoldy
pushed a commit
that referenced
this pull request
Oct 31, 2026
- 首审 P2:bytedcli-home / vc-meeting-daemon-auth / oauth-pending / cli-identity 的固定遮挡不再受「数据目录存在」门控(自定义 SESSION_DATA_DIR 时 ~/.botmux/data 可能在会话中途才由首次登录创建);补单测与真容器变体 - 首审 P3:docs-site 中英 sandbox.md 写清 scratch 不隔离凭据;顺带把已失效的 scratch 启动失败报错说明更新为 #2545 之后的原因 + 修法 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🚀 Released in v3.56.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改了什么
起因是用户反馈:scratch 文件沙盒在非 root 的 daemon 上用默认的 tmpfs 存储时必然失败,Dashboard 不预先提示,会话失败时只给一句笼统的「start a new session」。维护者定的方向(决策看板 #84,方案 A):非 root 下 tmpfs 仍然失败、不自动降级,但要提前告诉用户「这台机器只能用 disk」,失败时说清楚原因和修法。
只读能力探测(新文件
src/adapters/backend/scratch-capability.ts)。daemon 侧检查 uid、PATH 里的 bwrap / fuse-overlayfs / fusermount3、/dev/fuse能否以读写打开(打开后立刻关)、/proc/filesystems里有没有 overlay、user namespace 相关 sysctl(user.max_user_namespaces、kernel.unprivileged_userns_clone、AppArmor 的apparmor_restrict_unprivileged_userns)、bwrap 的 setuid 位、/proc/self/status的 NoNewPrivs。不挂载、不起 bwrap、不安装任何东西。给出 tmpfs、disk 各自可用 / 不可用 / 无法确定,以及缺的包和安装命令。读不出结论的项只标「无法确定」,不按失败算。NoNewPrivileges=yes)时,setuid 的 fusermount3 拿不到权限,非 root 的 disk 存储也起不来。实测报错是fusermount3: mount failed: Operation not permitted。Dashboard 提示:Bot 配置 → 权限与安全 → 文件沙盒,选中 scratch 时按探测结果显示:
只提示,不阻止保存,默认值仍是 tmpfs。
/api/bots加了scratchCapability字段;老 daemon 不回这个字段,页面就不显示提示。失败原因:新增
prepareScratchSandboxDetailed/prepareMacScratchSandboxDetailed,失败时返回原因枚举(18 种,SCRATCH_FAILURE_REASONS)和宿主细节(stderr 首行、路径、缺的包)。原来的prepareScratchSandbox/prepareMacScratchSandbox签名不变,仍是失败返回 null,供探针脚本和老测试用。worker 改调 Detailed 版,用scratchFailureNotice把原因翻成中文提示加修法发到话题里;只有「tmpfs 在机器重启后丢失」才建议新开会话,其余都给宿主或配置上的修法。原来十几处console.error照旧保留在日志里。文档
docs/file-sandbox.md:修正「非 root 自动走 fuse-overlayfs,storage 强制为 disk 语义」这句,代码里从来没有强制。补了两张表:前置条件表(root / 非 root × tmpfs / disk,含 /dev/fuse、bwrap、fuse-overlayfs、fusermount3、NoNewPrivileges),以及每条[scratch-sandbox]日志对应的原因和修法。影响面
/api/bots时执行,都是只读的文件和 sysctl 读取,外加打开一次/dev/fuse。scratch-sandbox.ts(内部函数返回值从 boolean 改成失败原因,挂载、卸载、回滚逻辑没动;失败日志里的 stderr 改为取第一行,mount 会在真实错误后面追加一句 dmesg 提示)、scratch-sandbox-darwin.ts(同样只改返回值)、worker.ts的 scratch 分支(只改失败时的文案)、dashboard-ipc-server.ts(新增一个只读字段)、Dashboard 文件沙盒区块。oncall 沙盒、off 模式、其它 CLI、tmux / pty 后端都不经过这些改动。docs/file-sandbox.md的 scratch 一节,后合的一方同步 master 再改。验证
bun run build通过(含 tsc、scripts / test-mocks 类型检查、dashboard bundle)。npx vitest run test/scratch-capability.test.ts test/scratch-capability-note.test.ts test/dashboard-i18n.test.ts test/dashboard-i18n-c5.test.ts test/dashboard-bot-payload.test.ts test/scratch-sandbox-unit.test.ts test/scratch-sandbox-darwin-profile.test.ts test/sandbox-mode.test.ts test/scratch-submount-plan.test.ts test/test-hygiene.test.ts:8 个文件、568 例通过(加上新增的两个文件,共 23 例)。bun test跑新增的三个文件:26 pass。test/scratch-prepare-failure.test.ts)在isolate-run --timeout 5m里跑,每个用例再套私有挂载 + PID 命名空间(test/helpers/private-mount-ns.ts),挂载出不到宿主:tmpfs-upper-lost;storage-conflict并带上原来的存储;tmpfs-needs-root;scratchFailureNotice生成的原因 + 修法,不再是固定文案。must be superuser to use mount、disk 报fusermount3: mount failed: Operation not permitted,与探测一致。第二轮(首审 4 条 P3,已在本 PR 修)
fuse3包。/dev/fuse(比如旧式 0660 root:root 的设备节点),但 setuid 的 fusermount3 可用、且没有 NoNewPrivs 时,改判为「无法确定」,不再直接判「不能用」。原因是 fusermount3 以 root 身份打开设备。没有 fusermount3 或有 NoNewPrivs 时仍判不可用。bot-payload.ts透传scratchCapability补了测试:正常透传;老 daemon 不回这个字段时为 null;非对象值丢弃。变异 4 处(去掉 fuse3 安装提示、去掉「无法确定」降级、不显示待验证项、payload 不透传),全部变红。文档前置条件表同步改了
/dev/fuse那一格。截图(合成数据,隔离 daemon + Dashboard)
daemon 以 root 运行,所以截图时把
/api/bots里的scratchCapability换成了真实evaluateScratchCapability对非 root 主机算出的结果。非 root,当前选的是内存存储(提示改成磁盘):
非 root,当前选的是磁盘存储:
没有 /dev/fuse、也没装 fuse-overlayfs(不能用 scratch):
root 且依赖齐全时不显示提示。
🤖 Generated with Claude Code