From 4f4e151ff8d2a545fbc06a7b7342113c159a6195 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Wed, 12 Aug 2026 14:37:37 +1000 Subject: [PATCH] fix(agent): resolve git dubious-ownership in sandbox containers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent containers bind-mount the worktree from the host at /data/worktree, where the owning UID differs from the container user's UID. Git refuses to operate in such directories, so every gate command that calls the Go toolchain (go build/test/vet) fails with 'fatal: detected dubious ownership in repository' before any real work begins. Add 'git config --global --add safe.directory /data/worktree' at archie-agent startup so all subsequent git-spawned operations (baseline gate, build gate, agent shell tool invocations) work correctly. Logs a warning if git is unavailable rather than failing — the agent remains usable for repos with no gate config. --- cmd/archie-agent/main.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmd/archie-agent/main.go b/cmd/archie-agent/main.go index f19ce6f87..01b1efa42 100644 --- a/cmd/archie-agent/main.go +++ b/cmd/archie-agent/main.go @@ -21,6 +21,7 @@ import ( "fmt" "log/slog" "os" + "os/exec" "os/signal" "path/filepath" "strings" @@ -77,6 +78,20 @@ func run() int { log := slog.New(slog.NewJSONHandler(os.Stderr, nil)) + // Worktrees are bind-mounted from the host into the container at + // /data/worktree. The host-side UID that owns the worktree differs + // from the container user's UID. Git refuses to operate when the + // containing directory is owned by another user ("fatal: detected + // dubious ownership in repository"). The Go toolchain calls git for + // VCS status during go build/test/vet, so every gate fails before + // any real work begins. Marking the mount directory as safe resolves + // this for the container's lifetime. + gitSafeDir := exec.Command("git", "config", "--global", "--add", "safe.directory", storage.WorktreeMountDir) + if out, gitErr := gitSafeDir.CombinedOutput(); gitErr != nil { + log.Warn("git safe.directory config failed (gate commands that shell out to git may encounter dubious-ownership errors)", + "dir", storage.WorktreeMountDir, "err", gitErr, "output", string(out)) + } + ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) defer stop()