From: Kristoffer Haugsbakk Date: Thu, 29 Oct 2026 11:05:12 GMT Subject: Re: [PATCH] notes: do not drop notes written by a concurrent process Message-ID: <3c4f3793-07d4-47c7-b503-13a6ae567147@app.fastmail.com> In-Reply-To: <20261028-fz-notes-concurrent-write-v1-1-3d513e1fdbb7@gmail.com> On Thu, Oct 29, 2026, at 04:55, Farid Zakaria wrote: > "git notes add" and the other commands that modify notes read the > notes ref, update the notes tree in memory, and then commit it on top > of whatever the ref points to by then. If another process updated the > ref in the meantime, its notes are silently lost. This looks like a really nice find. > > The fix is to remember the commit the notes were read from, and use > it as both the parent of the new notes commit and the expected old > value of the ref update. A concurrent update now makes the command > fail with "cannot lock ref" instead. This makes sense and is how I would have assumed `git notes add` and similar to work. Because you have: git update-ref [ Exactly so that you can try to update a ref with the assumption that nothing else intervenes, because it will fail if does not become the previous OID. So I thought that the code that git-notes(1) uses would work the same way. > > Signed-off-by: Farid Zakaria > --- >[snip] So if this change is: • Before it silently dropped the change • Now it loudly fails Then that is a pure improvement. However, thinking beyond this patch. Let’s say one program wants to add a note on `master`. But another one wants to add a note on `feature1`. One will fail. But should that happen in a perfect world? Let’s say that `master` wins. `feature1` is not trying to “clobber” anything relative to the `master` program; it wants to add a note to a different commit. And does the `feature1` program care if the commit corresponding to the note is a child of the commit when it first started the process? I don’t think so. It does matter for two programs that want to update a branch, but here the commit structure is a kind of implementation detail, how Notes are implemented so that you get snapshot of the notes as well as the whole edit history. As an example: commit A, commit B, commit C, commit D... It could just be shuffled. Instead, maybe this would happen in an ideal world: 1. `master` and `feature1` race to commit a note 2. `master` wins 3. `feature1` notices that there is a new note commit (from `master`) 4. It checks whether that commit changed the commit that *it* (`feature1`) wanted to update • If so: fail • If not: continue 5. `feature1` retries (go to (1)) Maybe this is too much logic for a “porcelain” command (interactive use), but there is no plumbing Notes command.