From 8c2f5fdb384837785e24abfa4327f887c6a123df Mon Sep 17 00:00:00 2001 From: patrick ruster <155988469+prasta1@users.noreply.github.com> Date: Fri, 31 Jul 2026 22:04:40 -0400 Subject: [PATCH] fix(macos): adopt a running Apfel instead of racing for its port MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apfel is started with a blind `nohup apfel --serve --port 11435 &` with no check for an existing instance, while ChromaDB 25 lines below does probe its port first. An Apfel that outlives its run — a nohup'd child whose EXIT trap never fired, e.g. on force-quit — therefore makes every later run log `error: Port 11435 is already in use`. Probe the port the same way the ChromaDB block does and adopt a live instance. APFEL_PID stays empty on that path, so the EXIT trap (which guards on `[ -n "$APFEL_PID" ]`) won't kill a server this run didn't start — matching CHROMA_PID semantics exactly. Co-Authored-By: Claude Fable 5 --- start-macos.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/start-macos.sh b/start-macos.sh index 2aa15d261..6ab78e7f2 100755 --- a/start-macos.sh +++ b/start-macos.sh @@ -170,7 +170,13 @@ ODYSSEUS_SKIP_RUN_HINT=1 ./venv/bin/python setup.py MACHINE_ARCH="$(uname -m)" APFEL_PID="" if [ "$MACHINE_ARCH" = "arm64" ]; then - if command -v apfel >/dev/null 2>&1; then + if (exec 3<>"/dev/tcp/127.0.0.1/11435") 2>/dev/null; then + # An Apfel from a previous run can outlive it (nohup'd child + a trap + # that never fires on force-quit). Adopt it instead of blindly racing + # for the port — same policy as ChromaDB below. APFEL_PID stays empty, + # so the EXIT trap won't kill a server this run didn't start. + echo "▶ Apfel already running on 127.0.0.1:11435 — using it." + elif command -v apfel >/dev/null 2>&1; then APFEL_LOG="${TMPDIR:-/tmp}/odysseus-apfel.log" echo "▶ Starting Apfel server in the background on port 11435…" echo " logging to $APFEL_LOG"