Skip to content

fix(remote-control): fix daemon spawning and resolve Android seccomp SIGSYS crashes (fixes #51) - #52

Open
hihumanzone wants to merge 4 commits into
wallentx:devfrom
hihumanzone:fix/issue-51-remote-control
Open

hihumanzone wants to merge 4 commits into
wallentx:devfrom
hihumanzone:fix/issue-51-remote-control

Conversation

@hihumanzone

Copy link
Copy Markdown

Summary

Resolves #51 by fixing background daemon spawning failure and Android kernel seccomp SIGSYS crashes when running remote control (agy remote-control start, agy --remote-control, or /remote-control).

Root Cause Analysis

  1. Daemon Spawning Failure (remote-control: cannot open shared object file):
    • Upstream lib/agy_helper.c directly executed the glibc dynamic linker (ld-linux-aarch64.so.1), causing the Linux kernel to associate /proc/self/exe with the dynamic linker rather than the application binary.
    • When Go's os.Executable() was invoked during agy remote-control start daemonization, it resolved to ld.so. The spawned child executed ld.so remote-control serve, which failed because ld.so attempted to load remote-control as an ELF shared library.
  2. Foreground Remote Control Crash (SIGSYS / Exit 159):
    • Antigravity CLI v1.4.4+ introduced mesh network primitives (InitializeMeshDaemon, primeLocalNetworkAccess) which issue syscall 788533211 (0x2f000fdb).
    • On standard desktop Linux, the kernel returns -ENOSYS, which Go handles gracefully.
    • On Android Termux, kernel seccomp policies trap unknown system calls with SECCOMP_RET_TRAP, terminating the process with SIGSYS (exit code 159).

Solution

  1. Direct Kernel Execution in lib/agy_helper.c:
    • For native aarch64 execution, attempts direct execution of patched_bin via execv(patched_bin, argv). This preserves /proc/self/exe as agy.va39, enabling Go daemonization to locate and spawn the binary correctly.
    • Preserves seamless fallback to execv(loader, new_argv) for QEMU environments or unpatched binaries.
  2. Auxiliary Compatibility Shim (lib/agy_compat.c):
    • Implements a lightweight syscall() filter intercepting syscall 788533211 / 0x2f000fdb and returning -1 (errno = ENOSYS), bypassing Android kernel seccomp traps.
    • Resolves __errno_location from glibc libc.so.6 and compiles cleanly with -nostdlib.
    • Conforms strictly to upstream .clang-format, .clang-tidy, and cppcheck requirements with zero warnings under WarningsAsErrors: '*'.
  3. Automated ELF Patching in build.sh:
    • Sets PT_INTERP and RUNPATH on bin/agy.va39 using patchelf.
    • Links libagy_compat.so via patchelf --add-needed, ensuring it is loaded automatically by the glibc dynamic linker.
  4. Packaging & Installer Integration:
    • Updates install.sh, pr-check.yml, and auto-sync-release.yml to package and deploy libagy_compat.so alongside agy and agy.va39.

Verification

  • Passed clang-format --dry-run --Werror lib/*.c
  • Passed clang-tidy lib/*.c -- -std=gnu11 with zero warnings under WarningsAsErrors: '*'
  • Passed cppcheck --enable=warning,performance,portability lib/ with zero warnings
  • Passed strict-termux-clang compile checks
  • Validated standalone package build with ./build.sh
  • Verified agy remote-control start daemonization on native Termux (aarch64) - daemon active and healthy
  • Verified agy --remote-control interactive session without SIGSYS crashes

…YS crashes (fixes wallentx#51)

- lib/agy_compat.c: add auxiliary compatibility library intercepting syscall() to bypass Android seccomp SIGSYS trap on syscall 788533211 (0x2f000fdb)
- lib/agy_helper.c: attempt direct kernel execv() of agy.va39 when running natively on aarch64 to maintain correct /proc/self/exe resolution for Go daemonization
- build.sh: compile libagy_compat.so with -nostdlib, set PT_INTERP and RUNPATH on agy.va39 with patchelf, and add libagy_compat.so to DT_NEEDED
- install.sh: extract and install libagy_compat.so alongside binaries with full backup and rollback support
- workflows: package and verify libagy_compat.so in release archive, add patchelf to build dependencies
@hihumanzone
hihumanzone marked this pull request as ready for review October 25, 2026 12:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The shim’s incompatible Bionic/glibc interfaces and unsafe in-place installation can corrupt memory at launch and crash running processes during installation.

6 open issues
What changed in this PR

This PR updates the Termux port’s launch and packaging flow to address remote-control daemon spawning failures and Android seccomp crashes reported in #51.

Changes:

  • Attempts direct execution of the patched payload on native CPUs while retaining the loader/QEMU fallback.
  • Adds a compatibility library with syscall filtering and SIGSYS handling.
  • Patches ELF loading metadata and updates installation and release packaging to include the library.
File Description
lib/​agy_helper.c Attempts direct payload execution to preserve executable identity during daemon spawning.
lib/​agy_compat.c Adds syscall filtering, a SIGSYS handler, and a handler-restoration watchdog.
install.sh Installs the compatibility library and adds backup and cleanup handling.
build.sh Builds the library and patches the payload’s interpreter, RUNPATH, and dependencies.
.github/​workflows/​pr-check.yml Adds patchelf and packages and validates the compatibility library.
.github/​workflows/​auto-sync-release.yml Includes the compatibility library in release archives.

Review effort: Max (adaptive)

Comment thread build.sh Outdated
# Compile auxiliary compatibility library if present.
if [[ -f "lib/agy_compat.c" ]]; then
info "Compiling auxiliary compatibility library..."
if ! "$local_cc" -O2 -fPIC -shared -nostdlib -o bin/libagy_compat.so lib/agy_compat.c; then
Comment thread install.sh Outdated
Comment on lines +321 to +323
install -m 0755 "$EXTRACT_DIR/libagy_compat.so" "$INSTALL_BIN_DIR/libagy_compat.so" || die "Failed to install libagy_compat.so to $INSTALL_BIN_DIR"
mkdir -p "${TERMUX_PREFIX}/glibc/lib" 2>/dev/null || true
cp -pf "$EXTRACT_DIR/libagy_compat.so" "${TERMUX_PREFIX}/glibc/lib/libagy_compat.so" 2>/dev/null || true
Comment thread lib/agy_compat.c Outdated
extern int *__errno_location(void);

static inline void set_errno(int err) {
int *loc = __errno_location();
Comment thread build.sh Outdated
# Patch ELF interpreter and RPATH on agy.va39.
termux_prefix="${PREFIX:-/data/data/com.termux/files/usr}"
info "Patching ELF interpreter and RPATH on bin/agy.va39..."
patchelf --set-interpreter "${termux_prefix}/glibc/lib/ld-linux-aarch64.so.1" \
Comment thread build.sh Outdated

if [[ -f "bin/libagy_compat.so" ]]; then
info "Adding libagy_compat.so DT_NEEDED dependency to bin/agy.va39..."
patchelf --add-needed "libagy_compat.so" bin/agy.va39
Comment thread lib/agy_compat.c Outdated
Comment on lines +60 to +61
usleep(AGY_WATCHDOG_INITIAL_DELAY_US);
install_sigsys_handler();
@wallentx

Copy link
Copy Markdown
Owner

Thanks for the PR and for digging into #51, @hihumanzone.

First, quick update: Google's official Antigravity CLI now ships a native Android/Termux Bionic binary (android_arm64, no glibc required). We just verified v1.5.13 works on Termux including --remote-control without SIGSYS crashes:

curl -fsSL https://antigravity.google/cli/install.sh | bash

It installs to ~/.local/bin/agy so you can test it side-by-side without removing $PREFIX/bin/agy. Could you try the official upstream binary and report back if it doesn't cover your workflow?

Separately, holding off on merging this PR as-is due to a few blockers if we do decide to ship a fix in this port:

  1. Bionic-vs-glibc ABI mismatch in lib/agy_compat.c: compiling with Termux Bionic headers (sizeof(sigset_t)=8, sizeof(struct sigaction)=32, sizeof(pthread_attr_t)=56) and loading into glibc (128, 152, 64) overflows stack buffers in sigemptyset/sigaction/pthread_attr_init.
  2. agy update breakage: perform_transactional_update() in lib/agy_helper.c still only extracts/installs agy and agy.va39, so existing users updating in place would get an agy.va39 with DT_NEEDED: libagy_compat.so and no .so installed.
  3. CI / release breakage: build.sh requires patchelf, which isn't installed in auto-sync-release.yml (ubuntu-latest).

(If we still need to fix #51 in this port, the 0x2f000fdb probe can be patched cleanly in build.sh with a single 4-byte instruction rewrite without needing libagy_compat.so or a polling thread.)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v1.4.4] Bug: remote-control subcommand fails with shared library error on Termux

3 participants