Repository navigation
Conversation
Root cause: the v2 native mainline (and the B-line build) ships the upstream
glibc librust_pty inside the bunfs payload. bun-pty resolves its lib as
$BUN_PTY_LIB -> embedded asset -> on-disk paths, so a launcherless install
always dlopens the glibc copy and fails on bionic:
ERR_DLOPEN_FAILED: library "libpthread.so.0" not found
TUI rendering and serve startup are unaffected (the Pty service lazily imports
the FFI chunk), so the defect only shows up when a terminal is created: TUI
panes and, for a headless server, a remote client's POST /api/pty.
Fix:
- tools/transplant/swap_pty.py: equal-or-smaller byte swap of the embedded
asset with tools/bun-pty-embed/vendor/librust_pty_arm64_bionic.so
(8-symbol ABI, zero undefined syms), NUL-padded to the exact slot, with a
ctypes.CDLL dlopen gate; consolidated-registry (bun >=1.4.2) fallback.
- transplant.py: step 8b grafts both packaging winners (-tui, -revived),
new pty-swap subcommand, steps.pty/pty report fields.
- build-bionic.sh: step 4a applies the same graft to the B-line product
(PTY_ASSET_FIX=0 to disable).
- make pty-check BIN=<product>: release gate, non-zero on a glibc asset.
- tests/transplant/test_swap_pty.py: synthetic fixtures (marker decoy,
consolidated layout, replacement gates, in-place swap).
Verified on Android 15/aarch64 with the installed 2.0.22 build:
before -> /api/pty 500 + libpthread.so.0 dlopen error;
after -> {status: running, pid: ...} and the shell shows up in ps;
BUN_PTY_LIB=<vendor> on the pristine binary works too.
|
Thanks — the diagnosis is exactly right, and it matches what we measured independently: Two things before this can be merged as-is:
Result on the reference device (Android 9 / kernel 3.18.140): So: we're going to keep our implementation for now, but your gates (glibc-marker check, 8-symbol check, dlopen verification) are good and we adopted equivalents. If you'd like, the most useful follow-up is your |
症状
headless
opencode serve起来后一切正常(WebUI 可用),但任何终端都创建不出来:远程客户端
POST /api/pty失败,服务器只在自己的 stderr 里留一行TUI 里开 pane 也一样(pty 是懒加载的,所以启动/渲染都正常,不碰到终端就不报错)。
根因
v2 native 主线(以及 B 线
build-bionic.sh产物)内嵌的是 bun-pty 的upstream glibc
librust_pty_arm64.so。bun-pty 的解析顺序是native 主线把运行时直接装到
$PREFIX/bin/opencode(没有 launcher),所以既没有
BUN_PTY_LIB,也没有磁盘候选,永远走内嵌的 glibc 那份 → bionic 上libpthread.so.0不存在 → dlopen 失败。scripts/build-bionic.sh的PTY_VARIANT只替换@opencode-ai/pty(那个 helperdaemon),碰不到
Pty服务懒加载的 bun-pty FFI,所以两条产线都有这个洞。修法
tools/transplant/swap_pty.py:定位 bunfs 里那份 pty 资产的真实 ELF 边界,用
tools/bun-pty-embed/vendor/librust_pty_arm64_bionic.so(558 个符号同 ABI,8 个
bun_pty_*导出、0 undefined)等长/更短替换,NUL 补齐到原槽位长度,末尾用
ctypes.CDLL做 dlopen 门禁;兼容 bun ≥ 1.4.2 的 consolidated registry 布局。transplant.py:新增步骤 8b,对两个打包赢家(opencode-native-tui/opencode-native-revived)都做 graft;新增pty-swap子命令与steps.pty报告字段。scripts/build-bionic.sh:新增步骤 4a,B 线产物同样 graft(PTY_ASSET_FIX=0可关)。make pty-check BIN=<product>:发版门禁,资产是 glibc 就非零退出。tests/transplant/test_swap_pty.py:合成夹具(JS 诱饵、consolidated 布局、替换门禁、等长替换),已接进
tests.ymlCI。验证(Android 15 / aarch64,已安装的 2.0.22)
POST /api/ptyBUN_PTY_LIB=<vendor>POST /api/pty{status: running, pid: ...},ps能看到/system/bin/sh -lmake pty-check对 glibc 产物tests/transplant/test_swap_pty.py已知边界(请 reviewer 注意)
ELF 边界动态定位,但请在有产物的版本矩阵上各跑一次
make pty-check BIN=...确认没有absent。.so是预编译产物(sha25658aeeb46…,由tools/bun-pty-embed/build-embed.sh重建),换 bun-pty 大版本时需重新走一遍 ABI 比对。
Pty服务改用它路(比如彻底切到@opencode-ai/pty的 musl daemon),资产不存在时工具会报
absent并跳过,不会误伤。pkg upgrade覆盖安装后需重跑补丁(已写进
docs/transplant.md§0.5 与 incident 记录)。