Skip to content

A reused Gradle daemon can make cribro treat tracked files as untracked #24

Done

Description

@msridhar

AI-generated report: This report was generated by OpenAI Codex (AI). The agent ran the local diagnostics below.

With cribro 1.1.1 in a reused macOS Gradle daemon, changedLines treated tracked Java files as untracked and expanded the diff coverage and mutation scope to essentially the whole module. The cause is the daemon's native child-process environment retaining GIT_INDEX_FILE= even though System.getenv("GIT_INDEX_FILE") returns null for the current build.

Observed behavior

While working on apache/nullaway#2175, ordinary Git commands showed two changed production Java files against the chosen base and no untracked Java/Kotlin files. Cribro instead listed nearly the entire main source set as changed. The incorrectly scoped mutation run was stopped; a fresh-daemon run restored the correct scope.

Inside the affected daemon, both cribro's Git wrapper and a separate ProcessBuilder invocation of Git reported 337 untracked Java/Kotlin files. Calling ProcessBuilder.environment() before start() changed the result to zero, without changing the repository. A native env subprocess showed GIT_INDEX_FILE= while Java reported the variable as absent.

Outside Gradle, the distinction was reproducible too:

GIT_INDEX_FILE= git ls-files --others --exclude-standard -- ':(glob)**/*.java' ':(glob)**/*.kt' | wc -l
# 337
git ls-files --others --exclude-standard -- ':(glob)**/*.java' ':(glob)**/*.kt' | wc -l
# 0

Diagnostic reproduction

This init script was run in the affected NullAway checkout. It diagnoses an already affected daemon; the earlier invocation that originally introduced GIT_INDEX_FILE was not traced. The related Gradle issue below provides a reproduction of stale native environment variables across daemon invocations.

Save as git-environment.gradle:

gradle.rootProject { project ->
    project.tasks.register('cribroGitEnvironmentProbe') {
        doLast {
            println "System.getenv(GIT_INDEX_FILE): ${System.getenv('GIT_INDEX_FILE')}"
            for (def copyEnvironment : [false, true]) {
                def builder = new ProcessBuilder('git', '-c', 'core.quotePath=false', 'ls-files', '--others', '--exclude-standard', '--', ':(glob)**/*.java', ':(glob)**/*.kt').directory(project.projectDir)
                if (copyEnvironment) builder.environment()
                def process = builder.start()
                def output = process.inputStream.getText('UTF-8')
                def error = process.errorStream.getText('UTF-8')
                println "environment() called: ${copyEnvironment}, untracked: ${output.readLines().size()}, exit: ${process.waitFor()}"
                if (error) println error
            }
            def envProcess = new ProcessBuilder('env').start()
            def envOutput = envProcess.inputStream.getText('UTF-8')
            envProcess.waitFor()
            println "Native child: ${envOutput.readLines().find { it.startsWith('GIT_INDEX_FILE=') }}"
        }
    }
}
./gradlew :cribroGitEnvironmentProbe --init-script git-environment.gradle

Observed output:

System.getenv(GIT_INDEX_FILE): null
environment() called: false, untracked: 337, exit: 0
environment() called: true, untracked: 0, exit: 0
Native child: GIT_INDEX_FILE=

In a fresh process using --no-daemon, both subprocess variants reported zero untracked files and the native child had no GIT_INDEX_FILE entry. The normal cribro changedLines task also returned the correct two-file scope.

Expected behavior and possible fix

Git should receive the current build's Java environment, including the absence of GIT_INDEX_FILE, so stale native daemon state does not make tracked files count as untracked.

Git.execute on main at 4925236 starts new ProcessBuilder(command).directory(repositoryRoot).start() without materializing the environment. Calling builder.environment() before builder.start() fixed the Git result in the diagnostic above. This preserves Git environment variables intentionally supplied to the current build.

Related issue

This matches the open upstream Gradle issue gradle/gradle#27346: Subprocesses of Gradle daemon spawned through ProcessBuilder on macOS inherit empty environment variables from previous daemon calls, which also documents calling ProcessBuilder.environment() as a workaround. This report asks cribro to apply that workaround to its Git launcher. I found no matching cribro issue after reviewing the repository's current issues and searching related pull requests.

Environment

  • Cribro 1.1.1.
  • Gradle 9.8.2, reused daemon.
  • Eclipse Temurin OpenJDK 25.0.5+8.
  • macOS 27.2.1, build 26B131.
  • Default Git: 2.56.1. The same bad file list was also observed using /usr/bin/git inside the daemon.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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