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
7 changes: 6 additions & 1 deletion engine/bin/gbq
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ if [ "$IS_READ" = "1" ]; then
sleep 0.5
done
kill -9 "$GP" 2>/dev/null
RC=0 # read output captured; the force-kill is intentional, not a failure
else
# Writes exit cleanly and may legitimately pause (LLM call) — just wait.
wait "$GP" 2>/dev/null
wait "$GP"; RC=$?
fi

cat "$TMP"
Expand All @@ -68,3 +69,7 @@ if ! pgrep -f "bun.*gbrain" >/dev/null 2>&1; then
L="$HOME/.gbrain/brain.pglite/.gbrain-lock"
[ -d "$L" ] && mv "$L" "$L.stale-$(date +%s)" 2>/dev/null
fi

# Propagate gbrain's real exit code — NOT the lock-sweep test above (which is
# false, hence exit 1, whenever there's no stale lock to clear → false failures).
exit $RC
2 changes: 1 addition & 1 deletion engine/hooks/correction-detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

reminder = (
"⚠️ CORRECTION DETECTED — BEFORE doing anything else:\n"
f"1. Append a line to {brain}/Profile/lessons.md under today's header (## YYYY-MM-DD).\n"
f"1. Append a line to {brain}/Profile/lessons.md under today's header (## YYYY-MM-DD). The file is chronological (most recent day at the BOTTOM — that is what the tail-injection re-reads): today's header lives at the END of the file. Create it at the end if missing and add the entry right below it, NEVER at the top.\n"
" Format: - **[short context]** -> rule: [what to do] (when: [trigger condition])\n"
"2. Confirm visibly: ✓ noted in lessons.md\n"
"3. Only then apply the correction and continue."
Expand Down
15 changes: 15 additions & 0 deletions engine/nightly/gbrain-nightly.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,28 @@ VAULT_CO="$HOME/Documents/BrainCo"
GREPO="$HOME/DEV/gbrain"
LOG="$HOME/.gbrain/nightly.log"

# Sweep an orphan .git/index.lock that silently breaks `git commit` (a crashed
# git leaves it behind → the vault never commits → gbrain sync stalls on "No
# commits in repo" → the index freezes, unnoticed). Only remove it when no git
# runs in the repo AND the lock is >5 min old (a fresh one may be a legit
# concurrent commit). Root-caused 2026-06-28: a 14-day-old lock froze the index.
sweep_git_lock() {
local repo="$1" lock="$1/.git/index.lock"
[ -f "$lock" ] || return 0
if ! pgrep -f "[g]it .*$repo" >/dev/null 2>&1 && [ -z "$(find "$lock" -mmin -5 2>/dev/null)" ]; then
rm -f "$lock" && echo "[lock] removed stale .git/index.lock in $repo" >> "$LOG"
fi
}

echo "===== $(date '+%Y-%m-%d %H:%M:%S') nightly start =====" >> "$LOG"

# -1. Stale-lock recovery (a gbrain killed with SIGKILL leaves a .gbrain-lock that blocks everything).
if ! pgrep -f "bun.*gbrain" >/dev/null 2>&1; then
L="$HOME/.gbrain/brain.pglite/.gbrain-lock"
[ -d "$L" ] && mv "$L" "${L}.stale-$(date +%s)" 2>/dev/null && echo "[lock] rotated stale lock" >> "$LOG"
fi
sweep_git_lock "$VAULT"
[ -d "$VAULT_CO/.git" ] && sweep_git_lock "$VAULT_CO"

# 0. Self-update GBrain (resilient: a failure must never block the cycle).
if cd "$GREPO" 2>/dev/null; then
Expand Down
Loading