The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
fix(gitlink): wait for packed-refs.lock when deleting note transaction refs (#892)
Claude033315b18744
diff --git a/cli/beacon/internal/gitlink/notes.go b/cli/beacon/internal/gitlink/notes.goindex 4420692b..7e35a281 100644--- a/cli/beacon/internal/gitlink/notes.go+++ b/cli/beacon/internal/gitlink/notes.go@@ -103,10 +103,11 @@ func updateNoteOnce(ctx context.Context, g Git, commit string, update func(strin}defer func() {// Best effort, and on a fresh context: a transaction that timed out must still not leave- // its working ref behind.- cleanup, cancel := context.WithTimeout(context.Background(), 2*time.Second)+ // its working ref behind. Every ref deletion takes packed-refs.lock, which concurrent+ // writers contend for, and git gives up on it after one second by default.+ cleanup, cancel := context.WithTimeout(context.Background(), 6*time.Second)defer cancel()- _, _ = g.Run(cleanup, nil, "update-ref", "-d", txRef)+ _, _ = g.Run(cleanup, nil, "-c", "core.packedRefsTimeout=5000", "update-ref", "-d", txRef)}()current, err := readNote(ctx, g, txRef, commit)diff --git a/cli/beacon/internal/gitlink/notes_test.go b/cli/beacon/internal/gitlink/notes_test.goindex 42a8c9d0..6e4108ce 100644--- a/cli/beacon/internal/gitlink/notes_test.go+++ b/cli/beacon/internal/gitlink/notes_test.go@@ -266,6 +266,30 @@ func TestAddLinksConcurrentWritersLoseNothing(t *testing.T) {}}+func TestAddLinksWaitsForPackedRefsLock(t *testing.T) {+ r := newTestRepo(t)+ r.write("f", "1")+ sha := r.commitAt("c", t0)+ // Another writer's ref deletion holds packed-refs.lock for longer than git's default wait.+ lock := filepath.Join(r.root, ".git", "packed-refs.lock")+ if err := os.WriteFile(lock, nil, 0o644); err != nil {+ t.Fatal(err)+ }+ released := make(chan struct{})+ go func() {+ defer close(released)+ time.Sleep(1500 * time.Millisecond)+ _ = os.Remove(lock)+ }()+ if _, err := AddLinks(context.Background(), r.gitClient(), sha, []Link{{Harness: "codex", SessionID: "s"}}); err != nil {+ t.Fatal(err)+ }+ <-released+ if refs := r.git("for-each-ref", "--format=%(refname)", "refs/notes/"); refs != NotesRef {+ t.Fatalf("leftover transaction refs:\n%s", refs)+ }+}+func TestListLinked(t *testing.T) {r := newTestRepo(t)ctx := context.Background()