Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/runbooks/nos-runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,4 @@ Key lines to look for:
- `no IPv4 address in container ls yet`: a VM has no IP yet. Normal for a few seconds after a start.
- `ntfy delivery failed`: an alert did not send. Check the topic and the network.
- `updater plist changed`: run `install.sh` by hand.
- `git pull failed; will retry` (update log): the clone is behind. The updater retries.
- `git update failed; will retry` (update log): the fetch or the fast-forward failed, so the clone is behind. The updater retries. If it repeats, run `git -C ~/.local/share/dev-env fetch origin` and `git -C ~/.local/share/dev-env merge --ff-only origin/main` by hand to see the error.
3 changes: 2 additions & 1 deletion docs/runbooks/swm-macos-runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ Drill the alert path (touches no VM):

The updater job runs `update.sh` at load and every 600 s. It always exits 0.

- It runs `git pull --ff-only` in `~/.local/share/dev-env`. A failed pull (network down, or the NOS updater holding the clone's lock) is logged and tried again on the next run.
- It runs `git fetch --no-write-fetch-head origin` and `git merge --ff-only origin/main` in `~/.local/share/dev-env`. A failure (network down, or a lost race with the NOS updater) is logged as `git update failed; will retry` and tried again on the next run.
- Not `git pull`: launchd starts this job and the NOS updater in the same second. Two pulls then both fail with `Cannot rebase onto multiple branches`, because each fetch appends to the shared `FETCH_HEAD`. That stalled both updaters on every pass on 2026-11-18.
- The version is the last commit that touched `scripts/swm-macos-runner/` or `scripts/nos-runner/github-app.sh`.
The installed version is in `~/.local/state/swm-macos-runner/installed`.
- A hand run of `install.sh` records the version it installs, so the updater's first run does not restart the supervisor a second time.
Expand Down
13 changes: 10 additions & 3 deletions scripts/nos-runner/tests/test-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ cat >"${WORK}/bin/git" <<'STUB'
#!/usr/bin/env bash
echo "$*" >>"${STUB_LOG}/git"
case " $* " in
*" pull "*) exit "${STUB_PULL_RC:-0}" ;;
*" fetch "*) exit "${STUB_PULL_RC:-0}" ;;
*" merge "*) exit "${STUB_MERGE_RC:-0}" ;;
*" log "*) echo "${STUB_REV:-rev1}" ;;
esac
STUB
Expand Down Expand Up @@ -424,7 +425,9 @@ rc=0
STUB_REV=rev1 run_update || rc=$?
check "update_skips_install_when_no_change: exit 0" test "${rc}" -eq 0
check_not "update_skips_install_when_no_change: install not run" test -e "${WORK}/log/install-run"
check "update pulls with --ff-only" grep -qF -- 'pull --ff-only' "${WORK}/log/git"
check "update fetches without FETCH_HEAD" grep -qF -- 'fetch --quiet --no-write-fetch-head origin' "${WORK}/log/git"
check "update fast-forwards to origin/main" grep -qF -- 'merge --quiet --ff-only origin/main' "${WORK}/log/git"
check_not "update never runs git pull (it races the swm updater)" grep -qF -- ' pull' "${WORK}/log/git"
rc=0
STUB_REV=rev2 run_update || rc=$?
check "update_runs_install_on_change: exit 0" test "${rc}" -eq 0
Expand All @@ -436,9 +439,13 @@ check_not "update does not rerun install for a recorded rev" test -e "${WORK}/lo
rc=0
STUB_PULL_RC=1 STUB_REV=rev3 run_update || rc=$?
check "update_pull_failure_exits_0" test "${rc}" -eq 0
check "update_pull_failure_logs" grep -qF -- 'git pull failed' "${WORK}/err"
check "update_pull_failure_logs" grep -qF -- 'git update failed' "${WORK}/err"
check_not "update_pull_failure_skips_install" test -e "${WORK}/log/install-run"
rc=0
STUB_MERGE_RC=1 STUB_REV=rev3 run_update || rc=$?
check "update_merge_failure_exits_0" test "${rc}" -eq 0
check_not "update_merge_failure_skips_install" test -e "${WORK}/log/install-run"
rc=0
STUB_INSTALL_RC=1 STUB_REV=rev4 run_update || rc=$?
check "update_install_failure_exits_0" test "${rc}" -eq 0
check "update_install_failure_keeps_old_rev" grep -qF -- rev2 "${WORK}/home/.local/state/nos-runner/installed-rev"
Expand Down
10 changes: 6 additions & 4 deletions scripts/nos-runner/update.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Updater LaunchAgent job (every 600 s): pull the clone, run install.sh when scripts/nos-runner/ changed. Always exits 0.
# Updater LaunchAgent job (every 600 s): update the clone, run install.sh when scripts/nos-runner/ changed. Always exits 0.
set -uo pipefail
unset CDPATH

