fix(agent): resolve git dubious-ownership in sandbox containers

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.
This commit is contained in:
sam committed 2026-08-12 14:37:37 +10:00
1 parent 4e0eade43f
commit 4f4e151ff8
1 file changed
+15
+15
View File
@@ -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()