起不来的三种姿势:启动失败、渲染回退、权限缺失

原创2026-10-30 13:17:08996 阅读
文章标签:人工智能AI 应用AI AgentAgent 编排Agent 沙箱工具调用浏览器控制本地部署AI 技能后端前端桌面应用移动开发认证鉴权单点登录可观测性任务调度云原生

起不来的三种姿势:启动失败、渲染回退、权限缺失

一个 AI 同事类应用最难解释的部分,往往不是模型能力,而是它“没起来”的那几分钟。OpenBot 的桌面端要把自带的 server、app、worker,外加一个容器的引擎一起拉起来;其中任何一层缺条件,表现都是同一句话——窗口停在 onboarding、进度条不动,或者干脆一闪而过。而这三类失败在代码里是完全不同的东西:启动失败是编排层(引擎、WSL、AppImage 挂载)没有把拼图拼齐;渲染回退是显示路径的选择被逼到了备用分支;权限缺失则是某一层被操作系统明确拒绝,但拒绝的理由藏在另一层里。

本文将从仓库源码出发,研究这三种故障姿势各自的判定证据在哪里、先后顺序是什么。需要先说明一个前提:这个仓库的桌面端已经从 Electron 迁移到 Tauri 2。仓库里找不到 electron-builder.yml、build/linux/openbot.apparmor 或 src/main/linux-gpu-mode.ts;gpu-crash.json、OPENBOT_DISABLE_GPU 也不存在。社区里流传的那套 GPU 回退规则属于上一代桌面壳。当前真实的回退点在哪里,正是下面要逐一说明的。

一、打包形态并不是同一份代码的三个外壳

打包目标写在 tauri.conf.json:

"targets": ["dmg", "nsis", "appimage", "deb", "rpm"]

五种产物带来了至少三种不同的启动路径,而且差异并不在“图标会不会丢”这个层面上。

Linux:deb 和 rpm 有钩子,AppImage 没有

.deb 和 .rpm 都挂了卸载脚本,并声明了运行时依赖:

"linux": {
  "deb": {
    "depends": ["pkexec", "procps", "lsof", "ca-certificates"],
    "postRemoveScript": "./linux/remove.sh"
  },
  "rpm": {
    "depends": ["/usr/bin/pkexec", "/usr/bin/ps", "/usr/bin/lsof", "ca-certificates"],
    "postRemoveScript": "./linux/remove.sh"
  }
}

注意依赖里有 pkexec。这不是可选项:install.rs 在 Linux 上安装 Podman 时明确不用 sudo:

// `pkexec` rather than `sudo`: sudo on a desktop with no terminal has nowhere to ask for a
// password, and pkexec raises the desktop's own authorization dialog.
let output = crate::quiet::command("pkexec")
    .arg(manager).args(args).arg("podman").output()

一个从桌面启动的 GUI 进程没有终端可以让 sudo 索要密码,pkexec 是唯一能弹出系统授权对话框的路径。这也是为什么在一个精简容器或没有 polkit 的发行版里,OpenBot 的表现是“装到一半停住”,而不是报一条明确的权限错误——后面第三节会回到这一点。

AppImage 则是另一类问题。它自带运行时,但仓库里有一段专门针对它的判断,见 recorder_install.rs:

Os::Linux => {
    if let Some(appimage) = appimage {
        Ok(appimage.to_path_buf())
    } else if exe.starts_with("/tmp/.mount_") {
        Err(Problem::plain(
            "Run OpenBot Desktop from its AppImage file to let the Recorder find it.",
        ))
    } else {
        Ok(current_exe.to_path_buf())
    }
}

逻辑很直接:Recorder 需要一个“进程退出后依然存在”的宿主路径。AppImage 运行时的可执行文件位于 /tmp/.mount_XXXX 下,这个挂载点会随进程消失;如果把它写进浏览器的 native messaging host manifest,下一次启动时该 manifest 就会指向一个已经消失的目录。所以代码要么拿到 AppImage 文件本身的路径,要么拒绝写入。这是“装好了但功能半残”的典型:应用能开,Recorder 连不上,Bot 的浏览器控制降级。

同一段逻辑里还有 macOS 的对应物:

Os::Mac if exe.contains("/AppTranslocation/") => Err(Problem::plain(
    "Move OpenBot Desktop to Applications to let the Recorder find it.",
))

从 ~/Downloads 直接双击 .dmg 里的 app 而不拖进 /Applications,Gatekeeper 会把它放到随机化的 AppTranslocation 路径下,同样不满足稳定路径要求。

Windows:四种“起不来”,四个独立的界面

windows.rs 把 Windows 的失败枚举成一个 Blocker,而不是一条“setup failed”:

