Skip to content

Telemetry git-labels run git fetch --depth 1 in the host working tree, shallow-cloning the user's repo on GitHub Actions PR builds #13351

Closed

Description

@mnencia

What is the issue?

When GITHUB_REF is a refs/pull/... ref (i.e. a GitHub Actions pull_request build), Dagger's telemetry git-label collection runs git fetch --depth 1 inside the host working tree, which writes .git/shallow and turns the user's checkout into a shallow (depth-1) clone. This silently corrupts the repository: after it runs, git merge-base, git log, git describe, etc. no longer see history.

The offending code is engine/telemetry/labels.go:

// WithGitLabels(workdir)
if ref, ok := os.LookupEnv("GITHUB_REF"); ok {
    if strings.HasPrefix(ref, "refs/pull/") {
        refCommit, err := fetchRef(repo, workdir, "origin", ref)   // runs in the host workdir
        ...

// fetchRef(...)
dest := fmt.Sprintf("refs/dagger/%s", target)
cmd := exec.Command("git", "fetch", "--depth", "1", remote, fmt.Sprintf("+%s:%s", src, dest))

GIT_TRACE from a real GitHub Actions run, showing the fetch executing against the checkout's own .git:

git.c:502  trace: built-in: git fetch --depth 1 origin +refs/pull/946/head:refs/dagger/pull/946/head
            setup: git_dir: .git
            setup: worktree: /home/runner/work/<repo>/<repo>
            setup: cwd:      /home/runner/work/<repo>/<repo>

The destination is a scratch refs/dagger/... ref, but the fetch still runs in (and shallows) the host repository.

Impact

Dagger mutates/corrupts the user's source checkout as a side effect of telemetry. Any tool run afterwards that needs history breaks. In our case it surfaced as commitlint --from=origin/main failing for every pull request with Cannot find merge-base between 'origin/main' and 'HEAD', because the checkout had been reduced to a single commit. It would equally break git describe, changelog generation, coverage diffs, etc. It also took a long investigation to trace, since the corruption happens out-of-band from the failing tool.

Reproduction

In a clone of any GitHub repo that has PRs (history intact, not shallow):

git clone https://github.com/dagger/dagger /tmp/r && cd /tmp/r
git rev-list --count HEAD                              # e.g. 50000+
test -f .git/shallow && echo shallow || echo full      # -> full

# Simulate a GitHub Actions PR build (GITHUB_REF set to a refs/pull/* ref):
GITHUB_REF=refs/pull/1/head dagger core container \
  from --address=alpine/git \
  with-mounted-directory --path=/src --source=. \
  with-exec --use-entrypoint=false --args=true \
  stdout

test -f .git/shallow && echo "SHALLOW (corrupted)" || echo full   # -> SHALLOW (corrupted)
cat .git/shallow                                       # the grafted commit

Reproduced with engine/CLI v0.21.4 both on GitHub-hosted ubuntu-latest and locally on Linux.

Expected behavior

Computing telemetry git labels must never mutate the user's working tree. The ref resolution should fetch into an isolated GIT_DIR (or a temp clone), or resolve the commit read-only, and must not pass --depth 1 to a fetch that targets the user's repository.

Workaround

Unset GITHUB_REF for the affected invocations (GITHUB_REF= dagger ...), which makes WithGitLabels skip the fetch.

I searched open/closed issues and didn't find an existing report for this.

Activity

  1. self-assigned this
    on Jun 8, 2026
  2. added a commit that references this issue on Jun 8, 2026
    938ec81
  3. added a commit that references this issue on Jun 8, 2026
    7f38c12
  4. added a commit that references this issue on Jun 9, 2026
    3fcfba5
  5. added a commit that references this issue on Jun 9, 2026
    2154a82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions