You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Nothing protects the memory bank from concurrent operations #3
The semantic memory bank has no locking. An administrative rebuild deletes the bank and repopulates it; a run reads from it at start and writes at end. Nothing prevents these overlapping.
Observed twice:
A rebuild of the experimental bank aborted mid-write with TimeoutError because a research run and a second rebuild were hitting the same instance. The bank was left deleted and only partially repopulated — neither the old state nor the new one.
A test that touches live infrastructure failed once during a concurrent rebuild and passed on re-run.
Nothing was lost because a full export is taken before any destructive step, but that is a procedure, not a safeguard.
What is needed: at minimum an advisory lock that makes a rebuild refuse to start while a run is active, and makes a run refuse to start while a rebuild holds the lock. A read-only snapshot for recall during rebuilds would be better still.
src/lib/db/advisory-lock.ts adds withAdvisoryLock(), used by scripts/memory-rebuild.ts. Postgres session-level advisory locks were chosen because they need no new table and are released automatically when the process dies — which is the failure that left the bank wedged in the first place.
Two things surfaced while building it, both kept in the code with their reasoning:
Postgres advisory locks are re-entrant within a session, and Prisma pools connections, so the lock alone gives no intra-process guarantee. A test caught this: the nested acquisition in 'refuses a second holder' succeeded against an implementation whose own docstring promised exclusion. A process-local heldLocally set is what makes the promise true inside one process; the Postgres lock is what excludes others.
pg_advisory_unlock returns false rather than raising when the session does not hold the lock. The release discarded that boolean, so the one failure this design has looked exactly like success. Orphaned locks are now recorded, and the next acquisition says so instead of blaming a concurrent rebuild that does not exist.
Activity
Stagnation detection, and negatives that say how to reopen them
The memory bank called things verified that nobody had verified
krapcys1-maker commentedon Aug 31, 2026
Fixed.
src/lib/db/advisory-lock.tsaddswithAdvisoryLock(), used byscripts/memory-rebuild.ts. Postgres session-level advisory locks were chosen because they need no new table and are released automatically when the process dies — which is the failure that left the bank wedged in the first place.Two things surfaced while building it, both kept in the code with their reasoning:
heldLocallyset is what makes the promise true inside one process; the Postgres lock is what excludes others.pg_advisory_unlockreturns false rather than raising when the session does not hold the lock. The release discarded that boolean, so the one failure this design has looked exactly like success. Orphaned locks are now recorded, and the next acquisition says so instead of blaming a concurrent rebuild that does not exist.README: the known-broken list was stale, and the defect list was two …