pub enum Blocker {
    WslAbsent,
    WslOne,
    WslNoKernel,
    VirtualMachinePlatformDisabled,
    VirtualizationDisabled,
    NotAdministrator,
}

这种拆分是有代价换来的。其中 WslNoKernel 的注释写了一次实测:

Measured on Windows Server 2022. wsl --install enabled both features and stopped there, leaving the inbox WSL with no kernel, and Get-WindowsOptionalFeature says Enabled for exactly that state. Nothing looked wrong until podman machine init died on wsl --import ... --version 2 with exit status 0xffffffff.

0xffffffff 不是一个用户能够据以行动的报错。把“WSL 已启用”和“WSL 内核存在”分开探测,才能把一句乱码换成一个具体命令(wsl --update)。同时,枚举里有一只脚明确踩在应用之外:

VirtualizationDisabled → "It has to be turned on there, which OpenBot cannot do: restart, open the firmware settings, and enable Intel VT-x or AMD-V."

ours_to_fix() 也只对四个 WSL/虚拟化平台项返回 true,固件那一项永远为 false。这个区分很重要:它决定了界面应该说“点这里重试”,还是“这件事只能你自己去 BIOS 里做”。

引擎选择:一条被固定下来的顺序

install.rs 的第一段注释就是选择顺序:

  1. 一个能应答的 Docker;
  2. macOS/Windows 上一个曾经运行过的 Docker Desktop(会尝试打开);
  3. Podman:已有的,或者当场安装的。

选定之后会被 preparation::saved_engine 记住,“every later install and start uses it and only it”。这解释了为什么换引擎后行为不是随机的——它不会在第二次启动时偷偷换成另一个引擎。

还有两条经验,对应两类看起来相似、实际原因不同的“找不到引擎”。第一条关于 PATH:

When OpenBot installs Podman itself, the installer extends the user's PATH, and this process was started with the old one. podman then cannot be run for the rest of the session, so the app reports no engine while podman.exe sits on disk where it was just put.

换成人类语言:装完了,文件确实在磁盘上,但这个进程还在使用旧的 PATH。所以引擎命令全部通过解析后的绝对路径构建,而不是靠名字查找。

第二条关于 Podman 的“环境默认连接”,见 engine.rs:

podman sends every command to whichever machine is marked default, and that machine belongs to whoever made it. A person with a stopped machine of their own gets Cannot connect to Podman from a machine of ours that is running perfectly well.

所以引擎被抽象成 Address,每次调用都显式指定连接;pin() 会在 Compose 创建容器之前,先把 DOCKER_CONTEXT / DOCKER_HOST / CONTAINER_CONNECTION / CONTAINER_HOST 固定下来,否则后续命令可能被环境变量改指到别处。这一条对排查的人最有用:看到 Cannot connect to Podman,先怀疑默认连接是不是指向了用户自己的 machine,而不是怀疑 OpenBot 的 machine 没有起来。

二、渲染回退:在这个仓库里,它发生在三个不同的层面

“渲染回退”通常在谈论 GPU 驱动。但在当前这棵树里,桌面壳是 Tauri + WebKitGTK(CI 中安装的是 libwebkit2gtk-4.1-dev,见 desktop.yml),而真正绘制网页的是另一套东西:Agent 运行的 Chromium。因此这里其实有三处独立的回退决策。

第一层:容器里的 Chromium 沙箱,默认关闭且主动宣告

profiles.ts 的选择函数只有一行:

const sandboxFor = (runtime: BrowserRuntime) =>
  runtime.backend === "local-chrome" || process.env.COMPUTER_SANDBOX === "on";

默认关闭的原因不是偏好:

Chromium's sandbox creates user namespaces, and Docker's default seccomp profile blocks the syscall it needs, so a container that does nothing special gets No usable sandbox! and the browser will not start at all. Verified both ways in this image: default profile fails, relaxed profile renders.

启动时会打印一条结构化日志,把这件事说清楚:

console.info(JSON.stringify({
  type: "computer-sandbox",
  sandbox: SANDBOX_ENABLED ? "on" : "off",
  ...(SANDBOX_ENABLED
    ? { note: "Chromium's own sandbox is in use. It will refuse to start if the host does not permit user namespaces." }
    : { note: "Chromium runs without its own sandbox, ... Set COMPUTER_SANDBOX=on where the host allows it." }),
}));

这一行是区分“驱动问题”与“配置问题”的最快证据:如果它写着 sandbox: "on",而浏览器仍然起不来,那么问题在宿主是否允许 user namespace(驱动/内核/权限层);如果写着 off,就说明这是配置层做出的选择,换个 profile 就行,不要再去翻驱动日志。

第二层:Linux 的显示服务器

