Run workspace-side mirror git commands with the checkout's git environment; adopt mirrors owned by another user - #53
Merged
Conversation
…nment; adopt mirrors owned by another user In a job container the runner creates the workspace as the VM user while the action runs git as root. The action marks the workspace as a safe.directory in a temporary global config that only the git command manager's environment (HOME override) points at. dissociate's `git repack -a -d` and the mirror ref copy ran git with the plain process environment, so git rejected the workspace as dubiously owned: dissociate failed the checkout step outright, and the ref copy silently fell back to a local fetch. Both now receive IGitCommandManager.getEnvironment(). A shared sticky-disk mirror can likewise have been hydrated by a job running as another user (root container vs. runner VM); ensureMirror now chowns it to the current user before it is read or synced. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
ajwerner
approved these changes
Sep 8, 2026
…ksmith runners Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…f the workspace root Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 9248df6. Configure here.
…es the in-job chown (each step mounts a fresh copy) Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Bug. In a job container (
allow-inside-container: true,--privileged -v /dev:/dev) the runner creates/__w/<repo>/<repo>as the VM's runner user while the action runs git as root. The action handles that for its own commands by adding the workspace assafe.directoryto a temporary global config and pointing theGitCommandManager'sHOMEat it. Two mirror-related paths inblacksmith-cache.tsrangitthrough@actions/execwith the plain process environment instead, so they never saw that config:dissociate()—git -C <workspace> repack -a -d→fatal: detected dubious ownership in repository→ exit 128 → checkout step fails whenever a mirror is mounted anddissociate: trueis set on a top-level container checkout. (Sub-path checkouts pass only because the action creates that directory itself.)copyRefsFromMirror()(fetch-depth: 0) — the workspaceconfig/for-each-ref/update-ref/pack-refscalls fail the same way and silently fall back to the local fetch.-c safe.directory=…is not a fix: git rejects it from the command line (it must come from a global/system config), verified on 2.34 — only theHOMEroute works.Fix.
git-source-provider.tspassesgit.getEnvironment()to both.execGitnow builds its env through the same method.Related: mirror ownership. The same job mix (root container jobs and runner-user VM jobs) shares one sticky-disk mirror. A mirror hydrated by the other kind of job is dubiously owned to git and, for the runner user, not even writable, so every mirror sync/ref read would fail (fallback to network, no commit) until re-hydrated.
ensureMirrornow checksstat(mirrorPath).uidon an existing mirror andsudo chown -Rthe mirror dir to the current user when it differs (adoptMirrorOwnership, logged with duration; no-op in the common single-user case).CI (
test-blacksmith.yml).test-git-mirror-container:runs-on: blacksmithwithcontainer: ubuntu:24.04,--privileged -v /dev:/dev, checking out as root withallow-inside-container: true+dissociate: trueinto a directorychown --reference=.'d to the runner user (same ownership check as the workspace root — git ≥2.36 checks the worktree owner — without wiping the local action, whoseproblem-matcher.jsonthe runner reads asynchronously). Asserts the sticky disk is actually mounted in the container, the mirror ended up root-owned (taken over from uid 1001), alternates gone,HEAD == GITHUB_SHA,fsckclean. Fails onmainwith the dubious-ownership error.test-git-mirror-after-container: VM jobneeds-chained after it — mirror runner-owned and used. Only a real takeover once a trusted-trigger (push to main) container job has committed a root-owned mirror; each checkout step mounts its own copy of the last commit, so ownership can't be flipped between steps of one job.End-to-end control-vs-candidate on staging runners: useblacksmith/test-workflows#217.
Test.
__test__/mirror-workspace-env-git.test.tsuses git'sGIT_TEST_ASSUME_DIFFERENT_OWNER=1to make a real workspace foreign-owned and a tempHOME/.gitconfigwithsafe.directory = <workspace>:dissociatewith the plain env fails with exit 128 (the bug), andfetchRefsFromMirror+dissociatewith the checkout env succeed and leave a self-contained workspace (fsckafter deleting the mirror). Skipped on git builds without the knob.dist/rebuilt.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled. (Staging)Link to Devin session: https://app.devin.ai/sessions/a3b42ef15226438faf3f9cdde9662918
Open in Devin Desktop: https://app.devin.ai/desktop/session/a3b42ef15226438faf3f9cdde9662918?variant=devin
Requested by: @piob-io