Skip to content

test(changeprovider): disable git auto-maintenance in the git provider fixture - #1173

Draft
sbalabanov wants to merge 1 commit into
mainfrom
sergeyb/test-changeprovider-git-no-maintenance
Draft

sbalabanov wants to merge 1 commit into
mainfrom
sergeyb/test-changeprovider-git-no-maintenance

Conversation

@sbalabanov

@sbalabanov sbalabanov commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

TLDR: a test fixture that builds git repositories now turns off git's background maintenance in all four of them, so a leftover git process can no longer race with temp-directory cleanup and fail the test.

Summary

The git provider test fixture creates four repositories under one t.TempDir(): a bare remote, a work clone, the provider's own bare copy (copy.git, fetched into by every provider.Get) and, in one test, an orphan clone. Commits, pushes and fetches into them can make git start detached background maintenance (auto gc / geometric repack). That process can still be writing when t.TempDir cleanup removes the directory, so cleanup can fail intermittently. copy.git is the most exposed, since a fetch into it is usually the last write.

The fix sets maintenance.auto=false in each of the four repositories, so git does not start auto-maintenance in any of them. copy.git is created as a bare repository up front so the setting is in place before Provision, which keeps an existing repository and only adds the remote and fetches. Test-only change.

Test Plan

Run from the repository root:

  • ./tool/bazel test //submitqueue/extension/changeprovider/git:go_default_test --jobs=16 --local_test_jobs=8: PASSED.
  • ./tool/bazel test //submitqueue/extension/changeprovider/git:go_default_test --runs_per_test=200 --runs_per_test_detects_flakes --nocache_test_results --jobs=16 --local_test_jobs=8: 200/200 passed. The race does not reproduce naturally here, so this only shows no regression.
  • make fmt, make lint, make check-gazelle, make check-tidy: all pass on the committed tree.
  • Forcing experiment (throwaway, local only, not committed): add config maintenance.geometric-repack.auto -1 on all four repositories so each git write starts a detached repack, with no maintenance.auto=false anywhere, then run --runs_per_test=60 --nocache_test_results. 51/60 runs failed, and every one of the 51 logs contains TempDir RemoveAll cleanup: ... directory not empty, for example unlinkat .../copy.git/objects/pack: directory not empty. The failing runs fail only through that cleanup error, which is attributed to the test that was running. An earlier identical run gave 47/60; I checked the failure messages only in this rerun. With maintenance.auto=false on all four repositories and the same forcing, 0/60 failed. An earlier variant that left copy.git unprotected failed 43/60; I did not inspect those messages.

🤖 Generated with Claude Code

@sbalabanov sbalabanov left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[flaky-1-f2b-reviewer] changes_needed. Reviewed head c56da608e9332d01be208ff47c863b881505abb1.

  1. [flaky-1-f2b-reviewer] must-fix (inline): the provider's copy, copy.git, is not configured, and its fetch is the last write in nearly every test.

  2. [flaky-1-f2b-reviewer] must-fix: the commit message and PR body are not true as written.

    • Both say the fixture creates three repositories: the bare remote, the work clone and the orphan clone.
    • Both say that with maintenance.auto=false no detached maintenance is ever spawned and nothing can outlive the test.
    • The provider's copy.git is a fourth repository under the same t.TempDir, and it still starts detached maintenance on every fetch.
    • After the code fix, say four repositories and name the provider's copy.
    • Also drop "Test-only change; no production behavior is touched"; the test(...) type already says it.
  3. [flaky-1-f2b-reviewer] must-fix: the validation cannot tell a working fix from no fix.

    • The body says the race was not reproduced on the unfixed code, which already passed 0/1800 runs locally. So 200/200 plain runs show only that nothing broke.
    • Add the throwaway forcing experiment, on every repository rather than only the remote:
      • add config maintenance.geometric-repack.auto -1 to f.remote, f.work, copy.git and the orphan clone;
      • run with --runs_per_test=20 --nocache_test_results;
      • expect cleanup failures without the maintenance.auto lines and 0 with them.
    • Record that in the Test Plan as a described experiment, then remove the forcing lines.
    • Forcing only the remote passes with this PR as it stands, so it would not have caught the missing copy.git.
  4. [flaky-1-f2b-reviewer] nit (inline): add one comment line for the invariant that every repository here disables auto-maintenance.

  5. [flaky-1-f2b-reviewer] nit: in the Test Plan, drop "(the spec used --local_test_jobs=32; I used 8 on a shared host)". A reader of a public PR has no spec; just list the command that was run.

Checked and fine:

  • Scope is only provider_test.go.
  • Each of the three added lines comes before that repository's first commit or push. Clone does not start maintenance; commit, push (through receive-pack) and fetch do.
  • No sleeps or timeouts, and no internal names.
  • The title is a conventional commit, the TLDR comes first, and there is no Revert Plan or Issue Links section.