一台 Linux 上的 computer 默认 headed,而 headed 需要一块屏幕,于是它启动自己的 Xvfb。virtual-display.ts 处理得比通常仔细:

const child = spawn(command, args, {
  // fd 3 is private to this child. Xvfb writes its selected display there only after that display
  // is ready, so a stale socket or another X server can never satisfy our readiness check.
  stdio: ["ignore", "ignore", "inherit", "pipe"],
});

-displayfd 通过 fd 3 传回实际分配的显示号;只有这个号出现了,才算 display 就绪。超时 5 秒(READY_BUDGET_MS)、停止预算 2 秒、先 SIGTERM 再 SIGKILL。这三条数字让“浏览器白屏”和“Xvfb 没有起来”可以区分开:前者 display 已经就绪,后者根本拿不到显示号。

而人的浏览器不能画在虚拟屏幕,:, 见 person-launch.ts:

A headed computer on Linux starts its own Xvfb and points DISPLAY at it, which is right for every browser nobody sits in front of... A person's native window opened there would be drawn on a screen nobody can see.

personBrowserEnv() 因此把 DISPLAY / WAYLAND_DISPLAY 删掉,再换回进程启动时抓到的那个人自己的会话值。这里存在一个容易误判的现象:虚拟屏幕正常,但人的窗口不出现——这不是渲染失败,而是环境变量被换回了错误的显示目标。

第三层:Chromium 的软件光栅

人的原生浏览器启动参数里有两项值得单独说:

// A desktop has a GPU path and real shared memory. Software WebGL is off in an everyday Chrome.
"--enable-unsafe-swiftshader",
"--disable-dev-shm-usage",

--disable-dev-shm-usage 是个跨平台的坑,deployment.md 顺手把它变成了一条运维规则:

Chromium is launched with --disable-dev-shm-usage, so it writes to /tmp rather than /dev/shm and the 64 MB default is irrelevant. This matters because AWS Fargate does not support sharedMemorySize at all.

也就是说,看到“页面渲染一半崩掉 / 大页面必然 OOM”,第一步不该怀疑驱动,而该确认容器有没有被限制 /dev/shm。而这个限制在 Fargate 上根本没法调,所以应用侧用启动参数绕开了它,而不是要求用户改平台配置。

同一段里还有一条与“回退”高度相关、却常被忽略的说明,见 deployment.md 中关于云平台的提示:

Cloud Run runs every container under gVisor, which Chromium is sensitive to; test a navigation before trusting it.

这就是判定“驱动还是配置”的分界线:同一个镜像、同一份配置,在本地 Docker 正常而在 Cloud Run 上白屏,属于运行时隔离层的差异,不是你的 GPU 驱动。 反之,同一台机器上 COMPUTER_SANDBOX=off 能跑、on 不能跑,属于宿主内核能力(user namespace)的差异。

三、权限缺失:先读“说给人听的那句”,再读“留给调试的那段”

这是整个仓库里设计得最统一的一处,值得单独拎出来讲。

一条错误,永远两半

problem.rs 的结构体只有两个必填字段:

pub struct Problem {
    /// For the person. Their situation, and the next thing they can do about it.
    pub said: String,
    /// For whoever is debugging. Verbatim, and never shown as the headline.
    pub detail: Option<String>,
    ...
}

文件头写下了它存在的原因,并且举了一个真实例子:

a plain sentence alone throws away the evidence, and raw engine output alone is what put "pull access denied for openbot-agent-langgraph-agui, repository does not exist or may require 'docker login'" in front of somebody who was setting up an app.

前端在 Problem.tsx 里只实现一次这个规则:said 当标题,detail 塞进 <details>。注释说明了为什么只能有一份实现——“A second copy is how one screen ends up showing an engine dump as its title.”

分类顺序本身就是排查顺序

said_about() 是一个纯函数,输入引擎原话,输出一句人话。它的 if 顺序就是建议的定位顺序:

顺序 匹配到的原文 结论
1 pull access denied / repository does not exist / manifest unknown / not found: manifest 镜像没发布,不是登录问题
2 port is already allocated / address already in use 端口被占
3 no space left 磁盘满
4 cannot connect / is the docker daemon running / connection refused 引擎没在跑
5 timeout / timed out 慢或断
6 unauthorized / permission denied 被拒绝权限

为什么这个顺序不能随意改动,第一条的测试写得最直白:

assert!(!said.to_lowercase().contains("docker login"), "{said}");
assert!(!said.contains("openbot-agent"), "{said}");

一条“access denied”注定会被误读成凭据问题,从而把人送去修一个根本不存在、也不该由他修的仓库权限。所以判断“权限缺失”时,第一步不是找 allow 列表,而是确认这条报错到底是不是权限。 第 6 条被放在最后,正是因为它是这条链上最少见的一类。

