fix(notes): the edit lock excludes other processes; pin OpenLock and the rollback (#192)
Review round 1 on PR #194: - The edit lock did not exclude other processes (also on main): unlock removes the lock file, so a waiter could wake holding a flock on the orphaned inode while the next caller locked a fresh file. flockFile now re-checks after flock that the locked file is still the one at the path (brainfs LockIsCurrent) and retries otherwise; OpenLock reports a lock replaced mid-open as ErrLockChanged, which is retried instead of failing the edit. New cross-process test (3 re-executed processes x 400 rounds, O_EXCL marker under the lock): 0 overlaps; red without the re-check. - OpenLock unit test: relative dangling link (only the Lstat pre-check stops it; os.Root refuses absolute links on its own), live link, FIFO, directory, behind a symlinked dir, unclean path, positive control. - Rollback test: a symlink swapped in for the note before the rollback (test seam beforeStampHook) is refused, target untouched in and outside the brain. - The in-brain dangling-lock case uses a relative link and asserts the refusal names the lock. OpenLock reuses #189's RealParent; RemoveLock is dropped for brainfs.Remove. The doc comment names the swap residual. Rebased onto main after #189. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -137,6 +137,9 @@ func (s *Server) brainEdit(ctx context.Context, args json.RawMessage) (json.RawM
|
||||
// whoever edits a note is the author of what a reader now sees: re-stamp
|
||||
// to the editor after every edit (PR #147 review, escape E1).
|
||||
origin, writtenBy := provenanceFrom(ctx)
|
||||
if beforeStampHook != nil {
|
||||
beforeStampHook()
|
||||
}
|
||||
if serr := api.StampProvenanceFile(s.brainDir, res.Path, origin, writtenBy); serr != nil {
|
||||
if werr := bfs.WriteRegular(target.Rel, prior); werr != nil {
|
||||
// Say exactly what state the note is in: edited, unverified.
|
||||
@@ -148,6 +151,11 @@ func (s *Server) brainEdit(ctx context.Context, args json.RawMessage) (json.RawM
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// beforeStampHook is a test seam (nil in production): it runs between the
|
||||
// edit and the provenance stamp, so a test can swap the note before the
|
||||
// rollback path runs.
|
||||
var beforeStampHook func()
|
||||
|
||||
// brainEditRoot edits a governance file (CLAUDE.md). De-surfaced AND gated on
|
||||
// the authenticated principal: only the static local-CLI token may call it, so
|
||||
// a claude.ai-origin session — the one that may have just read an untrusted
|
||||
|
||||
Reference in New Issue
Block a user