From 342b4729eace2c3c7af5c3cfda081a7aecc6a969 Mon Sep 17 00:00:00 2001 From: Roberto Cano <3525807+robercano@users.noreply.github.com> Date: Mon, 20 Jul 2026 23:10:29 +0200 Subject: [PATCH 1/2] fix(loop): fail arm-loop loudly on leftover __PLACEHOLDER__ after sed (#130) Guard both installed unit files (pr-loop and claude-rc) right after the sed blocks write them: grep each for any surviving __[A-Z_]*__ token and exit 1 with the offending file/placeholder if one leaked through. Turns future template/script skew into an immediate, diagnosable arm-time failure instead of a silent status=127 at the next reboot. Co-Authored-By: Claude Sonnet 5 --- .claude/scripts/arm-loop.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.claude/scripts/arm-loop.sh b/.claude/scripts/arm-loop.sh index db2ef89..0ded7f6 100755 --- a/.claude/scripts/arm-loop.sh +++ b/.claude/scripts/arm-loop.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# @orchestrator-managed arm-loop v6 +# @orchestrator-managed arm-loop v7 # arm-loop.sh — installs the cron-less PR-loop as systemd (user) units # (issue #102). Templated + re-stamped by `/orchestrator:setup`/`sync`; do # not hand-edit the copy scaffold.sh wrote into this repo if you want future @@ -218,6 +218,20 @@ sed -e "s#__WORKDIR__#$repo_root#g" \ echo "arm-loop.sh: wrote $pr_loop_dst" echo "arm-loop.sh: wrote $claude_rc_dst" +# Guard against template/script skew (issue #130): if either sed block above +# is missing a substitution for a placeholder the template still contains +# (e.g. a new __FOO__ added to the .service template without a matching -e +# here), the installed unit silently keeps the literal token and systemd +# fails it at the NEXT boot with an opaque status=127 -- long after this +# script has exited 0. Fail loudly, right here, instead. +for dst in "$pr_loop_dst" "$claude_rc_dst"; do + leftover="$(grep -o '__[A-Z_]*__' "$dst" 2>/dev/null | sort -u | tr '\n' ' ')" + if [ -n "$leftover" ]; then + echo "arm-loop.sh: unsubstituted placeholder(s) leaked into $dst: $leftover-- the sed block that generated this file is missing a substitution (issue #130); fix arm-loop.sh before re-running." >&2 + exit 1 + fi +done + systemctl --user daemon-reload # pr-loop: enable --now on purpose (NOT restart) — never kill a daemon that # may have a driver in flight; a re-arm only rewrites its unit file, and the From 213fc82ac85826094468af9caf545fd8c94bbc1d Mon Sep 17 00:00:00 2001 From: Roberto Cano <3525807+robercano@users.noreply.github.com> Date: Mon, 20 Jul 2026 23:21:02 +0200 Subject: [PATCH 2/2] fix(loop): scope arm-loop placeholder guard to directive lines + pipefail-safe (#130) Two adversarial review findings on the arm-loop.sh leftover-placeholder guard: (1) grep -o found nothing on a clean install and, under set -euo pipefail, aborted the script before daemon-reload; (2) both systemd templates carry the literal doc token __PLACEHOLDER__ in their header comment, causing a false-positive exit 1 on every run. Scope the scan to non-comment (directive) lines only and add `|| true` so a no-match no longer aborts the healthy path. Co-Authored-By: Claude Sonnet 5 --- .claude/scripts/arm-loop.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.claude/scripts/arm-loop.sh b/.claude/scripts/arm-loop.sh index 0ded7f6..2206221 100755 --- a/.claude/scripts/arm-loop.sh +++ b/.claude/scripts/arm-loop.sh @@ -225,9 +225,14 @@ echo "arm-loop.sh: wrote $claude_rc_dst" # fails it at the NEXT boot with an opaque status=127 -- long after this # script has exited 0. Fail loudly, right here, instead. for dst in "$pr_loop_dst" "$claude_rc_dst"; do - leftover="$(grep -o '__[A-Z_]*__' "$dst" 2>/dev/null | sort -u | tr '\n' ' ')" + # Scan only directive (non-comment) lines: the template header comments carry + # the literal doc token __PLACEHOLDER__, which is not a sed target and must + # not false-positive. A REAL leftover lives in a directive line. `|| true` + # keeps the no-leftover healthy path from aborting under `set -euo pipefail` + # (grep exits 1 on no match). Fail loudly on genuine skew (issue #130). + leftover="$(grep -v '^[[:space:]]*#' "$dst" | grep -o '__[A-Z_]*__' | sort -u | tr '\n' ' ' || true)" if [ -n "$leftover" ]; then - echo "arm-loop.sh: unsubstituted placeholder(s) leaked into $dst: $leftover-- the sed block that generated this file is missing a substitution (issue #130); fix arm-loop.sh before re-running." >&2 + echo "arm-loop.sh: unsubstituted placeholder(s) leaked into $dst: ${leftover}-- the sed block that generated this file is missing a substitution (issue #130); fix arm-loop.sh before re-running." >&2 exit 1 fi done