Skip to content

Harden brain pipeline: index.lock sweep, gbq exit code, lessons append-order#7

Merged
Chad-Mufasax merged 1 commit into
masterfrom
fix/brain-pipeline-hardening
Jun 29, 2026
Merged

Harden brain pipeline: index.lock sweep, gbq exit code, lessons append-order#7
Chad-Mufasax merged 1 commit into
masterfrom
fix/brain-pipeline-hardening

Conversation

@Chad-Mufasax

Copy link
Copy Markdown
Contributor

Three fixes to the brain maintenance pipeline, root-caused while debugging a vault whose semantic index had silently frozen for 17 days.

1. nightly — sweep orphan .git/index.lock

A crashed git leaves .git/index.lock behind. The vault then can't commit, and gbrain sync (git-diff based) aborts on "No commits in repo" → the index freezes, unnoticed. The nightly already sweeps the PGLite .gbrain-lock but not git's. Added sweep_git_lock() — removes the lock only when no git runs in the repo and it's >5 min old (a fresh one may be a legit concurrent commit).

2. gbq — propagate gbrain's real exit code

gbq's last statement is the stale-lock test [ -d "$LOCK" ], which is false (→ exit 1) whenever there's nothing to sweep. So gbq sync succeeded but returned 1, breaking gbq sync && …. Now captures gbrain's RC (wait/intentional-kill) and exit $RC.

3. correction-detector — spell out append order

The reminder didn't state where to write. Paired with a tail-injection that reads the end of the file, ambiguity let agents write at the top → lessons.md split into two regions and the tail re-read only stale entries. Now explicit: chronological, newest at the bottom, never at the top.

All three verified locally (parse + functional tests).

…ns append-order)

- nightly: sweep an orphan .git/index.lock before commit. A crashed git leaves it
  behind; the vault then never commits and 'gbrain sync' stalls on "No commits in
  repo", silently freezing the index (root-caused after a 17-day freeze). Only
  removed when no git runs in the repo and the lock is >5 min old.
- gbq: propagate gbrain's real exit code instead of the trailing lock-sweep test's
  (false — hence exit 1 — whenever there is no stale lock, breaking 'gbq sync && ...').
- correction-detector: spell out the append order (chronological, newest at the
  bottom, never at the top) so tail-injection re-reads recent lessons and the file
  doesn't split into two regions.
@Chad-Mufasax Chad-Mufasax merged commit 8ebfbda into master Jun 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant