mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-11 15:39:04 +02:00
fix(gbrain): brain worktree advances on the daily sync — no more silently stale brains (#2516)
The daily pull refreshed only ~/.gstack itself, never the detached worktree at ~/.gstack-brain-worktree that gbrain actually indexes — so after setup the brain served stale pages forever unless setup-gbrain/sync-gbrain happened to run. brain-sync --once now advances the worktree once per 24h behind an ATTEMPT stamp (.brain-worktree-last-advance — a persistently-failing advance warns once a day, not at every skill boundary), inside the existing run lock and before any ingest step touches the worktree. The new gstack-gbrain-source-wireup --advance-only is built for the unattended cadence: git-only (no gbrain prereqs), pins every operation to the managed worktree (refuses paths that are not worktrees of the artifacts repo), refuses dirty worktrees, and never runs the force-remove recovery — a cron path must not be able to delete local changes. A static pin keeps the force-remove out. docs/gbrain-sync.md stops overclaiming the old cadence. Fixes #2516. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
c4d91507dd
commit
40e4a53f74
@@ -377,6 +377,29 @@ subcmd_once() {
|
||||
local mode
|
||||
mode=$("$CONFIG_BIN" get artifacts_sync_mode 2>/dev/null || echo off)
|
||||
|
||||
# #2516: advance the brain worktree gbrain indexes to the artifacts repo's
|
||||
# HEAD once a day — previously it only moved when setup-gbrain / sync-gbrain
|
||||
# / brain-restore ran, so brains silently served stale code forever. Runs
|
||||
# inside THIS run lock (never concurrent with the ingest steps below) and
|
||||
# before they touch the worktree. Attempt-throttled: the stamp is written on
|
||||
# ATTEMPT, so a persistently-failing advance warns once per 24h, not at
|
||||
# every skill boundary. The advance itself refuses dirty or unmanaged
|
||||
# worktrees and never force-removes (see gstack-gbrain-source-wireup).
|
||||
if [ -e "${GSTACK_BRAIN_WORKTREE:-$HOME/.gstack-brain-worktree}" ]; then
|
||||
local adv_stamp adv_now adv_last adv_age
|
||||
adv_stamp="$GSTACK_HOME/.brain-worktree-last-advance"
|
||||
adv_now=$(date +%s)
|
||||
adv_last=$(cat "$adv_stamp" 2>/dev/null || echo 0)
|
||||
case "$adv_last" in ''|*[!0-9]*) adv_last=0 ;; esac
|
||||
adv_age=$(( adv_now - adv_last ))
|
||||
if [ "$adv_age" -ge 86400 ]; then
|
||||
echo "$adv_now" > "$adv_stamp" 2>/dev/null || true
|
||||
if ! "$SCRIPT_DIR/gstack-gbrain-source-wireup" --advance-only 1>&2; then
|
||||
echo "BRAIN_SYNC: warning: brain worktree advance failed — gbrain may be indexing stale code (run gstack-gbrain-source-wireup to repair)" >&2
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# #2549 unpushed-commit detector: a prior drain may have COMMITTED but
|
||||
# failed to push (auth blip, offline). The data was never lost — it sits in
|
||||
# a local commit — but nothing re-pushed it until NEW changes arrived.
|
||||
|
||||
Reference in New Issue
Block a user