Skip to content

Commit b39ebbe

Browse files
fluffy314cursoragent
authored andcommitted
Harden mac-bridge Python pinning and add reboot auto-recover module.
Pin mac-bridge preset execution to a configurable venv interpreter (with mlx_lm preflight checks) and add a launchd-based runner self-heal flow so Mac reboots automatically restore bridge availability. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 9bbe190 commit b39ebbe

4 files changed

Lines changed: 116 additions & 1 deletion

File tree

.github/workflows/mac-bridge.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ jobs:
9595
- name: Run preset (allowlist-validated executor)
9696
env:
9797
PYTHONPATH: .:sdks/python
98+
# Pin the interpreter used by the bridge executor so runner
99+
# reboots/PATH drift cannot silently fall back to a python
100+
# without mlx/mlx_lm.
101+
KAKEYA_MAC_PYTHON: ${{ vars.KAKEYA_MAC_PYTHON || '/Users/fluffy314/Documents/Kakeya-LLM-Inference-engine-pr109/.venv-mac/bin/python3' }}
98102
# Machine-local model locations come from the runner env,
99103
# never from the manifest (docs/ops/mac-m4-runner-setup.md).
100104
# Precedence: repo Actions variable > ~/kakeya-models/<name>
@@ -114,7 +118,9 @@ jobs:
114118
export KAKEYA_MAC_DRAFTER_ID="${KAKEYA_MAC_DRAFTER_ID_VAR:-z-lab/gemma-4-26B-A4B-it-DFlash}"
115119
export KAKEYA_MAC_FTHETA_DIR="${KAKEYA_MAC_FTHETA_DIR_VAR:-results/research/f_theta_v5_s5_sliding}"
116120
echo "verifier=$KAKEYA_MAC_VERIFIER_PATH"
117-
python3 scripts/mac_bridge/run_preset.py \
121+
"${KAKEYA_MAC_PYTHON}" --version
122+
"${KAKEYA_MAC_PYTHON}" -c "import mlx_lm"
123+
"${KAKEYA_MAC_PYTHON}" scripts/mac_bridge/run_preset.py \
118124
--manifest .mac-bridge/request.json
119125
120126
- name: Commit results back to the request branch
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
# Install a user LaunchAgent that re-checks the mac-bridge runner
3+
# after reboot and periodically self-heals it.
4+
5+
set -euo pipefail
6+
7+
REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
8+
RECOVER_SCRIPT="${REPO_ROOT}/scripts/mac_bridge/recover_runner_after_reboot.sh"
9+
PLIST_DIR="${HOME}/Library/LaunchAgents"
10+
PLIST_PATH="${PLIST_DIR}/com.kakeya.mac-bridge-runner-autorecover.plist"
11+
LABEL="com.kakeya.mac-bridge-runner-autorecover"
12+
UID_NUM="$(id -u)"
13+
14+
mkdir -p "$PLIST_DIR"
15+
[ -x "$RECOVER_SCRIPT" ] || chmod +x "$RECOVER_SCRIPT"
16+
17+
cat >"$PLIST_PATH" <<EOF
18+
<?xml version="1.0" encoding="UTF-8"?>
19+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
20+
<plist version="1.0">
21+
<dict>
22+
<key>Label</key>
23+
<string>${LABEL}</string>
24+
25+
<key>ProgramArguments</key>
26+
<array>
27+
<string>/bin/bash</string>
28+
<string>${RECOVER_SCRIPT}</string>
29+
</array>
30+
31+
<key>WorkingDirectory</key>
32+
<string>${REPO_ROOT}</string>
33+
34+
<key>RunAtLoad</key>
35+
<true/>
36+
<key>StartInterval</key>
37+
<integer>60</integer>
38+
39+
<key>StandardOutPath</key>
40+
<string>${HOME}/actions-runner/_diag/launchagent-autorecover.out.log</string>
41+
<key>StandardErrorPath</key>
42+
<string>${HOME}/actions-runner/_diag/launchagent-autorecover.err.log</string>
43+
</dict>
44+
</plist>
45+
EOF
46+
47+
launchctl bootout "gui/${UID_NUM}" "${PLIST_PATH}" >/dev/null 2>&1 || true
48+
launchctl bootstrap "gui/${UID_NUM}" "${PLIST_PATH}"
49+
launchctl enable "gui/${UID_NUM}/${LABEL}" || true
50+
launchctl kickstart -k "gui/${UID_NUM}/${LABEL}" || true
51+
52+
echo "[mac-bridge-autorecover] installed: ${PLIST_PATH}"
53+
echo "[mac-bridge-autorecover] label: ${LABEL}"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
# Self-heal the GitHub Actions runner after Mac reboot.
3+
#
4+
# Idempotent:
5+
# - if Runner.Listener is already alive: no-op
6+
# - else try svc.sh start (when service is installed)
7+
# - if service is not installed/usable, fall back to foreground run.sh
8+
# via nohup so bridge jobs can still execute.
9+
10+
set -euo pipefail
11+
12+
RUNNER_DIR="${RUNNER_DIR:-$HOME/actions-runner}"
13+
LOG_DIR="${RUNNER_LOG_DIR:-$HOME/actions-runner/_diag}"
14+
mkdir -p "$LOG_DIR"
15+
16+
log() { echo "[mac-bridge-recover] $*" >&2; }
17+
18+
if pgrep -f "Runner.Listener.*${RUNNER_DIR}" >/dev/null 2>&1; then
19+
log "Runner.Listener already running."
20+
exit 0
21+
fi
22+
23+
if [ ! -x "${RUNNER_DIR}/run.sh" ]; then
24+
log "runner not found at ${RUNNER_DIR}; skipping."
25+
exit 0
26+
fi
27+
28+
if [ -x "${RUNNER_DIR}/svc.sh" ] && "${RUNNER_DIR}/svc.sh" status 2>/dev/null | grep -q "installed"; then
29+
log "service installed; attempting svc.sh start"
30+
if "${RUNNER_DIR}/svc.sh" start >/dev/null 2>&1; then
31+
sleep 2
32+
if pgrep -f "Runner.Listener.*${RUNNER_DIR}" >/dev/null 2>&1; then
33+
log "runner started via service."
34+
exit 0
35+
fi
36+
fi
37+
log "service start did not bring up listener, falling back to run.sh"
38+
fi
39+
40+
ts="$(date +%Y%m%d_%H%M%S)"
41+
nohup "${RUNNER_DIR}/run.sh" >"${LOG_DIR}/runner-nohup-${ts}.log" 2>&1 &
42+
sleep 2
43+
if pgrep -f "Runner.Listener.*${RUNNER_DIR}" >/dev/null 2>&1; then
44+
log "runner started via nohup run.sh fallback."
45+
exit 0
46+
fi
47+
48+
log "failed to start runner listener."
49+
exit 1

scripts/mac_bridge/setup_mac.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ else
173173
ok "skipped (rerun with --with-tailscale to enable M2 interactive SSH)"
174174
fi
175175

176+
step "Runner auto-recover module (reboot self-heal)"
177+
chmod +x scripts/mac_bridge/recover_runner_after_reboot.sh \
178+
scripts/mac_bridge/install_autorecover_launchagent.sh
179+
bash scripts/mac_bridge/install_autorecover_launchagent.sh \
180+
|| die "failed to install launchagent auto-recover module"
181+
ok "launchagent auto-recover installed (checks runner every 60s + RunAtLoad)"
182+
176183
printf '\n\033[1m\033[32mMac bridge ready.\033[0m Any push to mac-bridge/** (or AgentMemory/mac-bridge-*) now executes here.\n'
177184
printf 'Smoke it from any clone with push rights:\n'
178185
printf ' PYTHONPATH=.:sdks/python python3 scripts/mac_bridge/kakeya_mac.py run --preset mlx-env-probe --wait 600\n'

0 commit comments

Comments
 (0)