This repository has been archived on 2026-09-16. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Syplheed-Reborn/docker/agent/bin/sylph-doctor
MechaCat02 23fdf12194 docker: a container the autonomous RE agent can be turned loose in
Builds and runs both halves of the project -- Canary as the oracle, Reborn as
the port -- plus the dynamic-RE toolkit. Claude Code runs with
--dangerously-skip-permissions as an unprivileged `agent` user, because that
flag is refused under root.

Capped at half the machine, computed at launch: --cpus nproc/2, --memory half
of MemTotal with --memory-swap equal to it (no swap escape hatch -- a swapping
build thrashes the host, which is the failure the cap exists to prevent), and
build parallelism derived INSIDE the container from available memory rather
than core count, since a full-parallel build of this tree has OOM-killed the
host outright.

Three things the old box got wrong are fixed rather than reproduced: a real
toolchain (so rebuild_canary.sh's hand-relinking is obsolete), numpy and Pillow
(whose absence silently disabled every image oracle and looked like a logic
bug), and a display owned by PID 1 (so Xvfb no longer "dies on its own every
few minutes" -- it was being reaped because nothing owned it).

Verified end to end, not by inspection: the image builds, sylph-doctor is green,
`build-canary` links xenia_canary inside the container, and that binary then
runs -- guest memory and the JIT code cache appear in /dev/shm within 4 s,
1 205 log lines, gmem.py reads guest RAM, pad.py drives the file pad, and
screenshot captures the display.

Five environment defects found and fixed on the way, each of which fails in a
way that points somewhere else entirely:

  * /dev/shm is `noexec` under Docker. Xenia maps its JIT code cache out of an
    shm file, so it died with "Unable to allocate code cache generated code
    storage / Cannot initalize processor" -- which reads as an address-space
    clash, not a mount flag. Now `--tmpfs /dev/shm:rw,exec`.
  * An unknown xenia flag HANGS rather than errors: ParseLaunchArguments calls
    ShowSimpleMessageBox before logging is initialised, and that SDL dialog
    blocks on XIfEvent forever. `--audio` (which the RE notes recommend) is not
    a cvar in this tree; the symptom was a 10x10 window and an empty log.
  * Named volumes come up root-owned unless their mount point exists in the
    image, so the first cmake configure failed on pkgRedirects.
  * Ubuntu 24.04 ships its own uid-1000 account, colliding with the host user.
  * Ubuntu's spirv-opt has no --canonicalize-ids, so the shader step dies ~500
    objects in; the launcher mounts the host's LunarG SDK instead of baking one
    in, which also keeps shader output byte-identical to a host build.

Known limits, stated rather than papered over: on an NVIDIA host without the
NVIDIA Container Toolkit there is no hardware Vulkan (/dev/dri alone does
nothing for NVIDIA), and under lavapipe the emulator runs correctly but was not
observed to reach a rendered frame within a couple of minutes. gdb needs `sudo`
inside the container because the host's yama ptrace_scope outranks SYS_PTRACE.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-17 23:05:48 +02:00

89 lines
4.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Prove the container can actually do the four things it exists for, before an
# unattended agent spends an hour discovering otherwise.
#
# Every check here stands for a failure that has already happened once: a
# display that was not there, a missing numpy that looked like a logic bug, a
# /dev/shm too small for guest memory, a Vulkan stack with no ICD.
set -u
fail=0
ok() { printf ' \033[32m✔\033[0m %s\n' "$*"; }
bad() { printf ' \033[31m✖\033[0m %s\n' "$*"; fail=$((fail+1)); }
warn() { printf ' \033[33m!\033[0m %s\n' "$*"; }
echo "── resources ──"
# nproc shows the HOST's cores: --cpus is a quota, not a mask. Report both so
# "12 cpus" is never mistaken for 12 cpus' worth of throughput.
quota="unlimited"
if [ -r /sys/fs/cgroup/cpu.max ]; then
read -r q p < /sys/fs/cgroup/cpu.max
[ "$q" != max ] && quota="$(( q / p )) (quota)"
fi
echo " cpus: $(nproc) visible, $quota"
if [ -r /sys/fs/cgroup/memory.max ]; then
m=$(cat /sys/fs/cgroup/memory.max)
[ "$m" = max ] && warn "memory: UNLIMITED — the half-the-box cap is not applied" \
|| ok "memory cap: $(( m / 1024 / 1024 / 1024 )) GiB"
fi
shm=$(df -BM /dev/shm | awk 'NR==2{print $2}' | tr -d M)
# Guest memory for a 512 MB console plus the code cache does not fit in
# Docker's 64 MB default, and the symptom is an mmap error, not a disk-full one.
[ "${shm:-0}" -ge 512 ] && ok "/dev/shm: ${shm} MiB" || bad "/dev/shm only ${shm:-?} MiB — need >=512; pass --shm-size"
echo "── toolchain ──"
for t in clang clang++ cmake ninja cargo rustc python3 node claude; do
command -v "$t" >/dev/null && ok "$t ($("$t" --version 2>/dev/null | head -1))" || bad "$t missing"
done
echo "── python (dynamic RE) ──"
# numpy and PIL missing is the specific hole that silently disabled entities2.py
# and every image oracle in the toolkit.
for m in numpy PIL duckdb; do
python3 -c "import $m" 2>/dev/null && ok "python: $m" || bad "python: $m MISSING"
done
echo "── display ──"
if xdpyinfo >/dev/null 2>&1; then
ok "display $DISPLAY ($(xdpyinfo | awk '/dimensions:/{print $2; exit}'))"
pgrep -x openbox >/dev/null && ok "openbox running" || warn "no window manager — window geometry oracles will misread"
out=$(screenshot /tmp/_doctor.png 2>&1) && [ -s /tmp/_doctor.png ] \
&& ok "screenshot works -> $(identify -format '%wx%h' /tmp/_doctor.png 2>/dev/null || echo ok)" \
|| bad "screenshot failed: $out"
rm -f /tmp/_doctor.png
else
bad "no display on ${DISPLAY:-<unset>}"
fi
echo "── vulkan ──"
if command -v vulkaninfo >/dev/null 2>&1; then
dev=$(vulkaninfo --summary 2>/dev/null | grep -m3 -E 'deviceName' | sed 's/^ *//')
[ -n "$dev" ] && { ok "Vulkan devices:"; echo "$dev" | sed 's/^/ /'; } \
|| bad "vulkaninfo found no device (ICD missing?)"
else
bad "vulkaninfo missing"
fi
# Judge by what enumerated, not by whether a device node is present: an NVIDIA
# card needs the NVIDIA Container Toolkit, and /dev/dri alone does nothing.
case "${dev:-}" in
*llvmpipe*|*lavapipe*)
warn "SOFTWARE Vulkan only — correct but slow."
command -v nvidia-smi >/dev/null 2>&1 \
&& warn " host has an NVIDIA GPU: install nvidia-container-toolkit for hardware" ;;
"") ;;
*) ok "hardware Vulkan" ;;
esac
echo "── project ──"
[ -d /work/xenia-canary ] && ok "/work/xenia-canary" || bad "/work/xenia-canary not mounted"
[ -d /work/Syplheed-Reborn ] && ok "/work/Syplheed-Reborn" || bad "/work/Syplheed-Reborn not mounted"
iso=$(find /work -maxdepth 2 -type f -iname '*.iso' -printf '%s\t%p\n' 2>/dev/null | sort -rn | head -1 | cut -f2-)
[ -n "$iso" ] && ok "ISO: $iso" || warn "no ISO under /work — run-canary needs SYLPH_ISO"
[ -d /work/sylph_extract/dat ] && ok "extracted disc (disc-gated tests will run)" \
|| warn "no extracted disc — Reborn disc tests will SKIP"
[ -w /sylph-home/re/.claude ] && ok "~/.claude writable (token refresh works)" \
|| warn "~/.claude not writable — Claude Code may fail to refresh auth"
echo
[ "$fail" -eq 0 ] && { echo "all good."; exit 0; }
echo "$fail check(s) failed."; exit 1