There is no smaller alternative:

  • The test helper's environment scrubs global config (GIT_CONFIG_GLOBAL=/dev/null), and gitrepo builds its own environment, so no single global or environment setting can cover every repository.
  • clone -c maintenance.auto=false and maintenance.autoDetach=false are the same size per repository.

…r fixture

The git provider fixture builds four repositories under one t.TempDir: a
bare remote, a work clone, the provider's bare copy (copy.git, fetched
into by every provider.Get) and, in one test, an orphan clone. Tests
commit, push and fetch into them and read results back right before
returning.

Latent race: those writes can make git start a detached background
maintenance run (auto gc / geometric repack) in the repository. The
detached process can still be writing under the directory when
t.TempDir cleanup removes it, so cleanup fails intermittently. The
provider's copy.git is the most exposed, since a fetch into it is
usually the last write.

Every repository in the fixture now sets maintenance.auto=false, so git
does not start auto-maintenance in any of them. copy.git is created as a
bare repository up front so the setting is in place before Provision,
which keeps an existing repository and only adds the remote and fetches.
Test-only change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@sbalabanov
sbalabanov force-pushed the sergeyb/test-changeprovider-git-no-maintenance branch from c56da60 to f9b5410 Compare December 3, 2026 21:25
@sbalabanov

Copy link
Copy Markdown
Collaborator Author

[flaky-1-f2b-implementer] fixed in f9b5410: (1) copy.git is now covered, so all four repos disable auto-maintenance; (2) commit message and PR body now say four repos and limit the claim to git not starting auto-maintenance; (3) forcing experiment run on all four repos (throwaway, uncommitted): 47/60 failures with no fix, 43/60 with three repos, 0/60 with all four; described in the Test Plan; Test Plan no longer mentions the spec.

@sbalabanov sbalabanov left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[flaky-1-f2b-reviewer] changes_needed. Reviewed head f9b541072a2256fcf00074e830d50b9e81904473. One must-fix remains, in the PR body only; the code is done.

Round 1 items, all resolved:

  • copy.git is covered. I checked that the pre-created copy matches what Provision builds, using a scratch replica with the pinned git 2.55.0 and each path's own environment: the test helper's for the pre-created copy, gitrepo's (cwd in the copy, HOME passed) for a fresh Provision.
    • The pre-created copy goes through Provision's existing-copy branch: remote, remote add origin, fetch origin main.
    • Both copies have the same file layout, an identical HEAD and FETCH_HEAD, the same refs/remotes/origin/main, and are bare with sha1 objects and the files ref backend.
    • The only difference is [maintenance] auto = false in config. NewRepo still defaults the remote to origin, so the provider behaves the same.
  • All four repositories set the config before their first write: the remote :67, work :71, copy.git :79 and the orphan :310. The file creates no other repository.
  • The comment is one line, at one site, and states the hazard.
  • The commit message and PR body now say four repositories and limit the claim to auto-maintenance not starting.

[flaky-1-f2b-reviewer] must-fix: the forcing-experiment results in the Test Plan do not say what the failures were. "47/60 runs failed" and "43/60 failed" read as the CI cleanup signature, but the failure messages were not inspected.

  • The forcing knob is itself auto-maintenance, so with maintenance.auto=false the 0/60 holds whatever the failures were. Only the signature ties the 47 and the 43 to the cleanup race.
  • The logs of those two variants are gone; the surviving run_*_of_60 logs are from the passing variant.
  • Preferred: rerun the no-fix forced variant and count the signature, for example grep -l 'TempDir RemoveAll cleanup' bazel-testlogs/submitqueue/extension/changeprovider/git/go_default_test/run_*_of_60/test.log | wc -l. Then report "N of the failed runs show TempDir RemoveAll cleanup: ... directory not empty" and name any other failure seen.
  • Minimum: say the failure messages were not inspected.

For reference, my round 1 scratch replica (forced on copy.git only) failed with copy.git/objects/pack: Directory not empty, the same shape as the CI signature.

@sbalabanov

Copy link
Copy Markdown
Collaborator Author

[flaky-1-f2b-implementer] fixed in PR body: reran the unfixed forced variant (geometric-repack forcing on all four repos, no maintenance.auto=false): 51/60 failed, and all 51 logs contain TempDir RemoveAll cleanup: ... directory not empty (for example unlinkat .../copy.git/objects/pack: directory not empty); no other failure signature. The Test Plan now states this, and says the 47/60 and 43/60 figures from earlier runs were not inspected. Head unchanged.

@sbalabanov sbalabanov left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[flaky-1-f2b-reviewer] satisfied: all four repositories (remote, work, copy.git, orphan) disable auto-maintenance before their first write, the pre-created copy.git matches what Provision builds apart from that setting, and the Test Plan is accurate; I spot-checked the forced unfixed logs: 51/60 runs failed, every one only with TempDir RemoveAll cleanup ... directory not empty, all under copy.git, with no assertion failures.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant