From 6544ee39cbc4b1e3af5467239fed6984f31c63e7 Mon Sep 17 00:00:00 2001 From: clover caruso Date: Sun, 25 Oct 2026 04:33:53 -0700 Subject: [PATCH] Stabilize Snow Globe networking and add the workspace SSD Preserve the live CPU partition and published runtime launcher, protect the new server processes, include browser dependencies, and record the Mac VM code-share mount retry. Match the Ethernet adapter by MAC address so PCI renumbering does not change its configured interface name. Import the work pool and bind it into Knife at /work on startup. Assisted-by: gpt-6.1-sol Assisted-by: gpt-6.1-terra --- guest/net.paperclover.code-share.plist | 19 +++++++++++++ nixos/knife-linux.Containerfile | 2 +- nixos/knife-linux.nix | 19 ++++++++----- nixos/snowglobe-network.nix | 8 ++++++ nixos/snowglobe.nix | 2 +- tools/knife-linux-oom.py | 9 +++++-- tools/knife-linux.md | 37 ++++++-------------------- tools/knife-server | 19 ++++++++----- tools/mac-agent-vm.md | 4 +++ 9 files changed, 73 insertions(+), 46 deletions(-) create mode 100644 guest/net.paperclover.code-share.plist diff --git a/guest/net.paperclover.code-share.plist b/guest/net.paperclover.code-share.plist new file mode 100644 index 0000000000000000000000000000000000000000..68f2e20cdca2a0dbd24374364e80cb8f1ba6f8d0 --- /dev/null +++ b/guest/net.paperclover.code-share.plist @@ -0,0 +1,19 @@ + + + + + Label + net.paperclover.code-share + ProgramArguments + + /bin/sh + -c + /sbin/mount | /usr/bin/grep -Fq ' on /Volumes/Code (' && exit 0 +/bin/mkdir -p /Volumes/Code && /sbin/mount /Volumes/Code + + RunAtLoad + + StartInterval + 30 + + diff --git a/nixos/knife-linux.Containerfile b/nixos/knife-linux.Containerfile index f46c8369fbbdcd960e5f52f7a72c5ae2fb0bb65f..2546c21d1aedb4515ca0854e18a972615c918516 100644 --- a/nixos/knife-linux.Containerfile +++ b/nixos/knife-linux.Containerfile @@ -7,7 +7,7 @@ RUN dnf -y install --setopt=install_weak_deps=False \ openssh-clients openssl-devel patch procps-ng python3 ripgrep rsync rust tar time tree unzip \ which xz zip zlib-ng-compat-devel zsh \ chromium fontconfig google-noto-sans-fonts google-noto-sans-mono-fonts google-noto-serif-fonts \ - liberation-mono-fonts liberation-sans-fonts liberation-serif-fonts mesa-dri-drivers \ + liberation-mono-fonts liberation-sans-fonts liberation-serif-fonts mesa-dri-drivers mesa-libGLES dbus-daemon \ xorg-x11-server-Xvfb \ && dnf clean all diff --git a/nixos/knife-linux.nix b/nixos/knife-linux.nix index 68aefd475d1b931abf4bbd3a8ae696a914c7d9ec..73b7e5fe3f6ae6472b217c458c6d639589a05d34 100644 --- a/nixos/knife-linux.nix +++ b/nixos/knife-linux.nix @@ -15,7 +15,10 @@ let exec ${pkgs.podman}/bin/podman --root=${root}/containers/storage --runroot=/run/knife-linux/containers "$@" ''; run = "${podman}/bin/knife-linux-podman"; - ccd = "8-15,24-31"; + cpus = "3-15,19-31"; + checkWork = pkgs.writeShellScript "check-knife-work" '' + test "$(${pkgs.util-linux}/bin/findmnt -n -o SOURCE --mountpoint /srv/work)" = work + ''; in { environment.systemPackages = [ podman ]; @@ -24,8 +27,8 @@ in description = "The Knife Linux agent container"; wantedBy = [ "multi-user.target" ]; wants = [ "network-online.target" ]; - after = [ "network-online.target" "mac-studio-sandbox.service" ]; - requires = [ "mac-studio-sandbox.service" ]; + after = [ "network-online.target" "mac-studio-sandbox.service" "zfs-import-work.service" "zfs-mount.service" ]; + requires = [ "mac-studio-sandbox.service" "zfs-import-work.service" ]; # Restarting stops every running agent, so changes wait for a manual restart. restartIfChanged = false; serviceConfig = { @@ -33,6 +36,7 @@ in NotifyAccess = "all"; ExecStartPre = [ "${pkgs.util-linux}/bin/mountpoint -q ${root}" + checkWork "${run} build --quiet --build-arg=UID=${uid} --build-arg=GID=${gid} --tag=localhost/knife-linux --file=${./knife-linux.Containerfile} /var/empty" ]; ExecStart = lib.concatStringsSep " " [ @@ -42,18 +46,19 @@ in "--memory=96g --pids-limit=32768 --shm-size=2g --network=podman" "--volume=${root}/home:/home/clo" "--volume=${sandbox}:/Volumes/Code" + "--volume=/srv/work:/work" "--volume=/opt/studio-project-store/current/bin/jj-real:/usr/local/bin/jj:ro" "--device=/dev/kvm" "localhost/knife-linux" ]; - # Agents get the second CCD to themselves and the host keeps the first. A partition + # Agents get 13 cores to themselves and the host keeps three. A partition # rather than a CPU quota: an exhausted quota freezes the Knife server with the builds. ExecStartPost = "-" + pkgs.writeShellScript "knife-linux-cpus" '' set -e scope=/sys/fs/cgroup$(${run} inspect --format '{{.State.CgroupPath}}' knife-linux) - echo ${ccd} > /sys/fs/cgroup/machine.slice/cpuset.cpus.exclusive - echo ${ccd} > $scope/cpuset.cpus.exclusive - echo ${ccd} > $scope/cpuset.cpus + echo ${cpus} > /sys/fs/cgroup/machine.slice/cpuset.cpus.exclusive + echo ${cpus} > $scope/cpuset.cpus.exclusive + echo ${cpus} > $scope/cpuset.cpus echo root > $scope/cpuset.cpus.partition ''; ExecStop = "${run} stop --ignore --time=90 knife-linux"; diff --git a/nixos/snowglobe-network.nix b/nixos/snowglobe-network.nix index 34ac0759d7065889e8058d1bdcfdef3acffbb4d4..ece32412c42599e0d9ab7a11d23b897c050d8407 100644 --- a/nixos/snowglobe-network.nix +++ b/nixos/snowglobe-network.nix @@ -1,4 +1,12 @@ { + systemd.network.links."10-snowglobe-ethernet" = { + matchConfig.MACAddress = "04:42:1a:0d:e9:b3"; + linkConfig = { + NamePolicy = ""; + Name = "enp4s0"; + }; + }; + networking.useDHCP = false; networking.interfaces.enp4s0.useDHCP = false; networking.interfaces.enp4s0.ipv4.addresses = [ diff --git a/nixos/snowglobe.nix b/nixos/snowglobe.nix index 662090570e4397ec1ddf881768f66b7b877e7553..a6a68386b1fe933305fa978269ef9f5dfdfe35b6 100644 --- a/nixos/snowglobe.nix +++ b/nixos/snowglobe.nix @@ -52,7 +52,7 @@ in boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; boot.zfs.forceImportRoot = false; - boot.zfs.extraPools = [ pool ]; + boot.zfs.extraPools = [ pool "work" ]; boot.zfs.requestEncryptionCredentials = false; security.tpm2.enable = true; diff --git a/tools/knife-linux-oom.py b/tools/knife-linux-oom.py index 1ed5b69b711fed314259e5e4abed9dfc0d10324a..9f24c7ecea5cacb654d8ebc05a29bff1475349ea 100644 --- a/tools/knife-linux-oom.py +++ b/tools/knife-linux-oom.py @@ -13,6 +13,7 @@ HARNESS = re.compile( r"|/home/clo/\.knife/tools/(claude/[^/]+/claude|codex/[^/]+/bin/codex)" ) SERVER = re.compile(r"/home/clo/\.local/share/knife-server/[^/]+/apps/server/dist/bin\.mjs") +RUNTIME = re.compile(r"/home/clo/\.knife/runtime/versions/[^/]+/t3") PROTECTED, WORK = -1000, 800 NETLINK_CONNECTOR, CN_IDX_PROC, PROC_CN_MCAST_LISTEN, PROC_EVENT_EXEC = 11, 1, 1, 2 @@ -25,7 +26,11 @@ def adjust(pid, scope): names = [os.readlink(f"/proc/{pid}/exe"), *(a.decode(errors="replace") for a in argv[1:2])] path = f"/proc/{pid}/oom_score_adj" current = int(open(path).read()) - protected = any(HARNESS.fullmatch(name) for name in names) + server = any(SERVER.fullmatch(name) for name in names) or ( + argv[1:2] in ([b"serve"], [b"__service-launcher"]) + and any(RUNTIME.fullmatch(name) for name in names) + ) + protected = server or any(HARNESS.fullmatch(name) for name in names) if protected: wanted = PROTECTED elif current < 0: @@ -34,7 +39,7 @@ def adjust(pid, scope): wanted = current if current != wanted: open(path, "w").write(str(wanted)) - nice = -20 if any(SERVER.fullmatch(name) for name in names) else 0 if protected else 19 + nice = -20 if server else 0 if protected else 19 # Niceness belongs to each thread; renicing the leader leaves workers unchanged. for tid in os.listdir(f"/proc/{pid}/task"): try: diff --git a/tools/knife-linux.md b/tools/knife-linux.md index 00dd4c60904287bd8b18b37639ab980a5bd09278..00a0cddfbb3dea6184b695c0bfa66d6ff92e379d 100644 --- a/tools/knife-linux.md +++ b/tools/knife-linux.md @@ -4,7 +4,7 @@ agents directly beside ZFS. [knife-linux.nix](../nixos/knife-linux.nix) builds it from [knife-linux.Containerfile](../nixos/knife-linux.Containerfile) on each start and runs it as the `knife-linux` system service: uid 3000 (`clo`), no -capabilities, the 16 threads of the second CCD to itself, a 96 GiB memory limit, `/dev/kvm`, and Podman's NAT network. +capabilities, 13 cores (26 threads) to itself, a 96 GiB memory limit, `/dev/kvm`, and Podman's NAT network. Knife listens on container loopback port 3773; devices reach it through the mesh as `snowglobe` (device `4b85ee48…`). User namespaces work inside, but Podman's seccomp filter blocks the `chroot` Chromium-based sandboxes need, so Chromium, @@ -24,6 +24,7 @@ added to the running container. | Container path | Host source | | --- | --- | | `/Volumes/Code` | the Mac VM's NFS export, `/srv/mac-studio-vm/sandbox` | +| `/work` | the unencrypted, uncompressed `work` SSD pool, `/srv/work` | | `/home/clo` | `/srv/knife-linux/home` on `globe/clover/knife-linux` | | `/usr/local/bin/jj` | the storage host's `jj-real`, read-only | @@ -63,34 +64,12 @@ store in `~/.git-credentials`. ## Runtime and updates -The active runtime is `~/.local/share/knife-server/current`, pointing to -`build-372d14b9d5b4-linux-tmp`. This is a pinned native build of Clover's -`knife-merge` fork, not the older published Linux container. Source archive -SHA256: `372d14b9d5b41eef1e8bcc856966fbc8749dd091df1ac09682c9238770f68b39`. -Private installation archives are on ZFS in `/srv/vm/.knife-linux-deploy-20261023`. -Apply [knife-linux-codex.patch](knife-linux-codex.patch) before building. It keeps -Codex's `.tmp` plugin locks local to each profile so restarts can recreate drivers. -[knife-server](knife-server) is the `~/.local/bin/knife` launcher. - -Build inside the container from a fresh source directory, keeping the current -runtime available until verification succeeds: - -```sh -pnpm install --frozen-lockfile -vp run --filter t3 build -CARGO_BUILD_JOBS=8 cargo build --locked --release \ - --manifest-path native/knife-mesh/Cargo.toml -p knife-mesh-node \ - --target x86_64-unknown-linux-gnu -CARGO_BUILD_JOBS=4 cargo build --locked --release \ - --manifest-path native/resource-monitor/Cargo.toml -``` - -After the server build, stage `libknife_mesh_node.so` as -`apps/server/dist/knife-mesh/linux-x64/knife_mesh.node` and the resource monitor as -`apps/server/dist/resource-monitor/linux-x64/t3-resource-monitor`. Stage the font -assets in `apps/server/dist/client/fonts` and link `node` in the runtime root to -`/opt/node/26.12.1/bin/node`. Switch `current` and restart only when agents are -idle. Automatic fork updates are not configured for this source build. +The published Linux runtime lives under `~/.knife/runtime/versions`, with +`~/.knife/runtime/current` selecting the active version and `runtime/release-feed` +selecting the Knife release feed. [knife-server](knife-server) is installed as +`~/.local/bin/knife`; the container's `start` command runs the foreground service +launcher in web mode, allowing remote updates to replace the server in place. +The previous source build remains under `~/.local/share/knife-server`. ## Agent homes diff --git a/tools/knife-server b/tools/knife-server index 2450a88e11a43bdfcc46d9ddfdcad8d21f450503..59084825734eefe364876257b6e7c92e636d0d4e 100755 --- a/tools/knife-server +++ b/tools/knife-server @@ -1,9 +1,16 @@ #!/bin/sh set -eu -runtime="$HOME/.local/share/knife-server/current" -export T3CODE_HOME="${T3CODE_HOME:-$HOME/.knife}" -export T3CODE_CLI_PATH="$HOME/.local/bin/knife" -export KNIFE_MESH_ADDON="$runtime/apps/server/dist/knife-mesh/linux-x64/knife_mesh.node" -export T3CODE_RESOURCE_MONITOR_PATH="$runtime/apps/server/dist/resource-monitor/linux-x64/t3-resource-monitor" -exec "$runtime/node" "$runtime/apps/server/dist/bin.mjs" "$@" +export KNIFE_HOME="$HOME/.knife" +export T3CODE_HOME="$KNIFE_HOME" + +if [ "${1:-}" = start ]; then + shift + if [ "${1:-}" = --mode ] && [ "${2:-}" = desktop ]; then + shift 2 + set -- --mode web "$@" + fi + export KNIFE_FOREGROUND_SUPERVISOR=1 + exec "$KNIFE_HOME/runtime/current/t3" __service-launcher serve "$@" +fi +exec "$KNIFE_HOME/runtime/current/t3" "$@" diff --git a/tools/mac-agent-vm.md b/tools/mac-agent-vm.md index 1cfaf85411c27fb068694321f0de0dd08d733e5a..c7bb5231dd60dd37efb3e2bdbcb958d98e1dc00f 100644 --- a/tools/mac-agent-vm.md +++ b/tools/mac-agent-vm.md @@ -166,6 +166,10 @@ through the guest agent into the logged-in session's pasteboard; no automatic keystroke or continuous clipboard sharing is enabled. SSH resolves the current VM address each time and reuses the existing pinned key configuration. +The guest mounts Snow Globe’s NFS export at `/Volumes/Code` using `/etc/fstab`. +[net.paperclover.code-share.plist](../guest/net.paperclover.code-share.plist) +runs as a system LaunchDaemon at boot and retries every 30 seconds if needed. + The guest's `/etc/hosts` maps `file.paperclover.net` to the NAS LAN address `10.0.0.1`. Traffic uses the VM's NAT gateway `192.168.64.1`; the host's hosts file is not inherited. The previous guest file is `/etc/hosts.before-code-nas`. -- 2.54.1