退出码是权限与失败的分水岭

pkexec 这一段是全书最实用的细节:

// pkexec's own refusal. 126 is "not authorized", 127 is "dialog dismissed", and neither is a
// package manager that failed.
if matches!(output.status.code(), Some(126) | Some(127)) {
    return Err(Problem::plain(
        "The install was not allowed, so OpenBot does not have the software it needs yet. \
         Press Start to try again.",
    ));
}

126/127 意味着用户没有授权或者关掉了对话框;此时 detail 是空的(Problem::plain),因为确实没有底层输出可看。任何其他非零才是包管理器真的失败,走 Problem::with(said, stderr)。这条区分让“再点一次”和“去看 stderr”变成两个不同的按钮行为,而不是一句“安装失败请重试”包打天下。

被拒绝的三种来源,log 里长得不一样

权限拒绝在这个仓库里至少有三个源,定位时要分开看:

  1. 宿主进程所有权。stack.rs 中 unix_ownership_problem 的文案是固定的一句:“OpenBot could not verify its host process ownership.”,而 detail 里带的是 could not resolve deployment: ...、inventory denied、signal denied、stop denied、status denied 这类具体动作。看到这句话,先去读 detail 里的动词,而不是去改文件权限。 代码里连 safe_unix_pid() 都排除了 getppid() 和自己,说明它防的是 pidfile 被替换后的越权动作,不是普通文件权限。

  2. 宿主访问代理。host_access.rs 开头就给这类失败定了性:

    There is deliberately no unsandboxed fallback: a missing runtime, image, approval, grant, path check, or stop cleanup is an error.

    HostAccessError::Denied 覆盖了路径不在授权目录内、grant 已撤销、审批未通过、命令为空等情形。默认实现 DenyAllApprovalUi 连“没接线”都返回拒绝而不是放行——这是一个刻意的方向:宁可拒绝,不可降级。所以“宿主工具突然不能用了”,最可能的原因是某次审批没有通过、或者 grant 过期被撤销,而不是磁盘权限。

  3. Recorder 的 manifest 写入。这一处会带上路径:

    Problem::with(
        "OpenBot Desktop could not set up the Recorder.",
        format!("{}: {error}", path.display()),
    )
    

    这是少数会把完整路径写进 detail 的地方,因为要修它必须知道是哪一个浏览器的目录写不进去(Chromium / Chrome / Edge 各自一份)。

遥测字段是最后的旁证

telemetry.rs 把失败归到有限的几个 error_class:

["engine_unavailable", "engine_install_failed", "image_pull_failed",
 "invalid_configuration", "network_unavailable", "permission_denied", "unknown"]

permission_denied 是其中之一,但它不是从报错文本猜出来的——Problem.connection 字段的注释特意写了“never inferred from provider log text”。设置流程的 step 到 class 的映射在 main.rs 中显式写成 match,"install-engine" 才算安装失败,"engine" / "create-machine" / "start-machine" / "health-gate" 都算引擎不可用。这意味着你可以从一次失败落在哪个 step 反推它属于哪一层,而不是从错误字符串做文本挖掘。

一条可操作的判定路径

把上面三节压成一条顺序,遇到“起不来”时可以照着走:

  1. 先确认产物形态。 AppImage 还是 deb/rpm,决定有没有 pkexec;是不是从 /tmp/.mount_ 或 /AppTranslocation/ 启动,决定 Recorder 会不会被拒绝安装。
  2. 再看是不是平台前置条件。 Windows 上先分辨六个 Blocker 中的哪一个——尤其 WslNoKernel 与 WslAbsent 的症状几乎一样,但命令不同(wsl --update vs wsl --install)。
  3. 然后看引擎,而不是看应用。 Cannot connect to Podman 先查默认连接与 Address::pin() 固定的选择器;引擎刚被应用自己装上时,先怀疑 PATH 还是旧的。
  4. 渲染问题先分层。 容器里的 type: "computer-sandbox" 那行 JSON 说明的是配置选择;Xvfb 有没有通过 -displayfd 回报显示号说明的是显示服务器;/dev/shm 与 gVisor 说明的是运行时隔离。这三者都不该用“更新显卡驱动”来回答。
  5. 权限问题最后看,但看的时候看两半。 先读 said,它已经被 said_about() 排过序;再展开 detail;再对照退出码(126/127 是拒绝,不是失败);最后才去查所有权、grant 与 manifest 路径。

这套设计的共同点不在“让错误更好看”,而在让每一种失败都带着能指向下一层的证据:一个稳定的路径、一个退出码、一行结构化日志、一段原样保留的 stderr。真正让 OpenBot 起不来的,从来不是缺一条命令,而是缺一条能指出该敲哪条命令的信息。

登录后查看全文
OpenBot