2026-10-31: Six Daemons Forged in Rust and Hardened Runtime

Six quiet daemons on manoir had stopped evolving months ago. Under Language Maturity, Python and Node stop paying rent there and start charging interest. So we read every line first. Auditing those six listeners before porting them to sanctum-rs exposed three live boundary flaws, plus a silent launchd duel leaking token prefixes every ten seconds.
What was still running in interpreted runtimes
Section titled “What was still running in interpreted runtimes”Memory and CPU told the first half of the story. Before cutover, ps on manoir showed six steady-state daemons burning 151 MB of resident RAM and over thirty minutes of cumulative CPU on busy-polling loops and repeated interpreter startups:
| Legacy unit | Runtime | Port / trigger | Baseline RSS & CPU | Boundary or efficiency flaw uncovered |
|---|---|---|---|---|
ha-gateway.js |
Node.js | bridge100:8199 |
19.0 MB |
Checked ALLOWED_PATHS with raw req.url.startsWith('/api/states/') without URL-decoding or dot-segment normalization (%2e%2e traversal), compared bearer tokens with ===, and logged the first 20 chars of HA_TOKEN on startup. |
dench-proxy.js |
Node.js (root) |
0.0.0.0:80 |
15.7 MB |
Ran the entire V8 runtime as uid 0 solely to bind port 80, and reconstructed WebSocket Upgrade requests by concatenating raw HTTP header strings. |
msg-bus/bus.py |
Python .venv |
127.0.0.1:4076 |
18.0 MB, 9m 05s CPU |
Polled SQLite queue.db four times per second (time.sleep(0.25)) around the clock and interpolated message bodies into AppleScript source strings. |
chi-sentinel.py + fseventsd-sentinel.sh |
Python + root Bash |
127.0.0.1:7777 + 300s |
60.2 MB, 20m 51s CPU |
Held a 60 MB Python process for a 30-second /chi JSON gauge while a separate root daemon spawned Python subprocesses every five minutes just to parse JSON state for Reclaiming the FSEventsd Reservoir. |
grok-oauth-proxy.js |
Node.js | 127.0.0.1:4200 |
23.3 MB, 28s CPU |
Stored live OAuth refresh and bearer tokens in plain V8 heap strings and rewrote ~/.grok/auth.json without Zeroizing buffers. |
agy-proxy.js |
Node.js | 127.0.0.1:6543 |
11.3 MB, 15s CPU |
Ran under ProcessType: Background (susceptible to E-core starvation under GPU load) and spawned agy CLI subprocesses without isolated POSIX process-group reaping. |
Four Rust crates, built the Apple way
Section titled “Four Rust crates, built the Apple way”Rather than redesigning any wire contract, we ported all six units into four focused crates in sanctum-rs (bb52ca4) with 100% HTTP, SQLite WAL, and CLI parity:
services/sanctum-airlock(sanctum-ha-gateway+sanctum-dench).sanctum-ha-gatewaycanonicalizes every incoming URI — rejecting%2e,%25,%2f,%5c, nul bytes, backslashes, double slashes, and..segments before checking the method-scoped allowlist — validates bearer tokens via length-hiding SHA-256subtle::ConstantTimeEq, holdsHA_TOKENinzeroize::Zeroizing<String>, logs only an 8-hex-char SHA-256 fingerprint, and writes0600structured audit entries.sanctum-denchlinks directly against Apple’s<launch.h>launch_activate_socket("Listeners", ...)FFI solaunchd(PID 1) binds:80and hands the descriptor to an unprivilegedUserName=sanctumprocess, proxying HTTP and RFC 6455 WebSockets overhyper 1.xon_upgradewith zero raw header concatenation.services/sanctum-msg-bus(sanctum-msg-bus). Preserves the exact SQLite WALqueue.dbschema and/enqueue,/msg/{id}, and/healthzroutes on127.0.0.1:4076, but replaces Python’s4 Hzpolling loop withtokio::sync::Notify(0.0%idle CPU) and passes iMessage text and buddy handles as positionalon run argvparameters to/usr/bin/osascriptso untrusted text never touches AppleScript syntax.services/sanctum-chi(sanctum-chi). Serves/chiand/healthon127.0.0.1:7777while preserving all five Jedi Council capacity invariants (--self-testverified), and folds the rootfseventsdballoon sentinel intosanctum-chi fseventsdusing XNUproc_pid_rusage(RUSAGE_INFO_V4ri_phys_footprint) plus existingNOPASSWDfootprint/pkillrules from an unprivilegedStartInterval=300LaunchAgent.services/sanctum-sub-proxy(sanctum-grok-proxy+sanctum-agy-proxy). Wraps OAuth credentials inZeroizing<String>with single-flight atomic0600refresh and499client-hangup stream aborts on:4200, while serving:6543/healthfrom memory in418 µs(test-agy-proxy-health.sh3/3pass) and reaping timed-out CLI trees via negative-PGIDSIGTERM -> 2s -> SIGKILL.
Two traps caught during live cutover
Section titled “Two traps caught during live cutover”Hot-swapping the LaunchAgents on manoir exposed two real host seams. Unit tests never saw them:
- The silent
launchdduel on:8199. The moment we booted outgui/501/haus.sanctum.ha-gateway, a stale duplicate/Library/LaunchDaemons/haus.sanctum.ha-gateway.plist(system/domain,ThrottleInterval: 10,SuccessfulExit: false) grabbed10.10.10.1:8199. Inspecting~/.sanctum/logs/ha-gateway/launchagent.logshowed that whichever copy lost the boot race had been failing withEADDRINUSEand respawning every ten seconds —8,640failed Node startups per day, each printing theHA_TOKENprefix. Retiringha-gateway.jsinto an immediateexit(0)stub satisfiedSuccessfulExit: falseon the stale daemon immediately while~/.sanctum/scripts/sanctum-seal-root-daemons.shremoves the duplicate plist permanently alongside the:80sanctum-denchsocket-activation cutover. - macOS Application Firewall (
socketfilterfw) vs. ad-hoc Mach-O onbridge100. Loopback (lo0) daemons answered on the first millisecond, butcurl http://10.10.10.1:8199/healthcompleted the TCP handshake and stalled. Checking/usr/libexec/ApplicationFirewall/socketfilterfwexplained why:Firewall is enabled (State = 1)withAutomatically allow built-in/downloaded signed software ENABLED./opt/homebrew/bin/nodesat on the firewall allowlist; an ad-hoc (codesign -s -) Mach-O binary on non-loopbackbridge100did not. Re-signing all six binaries with our AppleDeveloper ID Applicationcertificate and Hardened Runtime (--options runtime,flags=0x10000(runtime)) both clearedsocketfilterfwcleanly and turned on XNU’s kernel enforcement againstDYLD_*injection, unsigned code pages, andtask_for_pidattachment.