Skills › gstack › gstack-upgrade › v1.91.19.0.sh
v1.91.19.0.sh
53 lines · gstack-upgrade/migrations/v1.91.19.0.sh at 3f79d81
1#!/usr/bin/env bash
2# Migration: v1.91.19.0 — severe fix wave (memory ingest, artifacts remote).
3# Placeholder name: the release queue may rename this file at /ship.
4#
5# Each step is independent and guarded. Idempotent and non-fatal: every path
6# exits 0, and no step calls gbrain or the network unless it has work to do.
7set -u
8_gstack_migration_dir="${BASH_SOURCE[0]//\\//}"; _gstack_migration_dir="${_gstack_migration_dir%/*}"
9. "${_gstack_migration_dir}/../../bin/gstack-state-root.sh" 2>/dev/null || { echo "$0: cannot resolve the gstack state root: ${_gstack_migration_dir}/../../bin/gstack-state-root.sh is missing. fix: reinstall with ./setup or /gstack-upgrade (docs/state-root.md)" >&2; exit 1; }
10gstack_state_root_select; GH="$_gstack_sr_root"
12# Step 1 (A1, #2778): older versions could mark a transcript ingested that
13# gbrain had skipped. Record that a reconcile pass is pending; the next memory
14# ingest re-checks stamped pages in bounded batches and re-queues the missing
15# ones. This only writes a flag under the ingest's state lock; it never calls
16# gbrain.
17if [ -f "$GH/.transcript-ingest-state.json" ]; then
18 INGEST="${_gstack_migration_dir}/../../bin/gstack-memory-ingest.ts"
19 if command -v bun >/dev/null 2>&1 && [ -f "$INGEST" ]; then
20 if bun "$INGEST" --request-reconcile --quiet; then
21 echo "memory ingest: reconcile pending; the next /sync-gbrain re-checks transcripts already marked ingested."
22 else
23 echo "memory ingest: could not record a pending reconcile now; run: gstack-memory-ingest --reconcile" >&2
24 fi
25 fi
26fi
28# Step 2 (A8, #1437): the v1.27.0.0 migration passed a bare repo name to
29# `gh repo rename`, which always failed, then pointed the artifacts remote at
30# gstack-artifacts-<user> anyway. When that repository does not exist but the
31# old gstack-brain-<user> does, point the remote back at the old one. Only a
32# remote that names a gstack-artifacts-* GitHub repo is checked.
33REMOTE_TXT="${HOME:-}/.gstack-artifacts-remote.txt"
34if [ -n "${HOME:-}" ] && [ -f "$REMOTE_TXT" ]; then
35 URL=$(head -1 "$REMOTE_TXT" 2>/dev/null | tr -d '[:space:]')
36 OWNER=$(printf '%s\n' "$URL" | sed -n 's#^.*github\.com[:/]\([^/]*\)/gstack-artifacts-[^/]*$#\1#p')
37 NEW_NAME=$(printf '%s\n' "$URL" | sed -n 's#^.*/\(gstack-artifacts-[^/]*\)$#\1#p' | sed 's/\.git$//')
38 if [ -n "$OWNER" ] && [ -n "$NEW_NAME" ]; then
39 OLD_NAME="gstack-brain-${NEW_NAME#gstack-artifacts-}"
40 if ! command -v gh >/dev/null 2>&1 || ! gh auth status >/dev/null 2>&1; then
41 echo "artifacts remote: could not confirm $OWNER/$NEW_NAME exists (gh is not installed or not signed in). If artifact pushes fail, run: gh repo rename $NEW_NAME --repo $OWNER/$OLD_NAME --yes"
42 elif ! gh repo view "$OWNER/$NEW_NAME" >/dev/null 2>&1 && gh repo view "$OWNER/$OLD_NAME" >/dev/null 2>&1; then
43 OLD_URL=$(printf '%s\n' "$URL" | sed "s#/${NEW_NAME}#/${OLD_NAME}#")
44 echo "$OLD_URL" > "$REMOTE_TXT" && chmod 600 "$REMOTE_TXT"
45 if [ "$(git -C "$GH" remote get-url origin 2>/dev/null)" = "$URL" ]; then
46 git -C "$GH" remote set-url origin "$OLD_URL" 2>/dev/null || true
47 fi
48 echo "artifacts remote: restored $OLD_URL because $OWNER/$NEW_NAME does not exist and $OWNER/$OLD_NAME does (an earlier upgrade rewrote it before the rename ran). To finish the rename later: gh repo rename $NEW_NAME --repo $OWNER/$OLD_NAME --yes"
49 fi
50 fi
51fi
53exit 0