| author | |
| committer | |
| log | 6544ee39cbc4b1e3af5467239fed6984f31c63e7 |
| tree | b85f2da91635b6d06ebd43b954a37019cdbc61d7 |
| parent | ecf3b9eed4f36a0f45f018eff1eef6cf79646a31 |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
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-terra9 files changed, 73 insertions(+), 46 deletions(-)
guest/net.paperclover.code-share.plist created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| 3 | <plist version="1.0"> | ||
| 4 | <dict> | ||
| 5 | <key>Label</key> | ||
| 6 | <string>net.paperclover.code-share</string> | ||
| 7 | <key>ProgramArguments</key> | ||
| 8 | <array> | ||
| 9 | <string>/bin/sh</string> | ||
| 10 | <string>-c</string> | ||
| 11 | <string>/sbin/mount | /usr/bin/grep -Fq ' on /Volumes/Code (' &amp;&amp; exit 0 | ||
| 12 | /bin/mkdir -p /Volumes/Code &amp;&amp; /sbin/mount /Volumes/Code</string> | ||
| 13 | </array> | ||
| 14 | <key>RunAtLoad</key> | ||
| 15 | <true/> | ||
| 16 | <key>StartInterval</key> | ||
| 17 | <integer>30</integer> | ||
| 18 | </dict> | ||
| 19 | </plist> | ||
nixos/knife-linux.Containerfile+1-1| ... | @@ -7,7 +7,7 @@ RUN dnf -y install --setopt=install_weak_deps=False \ | ... | @@ -7,7 +7,7 @@ RUN dnf -y install --setopt=install_weak_deps=False \ |
| 7 | openssh-clients openssl-devel patch procps-ng python3 ripgrep rsync rust tar time tree unzip \ | 7 | openssh-clients openssl-devel patch procps-ng python3 ripgrep rsync rust tar time tree unzip \ |
| 8 | which xz zip zlib-ng-compat-devel zsh \ | 8 | which xz zip zlib-ng-compat-devel zsh \ |
| 9 | chromium fontconfig google-noto-sans-fonts google-noto-sans-mono-fonts google-noto-serif-fonts \ | 9 | chromium fontconfig google-noto-sans-fonts google-noto-sans-mono-fonts google-noto-serif-fonts \ |
| 10 | liberation-mono-fonts liberation-sans-fonts liberation-serif-fonts mesa-dri-drivers \ | 10 | liberation-mono-fonts liberation-sans-fonts liberation-serif-fonts mesa-dri-drivers mesa-libGLES dbus-daemon \ |
| 11 | xorg-x11-server-Xvfb \ | 11 | xorg-x11-server-Xvfb \ |
| 12 | && dnf clean all | 12 | && dnf clean all |
| 13 | 13 |
nixos/knife-linux.nix+12-7| ... | @@ -15,7 +15,10 @@ let | ... | @@ -15,7 +15,10 @@ let |
| 15 | exec ${pkgs.podman}/bin/podman --root=${root}/containers/storage --runroot=/run/knife-linux/containers "$@" | 15 | exec ${pkgs.podman}/bin/podman --root=${root}/containers/storage --runroot=/run/knife-linux/containers "$@" |
| 16 | ''; | 16 | ''; |
| 17 | run = "${podman}/bin/knife-linux-podman"; | 17 | run = "${podman}/bin/knife-linux-podman"; |
| 18 | ccd = "8-15,24-31"; | 18 | cpus = "3-15,19-31"; |
| 19 | checkWork = pkgs.writeShellScript "check-knife-work" '' | ||
| 20 | test "$(${pkgs.util-linux}/bin/findmnt -n -o SOURCE --mountpoint /srv/work)" = work | ||
| 21 | ''; | ||
| 19 | in | 22 | in |
| 20 | { | 23 | { |
| 21 | environment.systemPackages = [ podman ]; | 24 | environment.systemPackages = [ podman ]; |
| ... | @@ -24,8 +27,8 @@ in | ... | @@ -24,8 +27,8 @@ in |
| 24 | description = "The Knife Linux agent container"; | 27 | description = "The Knife Linux agent container"; |
| 25 | wantedBy = [ "multi-user.target" ]; | 28 | wantedBy = [ "multi-user.target" ]; |
| 26 | wants = [ "network-online.target" ]; | 29 | wants = [ "network-online.target" ]; |
| 27 | after = [ "network-online.target" "mac-studio-sandbox.service" ]; | 30 | after = [ "network-online.target" "mac-studio-sandbox.service" "zfs-import-work.service" "zfs-mount.service" ]; |
| 28 | requires = [ "mac-studio-sandbox.service" ]; | 31 | requires = [ "mac-studio-sandbox.service" "zfs-import-work.service" ]; |
| 29 | # Restarting stops every running agent, so changes wait for a manual restart. | 32 | # Restarting stops every running agent, so changes wait for a manual restart. |
| 30 | restartIfChanged = false; | 33 | restartIfChanged = false; |
| 31 | serviceConfig = { | 34 | serviceConfig = { |
| ... | @@ -33,6 +36,7 @@ in | ... | @@ -33,6 +36,7 @@ in |
| 33 | NotifyAccess = "all"; | 36 | NotifyAccess = "all"; |
| 34 | ExecStartPre = [ | 37 | ExecStartPre = [ |
| 35 | "${pkgs.util-linux}/bin/mountpoint -q ${root}" | 38 | "${pkgs.util-linux}/bin/mountpoint -q ${root}" |
| 39 | checkWork | ||
| 36 | "${run} build --quiet --build-arg=UID=${uid} --build-arg=GID=${gid} --tag=localhost/knife-linux --file=${./knife-linux.Containerfile} /var/empty" | 40 | "${run} build --quiet --build-arg=UID=${uid} --build-arg=GID=${gid} --tag=localhost/knife-linux --file=${./knife-linux.Containerfile} /var/empty" |
| 37 | ]; | 41 | ]; |
| 38 | ExecStart = lib.concatStringsSep " " [ | 42 | ExecStart = lib.concatStringsSep " " [ |
| ... | @@ -42,18 +46,19 @@ in | ... | @@ -42,18 +46,19 @@ in |
| 42 | "--memory=96g --pids-limit=32768 --shm-size=2g --network=podman" | 46 | "--memory=96g --pids-limit=32768 --shm-size=2g --network=podman" |
| 43 | "--volume=${root}/home:/home/clo" | 47 | "--volume=${root}/home:/home/clo" |
| 44 | "--volume=${sandbox}:/Volumes/Code" | 48 | "--volume=${sandbox}:/Volumes/Code" |
| 49 | "--volume=/srv/work:/work" | ||
| 45 | "--volume=/opt/studio-project-store/current/bin/jj-real:/usr/local/bin/jj:ro" | 50 | "--volume=/opt/studio-project-store/current/bin/jj-real:/usr/local/bin/jj:ro" |
| 46 | "--device=/dev/kvm" | 51 | "--device=/dev/kvm" |
| 47 | "localhost/knife-linux" | 52 | "localhost/knife-linux" |
| 48 | ]; | 53 | ]; |
| 49 | # Agents get the second CCD to themselves and the host keeps the first. A partition | 54 | # Agents get 13 cores to themselves and the host keeps three. A partition |
| 50 | # rather than a CPU quota: an exhausted quota freezes the Knife server with the builds. | 55 | # rather than a CPU quota: an exhausted quota freezes the Knife server with the builds. |
| 51 | ExecStartPost = "-" + pkgs.writeShellScript "knife-linux-cpus" '' | 56 | ExecStartPost = "-" + pkgs.writeShellScript "knife-linux-cpus" '' |
| 52 | set -e | 57 | set -e |
| 53 | scope=/sys/fs/cgroup$(${run} inspect --format '{{.State.CgroupPath}}' knife-linux) | 58 | scope=/sys/fs/cgroup$(${run} inspect --format '{{.State.CgroupPath}}' knife-linux) |
| 54 | echo ${ccd} > /sys/fs/cgroup/machine.slice/cpuset.cpus.exclusive | 59 | echo ${cpus} > /sys/fs/cgroup/machine.slice/cpuset.cpus.exclusive |
| 55 | echo ${ccd} > $scope/cpuset.cpus.exclusive | 60 | echo ${cpus} > $scope/cpuset.cpus.exclusive |
| 56 | echo ${ccd} > $scope/cpuset.cpus | 61 | echo ${cpus} > $scope/cpuset.cpus |
| 57 | echo root > $scope/cpuset.cpus.partition | 62 | echo root > $scope/cpuset.cpus.partition |
| 58 | ''; | 63 | ''; |
| 59 | ExecStop = "${run} stop --ignore --time=90 knife-linux"; | 64 | ExecStop = "${run} stop --ignore --time=90 knife-linux"; |
nixos/snowglobe-network.nix+8| ... | @@ -1,4 +1,12 @@ | ... | @@ -1,4 +1,12 @@ |
| 1 | { | 1 | { |
| 2 | systemd.network.links."10-snowglobe-ethernet" = { | ||
| 3 | matchConfig.MACAddress = "04:42:1a:0d:e9:b3"; | ||
| 4 | linkConfig = { | ||
| 5 | NamePolicy = ""; | ||
| 6 | Name = "enp4s0"; | ||
| 7 | }; | ||
| 8 | }; | ||
| 9 | |||
| 2 | networking.useDHCP = false; | 10 | networking.useDHCP = false; |
| 3 | networking.interfaces.enp4s0.useDHCP = false; | 11 | networking.interfaces.enp4s0.useDHCP = false; |
| 4 | networking.interfaces.enp4s0.ipv4.addresses = [ | 12 | networking.interfaces.enp4s0.ipv4.addresses = [ |
nixos/snowglobe.nix+1-1| ... | @@ -52,7 +52,7 @@ in | ... | @@ -52,7 +52,7 @@ in |
| 52 | boot.loader.systemd-boot.enable = true; | 52 | boot.loader.systemd-boot.enable = true; |
| 53 | boot.loader.efi.canTouchEfiVariables = true; | 53 | boot.loader.efi.canTouchEfiVariables = true; |
| 54 | boot.zfs.forceImportRoot = false; | 54 | boot.zfs.forceImportRoot = false; |
| 55 | boot.zfs.extraPools = [ pool ]; | 55 | boot.zfs.extraPools = [ pool "work" ]; |
| 56 | boot.zfs.requestEncryptionCredentials = false; | 56 | boot.zfs.requestEncryptionCredentials = false; |
| 57 | security.tpm2.enable = true; | 57 | security.tpm2.enable = true; |
| 58 | 58 |
tools/knife-linux-oom.py+7-2| ... | @@ -13,6 +13,7 @@ HARNESS = re.compile( | ... | @@ -13,6 +13,7 @@ HARNESS = re.compile( |
| 13 | r"|/home/clo/\.knife/tools/(claude/[^/]+/claude|codex/[^/]+/bin/codex)" | 13 | r"|/home/clo/\.knife/tools/(claude/[^/]+/claude|codex/[^/]+/bin/codex)" |
| 14 | ) | 14 | ) |
| 15 | SERVER = re.compile(r"/home/clo/\.local/share/knife-server/[^/]+/apps/server/dist/bin\.mjs") | 15 | SERVER = re.compile(r"/home/clo/\.local/share/knife-server/[^/]+/apps/server/dist/bin\.mjs") |
| 16 | RUNTIME = re.compile(r"/home/clo/\.knife/runtime/versions/[^/]+/t3") | ||
| 16 | PROTECTED, WORK = -1000, 800 | 17 | PROTECTED, WORK = -1000, 800 |
| 17 | NETLINK_CONNECTOR, CN_IDX_PROC, PROC_CN_MCAST_LISTEN, PROC_EVENT_EXEC = 11, 1, 1, 2 | 18 | NETLINK_CONNECTOR, CN_IDX_PROC, PROC_CN_MCAST_LISTEN, PROC_EVENT_EXEC = 11, 1, 1, 2 |
| 18 | 19 | ||
| ... | @@ -25,7 +26,11 @@ def adjust(pid, scope): | ... | @@ -25,7 +26,11 @@ def adjust(pid, scope): |
| 25 | names = [os.readlink(f"/proc/{pid}/exe"), *(a.decode(errors="replace") for a in argv[1:2])] | 26 | names = [os.readlink(f"/proc/{pid}/exe"), *(a.decode(errors="replace") for a in argv[1:2])] |
| 26 | path = f"/proc/{pid}/oom_score_adj" | 27 | path = f"/proc/{pid}/oom_score_adj" |
| 27 | current = int(open(path).read()) | 28 | current = int(open(path).read()) |
| 28 | protected = any(HARNESS.fullmatch(name) for name in names) | 29 | server = any(SERVER.fullmatch(name) for name in names) or ( |
| 30 | argv[1:2] in ([b"serve"], [b"__service-launcher"]) | ||
| 31 | and any(RUNTIME.fullmatch(name) for name in names) | ||
| 32 | ) | ||
| 33 | protected = server or any(HARNESS.fullmatch(name) for name in names) | ||
| 29 | if protected: | 34 | if protected: |
| 30 | wanted = PROTECTED | 35 | wanted = PROTECTED |
| 31 | elif current < 0: | 36 | elif current < 0: |
| ... | @@ -34,7 +39,7 @@ def adjust(pid, scope): | ... | @@ -34,7 +39,7 @@ def adjust(pid, scope): |
| 34 | wanted = current | 39 | wanted = current |
| 35 | if current != wanted: | 40 | if current != wanted: |
| 36 | open(path, "w").write(str(wanted)) | 41 | open(path, "w").write(str(wanted)) |
| 37 | nice = -20 if any(SERVER.fullmatch(name) for name in names) else 0 if protected else 19 | 42 | nice = -20 if server else 0 if protected else 19 |
| 38 | # Niceness belongs to each thread; renicing the leader leaves workers unchanged. | 43 | # Niceness belongs to each thread; renicing the leader leaves workers unchanged. |
| 39 | for tid in os.listdir(f"/proc/{pid}/task"): | 44 | for tid in os.listdir(f"/proc/{pid}/task"): |
| 40 | try: | 45 | try: |
tools/knife-linux.md+8-29| ... | @@ -4,7 +4,7 @@ | ... | @@ -4,7 +4,7 @@ |
| 4 | agents directly beside ZFS. [knife-linux.nix](../nixos/knife-linux.nix) builds it | 4 | agents directly beside ZFS. [knife-linux.nix](../nixos/knife-linux.nix) builds it |
| 5 | from [knife-linux.Containerfile](../nixos/knife-linux.Containerfile) on each start | 5 | from [knife-linux.Containerfile](../nixos/knife-linux.Containerfile) on each start |
| 6 | and runs it as the `knife-linux` system service: uid 3000 (`clo`), no | 6 | and runs it as the `knife-linux` system service: uid 3000 (`clo`), no |
| 7 | capabilities, the 16 threads of the second CCD to itself, a 96 GiB memory limit, `/dev/kvm`, and Podman's NAT network. | 7 | capabilities, 13 cores (26 threads) to itself, a 96 GiB memory limit, `/dev/kvm`, and Podman's NAT network. |
| 8 | Knife listens on container loopback port 3773; devices reach it through the mesh | 8 | Knife listens on container loopback port 3773; devices reach it through the mesh |
| 9 | as `snowglobe` (device `4b85ee48…`). User namespaces work inside, but Podman's | 9 | as `snowglobe` (device `4b85ee48…`). User namespaces work inside, but Podman's |
| 10 | seccomp filter blocks the `chroot` Chromium-based sandboxes need, so Chromium, | 10 | seccomp filter blocks the `chroot` Chromium-based sandboxes need, so Chromium, |
| ... | @@ -24,6 +24,7 @@ added to the running container. | ... | @@ -24,6 +24,7 @@ added to the running container. |
| 24 | | Container path | Host source | | 24 | | Container path | Host source | |
| 25 | | --- | --- | | 25 | | --- | --- | |
| 26 | | `/Volumes/Code` | the Mac VM's NFS export, `/srv/mac-studio-vm/sandbox` | | 26 | | `/Volumes/Code` | the Mac VM's NFS export, `/srv/mac-studio-vm/sandbox` | |
| 27 | | `/work` | the unencrypted, uncompressed `work` SSD pool, `/srv/work` | | ||
| 27 | | `/home/clo` | `/srv/knife-linux/home` on `globe/clover/knife-linux` | | 28 | | `/home/clo` | `/srv/knife-linux/home` on `globe/clover/knife-linux` | |
| 28 | | `/usr/local/bin/jj` | the storage host's `jj-real`, read-only | | 29 | | `/usr/local/bin/jj` | the storage host's `jj-real`, read-only | |
| 29 | 30 | ||
| ... | @@ -63,34 +64,12 @@ store in `~/.git-credentials`. | ... | @@ -63,34 +64,12 @@ store in `~/.git-credentials`. |
| 63 | 64 | ||
| 64 | ## Runtime and updates | 65 | ## Runtime and updates |
| 65 | 66 | ||
| 66 | The active runtime is `~/.local/share/knife-server/current`, pointing to | 67 | The published Linux runtime lives under `~/.knife/runtime/versions`, with |
| 67 | `build-372d14b9d5b4-linux-tmp`. This is a pinned native build of Clover's | 68 | `~/.knife/runtime/current` selecting the active version and `runtime/release-feed` |
| 68 | `knife-merge` fork, not the older published Linux container. Source archive | 69 | selecting the Knife release feed. [knife-server](knife-server) is installed as |
| 69 | SHA256: `372d14b9d5b41eef1e8bcc856966fbc8749dd091df1ac09682c9238770f68b39`. | 70 | `~/.local/bin/knife`; the container's `start` command runs the foreground service |
| 70 | Private installation archives are on ZFS in `/srv/vm/.knife-linux-deploy-20261023`. | 71 | launcher in web mode, allowing remote updates to replace the server in place. |
| 71 | Apply [knife-linux-codex.patch](knife-linux-codex.patch) before building. It keeps | 72 | The previous source build remains under `~/.local/share/knife-server`. |
| 72 | Codex's `.tmp` plugin locks local to each profile so restarts can recreate drivers. | ||
| 73 | [knife-server](knife-server) is the `~/.local/bin/knife` launcher. | ||
| 74 | |||
| 75 | Build inside the container from a fresh source directory, keeping the current | ||
| 76 | runtime available until verification succeeds: | ||
| 77 | |||
| 78 | ```sh | ||
| 79 | pnpm install --frozen-lockfile | ||
| 80 | vp run --filter t3 build | ||
| 81 | CARGO_BUILD_JOBS=8 cargo build --locked --release \ | ||
| 82 | --manifest-path native/knife-mesh/Cargo.toml -p knife-mesh-node \ | ||
| 83 | --target x86_64-unknown-linux-gnu | ||
| 84 | CARGO_BUILD_JOBS=4 cargo build --locked --release \ | ||
| 85 | --manifest-path native/resource-monitor/Cargo.toml | ||
| 86 | ``` | ||
| 87 | |||
| 88 | After the server build, stage `libknife_mesh_node.so` as | ||
| 89 | `apps/server/dist/knife-mesh/linux-x64/knife_mesh.node` and the resource monitor as | ||
| 90 | `apps/server/dist/resource-monitor/linux-x64/t3-resource-monitor`. Stage the font | ||
| 91 | assets in `apps/server/dist/client/fonts` and link `node` in the runtime root to | ||
| 92 | `/opt/node/26.12.1/bin/node`. Switch `current` and restart only when agents are | ||
| 93 | idle. Automatic fork updates are not configured for this source build. | ||
| 94 | 73 | ||
| 95 | ## Agent homes | 74 | ## Agent homes |
| 96 | 75 |
tools/knife-server+13-6| ... | @@ -1,9 +1,16 @@ | ... | @@ -1,9 +1,16 @@ |
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | set -eu | 2 | set -eu |
| 3 | 3 | ||
| 4 | runtime="$HOME/.local/share/knife-server/current" | 4 | export KNIFE_HOME="$HOME/.knife" |
| 5 | export T3CODE_HOME="${T3CODE_HOME:-$HOME/.knife}" | 5 | export T3CODE_HOME="$KNIFE_HOME" |
| 6 | export T3CODE_CLI_PATH="$HOME/.local/bin/knife" | 6 | |
| 7 | export KNIFE_MESH_ADDON="$runtime/apps/server/dist/knife-mesh/linux-x64/knife_mesh.node" | 7 | if [ "${1:-}" = start ]; then |
| 8 | export T3CODE_RESOURCE_MONITOR_PATH="$runtime/apps/server/dist/resource-monitor/linux-x64/t3-resource-monitor" | 8 | shift |
| 9 | exec "$runtime/node" "$runtime/apps/server/dist/bin.mjs" "$@" | 9 | if [ "${1:-}" = --mode ] && [ "${2:-}" = desktop ]; then |
| 10 | shift 2 | ||
| 11 | set -- --mode web "$@" | ||
| 12 | fi | ||
| 13 | export KNIFE_FOREGROUND_SUPERVISOR=1 | ||
| 14 | exec "$KNIFE_HOME/runtime/current/t3" __service-launcher serve "$@" | ||
| 15 | fi | ||
| 16 | exec "$KNIFE_HOME/runtime/current/t3" "$@" |
tools/mac-agent-vm.md+4| ... | @@ -166,6 +166,10 @@ through the guest agent into the logged-in session's pasteboard; no automatic | ... | @@ -166,6 +166,10 @@ through the guest agent into the logged-in session's pasteboard; no automatic |
| 166 | keystroke or continuous clipboard sharing is enabled. SSH resolves the current | 166 | keystroke or continuous clipboard sharing is enabled. SSH resolves the current |
| 167 | VM address each time and reuses the existing pinned key configuration. | 167 | VM address each time and reuses the existing pinned key configuration. |
| 168 | 168 | ||
| 169 | The guest mounts Snow Globe’s NFS export at `/Volumes/Code` using `/etc/fstab`. | ||
| 170 | [net.paperclover.code-share.plist](../guest/net.paperclover.code-share.plist) | ||
| 171 | runs as a system LaunchDaemon at boot and retries every 30 seconds if needed. | ||
| 172 | |||
| 169 | The guest's `/etc/hosts` maps `file.paperclover.net` to the NAS LAN address | 173 | The guest's `/etc/hosts` maps `file.paperclover.net` to the NAS LAN address |
| 170 | `10.0.0.1`. Traffic uses the VM's NAT gateway `192.168.64.1`; the host's hosts | 174 | `10.0.0.1`. Traffic uses the VM's NAT gateway `192.168.64.1`; the host's hosts |
| 171 | file is not inherited. The previous guest file is `/etc/hosts.before-code-nas`. | 175 | file is not inherited. The previous guest file is `/etc/hosts.before-code-nas`. |