Skip to content

ci: clear stale git locks before checkout on self-hosted runners #2296

In review

Description

@eric8810

What needs tracking?

Self-hosted runner workspaces outlive a job, and concurrency.cancel-in-progress: true cancels superseded PR runs, sometimes while actions/checkout is writing repository config. The cancelled Git process leaves a zero-byte .git/config.lock; nothing removes it before the next job. That job then fails inside actions/checkout's credential cleanup with error: could not lock config file .git/config: File exists, even though the fetch and git clean -ffdx / reset --hard had already succeeded. Rerunning does not help while the file remains.

Observed on runner R3E-3 in C:\actions-runner-3\_work\dim\dim:

  • The lock was timestamped 2026-11-27 17:59 CST, the same minute in which run 45978129985 was cancelled.
  • Run 46018200609 (main push, 2026-11-27): the web job failed at checkout.
  • Run 46113838137 (main push, 2026-11-28): the windows-cli job failed at checkout.
  • Run 46108329010 (PR, 2026-11-28): the windows-cli job failed at checkout.

Manual cleanup (removing the file and scanning all 4 runners / 8 workspaces) unblocked CI, but nothing prevents the next cancelled checkout from recreating the lock.

Every ci.yml job that runs on a self-hosted runner has this exposure: changes, dependencies, static-checks, windows-cli, web, scripts, verify, macos-native, acp-registry. The other runners were unaffected only because no checkout was interrupted in their workspaces.

A checked-in composite action cannot run before the first checkout, because its definition is not on disk yet. The cleanup therefore has to be an inline step before each self-hosted checkout, using shell: powershell on Windows (self-hosted Windows does not necessarily have pwsh) and shell: bash on Linux and macOS. Review on #2303 narrowed it to the known config.lock in the checkout the job owns and required the step to verify that checkout before removing the lock; a wider *.lock sweep cannot prove that no other process owns those files. The acp-registry job also checks its .acp-registry checkout.

References or acceptance criteria

  • Every self-hosted checkout in ci.yml is preceded by a step that removes that checkout's stale config.lock, including the second .acp-registry checkout in acp-registry.
  • Before removing a lock, the step verifies the checkout root and origin. A missing, unreadable, or different origin leaves the lock untouched and fails with the path; the nested .acp-registry checkout must match its registry origin.
  • The step removes only config.lock in the checkout the job owns. Wider *.lock cleanup is out of scope because the workflow cannot prove exclusive ownership; a runner instance has its own work directory and runs one job at a time, and maintenance must not run Git in a workspace that may accept a job.
  • A missing workspace or .git proceeds only after absence is confirmed through the workspace parent or RUNNER_WORKSPACE. An inaccessible workspace, inaccessible .git, or a lock that cannot be removed fails the step with an actionable path.
  • A workflow comment records the ownership assumption.
  • Verified by planting .git/config.lock in the R3E-3 workspace and dispatching the affected job: checkout succeeds and the lock is gone. The next regular PR exercises the Linux path.
  • The fix travels with the workflow; no manual runner cleanup or runner-side scheduled task is required.

Related: #1931, #1919, #1920.

Activity

  1. added
    roadmap
    P2
    on Nov 28, 2026
  2. self-assigned this
    on Nov 28, 2026
  3. eric8810 commented on Nov 28, 2026

    @eric8810
    CollaboratorAuthor

    Review on #2303 narrowed the cleanup to the known .git/config.lock per checkout (including .acp-registry) and asked the preflight to distinguish a fresh workspace from inaccessible metadata. Wider *.lock cleanup is out of scope because the workflow cannot prove that no other process owns those locks. Acceptance updated; the PR now carries commit a1121e1.

  4. eric8810 commented on Nov 28, 2026

    @eric8810
    CollaboratorAuthor

    Two more occurrences of the same class from today's main runs:

    • run 46113838137, push b829ec6c: windows-cli failed inside actions/checkout, before any job step ran.
    • 2026-11-27 14:41, push fcd36017: web failed in actions/checkout as well, and windows-cli failed in its daemon-shutdown step in the same run.

    The first is the lock-file case this issue describes; there is no step output to read, which is what makes it look like a test failure until the job list is opened. Worth having ci-ok name the job and step it failed on, not only that some job failed.

  5. eric8810 commented on Nov 28, 2026

    @eric8810
    CollaboratorAuthor

    Second review on #2303 required verifying that the Git metadata belongs to the job's checkout and confirming absence instead of treating every failed lookup as a fresh workspace. The PR now checks the checkout root and origin before removing a lock, and accepts a missing workspace only through its parent or the runner work directory. Acceptance updated.

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

Metadata

Metadata

Assignees

Labels

P2roadmap

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions