git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] notes: do not drop notes written by a concurrent process

From
KHKristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
Date
Oct 29, 2026, 11:05 UTC
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.
Show 5 quoted lines
>
> 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 <ref> <new-oid> [<old-oid>

Exactly so that you can try to update a ref with the assumption that nothing else intervenes, because it will fail if <old-oid> 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 <farid.m.zakaria@gmail.com>
> ---
>[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.

Previous: Farid ZakariaNext: Junio C Hamano
Message 2 of 11 in “notes: do not drop notes written by a concurrent process”
  1. notes: do not drop notes written by a concurrent processFarid Zakaria, Oct 29, 2026
  2. Kristoffer HaugsbakkOct 29, 2026
  3. Junio C HamanoOct 29, 2026
  4. Farid ZakariaOct 29, 2026
  5. Junio C HamanoOct 29, 2026
  6. Farid ZakariaOct 29, 2026
  7. Patrick SteinhardtOct 30, 2026
  8. Kristoffer HaugsbakkOct 30, 2026
  9. Farid ZakariaOct 30, 2026
  10. Kristoffer HaugsbakkOct 31, 2026
  11. Kristoffer HaugsbakkOct 30, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.