Expand All @@ -15,9 +15,11 @@ log() {
printf '%s update: %s\n' "${ts}" "$*" >&2
}

# A pull failure (network down, diverged clone) is not an error: log it and try again next interval.
if ! "${GIT_BIN}" -C "${CLONE}" pull --ff-only >/dev/null 2>&1; then
log "git pull failed; will retry"
# Not `git pull`: the swm updater runs in the same second, and two pulls
# collide on FETCH_HEAD. Any failure retries.
if ! "${GIT_BIN}" -C "${CLONE}" fetch --quiet --no-write-fetch-head origin >/dev/null 2>&1 ||
! "${GIT_BIN}" -C "${CLONE}" merge --quiet --ff-only origin/main >/dev/null 2>&1; then
log "git update failed; will retry"
exit 0
fi

Expand Down
20 changes: 16 additions & 4 deletions scripts/swm-macos-runner/tests/test-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ mkdir -p "${WORK}/bin"
# WORK is under TMPDIR, never a real clone or state dir.
trap 'rm -rf "${WORK:?}"' EXIT

# git stub: pull fails on STUB_PULL_FAIL; log prints the rev of the first matching "<path> <rev>" line.
# git stub: fetch fails on STUB_PULL_FAIL, merge on STUB_MERGE_FAIL; log prints the rev of the first matching "<path> <rev>" line.
cat >"${WORK}/bin/git" <<'STUB'
#!/usr/bin/env bash
echo "$*" >>"${STUB_LOG}/git"
args=("$@")
for ((i = 0; i < ${#args[@]}; i += 1)); do
case "${args[i]}" in
pull) if [[ -n "${STUB_PULL_FAIL:-}" ]]; then exit 1; fi; exit 0 ;;
fetch) if [[ -n "${STUB_PULL_FAIL:-}" ]]; then exit 1; fi; exit 0 ;;
merge) if [[ -n "${STUB_MERGE_FAIL:-}" ]]; then exit 1; fi; exit 0 ;;
log)
while read -r p r; do
for a in "${args[@]}"; do
Expand Down Expand Up @@ -86,7 +87,9 @@ newrev() { printf '%s\n' "scripts/swm-macos-runner REV2" >"${L}/revs"; }
echo "== no change"
run_update
check "exit 0" test "${RC}" -eq 0
check "pulled the clone" grep -q -- "-C ${WORK}/clone pull --ff-only" "${L}/git"
check "fetched without FETCH_HEAD" grep -q -- "-C ${WORK}/clone fetch --quiet --no-write-fetch-head origin" "${L}/git"
check "fast-forwarded to origin/main" grep -q -- "-C ${WORK}/clone merge --quiet --ff-only origin/main" "${L}/git"
check_not "never git pull (it races the NOS updater)" grep -q -- " pull" "${L}/git"
check_not "no install" test -e "${L}/install"
check "mark unchanged" test "$(cat "${S}/installed")" = REV1

Expand Down Expand Up @@ -166,7 +169,16 @@ again STUB_PULL_FAIL=1
check "exit 0" test "${RC}" -eq 0
check_not "no install" test -e "${L}/install"
check "mark unchanged" test "$(cat "${S}/installed")" = REV1
check "logged" grep -q 'pull failed' <<<"${OUT}"
check "logged" grep -q 'git update failed' <<<"${OUT}"

echo "== merge fails"
run_update
newrev
again STUB_MERGE_FAIL=1
check "exit 0" test "${RC}" -eq 0
check_not "no install" test -e "${L}/install"
check "mark unchanged" test "$(cat "${S}/installed")" = REV1
check "logged" grep -q 'git update failed' <<<"${OUT}"

echo "== install fails"
run_update
Expand Down
10 changes: 6 additions & 4 deletions scripts/swm-macos-runner/update.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Updater LaunchAgent job (every 600 s): pull the clone and run install.sh when the runner code changed and no job runs. Always exits 0.
# Updater LaunchAgent job (every 600 s): update the clone and run install.sh when the runner code changed and no job runs. Always exits 0.
set -uo pipefail
unset CDPATH

Expand All @@ -20,9 +20,11 @@ log() {
}

main() {
# A pull failure (network down, the NOS updater holding the clone's lock) is not an error: retry next interval.
if ! "${GIT_BIN}" -C "${CLONE}" pull --ff-only >/dev/null 2>&1; then
log "git pull failed; will retry"
# Not `git pull`: the NOS updater runs in the same second, and two pulls
# collide on FETCH_HEAD. Any failure retries.
if ! "${GIT_BIN}" -C "${CLONE}" fetch --quiet --no-write-fetch-head origin >/dev/null 2>&1 ||
! "${GIT_BIN}" -C "${CLONE}" merge --quiet --ff-only origin/main >/dev/null 2>&1; then
log "git update failed; will retry"
return 0
fi

Expand Down
Loading