Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA
TypeScript
Capy session: defer the upgrade while a /ship or review run is open; upgrade-path fixes (GST-1677, GST-1658) (#4095)
Garry Tan0c41ced4fd7a
diff --git a/bin/gstack-capy-install b/bin/gstack-capy-installindex 2a9b29a3e..b194527da 100755--- a/bin/gstack-capy-install+++ b/bin/gstack-capy-install@@ -673,7 +673,7 @@ elif [ -n "$REMOTE_VERSION" ] && [ "$REMOTE_VERSION" != "$INSTALLED" ] \fiif [ -n "${GSTACK_CAPY_STALE:-}" ] && [ -z "${GSTACK_CAPY_BEHIND:-}" ]; thennote "stale=$GSTACK_CAPY_STALE"- FIX_NOTE="check network access to origin, then ${GSTACK_CAPY_WRAPPER_PATH:+bash $GSTACK_CAPY_WRAPPER_PATH${FOR:+ --for $FOR}}"+ FIX_NOTE="check network access to origin, then bash ${GSTACK_CAPY_WRAPPER_PATH:-<skill>/scripts/install.sh}${FOR:+ --for $FOR}"fi# The project floor (the doctor's WARN floor row): the floor and its file ride# the trailer, and the fix is the install when it fast-forwards, else the row's.diff --git a/bin/gstack-capy-session b/bin/gstack-capy-sessionindex 1e07f1afb..314390708 100755--- a/bin/gstack-capy-session+++ b/bin/gstack-capy-session@@ -46,8 +46,13 @@# its fix at the install. Either way GSTACK_CAPY_STALE=<note> hands the# installer the trailer's `stale=` note, which also covers a failed fetch# with no successful one in 24 hours. Workflow boundary only: a live workflow-# lease (above) or a live eval run (gstack-detach's ~/.gstack/locks/gstack-evals.lock)-# skips every self-upgrade (UPGRADE_BUSY).+# lease (above), a live eval run (gstack-detach's ~/.gstack/locks/gstack-evals.lock),+# or a /ship or review run open on the state root (an unclosed ship-budget+# ledger written in the last 6 hours, an unconsumed review start under 120+# minutes old: open_run) skips every self-upgrade (UPGRADE_BUSY); an open run+# prints `SELF_UPGRADE: deferred (<run> is open ...)` and --check says the same.+# Below the supported minimum none of this applies: the bootstrapper's floor+# rules run before this script.# --check never moves the checkout; behind origin it prints# `gstack-capy-session: behind origin/<branch>: <installed> -> <remote> (<n> commits); fix: ...`.# Whenever the session ends behind origin (--check, or a self-upgrade that was@@ -129,11 +134,14 @@ fiRERUN="bash ${GSTACK_CAPY_WRAPPER_PATH:-<skill>/scripts/install.sh}${SKILL:+ --for $SKILL}"unset GSTACK_CAPY_STALENOW=$(date +%s) STALE_H="" PIN_WHAT="" UNREASONED="" SWITCH=""+mtime() { stat -c %Y "$1" 2>/dev/null || stat -f %m "$1" 2>/dev/null; } # GNU, then BSD/macOSGIT_DIR_ABS=$(git -C "$ROOT" rev-parse --absolute-git-dir 2>/dev/null)PIN_REASON="${GSTACK_PIN_REASON:-$(git -C "$ROOT" config --local --get gstack.pinReason 2>/dev/null)}"[ -n "$PIN_REASON" ] || [ -z "$REVISION_ARG" ] || PIN_REASON="--revision $REVISION_ARG"-[ -n "$PIN_REASON" ] || [ "$(git -C "$ROOT" config --local --bool --get gstack.contributor 2>/dev/null)" != true ] || PIN_REASON="contributor checkout (gstack.contributor)"-PIN_REASON=$(printf '%s' "$PIN_REASON" | tr ';\r\n' ' ' | tr -s ' ' | cut -c1-80)+[ -n "$PIN_REASON" ] || [ "$(git -C "$ROOT" config --local --bool --get gstack.contributor 2>/dev/null)" != true ] || PIN_REASON="contributor checkout, gstack.contributor"+# The reason rides the trailer inside `(pinned: ...)`: a note separator, a+# colon (`fix:`) or a parenthesis would let it end that note and add its own.+PIN_REASON=$(printf '%s' "$PIN_REASON" | tr -c 'A-Za-z0-9 ._/@#+=,-' ' ' | tr -s ' ' | sed 's/^ //; s/ $//' | cut -c1-80)DEFAULT_BRANCH=$(sed -n "1s/.*branch '\([^']*\)' of .*/\1/p" "$GIT_DIR_ABS/FETCH_HEAD" 2>/dev/null)# A failed fetch empties FETCH_HEAD and resets its mtime, so a successful one leaves its own stamp.if [ -n "${GSTACK_CAPY_REMOTE_MIN:-}" ] && [ "$GSTACK_CAPY_REMOTE_MIN" != unknown ] && [ -n "$GIT_DIR_ABS" ]; then@@ -145,8 +153,8 @@ elif behind; thencase "$_t" in ''|*[!0-9]*) ;; *) [ $((NOW - _t)) -gt 86400 ] && STALE_H=$(((NOW - _t) / 3600)) ;; esacelif [ "${GSTACK_CAPY_REMOTE_MIN:-}" = unknown ] && [ "$SKILL" != none ]; then_ft=""- if [ -f "$GIT_DIR_ABS/gstack-last-fetch" ]; then _ft=$(date -r "$GIT_DIR_ABS/gstack-last-fetch" +%s 2>/dev/null)- elif [ -s "$GIT_DIR_ABS/FETCH_HEAD" ]; then _ft=$(date -r "$GIT_DIR_ABS/FETCH_HEAD" +%s 2>/dev/null)+ if [ -f "$GIT_DIR_ABS/gstack-last-fetch" ]; then _ft=$(mtime "$GIT_DIR_ABS/gstack-last-fetch")+ elif [ -s "$GIT_DIR_ABS/FETCH_HEAD" ]; then _ft=$(mtime "$GIT_DIR_ABS/FETCH_HEAD")fiif [ -z "$_ft" ]; then export GSTACK_CAPY_STALE="no fetch from origin recorded"elif [ $((NOW - _ft)) -gt 86400 ]; then export GSTACK_CAPY_STALE="no fetch from origin in $(((NOW - _ft) / 3600))h"@@ -159,6 +167,8 @@ if [ -n "$STALE_H" ]; thenif [ -z "$_branch" ]; then PIN_WHAT="${PIN_WHAT:+$PIN_WHAT, }HEAD detached at $(git -C "$ROOT" rev-parse --short HEAD)"elif [ -n "$DEFAULT_BRANCH" ] && [ "$_branch" != "$DEFAULT_BRANCH" ]; then PIN_WHAT="${PIN_WHAT:+$PIN_WHAT, }on branch $_branch"fi+ # A reason explains a pin; with nothing pinned there is nothing to explain.+ [ -n "$PIN_WHAT" ] || PIN_REASON=""if gstack_doctor_install_profile "$SKILL"; then export GSTACK_CAPY_STALE="${STALE_H}h (shared checkout: the lane's install moves it)"elif [ -n "$PIN_REASON" ]; then export GSTACK_CAPY_STALE="${STALE_H}h (pinned: $PIN_REASON)"else@@ -182,11 +192,40 @@ foreign_busy() {[ "${GSTACK_UPGRADE_FORCE:-}" != 1 ] && [ -x "$ROOT/bin/gstack-lease" ] \&& "$ROOT/bin/gstack-lease" live --root "$ROOT" --exclude-ancestry-of $$ --count-shared-harness >/dev/null 2>&1}-# eval_live — a live eval run holds gstack-detach's machine-wide eval lock.+# eval_live — a live eval run holds gstack-detach's machine-wide eval lock+# (fcntl flock). Probed with flock(1), else python3 or perl (macOS has no+# flock); with no probe at all a lock file counts as held.eval_live() {local lock="$HOME/.gstack/locks/gstack-evals.lock"- [ -f "$lock" ] && command -v flock >/dev/null 2>&1 && ! flock -n "$lock" true 2>/dev/null+ [ -f "$lock" ] || return 1+ if command -v flock >/dev/null 2>&1; then ! flock -n "$lock" true 2>/dev/null+ elif command -v python3 >/dev/null 2>&1; then+ ! python3 -c 'import fcntl, sys; fcntl.flock(open(sys.argv[1], "a"), fcntl.LOCK_EX | fcntl.LOCK_NB)' "$lock" 2>/dev/null+ elif command -v perl >/dev/null 2>&1; then+ ! perl -e 'use Fcntl ":flock"; open(my $f, ">>", $ARGV[0]) or exit 1; flock($f, LOCK_EX | LOCK_NB) or exit 1' "$lock" 2>/dev/null+ fi+}+# open_run — a /ship or review run open on this state root, printed as+# "<kind> run <id> (<file>)": a ship-budget ledger with no closed_at that was+# written in the last 6 hours (every /ship program ends with a note that+# rewrites it, and Step 22's close stamps closed_at), or a review start capture+# under 120 minutes old that gstack-review-log --finish has not consumed. The+# age bounds keep an abandoned run from holding the upgrade back for good.+open_run() {+ local sr f+ sr=$("$ROOT/bin/gstack-paths" --get GSTACK_STATE_ROOT 2>/dev/null) && [ -n "$sr" ] || return 1+ while IFS= read -r f; do+ grep -q '"kind": *"gstack-ship-budget"' "$f" 2>/dev/null && ! grep -q '"closed_at"' "$f" 2>/dev/null || continue+ echo "/ship run $(basename "$(dirname "$f")") ($f)"+ return 0+ done < <(find "$sr/ship-runs" -mindepth 2 -maxdepth 2 -name budget.json -mmin -360 2>/dev/null)+ f=$(find "$sr/projects" -mindepth 3 -maxdepth 3 -path '*/.review-starts/*.json' -mmin -120 2>/dev/null | head -1)+ [ -n "$f" ] || return 1+ echo "review run $(basename "$f" .json) ($f)"}+RUN_OPEN=""+behind && [ "${GSTACK_UPGRADE_FORCE:-}" != 1 ] && RUN_OPEN=$(open_run)+DEFERRED="${RUN_OPEN:+$RUN_OPEN is open on this machine, so gstack stays at $(head -1 "$ROOT/VERSION" 2>/dev/null) until it ends (R75: upgrades wait for the workflow boundary); fix: $RERUN once the run ends (UPGRADE_BUSY)}"if [ "$CHECK" -eq 1 ]; thenif behind; then# The rerun fast-forwards only what gstack-upgrade would move; otherwise@@ -203,6 +242,7 @@ if [ "$CHECK" -eq 1 ]; thenBRANCH=$(git -C "$ROOT" symbolic-ref -q --short HEAD 2>/dev/null || echo HEAD)echo "gstack-capy-session: behind origin/$BRANCH: $(head -1 "$ROOT/VERSION" 2>/dev/null) -> $GSTACK_CAPY_BEHIND_TO ($GSTACK_CAPY_BEHIND commits); fix: $GSTACK_CAPY_BEHIND_FIX$([ "$GSTACK_CAPY_BEHIND_FIX" = "$RERUN" ] && echo ' (fast-forwards)')"[ -n "$STALE_H" ] && [ -z "$PIN_REASON" ] && ! gstack_doctor_install_profile "$SKILL" && echo "gstack-capy-session: stale: the oldest commit this checkout lacks is ${STALE_H}h old (over 24h); run the fix before the first workflow"+ [ -n "$DEFERRED" ] && echo "gstack-capy-session: upgrade deferred ($DEFERRED)"fielif [ "${GSTACK_CAPY_SELF_UPGRADED:-}" != 1 ]; thenif [ "${GSTACK_CAPY_SELF_UPGRADE:-}" = off ] && [ -z "$UNREASONED" ]; then disabled GSTACK_CAPY_SELF_UPGRADE@@ -233,28 +273,55 @@ EOF_OWNecho "SELF_UPGRADE: skipped ($REASON)"report_behind "$RERUN"export GSTACK_CAPY_BEHIND_BLOCKED="$REASON"+ elif [ -n "$DEFERRED" ]; then+ echo "SELF_UPGRADE: deferred ($DEFERRED)"+ report_behind "$RERUN"+ export GSTACK_CAPY_BEHIND_BLOCKED="$DEFERRED"elif [ -n "$SWITCH" ] && foreign_busy; thenREASON="live gstack sessions hold this installation, so the unreasoned pin ($PIN_WHAT) is not switched under them; fix: $RERUN once they finish (UPGRADE_BUSY)"echo "SELF_UPGRADE: skipped ($REASON)"report_behind "$RERUN"export GSTACK_CAPY_BEHIND_BLOCKED="$REASON"+ elif [ -n "$SWITCH" ] && ! { SETUP_LOCK="$("$ROOT/bin/gstack-paths" --get GSTACK_STATE_ROOT 2>/dev/null)/.setup-lock"; [ "$SETUP_LOCK" != /.setup-lock ] \+ && mkdir -p "$(dirname "$SETUP_LOCK")" 2>/dev/null && mkdir "$SETUP_LOCK" 2>/dev/null && echo "$$" > "$SETUP_LOCK/pid"; }; then+ # The switch and the fast-forward happen under gstack-upgrade's setup lock,+ # taken here and handed over in GSTACK_SETUP_LOCK_OWNER, so a concurrent+ # updater never sees the checkout between the two.+ REASON="another gstack updater holds $SETUP_LOCK (pid $(cat "$SETUP_LOCK/pid" 2>/dev/null || echo unknown)), so the unreasoned pin ($PIN_WHAT) is not switched; fix: $RERUN once it finishes (UPGRADE_BUSY)"+ echo "SELF_UPGRADE: skipped ($REASON)"+ report_behind "$RERUN"+ export GSTACK_CAPY_BEHIND_BLOCKED="$REASON"else- PRE_HEAD="" PRE_BRANCH="" NEW_BRANCH=""+ PRE_HEAD="" PRE_BRANCH="" NEW_BRANCH="" RESTORE_FAILED=""if [ -n "$SWITCH" ]; then+ trap '[ "$(cat "$SETUP_LOCK/pid" 2>/dev/null)" = "$$" ] && rm -rf "$SETUP_LOCK"' EXITPRE_HEAD=$(git -C "$ROOT" rev-parse HEAD) PRE_BRANCH=$(git -C "$ROOT" symbolic-ref -q --short HEAD 2>/dev/null)if git -C "$ROOT" show-ref --verify -q "refs/heads/$DEFAULT_BRANCH"; then git -C "$ROOT" checkout -q "$DEFAULT_BRANCH" 2>/dev/null || PRE_HEAD=""- elif git -C "$ROOT" checkout -q -b "$DEFAULT_BRANCH" 2>/dev/null; then NEW_BRANCH=1+ elif git -C "$ROOT" checkout -q -b "$DEFAULT_BRANCH" 2>/dev/null; then+ NEW_BRANCH=1+ git -C "$ROOT" config "branch.$DEFAULT_BRANCH.remote" origin+ git -C "$ROOT" config "branch.$DEFAULT_BRANCH.merge" "refs/heads/$DEFAULT_BRANCH"else PRE_HEAD=""fifiOLD=$(head -1 "$ROOT/VERSION" 2>/dev/null)- UP_OUT=$("$ROOT/bin/gstack-upgrade" --ff-only-no-reinstall 2>&1); UP_RC=$?+ LOCK_OWNER="${SWITCH:+$$}"+ if [ -n "$LOCK_OWNER" ] && ! grep -q GSTACK_SETUP_LOCK_OWNER "$ROOT/bin/gstack-upgrade" 2>/dev/null; then rm -rf "$SETUP_LOCK"; trap - EXIT; LOCK_OWNER=""; fi+ UP_OUT=$(GSTACK_SETUP_LOCK_OWNER="$LOCK_OWNER" "$ROOT/bin/gstack-upgrade" --ff-only-no-reinstall 2>&1); UP_RC=$?[ -n "$UP_OUT" ] && printf '%s\n' "$UP_OUT"if [ "$UP_RC" -ne 0 ] && [ -n "$PRE_HEAD" ]; then- if [ -n "$PRE_BRANCH" ]; then git -C "$ROOT" checkout -q "$PRE_BRANCH"; else git -C "$ROOT" checkout -q --detach "$PRE_HEAD"; fi- [ -n "$NEW_BRANCH" ] && git -C "$ROOT" branch -q -D "$DEFAULT_BRANCH"- echo "SELF_UPGRADE: pin kept (the fast-forward was refused, so HEAD is back at ${PRE_BRANCH:-$(git -C "$ROOT" rev-parse --short HEAD)})"+ if [ -n "$PRE_BRANCH" ]; then git -C "$ROOT" checkout -q "$PRE_BRANCH" 2>/dev/null; else git -C "$ROOT" checkout -q --detach "$PRE_HEAD" 2>/dev/null; fi \+ && [ "$(git -C "$ROOT" rev-parse HEAD 2>/dev/null)" = "$PRE_HEAD" ] \+ && [ "$(git -C "$ROOT" symbolic-ref -q --short HEAD 2>/dev/null)" = "$PRE_BRANCH" ] || RESTORE_FAILED=1+ if [ -z "$RESTORE_FAILED" ]; then+ [ -n "$NEW_BRANCH" ] && git -C "$ROOT" branch -q -D "$DEFAULT_BRANCH"+ echo "SELF_UPGRADE: pin kept (the fast-forward was refused, so HEAD is back at ${PRE_BRANCH:-$(git -C "$ROOT" rev-parse --short HEAD)})"+ else+ RESTORE_FAILED="the fast-forward was refused and the pin could not be restored: HEAD is at $(git -C "$ROOT" rev-parse --short HEAD 2>/dev/null) on $(git -C "$ROOT" symbolic-ref -q --short HEAD 2>/dev/null || echo 'a detached HEAD'), not ${PRE_BRANCH:-$PRE_HEAD}; fix: git -C $ROOT checkout -q ${PRE_BRANCH:---detach $PRE_HEAD}, then $RERUN (UPGRADE_REFUSED)"+ echo "SELF_UPGRADE: pin not restored ($RESTORE_FAILED)"+ fifi+ if [ -n "$LOCK_OWNER" ]; then rm -rf "$SETUP_LOCK"; trap - EXIT; fiif [ "$UP_RC" -eq 0 ]; then[ -n "$UNREASONED" ] && echo "SELF_UPGRADE: pin overridden ($PIN_WHAT, with no recorded reason, and the oldest commit this checkout lacks is ${STALE_H}h old; keep a pin with GSTACK_PIN_REASON=<why> or git -C $ROOT config gstack.pinReason <why>) (PIN_UNREASONED)"echo "SELF_UPGRADE: done $OLD -> $(head -1 "$ROOT/VERSION" 2>/dev/null)"@@ -263,6 +330,7 @@ EOF_OWNfiREASON=$(printf '%s\n' "$UP_OUT" | sed -n 's/^gstack-upgrade: \(.*\); nothing was changed; fix: /\1; fix: /p' | tail -1)[ -n "$REASON" ] || REASON=$(printf '%s\n' "$UP_OUT" | sed -n 's/^gstack-upgrade: //p' | tail -1)+ [ -z "$RESTORE_FAILED" ] || REASON="$RESTORE_FAILED"echo "SELF_UPGRADE: skipped (${REASON:-gstack-upgrade exit $UP_RC})"report_behind "$ROOT/bin/gstack-upgrade"export GSTACK_CAPY_BEHIND_BLOCKED="${REASON:-gstack-upgrade exit $UP_RC; fix: $ROOT/bin/gstack-upgrade (UPGRADE_REFUSED)}"diff --git a/bin/gstack-upgrade b/bin/gstack-upgradeindex 1849b1b02..6f933b424 100755--- a/bin/gstack-upgrade+++ b/bin/gstack-upgrade@@ -21,7 +21,8 @@# is not a gstack checkout, HEAD is detached or not on the remote default# branch (a pin), any tracked byte is dirty, a local commit diverged, the# incoming release's Bun floor holds, or another updater holds the setup-# lock; never stashes, never resets. Before any fetch it also refuses when+# lock, unless the caller holds it and names its pid in GSTACK_SETUP_LOCK_OWNER;+# never stashes, never resets. Before any fetch it also refuses when# bin/gstack-ff-update --preflight does: an enclosing project tracks the# install's files, or VERSION was put back behind HEAD (#1022). An unreachable remote is# UPGRADE_FETCH_FAILED (exit 3). While another live session holds a workflow@@ -52,7 +53,7 @@ case "${1:-}" in--check) CHECK=1 ;;--ff-only-no-reinstall) REINSTALL=0 ;;'') ;;- -h|--help) sed -n '2,41p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;+ -h|--help) sed -n '2,42p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;*) echo "gstack-upgrade: unknown argument '$1'" >&2; exit 2 ;;esac@@ -240,17 +241,25 @@ fi# The same lock directory the session-start auto-updater (bin/gstack-session-update)# holds while it pulls and runs setup; a live holder means refuse, never wait.+# A caller that took it first (bin/gstack-capy-session, before it switches a+# pin to the default branch) hands it over with GSTACK_SETUP_LOCK_OWNER=<the+# pid in the lock>; the lock stays the caller's to release.GSTACK_STATE_ROOT=$("$ROOT/bin/gstack-paths" --get GSTACK_STATE_ROOT); : "${GSTACK_STATE_ROOT:?gstack-paths failed; reinstall with ./setup or /gstack-upgrade}"LOCK_DIR="$GSTACK_STATE_ROOT/.setup-lock"-mkdir -p "$GSTACK_STATE_ROOT" 2>/dev/null-mkdir "$LOCK_DIR" 2>/dev/null || refuse "another gstack updater holds $LOCK_DIR (pid $(cat "$LOCK_DIR/pid" 2>/dev/null || echo unknown))" "wait for it to finish, then re-run"-echo "$$" > "$LOCK_DIR/pid"-trap '[ "$(cat "$LOCK_DIR/pid" 2>/dev/null)" = "$$" ] && rm -rf "$LOCK_DIR" 2>/dev/null' EXIT+LOCK_HANDED=0+if [ -n "${GSTACK_SETUP_LOCK_OWNER:-}" ] && [ "$(cat "$LOCK_DIR/pid" 2>/dev/null)" = "$GSTACK_SETUP_LOCK_OWNER" ]; then+ LOCK_HANDED=1+else+ mkdir -p "$GSTACK_STATE_ROOT" 2>/dev/null+ mkdir "$LOCK_DIR" 2>/dev/null || refuse "another gstack updater holds $LOCK_DIR (pid $(cat "$LOCK_DIR/pid" 2>/dev/null || echo unknown))" "wait for it to finish, then re-run"+ echo "$$" > "$LOCK_DIR/pid"+ trap '[ "$(cat "$LOCK_DIR/pid" 2>/dev/null)" = "$$" ] && rm -rf "$LOCK_DIR" 2>/dev/null' EXIT+figit -C "$ROOT" merge --ff-only -q FETCH_HEAD 2>/dev/null || refuse "git merge --ff-only FETCH_HEAD failed" "git -C $ROOT status, then re-run"NEW=$(head -1 "$ROOT/VERSION")echo "gstack-upgrade: upgraded $INSTALLED -> $NEW"-rm -rf "$LOCK_DIR"; trap - EXIT+[ "$LOCK_HANDED" -eq 1 ] || { rm -rf "$LOCK_DIR"; trap - EXIT; }[ "$REINSTALL" -eq 1 ] || exit 0reinstall "$INSTALLED"diff --git a/changelog.d/capy-gst-1677-defer-upgrade-open-run.md b/changelog.d/capy-gst-1677-defer-upgrade-open-run.mdnew file mode 100644index 000000000..9362ec1aa--- /dev/null+++ b/changelog.d/capy-gst-1677-defer-upgrade-open-run.md@@ -0,0 +1,2 @@+- **A Capy install run inside an open /ship or review no longer upgrades gstack under it.** During a /ship on gstack-evals #252, the docs audit's session check ran `install.sh --for <skill>` and moved gstack from 1.96.0.0 to 1.97.0.0 mid-run: the workflow lease that was meant to stop it only counts for 120 minutes, and a long /ship outlives it. The Capy session now also looks for a run that is still open on this machine's state root: a /ship budget ledger with no `closed_at` that was written in the last 6 hours, or a review start that `gstack-review-log --finish` has not consumed and that is under 120 minutes old. While one is open the session keeps the installed gstack, prints `SELF_UPGRADE: deferred (...)` naming the run, and still ends `gstack: ok <installed version>`; once the ledger closes, the next install upgrades as before. Below the supported minimum nothing changes, and the floor still refuses or fast-forwards. (GST-1677)+- **Smaller fixes on the same upgrade path.** The eval-lock probe now works without the `flock` binary (python3 or perl stand in, as on macOS). When an unreasoned pin is overridden, the session takes the setup lock before it switches branches and hands it to `gstack-upgrade`, so no other updater sees the checkout between the switch and the fast-forward; an older `gstack-upgrade` on the local default branch, which cannot take the lock over, gets it released and takes it itself, so it still upgrades. A default branch the override creates now tracks origin. A failed restore after a refused fast-forward says `pin not restored` with the command that puts HEAD back, instead of claiming the pin was kept. The no-fetch stale check reads file times with `stat` instead of GNU-only `date -r`. A pin reason can no longer add its own `fix:` note to the trailer, and a reason with nothing pinned is not reported as a pin. The no-fetch fix note names the install command even when the bootstrapper's path is unknown. (GST-1658)diff --git a/docs/capy-install.md b/docs/capy-install.mdindex 9283084cc..75153f896 100644--- a/docs/capy-install.md+++ b/docs/capy-install.md@@ -147,10 +147,25 @@ there is refused with the usual `--for <skill>` fix.undiverged checkout overrides it (`SELF_UPGRADE: pin overridden (...)(PIN_UNREASONED)`), switching to the default branch only when that localbranch is absent or fast-forwardable and no other session holds a lease,- and switching back if `bin/gstack-upgrade` refuses. A workflow lease of the+ and switching back if `bin/gstack-upgrade` refuses; the switch and the+ fast-forward run under the setup lock, which the session takes first and+ hands to `bin/gstack-upgrade` (an older copy on the local default branch,+ which cannot take it over, gets it released and takes it itself). A+ workflow lease of thecurrent run or a live eval run (gstack-detach's- `~/.gstack/locks/gstack-evals.lock`) defers every self-upgrade- (`UPGRADE_BUSY`). A `--for review-voice` reader gets+ `~/.gstack/locks/gstack-evals.lock`, probed with `flock`, else python3 or+ perl) defers every self-upgrade (`UPGRADE_BUSY`). So does a /ship or review+ run open on the state root, whatever the lease's age (GST-1677): a+ ship-budget ledger (`<state root>/ship-runs/<run>/budget.json`) with no+ `closed_at` that was written in the last 6 hours, or a review start+ (`<state root>/projects/<slug>/.review-starts/<token>.json`) under 120+ minutes old that `gstack-review-log --finish` has not consumed. The session+ prints `SELF_UPGRADE: deferred (<kind> run <id> (<file>) is open on this+ machine, so gstack stays at <version> until it ends ...; fix: <install>+ once the run ends (UPGRADE_BUSY))`, keeps the installed revision and stays+ ok; `--check` prints `gstack-capy-session: upgrade deferred (...)`.+ Below the supported minimum an open run changes nothing: `--check` fails+ `revision` and install mode applies the floor as above. A `--for review-voice` reader gets`stale=<h>h (shared checkout: the lane's install moves it)` and only reportsit. With `GSTACK_UPDATE_CHANNEL=stable` nothing is measured against main.4. When the fetch fails (offline), the bootstrapper says `remote minimumdiff --git a/docs/troubleshooting.md b/docs/troubleshooting.mdindex 767d6f71f..c2df46508 100644--- a/docs/troubleshooting.md+++ b/docs/troubleshooting.md@@ -1746,7 +1746,8 @@ yourself; or change the pin in the project.**Meaning.** An install-mode session start above the supported minimum foundthe checkout behind origin and could not fast-forward it: the checkout isdirty, diverged or pinned (`UPGRADE_REFUSED`), another live session holds a-lease (`UPGRADE_BUSY`), `bin/gstack-upgrade` is missing, or the session is a+lease or a /ship or review run is open on the state root (`UPGRADE_BUSY`,+[deferred](#upgrade-busy)), `bin/gstack-upgrade` is missing, or the session is a`--for review-voice` reviewer, which never moves a checkout a lane may share(`UPGRADE_SKIPPED`). Nothing was changed, the doctor certified the installedrevision, and the trailer stays `gstack: ok` with the notes above: a gap@@ -1769,7 +1770,8 @@ of the oldest commit it lacks, and pinned by `GSTACK_CAPY_SELF_UPGRADE=off`,`GSTACK_CAPY_AUTO_UPGRADE=0`, a detached HEAD (`--revision`) or another branch,with no recorded reason. It checked out the default branch where needed andfast-forwarded. A dirty or diverged checkout is still never moved, and a live-workflow lease or eval run still defers the upgrade (`UPGRADE_BUSY`). On+workflow lease, eval run or open /ship or review run still defers the upgrade+(`UPGRADE_BUSY`). On`--check` the trailer carries `stale=<h>h` with the install as its fix; unlike abare `behind=`, run that fix before the first workflow.@@ -1826,6 +1828,14 @@ this checkout (UPGRADE_BUSY))` and leaves thecheckout where the run started. Each `gstack-skill-start` renews the leaseand opens a run that its `gstack-skill-end` closes; a lease whose runs are allclosed is idle and never counts (GST-1205).+A run open on the state root defers the Capy install-mode upgrade whatever+its lease's age (GST-1677): `SELF_UPGRADE: deferred (/ship run <id>+(<ledger>) is open on this machine, so gstack stays at <version> until it+ends (R75: upgrades wait for the workflow boundary); fix: <install> once the+run ends (UPGRADE_BUSY))`, for a ship-budget ledger with no `closed_at`+written in the last 6 hours, or `review run <token> (<file>)` for a review+start under 120 minutes old that `gstack-review-log --finish` has not+consumed.**Fix.** Wait for those sessions to finish (`bin/gstack-lease list` showsevery lease with its age and `alive|idle|dead|stale`; a holder is named asdiff --git a/test/capy-skill-wrapper.test.ts b/test/capy-skill-wrapper.test.tsindex 6d9f3712b..e8083155b 100644--- a/test/capy-skill-wrapper.test.ts+++ b/test/capy-skill-wrapper.test.ts@@ -20,7 +20,7 @@ import * as path from 'path';import { MODEL_FAMILIES } from '../lib/agent-model';import { capyBootstrapCommand } from '../lib/doctor-components';import { RESULT_CODES } from '../lib/result-codes';-import { capyHost, type CapyHost } from './helpers/capy-host';+import { capyHost, pathWithout, type CapyHost } from './helpers/capy-host';const REPO = path.resolve(import.meta.dir, '..');const SKILL = path.join(REPO, 'capy/skill/gstack');@@ -927,12 +927,12 @@ describe('capy skill: R75 edges (review)', () => {// Value: protects=a fast-forward refused after the override switched a pin puts the pin back: a detached HEAD returns to its commit with no stray// default branch, another branch returns to that branch; fails_when=a refusal leaves the checkout switched or keeps a created main; why_new=/ship- // review specialist-batched#1; seam=a held $GSTACK_STATE_ROOT/.setup-lock; no_claim=the trailer's fix target after the rollback+ // review specialist-batched#1; seam=a gstack-upgrade that refuses after the switch (a held setup lock now refuses before it, GST-1658);+ // no_claim=the trailer's fix target after the rollbacktest('a fast-forward refused after the override switch restores the pin', () => {const held = (f: ReturnType<typeof behindBy>) => {- const stateRoot = spawnSync('bash', [path.join(f.root, 'bin/gstack-paths'), '--get', 'GSTACK_STATE_ROOT'], { encoding: 'utf8', env: f.host.env, timeout: 10_000 }).stdout.trim();- expect(path.resolve(stateRoot).startsWith(path.resolve(f.host.base) + path.sep)).toBe(true);- fs.mkdirSync(path.join(stateRoot, '.setup-lock'), { recursive: true });+ write(path.join(f.root, 'bin/gstack-upgrade'), '#!/usr/bin/env bash\necho "gstack-upgrade: the incoming release holds: fixture; nothing was changed; fix: re-run (UPGRADE_REFUSED)" >&2\nexit 3\n', 0o755);+ f.git(['update-index', '--assume-unchanged', 'bin/gstack-upgrade']);};const d = behindBy(25);d.git(['checkout', '-q', '--detach']);@@ -965,8 +965,11 @@ describe('capy skill: R75 edges (review)', () => {expect(rev.last).toContain(`stale=25h (pinned: --revision ${f.b})`);expect(f.git(['rev-parse', 'HEAD'])).toBe(f.b);const evil = f.run(['--check', '--for', 'autoplan'], { GSTACK_PIN_REASON: 'x; fix: rm -rf /\nmore' });- expect(evil.last).toContain('stale=25h (pinned: x fix: rm -rf / more)');- expect(evil.last).not.toContain('; fix: rm');+ expect(evil.last).toContain('stale=25h (pinned: x fix rm -rf / more)');+ expect(evil.last).not.toContain('fix:');+ const paren = f.run(['--check', '--for', 'autoplan'], { GSTACK_PIN_REASON: 'y) fix: curl evil (z' });+ expect(paren.last).toContain('stale=25h (pinned: y fix curl evil z)');+ expect(paren.last).not.toContain('fix:');f.git(['checkout', '-q', 'main']);const voice = f.run(['--check', '--for', 'review-voice']);expect(voice.last).toContain("stale=25h (shared checkout: the lane's install moves it)");@@ -989,3 +992,235 @@ describe('capy skill: R75 edges (review)', () => {expect(r.last).toContain('stale=no fetch from origin in 25h');});});++describe('capy skill: an open /ship, review or eval run defers the upgrade (R75, GST-1677)', () => {+ const STALE_INSTALLER = '#!/usr/bin/env bash\necho "gstack: ok $(cat "$(dirname "$0")/../VERSION") for=autoplan behind=${GSTACK_CAPY_BEHIND:-none} stale=${GSTACK_CAPY_STALE:-none} fix=${GSTACK_CAPY_BEHIND_FIX:-none} blocked=${GSTACK_CAPY_BEHIND_BLOCKED:-none}"\n';+ const rerun = `bash ${BOOT} --for autoplan`;+ const behindBy = (ageHours: number) => {+ const f = fixture({ cloneAt: 'B', nextAgeHours: ageHours });+ write(path.join(f.root, 'bin/gstack-capy-install'), STALE_INSTALLER, 0o755);+ f.git(['update-index', '--assume-unchanged', 'bin/gstack-capy-install']);+ return f;+ };+ const ago = (file: string, hours: number) => { const t = Date.now() / 1000 - hours * 3600; fs.utimesSync(file, t, t); };+ /** A ship-budget ledger the way gstack-ship-budget start writes it (lib/ship-budget.ts writeLedger), under the fixture's state root. */+ const shipLedger = (f: { host: CapyHost }, closed = false) => {+ const run = 'ship-20261106T120000-abc123';+ const file = path.join(f.host.stateRoot, 'ship-runs', run, 'budget.json');+ write(file, JSON.stringify({ schema_version: 1, kind: 'gstack-ship-budget', run, created_at: new Date().toISOString(), ...(closed ? { closed_at: new Date().toISOString() } : {}) }, null, 2) + '\n');+ return { run, file };+ };++ // Value: protects=an install run inside an open /ship (its ship-budget ledger has no closed_at) keeps the installed gstack, says so in one line+ // naming the run, and stays ok; the same install after Step 22 closes the ledger upgrades; --check says the upgrade is deferred; an unreasoned+ // pin is not overridden mid-run either; fails_when=gstack moves under a /ship (GST-1677: 1.96.0.0 -> 1.97.0.0 in gstack-evals#252's docs+ // audit); why_new=GST-1677; seam=the ledger file and its mtime; no_claim=ledgers written with a custom --ledger path+ test('an open ship ledger defers the upgrade and names the run; a closed one does not', () => {+ const f = behindBy(1);+ const { run, file } = shipLedger(f);+ const deferred = `${run} (${file}) is open on this machine, so gstack stays at 1.0.1 until it ends (R75: upgrades wait for the workflow boundary); fix: ${rerun} once the run ends (UPGRADE_BUSY)`;+ const r = f.run(['--for', 'autoplan']);+ expect(r.status, r.stdout + r.stderr).toBe(0);+ expect(r.stdout).toContain(`SELF_UPGRADE: deferred (/ship run ${deferred})`);+ expect(r.stdout).not.toContain('SELF_UPGRADE: done');+ expect(f.git(['rev-parse', 'HEAD'])).toBe(f.b);+ expect(r.last).toBe(`gstack: ok 1.0.1 for=autoplan behind=1 stale=none fix=${rerun} blocked=/ship run ${deferred}`);+ const check = f.run(['--check', '--for', 'autoplan']);+ expect(check.stdout).toContain(`gstack-capy-session: upgrade deferred (/ship run ${deferred})`);++ shipLedger(f, true);+ const closed = f.run(['--for', 'autoplan']);+ expect(closed.stdout).toMatch(/^SELF_UPGRADE: done 1\.0\.1 -> 1\.0\.2$/m);+ expect(f.git(['rev-parse', 'HEAD'])).toBe(f.c);+ });++ // Value: protects=a ledger idle for over 6 hours (an abandoned /ship) does not hold the upgrade back, and an open one also stops the unreasoned+ // pin override, leaving the detached HEAD where it was; fails_when=an abandoned ledger pins the machine, or the override switches a pin+ // mid-run; why_new=GST-1677; seam=the ledger's mtime and a detached HEAD; no_claim=none+ test('an idle ship ledger does not defer; an open one stops the pin override too', () => {+ const idle = behindBy(1);+ ago(shipLedger(idle).file, 7);+ expect(idle.run(['--for', 'autoplan']).stdout).toMatch(/^SELF_UPGRADE: done 1\.0\.1 -> 1\.0\.2$/m);++ const pinned = behindBy(25);+ pinned.git(['checkout', '-q', '--detach']);+ shipLedger(pinned);+ const p = pinned.run(['--for', 'autoplan']);+ expect(p.stdout).toContain('SELF_UPGRADE: deferred (/ship run ');+ expect(p.stdout).not.toContain('pin overridden');+ expect(pinned.git(['rev-parse', 'HEAD'])).toBe(pinned.b);+ expect(spawnSync('git', ['-C', pinned.root, 'symbolic-ref', '-q', 'HEAD'], { timeout: 10_000 }).status).not.toBe(0);+ });++ // Value: protects=a review start gstack-review-log --start captured and --finish has not consumed defers the upgrade; one over 120 minutes old+ // (an abandoned pass) does not; fails_when=a standalone /review has gstack moved under it, or an abandoned start pins the machine;+ // why_new=GST-1677; seam=<state root>/projects/<slug>/.review-starts/<token>.json; no_claim=reviews on another machine+ test('an unconsumed review start defers the upgrade; a stale one does not', () => {+ const f = behindBy(1);+ const start = path.join(f.host.stateRoot, 'projects/garrytan-gstack/.review-starts/0b0e4a52-1111-4222-8333-944445555666.json');+ write(start, JSON.stringify({ skill: 'review', started_at: new Date().toISOString() }));+ const r = f.run(['--for', 'autoplan']);+ expect(r.stdout).toContain(`SELF_UPGRADE: deferred (review run 0b0e4a52-1111-4222-8333-944445555666 (${start}) is open on this machine`);+ expect(f.git(['rev-parse', 'HEAD'])).toBe(f.b);+ ago(start, 3);+ expect(f.run(['--for', 'autoplan']).stdout).toMatch(/^SELF_UPGRADE: done 1\.0\.1 -> 1\.0\.2$/m);+ });++ // Value: protects=below the supported minimum an open run does not defer: --check still fails revision and a pinned checkout still fails, with no+ // deferral line; fails_when=a below-floor install is certified ok because a run is open; why_new=GST-1677 (the floor is a safety rule);+ // seam=fixture clone at A (1.0.0 < 1.0.1); no_claim=a clean below-floor install, which the frozen bootstrapper fast-forwards as before+ test('below the floor an open run still refuses the session', () => {+ const f = fixture();+ shipLedger(f);+ const check = f.run(['--check', '--for', 'autoplan']);+ expect(check.status).toBe(1);+ expect(check.last).toMatch(/^gstack: fail revision — installed 1\.0\.0 is below the supported minimum 1\.0\.1 .*\(REVISION_BELOW_MINIMUM\)$/);+ expect(check.stdout).not.toContain('deferred');+ f.git(['checkout', '-q', '--detach']);+ const pinned = f.run(['--for', 'autoplan']);+ expect(pinned.status).toBe(1);+ expect(pinned.last).toMatch(/^gstack: fail revision — installed 1\.0\.0 is below the supported minimum 1\.0\.1 \(pinned: HEAD is detached/);+ expect(pinned.stdout).not.toContain('deferred');+ expect(f.git(['rev-parse', 'HEAD'])).toBe(f.a);+ });++ // Value: protects=the eval-lock probe works without the flock binary (macOS): python3's fcntl sees gstack-detach's lock and the upgrade+ // defers; fails_when=an eval run has gstack moved under it on a host without flock (GST-1658 item 1); why_new=GST-1658; seam=PATH without+ // flock; no_claim=the perl fallback (python3 is on this host)+ test.skipIf(spawnSync('sh', ['-c', 'command -v flock && command -v python3'], { timeout: 5_000 }).status !== 0)('a live eval run defers the upgrade on a host without flock', () => {+ const f = behindBy(1);+ const lock = path.join(f.host.home, '.gstack/locks/gstack-evals.lock');+ fs.mkdirSync(path.dirname(lock), { recursive: true });+ const holder = spawn('bash', ['-c', 'exec 9>"$1" && flock 9 && exec sleep 300', '_', lock], { stdio: 'ignore' });+ const PATH = pathWithout(path.join(f.host.base, 'no-flock'), ['flock', 'bun', 'codex']);+ // The bootstrapper's install mode takes its own lock with flock, so the session runs as the bootstrapper hands over to it, after a --check+ // fetched FETCH_HEAD.+ expect(f.run(['--check', '--for', 'autoplan']).status).toBe(0);+ const session = () => spawnSync('bash', [path.join(f.root, 'bin/gstack-capy-session'), '--root', f.root, '--for', 'autoplan'], {+ cwd: f.host.home, encoding: 'utf8', timeout: 120_000,+ env: { ...f.host.env, PATH: [f.host.systemBin, PATH].join(path.delimiter), GSTACK_CAPY_REMOTE_MIN: '1.0.1', GSTACK_CAPY_WRAPPER_REV: '5', GSTACK_CAPY_WRAPPER_PATH: BOOT, GSTACK_CAPY_LOCK_HELD: '1' },+ });+ try {+ for (let i = 0; i < 50 && spawnSync('flock', ['-n', lock, 'true'], { timeout: 5_000 }).status === 0; i++) spawnSync('sleep', ['0.1']);+ expect(spawnSync('bash', ['-c', 'command -v flock'], { env: { ...f.host.env, PATH }, timeout: 5_000 }).status).not.toBe(0);+ const r = session();+ expect(r.stdout, r.stdout + r.stderr).toContain(`SELF_UPGRADE: skipped (a live eval run holds ${lock}`);+ expect(f.git(['rev-parse', 'HEAD'])).toBe(f.b);+ } finally {+ holder.kill('SIGKILL');+ }+ expect(session().stdout).toMatch(/^SELF_UPGRADE: done 1\.0\.1 -> 1\.0\.2$/m);+ });+});++describe('capy skill: upgrade-path edges (GST-1658)', () => {+ const STALE_INSTALLER = '#!/usr/bin/env bash\necho "gstack: ok $(cat "$(dirname "$0")/../VERSION") for=autoplan behind=${GSTACK_CAPY_BEHIND:-none} stale=${GSTACK_CAPY_STALE:-none} fix=${GSTACK_CAPY_BEHIND_FIX:-none}"\n';+ const behindBy = (ageHours: number) => {+ const f = fixture({ cloneAt: 'B', nextAgeHours: ageHours });+ write(path.join(f.root, 'bin/gstack-capy-install'), STALE_INSTALLER, 0o755);+ f.git(['update-index', '--assume-unchanged', 'bin/gstack-capy-install']);+ return f;+ };+ const stubUpgrade = (f: ReturnType<typeof behindBy>, body: string) => {+ write(path.join(f.root, 'bin/gstack-upgrade'), `#!/usr/bin/env bash\n${body}\n`, 0o755);+ f.git(['update-index', '--assume-unchanged', 'bin/gstack-upgrade']);+ };++ // Value: protects=the pin override takes the setup lock before it switches branches and hands it to gstack-upgrade, so another updater+ // holding the lock stops the switch before it happens, and the lock is released afterwards; fails_when=the checkout is switched while+ // another updater holds .setup-lock (GST-1658 item 2); why_new=GST-1658; seam=a held .setup-lock and a recording gstack-upgrade;+ // no_claim=bin/gstack-session-update's own locking+ test('the pin override switches only under the setup lock, which it hands to gstack-upgrade', () => {+ const held = behindBy(25);+ held.git(['checkout', '-q', '--detach']);+ held.git(['branch', '-q', '-D', 'main']);+ const lock = path.join(held.host.stateRoot, '.setup-lock');+ write(path.join(lock, 'pid'), '424242\n');+ const r = held.run(['--for', 'autoplan']);+ expect(r.stdout).toContain(`SELF_UPGRADE: skipped (another gstack updater holds ${lock} (pid 424242), so the unreasoned pin (HEAD detached at `);+ expect(held.git(['rev-parse', 'HEAD'])).toBe(held.b);+ expect(spawnSync('git', ['-C', held.root, 'show-ref', '--verify', '-q', 'refs/heads/main'], { timeout: 10_000 }).status).not.toBe(0);++ const f = behindBy(25);+ f.git(['checkout', '-q', '--detach']);+ const seen = path.join(f.host.base, 'seen');+ stubUpgrade(f, `echo "owner=$GSTACK_SETUP_LOCK_OWNER pid=$(cat "$GSTACK_STATE_ROOT/.setup-lock/pid") branch=$(git -C "$(dirname "$0")/.." symbolic-ref -q --short HEAD)" > "${seen}"; echo "gstack-upgrade: fixture refusal; nothing was changed; fix: re-run (UPGRADE_REFUSED)" >&2; exit 3`);+ const s = f.run(['--for', 'autoplan']);+ const [owner, pid, branch] = fs.readFileSync(seen, 'utf8').trim().split(' ');+ expect(owner.slice(6)).not.toBe('');+ expect(pid.slice(4)).toBe(owner.slice(6));+ expect(branch).toBe('branch=main');+ expect(s.stdout).toContain('SELF_UPGRADE: pin kept');+ expect(fs.existsSync(path.join(f.host.stateRoot, '.setup-lock'))).toBe(false);++ const real = behindBy(25);+ real.git(['checkout', '-q', '--detach']);+ expect(real.run(['--for', 'autoplan']).stdout).toMatch(/^SELF_UPGRADE: done 1\.0\.1 -> 1\.0\.2$/m);+ expect(fs.existsSync(path.join(real.host.stateRoot, '.setup-lock'))).toBe(false);+ });++ // Value: protects=a local default branch whose gstack-upgrade predates the lock handover still fast-forwards: the session releases .setup-lock+ // before that copy runs, so it takes the lock itself as it always did; fails_when=the old copy refuses against the session's own lock and an+ // unreasoned pin is never overridden (/ship #4095 review red-team#1); why_new=red-team; seam=a gstack-upgrade that takes the lock with mkdir+ // and ignores GSTACK_SETUP_LOCK_OWNER, as a7585d0's does; no_claim=none+ test('a local main whose gstack-upgrade predates the handover still upgrades', () => {+ const f = behindBy(25);+ f.git(['checkout', '-q', '--detach']);+ stubUpgrade(f, 'L="$GSTACK_STATE_ROOT/.setup-lock"; mkdir "$L" 2>/dev/null || { echo "gstack-upgrade: another gstack updater holds $L (pid $(cat "$L/pid" 2>/dev/null)); nothing was changed; fix: wait for it to finish, then re-run (UPGRADE_REFUSED)" >&2; exit 3; }; R="$(dirname "$0")/.."; git -C "$R" merge --ff-only -q origin/main; S=$?; rm -rf "$L"; exit $S');+ const r = f.run(['--for', 'autoplan']);+ expect(r.stdout, r.stdout + r.stderr).toMatch(/^SELF_UPGRADE: done 1\.0\.1 -> 1\.0\.2$/m);+ expect(f.git(['rev-parse', 'HEAD'])).toBe(f.c);+ expect(fs.existsSync(path.join(f.host.stateRoot, '.setup-lock'))).toBe(false);+ });++ // Value: protects=the default branch the override creates tracks origin, so a later @{upstream} read works (GST-1658 item 4); fails_when=the+ // created main has no upstream; why_new=GST-1658; seam=a detached pin with no local main; no_claim=an existing local main's config+ test('the default branch the override creates tracks origin', () => {+ const f = behindBy(25);+ f.git(['checkout', '-q', '--detach']);+ f.git(['branch', '-q', '-D', 'main']);+ const r = f.run(['--for', 'autoplan']);+ expect(r.stdout).toMatch(/^SELF_UPGRADE: done 1\.0\.1 -> 1\.0\.2$/m);+ expect(f.git(['rev-parse', '--abbrev-ref', 'main@{upstream}'])).toBe('origin/main');+ });++ // Value: protects=when the restore checkout after a refused fast-forward fails, the session says the pin was not restored, names where HEAD is+ // and the command that puts it back, instead of claiming "pin kept" (GST-1658 item 5); fails_when=pin kept prints with HEAD not restored;+ // why_new=GST-1658; seam=a gstack-upgrade that leaves git's index.lock behind; no_claim=none+ test('a failed restore is reported, never as pin kept', () => {+ const f = behindBy(25);+ f.git(['checkout', '-q', '-b', 'topic']);+ stubUpgrade(f, 'touch "$(git -C "$(dirname "$0")/.." rev-parse --absolute-git-dir)/index.lock"; echo "gstack-upgrade: fixture refusal; nothing was changed; fix: re-run (UPGRADE_REFUSED)" >&2; exit 3');+ const r = f.run(['--for', 'autoplan']);+ expect(r.stdout).not.toContain('SELF_UPGRADE: pin kept');+ expect(r.stdout).toContain(`SELF_UPGRADE: pin not restored (the fast-forward was refused and the pin could not be restored: HEAD is at ${f.b.slice(0, 7)} on main, not topic; fix: git -C ${f.root} checkout -q topic, then bash ${BOOT} --for autoplan (UPGRADE_REFUSED))`);+ fs.rmSync(path.join(f.root, '.git/index.lock'));+ });++ // Value: protects=the no-fetch stale note reads the stamp's mtime portably, so a BSD date (where -r takes seconds, not a file) still reports it+ // (GST-1658 item 3); fails_when=macOS reads "no fetch from origin recorded" for a fresh stamp, or misses a day-old one; why_new=GST-1658;+ // seam=a date shim with BSD -r semantics; no_claim=BSD stat itself (Linux stat answers first)+ test('the no-fetch stale note does not depend on GNU date -r', () => {+ const f = behindBy(1);+ expect(f.run(['--check', '--for', 'autoplan']).last).toContain('stale=none');+ const stamp = path.join(f.root, '.git/gstack-last-fetch');+ const t = Date.now() / 1000 - 25 * 3600 - 60;+ fs.utimesSync(stamp, t, t);+ const shim = path.join(f.host.base, 'bsd-date');+ write(path.join(shim, 'date'), '#!/usr/bin/env bash\nfor a in "$@"; do [ "$a" = -r ] && { echo "date: illegal time format" >&2; exit 1; }; done\nexec /bin/date "$@"\n', 0o755);+ f.git(['remote', 'set-url', 'origin', `file://${f.host.base}/gone.git`]);+ const r = f.run(['--check', '--for', 'autoplan'], { GSTACK_CAPY_REPO: `file://${f.host.base}/gone.git`, PATH: [shim, f.host.env.PATH].join(path.delimiter) });+ expect(r.stdout).toContain('remote minimum unknown (fetch failed)');+ expect(r.last).toContain('stale=no fetch from origin in 25h');+ });++ // Value: protects=a recorded pin reason with nothing pinned is not reported as a pin and does not hide the fix-before-workflow line+ // (GST-1658 red-team session:163); fails_when=the trailer says pinned for a checkout on its default branch; why_new=GST-1658; seam=+ // GSTACK_PIN_REASON on main; no_claim=none+ test('a pin reason with nothing pinned is not a pin', () => {+ const f = behindBy(25);+ const r = f.run(['--check', '--for', 'autoplan'], { GSTACK_PIN_REASON: 'left over from GST-3' });+ expect(r.last).toBe(`gstack: ok 1.0.1 for=autoplan behind=1 stale=25h fix=bash ${BOOT} --for autoplan`);+ expect(r.stdout).toContain('run the fix before the first workflow');+ });+});diff --git a/test/gstack-capy-install.test.ts b/test/gstack-capy-install.test.tsindex 6d1702654..7c2f8eca9 100644--- a/test/gstack-capy-install.test.ts+++ b/test/gstack-capy-install.test.ts@@ -318,6 +318,14 @@ describe('gstack-capy-install', () => {expect(lastLine(nofetch.stdout)).toBe('gstack: ok 1.2.3 for=autoplan (stale=no fetch from origin in 26h; fix: check network access to origin, then bash /s/install.sh --for autoplan)');});+ // Value: protects=the no-fetch fix note names a command even when the installer runs without the bootstrapper's GSTACK_CAPY_WRAPPER_PATH+ // (GST-1658: it ended in "then" with nothing after it); fails_when=the fix is truncated; why_new=GST-1658; seam=env; no_claim=none+ test('trailer grammar: the no-fetch fix note is complete without GSTACK_CAPY_WRAPPER_PATH', () => {+ const f = fixture();+ const bare = run(f, ['--for', 'autoplan'], { GSTACK_CAPY_STALE: 'no fetch from origin in 26h' });+ expect(lastLine(bare.stdout)).toBe('gstack: ok 1.2.3 for=autoplan (stale=no fetch from origin in 26h; fix: check network access to origin, then bash <skill>/scripts/install.sh --for autoplan)');+ });+test('a skipped session-start upgrade above the minimum is a WARN, never a fail: the trailer stays ok with behind=, the skip reason and the fix, exit 0, and a WARN behind row names the code', () => {const f = fixture();const busy = { GSTACK_CAPY_BEHIND: '3', GSTACK_CAPY_BEHIND_TO: '1.2.6', GSTACK_CAPY_BEHIND_FIX: `${f.root}/bin/gstack-upgrade`, GSTACK_CAPY_BEHIND_BLOCKED: 'live gstack sessions hold this installation: pid 379 (124m dbus-daemon); fix: wait for those sessions to finish, or re-run with GSTACK_UPGRADE_FORCE=1 when you know they are idle (UPGRADE_BUSY)' };