Skip to content

Fix slow cache restore on Windows - #515

Closed
antontroshin wants to merge 18 commits into
actions:mainfrom
antontroshin:windows-go-mod-cache
Closed

antontroshin wants to merge 18 commits into
actions:mainfrom
antontroshin:windows-go-mod-cache

Conversation

@antontroshin

@antontroshin antontroshin commented Nov 19, 2024 •

Copy link
Copy Markdown

Description:
The issue with running setup-go and restoring relatively big cache files, causes the cache restore process to be very slow on Github Action Windows runners.
Similar to the change that was made in version v5.0.0 (PR #411), I've made a change to override the default GOCACHE and GOMODCACHE variables on Windows runners to be using drive D.
On average, restoring ~1.7Gb cache on Windows pipelines took about 13-15 minutes to extract.
With this change, the extraction time was reduced to ~1m.

Restore cache logs before the change:

Wed, 20 Nov 2024 02:24:29 GMT Cache Size: ~1784 MB (1870225672 B)
Wed, 20 Nov 2024 02:24:30 GMT Received 1870225672 of 1870225672 (100.0%), 295.9 MBs/sec
Wed, 20 Nov 2024 02:37:21 GMT Cache restored successfully
Restore elapsed: 12 min 51 sec
Wed, 20 Nov 2024 01:38:54 GMT Cache Size: ~1784 MB (1870225672 B)
Wed, 20 Nov 2024 01:38:55 GMT Received 1870225672 of 1870225672 (100.0%), 118.7 MBs/sec
Wed, 20 Nov 2024 01:54:19 GMT Cache restored successfully
Restore elapsed: 15 min 24 sec

Restore cache logs after the change:

Wed, 20 Nov 2024 03:38:03 GMT Cache Size: ~1780 MB (1866088667 B)
Wed, 20 Nov 2024 03:38:04 GMT Received 1866088667 of 1866088667 (100.0%), 197.3 MBs/sec 
Wed, 20 Nov 2024 03:38:59 GMT Cache restored successfully
Restore elapsed: 55 sec
Wed, 20 Nov 2024 03:38:10 GMT Cache Size: ~1780 MB (1866088667 B)
Wed, 20 Nov 2024 03:38:11 GMT Received 1866088667 of 1866088667 (100.0%), 197.6 MBs/sec
Wed, 20 Nov 2024 03:39:06 GMT Cache restored successfully
Restore elapsed: 55 sec
Wed, 20 Nov 2024 04:04:07 GMT Cache Size: ~1780 MB (1866088667 B)
Wed, 20 Nov 2024 04:04:07 GMT Received 1866088667 of 1866088667 (100.0%), 88.8 MBs/sec
Wed, 20 Nov 2024 04:05:05 GMT Cache restored successfully
Restore elapsed: 1 min 2 sec

Solution:

At first, I tried to implement a solution similar to #411 by using symlink, however, during testing, it was clear that the GOCACHE and GOMODCACHE directories were created early by the tooling, which did not present an easy way to create symlinks without deleting the already in-use directories and introducing bigger code changes.

The solution to override the path for env vars as early as possible only on Windows runners is easier.

This PR adds the code to make this change by default for Windows runners, this "workaround" is possible to use via the Github Action code itself, by manually overriding the env vars.
Preferably, this change would be accepted and merged (after review of course), so users can enjoy this improvement by default without manually modifying each and every Github action.

Related issue:
Numerous related issues were raised regarding this issue, some improvements were made to address it.

Check list:

  • Mark if documentation changes are required.
  • Mark if tests were added or updated to cover the changes.

Use D drive for faster cache restore

Signed-off-by: Anton Troshin <[email protected]>
Signed-off-by: Anton Troshin <[email protected]>
Signed-off-by: Anton Troshin <[email protected]>
Signed-off-by: Anton Troshin <[email protected]>
Signed-off-by: Anton Troshin <[email protected]>
Signed-off-by: Anton Troshin <[email protected]>
Signed-off-by: Anton Troshin <[email protected]>
Signed-off-by: Anton Troshin <[email protected]>
Signed-off-by: Anton Troshin <[email protected]>
Signed-off-by: Anton Troshin <[email protected]>
Signed-off-by: Anton Troshin <[email protected]>
Signed-off-by: Anton Troshin <[email protected]>
Signed-off-by: Anton Troshin <[email protected]>
@antontroshin antontroshin changed the title Add GOCACHE AND GOMODCACHE symlink on Windows Fix slow cache restore on Windows Nov 20, 2024
@antontroshin
antontroshin marked this pull request as ready for review November 20, 2024 04:33
@antontroshin
antontroshin requested a review from a team as a code owner November 20, 2024 04:33
@y-bruin

y-bruin commented Dec 31, 2024

Copy link
Copy Markdown

@antontroshin When do you plan to merge it?

@antontroshin

Copy link
Copy Markdown
Author

@antontroshin When do you plan to merge it?

@y-bruin Unfortunately, I cannot merge, as this is up to repo maintainers, once the PR is reviewed and approved.

@MatthewRyanRead MatthewRyanRead mentioned this pull request Jan 15, 2025
2 of 5 tasks
@lmb

lmb commented Jan 21, 2025

Copy link
Copy Markdown

For anyone else also waiting for this to get some attention:

    env:
      # Fix slow Go compile and cache restore
      # See https://github.com/actions/setup-go/pull/515
      GOCACHE: D:\gocache
      GOMODCACHE: D:\gomodcache
      GOTMPDIR: D:\gotmp

    steps:
      # Go requires gotmp to be present
      - run: mkdir D:\gotmp
        shell: pwsh

Setting GOTMPDIR to D: was necessary to cut down the time it took to go install from cache.

add validation for GOCACHE, GOMODCACHE, and GOTMPDIR on Windows

Signed-off-by: Anton Troshin <[email protected]>
@antontroshin

Copy link
Copy Markdown
Author

Hi @lmvysakh
Thanks for checking the PR. The code was a bit outdated, so I've merged the changes from main, and I hope this will fix the failed Action run. I didn't find the check as it appears in the screenshot, so I wasn't able to investigate the exact cause.

As for lack of drive "D:", I've added this check to skip the customization of the Go cache paths because the only safe assumption we can make in this case is that drive "C:" (default path locations) is the only drive that exist.

It may be a good idea to add this limitation for Windows machines to the README, with instructions on how to customize these paths by setting ENV variables manually, as @lmb commented above.
WDYT?

@v-lmvysakh

Copy link
Copy Markdown

Hi @antontroshin,

Thank you for your contribution and for working to improve cache restore performance on Windows runners!

We wanted to highlight that, as per the update, the D drive will no longer be accessible on GitHub-hosted Windows Server 2025 runners starting from July 14, 2025. Most Windows runners already do not have a D drive available, and this change will make it unavailable across all relevant runners for performance and startup reasons.

Since the current implementation in this PR achieves its speed improvement primarily by utilising the D drive, it might not work reliably for the majority of users and will break entirely once the D drive is removed from the images.

Would you be open to exploring alternative approaches that do not rely on the D drive? This will help ensure broader compatibility and long-term support for all users of the action.

Thank you again for your efforts and for considering this feedback!

@antontroshin

Copy link
Copy Markdown
Author

Hi @lmvysakh,
Thanks for the update, that is indeed very welcome news! It seems that the new runners will be using fast disks for the C drive.
To address the absence of drive D, I've added the following check in my last commit.

export const setWindowsCacheDirectories = async () => {
  if (os.platform() !== 'win32') return;

  if (!fs.existsSync('D:')) return;
  ...
}

If there's no D drive, the function will exit early, and env variables will be kept as-is, pointing to default locations, which is drive C, and thus preserving original behavior.
This should work seamlessly on new runners, given the drives will be fast, and on the old runners that still have the D drive.

Please let me know if this answers the concerns. Of course, I'm open to feedback if anything needs to be changed or improved.

One last thing, would you be so kind as to please rerun the one failed action Validate 'setup-go'? It seems to have failed on HTTP error 500, which happened on the day of the Google outage. Most likely was a temporary issue.

Thanks.

@v-lmvysakh

Copy link
Copy Markdown

Hi @antontroshin,

We have noticed that there is a test case failing as per the current checks. Additionally, the changes in this PR are not working as expected on self-hosted runners—they are causing failures in those environments. We have mentioned this issue previously and encountered the same error before; it appears to have happened again. The screenshot of the failed workflow when ran with self hosted runner having D drive is given as of below.

Screenshot 2025-09-17 at 6 34 37 PM

Could you please investigate and address these issues to ensure compatibility with self-hosted runners ? Thank you for your contribution !

@v-lmvysakh v-lmvysakh self-assigned this Sep 18, 2025
@v-lmvysakh

Copy link
Copy Markdown

Hi @antontroshin,

Just a gentle reminder to please make the suggested updates to the PR as soon as possible.

@v-lmvysakh

Copy link
Copy Markdown

Hi @antontroshin,

Following up on the recent analysis and discussion in #495, we would like to provide further context regarding this pull request.

After conducting comprehensive testing using actions/setup-go v5 and v6 across various runner configurations, we observed that cache restoration is now working as expected and robustly across our workflows. The initial delays in cache loading appeared to be primarily due to underlying image IO performance issues on Windows runners, as documented in @actions/runner-images/issues/8755. These issues, stemming from differences between the C and D drives, previously affected runtime performance and cache restoration times.

Recent workflow runs with the current versions of actions/setup-go no longer exhibit the cache restoration delays we saw earlier. As a result, and in consultation with the observations we shared on the related issue, we have decided not to proceed with merging this PR. We greatly appreciate the contribution and the effort to address this problem. Should further issues arise, or if additional information is needed, please feel free to reach out. Thank you for your support and collaboration.

@antontroshin

Copy link
Copy Markdown
Author

Hi @lmvysakh
After doing some tests as well, I came to the same conclusion. New GitHub Windows runners solved the issue by using faster disks for the C: drive.
The issue may still exist on the older runners, but the advice would be to switch to the latest or newer versions after 20250713.
The disk change was introduced in the version 20250713 for both Windows Server 2022 and Windows Server 2025
Change also removed the drive D:, but that was later reverted, and drive D: should be available on the runners.

If someone still wishes to manually change Go env variables, they may follow the example in the comment by @lmb above #515 (comment)

I will close this PR, but will leave the branch.
If anyone uses this PR's commits, please change back the pipelines to official actions/setup-go.

Appreciate everyone's help and input throughout this PR's journey 🎉

@v-lmvysakh

Copy link
Copy Markdown

Hi @antontroshin,

Thank you for your contribution and for addressing issue #495.

We've confirmed that the issue with slow cache restore on Windows has already been resolved by other changes in the codebase. At this time, there's no longer a need for additional fixes targeting this problem.

We appreciate your effort in preparing this PR and helping improve the action. Please feel free to submit further enhancements or bug fixes in the future!

Closing as resolved.

@v-lmvysakh v-lmvysakh closed this Jan 21, 2026
brianaydemir added a commit to brianaydemir/pelicanplatform-pelican that referenced this pull request Jan 24, 2026
- I'm splitting the macOS and Windows workflows out into their own files
  because it's a mess trying to read through conditionals on every other
  step definition.

- Make various tweaks so that a three-way diff between test-linux.yml,
  test-macos.yml, and test-windows.yml highlights only real differences.

- On Windows, we don't do a real build of the web UI, so stop setting up
  Node.js and the Next.js cache.

- On Windows, actions/setup-go#515 has apparently
  been fixed, so we can get rid the workaround we've been using.

- Add/update comments to be more descriptive.
brianaydemir added a commit to brianaydemir/pelicanplatform-pelican that referenced this pull request Jan 24, 2026
- I'm splitting the macOS and Windows workflows out into their own files
  because it's a mess trying to read through conditionals on every other
  step definition.

- Make various tweaks so that a three-way diff between test-linux.yml,
  test-macos.yml, and test-windows.yml highlights only real differences.

- On Windows, we don't do a real build of the web UI, so stop setting up
  Node.js and the Next.js cache.

- On Windows, actions/setup-go#515 has apparently
  been fixed, so we can get rid the workaround we've been using.

- Add/update comments to be more descriptive.
brianaydemir added a commit to brianaydemir/pelicanplatform-pelican that referenced this pull request Jan 25, 2026
- I'm splitting the macOS and Windows workflows out into their own files
  because it's a mess trying to read through conditionals on every other
  step definition.

- Make various tweaks so that a three-way diff between test-linux.yml,
  test-macos.yml, and test-windows.yml highlights only real differences.

- On Windows, we don't do a real build of the web UI, so stop setting up
  Node.js and the Next.js cache.

- On Windows, actions/setup-go#515 has apparently
  been fixed, so we can get rid the workaround we've been using.

- Add/update comments to be more descriptive.
brianaydemir added a commit to brianaydemir/pelicanplatform-pelican that referenced this pull request Jan 27, 2026
- Split the macOS and Windows workflows out into their own files because
  it's a difficult trying to read through conditionals on every other step
  definition.

- Make various tweaks so that a three-way diff between test-linux.yml,
  test-macos.yml, and test-windows.yml highlights only real differences.

- On Windows, we don't do a real build of the web UI, so stop setting up
  Node.js and the Next.js cache.

- On Windows, the Go set up action no longer takes an inordinate amount of
  time, so remove the workaound.

  See the comments actions/setup-go#515 for more.
brianaydemir added a commit to brianaydemir/pelicanplatform-pelican that referenced this pull request Jan 27, 2026
- Split the macOS and Windows workflows out into their own files because
  it's challenging trying to read through conditionals on every other step
  definition.

- Make various tweaks so that a three-way diff between test-linux.yml,
  test-macos.yml, and test-windows.yml highlights only real differences.

- On Windows, we don't do a real build of the web UI, so stop setting up
  Node.js and the Next.js cache.

- On Windows, the Go set up action no longer takes an inordinate amount of
  time, so remove the workaound.

  See the comments on actions/setup-go#515 for more.
brianaydemir added a commit to brianaydemir/pelicanplatform-pelican that referenced this pull request Feb 1, 2026
- Split the macOS and Windows workflows out into their own files because
  it's challenging trying to read through conditionals on every other step
  definition.

- Make various tweaks so that a three-way diff between test-linux.yml,
  test-macos.yml, and test-windows.yml highlights only real differences.

- On Windows, we don't do a real build of the web UI, so stop setting up
  Node.js and the Next.js cache.

- On Windows, the Go set up action no longer takes an inordinate amount of
  time, so remove the workaound.

  See the comments on actions/setup-go#515 for more.
brianaydemir added a commit to brianaydemir/pelicanplatform-pelican that referenced this pull request Feb 1, 2026
- Split the macOS and Windows workflows out into their own files because
  it's challenging trying to read through conditionals on every other step
  definition.

- Make various tweaks so that a three-way diff between test-linux.yml,
  test-macos.yml, and test-windows.yml highlights only real differences.

- On Windows, we don't do a real build of the web UI, so stop setting up
  Node.js and the Next.js cache.

- On Windows, the Go set up action no longer takes an inordinate amount of
  time, so remove the workaound.

  See the comments on actions/setup-go#515 for more.
brianaydemir added a commit to brianaydemir/pelicanplatform-pelican that referenced this pull request Feb 4, 2026
- Split the macOS and Windows workflows out into their own files because
  it's challenging trying to read through conditionals on every other step
  definition.

- Make various tweaks so that a three-way diff between test-linux.yml,
  test-macos.yml, and test-windows.yml highlights only real differences.

- On Windows, we don't do a real build of the web UI, so stop setting up
  Node.js and the Next.js cache.

- On Windows, the Go set up action no longer takes an inordinate amount of
  time, so remove the workaound.

  See the comments on actions/setup-go#515 for more.
brianaydemir added a commit to brianaydemir/pelicanplatform-pelican that referenced this pull request Feb 5, 2026
- Split the macOS and Windows workflows out into their own files because
  it's challenging trying to read through conditionals on every other step
  definition.

- Make various tweaks so that a three-way diff between test-linux.yml,
  test-macos.yml, and test-windows.yml highlights only real differences.

- On Windows, we don't do a real build of the web UI, so stop setting up
  Node.js and the Next.js cache.

- On Windows, the Go set up action no longer takes an inordinate amount of
  time, so remove the workaound.

  See the comments on actions/setup-go#515 for more.
osterman added a commit to cloudposse/atmos that referenced this pull request Sep 4, 2026
The first run missed on both legs: main's setup-go archive is evicted by
the 10 GB LRU churn, and the only surviving entries are PR-scoped, which
other branches cannot read. A seed job per cache layout now populates a
real go-build+mod archive (go mod download + go build ./...) that
setup-go's post step saves under this branch, so the timed legs always
restore something real.

The topology job measured D: as a separate disk with ~8.8x the small-file
write rate of C: (4,545 vs 515 files/s), so a third leg relocates GOCACHE
and GOMODCACHE to D:\a\ before setup-go (actions/setup-go#515). It needs
its own seed: the cache version hashes the restore paths and the archive
holds absolute paths, so seed and restore must agree on layout.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
jorrite pushed a commit to jorrite/atmos that referenced this pull request Sep 7, 2026
…action (cloudposse#3049)

* ci: guard Windows DNS against harden-runner's post-step race; allowlist OS endpoints

Windows jobs have been finishing every step, including "Post Harden Runner"
and "Complete job", and then never reporting a conclusion until GitHub
cancels them 30-40 minutes later (0/day before harden-runner landed on the
Windows legs on Aug 31; 5, 9, 23/day on Sept 1-3). Root cause: harden-runner's
Windows post step waits at most 10 s for its agent, then kills it, and in the
losing case the agent is still restoring the runner's DNS settings, leaving
the adapter pointed at a DNS proxy that no longer exists.

- Add .github/actions/windows-dns-guard: a scheduled-task watchdog that
  resets DNS only once harden-runner's post step has begun, the agent is
  gone, and 127.0.0.1 is still configured. Wired into every Windows leg.
- Allowlist the Windows/macOS operating-system endpoints StepSecurity showed
  blocked on every job (NCSI probes, WNS, update/settings/telemetry, time
  sync, Sectigo OCSP/CRL, Apple update/CDN hosts); harden-runner stays in
  block mode everywhere.
- Drop the GOPROXY "|direct" fallback in block-mode workflows: it only fans
  out to blocked vanity-import hosts.
- Cancel superseded pull_request runs via a concurrency group.
- Skip SARIF uploads on merge_group runs, whose synthetic ref cannot be
  scanned and was evicting PRs from the merge queue.

Fix log: docs/fixes/2026-09-03-harden-runner-windows-dns-restore-race.md

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci: allow the whole NTP pool (*.pool.ntp.org), not just 0.pool.ntp.org

The pool advertises four rotating names (0-3.pool.ntp.org); a single one
was only what happened to be sampled. Push deferred until the first CI run
of the guard finishes so its Windows data isn't cancelled by the new
concurrency group.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci: address review on the Windows DNS guard

- Skip Harden Runner on draft-PR Windows jobs: every other Windows step
  (including checkout) is already skipped there, so its post step would
  race the agent's DNS restore with no guard available.
- Run the guard's scheduled task as the runner's own Administrator account
  (S4U) instead of SYSTEM; it grants nothing the job does not already have.
- Wrap the plain go mod download steps in pre-commit.yml and codeql.yml
  with go-mod-download-retry now that GOPROXY has no direct fallback.
- Measurement query: filter to Windows jobs and tolerate fractional-second
  timestamps.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci: Windows Defender exclusions and restore-only toolchain cache on shards

Phase 2 (part 1) of the CI-stability plan, stacked on the Phase 1 branch.

Windows Defender: on the Windows shards "Set up Go" averages 5.2 min
(max 10.5) restoring a 1.9 GB go-build+mod cache; the download is ~20 s,
the rest is tar/zstd extraction with Defender's real-time scanner
inspecting every extracted file, and the same scanner holding handles on
fresh test files surfaces as testing.TempDir cleanup failures
("unlinkat ... being used by another process"). Add a continue-on-error
pwsh step to every Windows leg of test.yml (build, terraform-registry-cache,
test, mock) and to setup-go-cache-warmup.yml that excludes D:\a,
C:\hostedtoolcache\windows, the Go caches, and the temp dirs, plus go.exe
as a process. These are ephemeral VMs and the step does not touch
harden-runner's egress policy.

Restore-only toolchain cache: the repo's Actions cache is 18.9 GB across
17 refs/pull/N/merge-scoped entries against a 10 GB LRU quota, so the
static atmos-toolchain-<os>-<arch>-v2 key never hits ("Cache not found
for input keys" on every shard), then all 10 shards race to save it
("Unable to reserve cache with key ...") and "Post Cache Atmos toolchain"
costs 43 s avg / 3 min max per shard for nothing. Add an opt-in
restore-only input (default 'false') to actions/cache/action.yml that
switches to actions/cache/restore at the same pinned SHA, keep cache-hit
and key outputs working, document it in the README, and set it on the
test job's "Cache Atmos toolchain" step for all three OSes.
terraform-registry-cache stays the single writer per OS and is unchanged.

Fix log: docs/fixes/2026-09-03-windows-defender-exclusions-and-restore-only-toolchain-cache.md

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(ci): drop the go.exe Defender process exclusion; it's spoofable

Add-MpPreference -ExclusionProcess 'go.exe' matches on image name only,
not path, so it would exempt any binary named go.exe from real-time
scanning regardless of where it actually lives - including one planted
by a compromised dependency during go build/go generate. The path
exclusions already in this step cover the actual scanning cost (file
I/O in the Go caches and workspace), so removing the process exclusion
gives up nothing measured.

(Skipped a second CodeRabbit finding on this PR: it asked test/
terraform-registry-cache to needs: a "cache-writer" job that doesn't
exist in this file - terraform-registry-cache itself is the writer,
and test is deliberately parallel to it so 30 shards don't wait on or
race the single writer job. Making test depend on it would serialize
two long-running job groups that currently run concurrently.)

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* temp: diagnostic - dump live Windows Defender state (to be reverted)

* Revert "temp: diagnostic - dump live Windows Defender state (to be reverted)"

This reverts commit 145a8c4.

* ci: drop Windows Defender exclusions, they're a no-op

GitHub's own actions/runner-images build script already disables
real-time monitoring and excludes C:\ and D:\ entirely on windows-latest
images, before any workflow step runs. Confirmed live via a temporary
diagnostic step (Get-MpComputerStatus/Get-MpPreference) on an actual
windows-latest runner: RealTimeProtectionEnabled was already False and
ExclusionPath already {C:\, D:\} before our own Add-MpPreference calls,
which only added redundant subpaths already covered by the existing C:\
exclusion. Since Defender was never doing real-time scanning to begin
with, it wasn't the cause of the measured Windows slowdown this step was
meant to fix - that root cause is still open.

Splits the fix-log doc accordingly: the restore-only-toolchain-cache half
(unrelated, unaffected) moves to its own file; a new doc records the
Defender investigation and reversal so it isn't re-attempted blind later.

* ci: add a dispatch-only Windows cache-restore perf lab

Restoring our ~1.9 GB go-build+mod cache on windows-2025 hosted runners
is ~6.5 minutes of pure tar extraction (download is ~16 s) - 40-60% of
every Windows acceptance shard's wall time. Iterating on that through the
full Tests suite costs a whole run per experiment.

This workflow restores the SAME production setup-go archive under one tar
configuration per matrix leg (gnu-tar = exactly what test.yml does today;
bsdtar = the proposed fix via a PROGRAMFILES override + System32-first
PATH, using only released @actions/cache code), asserts a real cache hit
so a miss can never masquerade as a fast restore, prints which tar was
actually selected, and writes each leg's "Set up Go" duration to the step
summary. A second job reports C:/D: disk topology and a small-file write
benchmark on each, to settle whether the D:\ that windows-2025-vs2026
still exposes is a distinct (fast) disk or a path onto the same volume.

Evidence for the two measured causes: actions/runner-images#12416/#12647
(D: removed on Windows Server 2025; C: ~540 IOPS, won't-fix) and
actions/cache#752 / actions/toolkit#2379 (MSYS GNU tar ~4x slower than
native bsdtar on many-small-files archives; PR unmerged). Windows Defender
is not a factor: real-time monitoring is disabled at the image level.

* ci: run the cache-perf lab on push, no merge to main needed

workflow_dispatch only resolves workflows that already exist on the
default branch, which would have meant merging the lab before running a
single experiment. A push trigger runs the pushed branch's own copy of the
file, so every push to a *ci-cache-perf* branch now runs it directly -
edit, push, read the step summary, repeat. A per-ref concurrency group
lets a newer push supersede a stale in-flight run. workflow_dispatch is
kept for once the file is on main.

* ci(cache-perf): seed the archive per layout; add a D:-relocated leg

The first run missed on both legs: main's setup-go archive is evicted by
the 10 GB LRU churn, and the only surviving entries are PR-scoped, which
other branches cannot read. A seed job per cache layout now populates a
real go-build+mod archive (go mod download + go build ./...) that
setup-go's post step saves under this branch, so the timed legs always
restore something real.

The topology job measured D: as a separate disk with ~8.8x the small-file
write rate of C: (4,545 vs 515 files/s), so a third leg relocates GOCACHE
and GOMODCACHE to D:\a\ before setup-go (actions/setup-go#515). It needs
its own seed: the cache version hashes the restore paths and the archive
holds absolute paths, so seed and restore must agree on layout.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci(cache-perf): pair each restore with its own seed; move steps to a composite

The second run lost the D: seed's archive before its restore leg ran:
this repo's cache sits at the 10 GB quota (9.9 GB across 5 entries,
~1.8 GB per Windows setup-go archive), so every save evicts the least
recently used entries, and the restore legs waited on both seeds - nine
minutes during which the D: archive was the oldest unread entry. Now
each layout is its own seed -> restore pair, so a restore starts (and
touches its archive) seconds after its seed saved it.

Each layout also gets its own cache key via a marker file hashed through
cache-dependency-path. The shared step sequence moves into
.github/actions/cache-perf-lab, which times the restore with its own
clock since the jobs API does not list nested composite steps.

Measured so far (both seeds through bsdtar): the cache save dropped from
590 s on C: to 175 s on D:, and go build ./... from 599 s to 455 s.
On C:, gnu-tar restored in 276 s and bsdtar in 295 s.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci(cache-perf): select bsdtar by renaming Git's tar aside; record D: numbers

Run 2's "bsdtar" legs silently used GNU tar: a step-level PROGRAMFILES
override does not take effect on Windows runners (the process keeps its
own ProgramFiles value), so @actions/cache's hardcoded
%PROGRAMFILES%\Git\usr\bin\tar.exe existence check kept passing. The
composite now takes tar: gnu|bsd and, for bsd, renames Git's tar.exe
aside for the job and puts C:\Windows\System32 first on PATH, so the
toolkit's PATH lookup lands on bsdtar. Nothing else in the job needs
Git's tar.

Measured so far with GNU tar on both sides: restore 276 s on C: vs 94 s
on D: (same 1.7 GB archive); save 590 s vs 175 s; go build 599 s vs 455 s.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci: put Windows Go caches on the fast work disk via a setup-go-cache action

New .github/actions/setup-go-cache: pinned actions/setup-go with caching,
plus one Windows-specific step before it - relocate GOCACHE and
GOMODCACHE onto the runner's work disk (derived from RUNNER_TEMP) when
that is a different drive from LOCALAPPDATA, where Go's defaults live.
On windows-latest that is D:, a separate disk with ~8.8x the small-file
write rate of C:. No-op on Linux/macOS or on an image without the split.

Measured with the cache-perf lab on our ~1.7 GB go-build+mod archive:
restore 276 s -> 94 s, save 590 s -> 175 s, go build ./... 599 s -> 455 s.

All eight setup-go call sites in test.yml that run on v5.6.0 (or on
Windows) and the cache-warmup workflow now use the action, so the pattern
lives in one place; the Linux-only coverage job stays on setup-go v6.
terraform-registry-cache moves from setup-go v6 to the action's v5.6.0.
The lab's D: layout now runs this exact action, so cache-perf.yml keeps
measuring what production runs.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* docs(fixes): Windows Go caches on the fast disk; measured tar numbers at the GNU tar steps

Run 4 of the lab settles the tar question: with real bsdtar (Git's tar
renamed aside) the restore takes 353 s on C: and 117 s on D: against GNU
tar's 264 s and 94 s, because @actions/cache's bsdtar path decompresses
the whole archive to a .tar on disk before extracting. The GNU tar steps
stay, now with the measured justification instead of the unmeasured
2024 belief; the lab keeps the bsdtar leg for re-checks.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci(cache-perf): record the bsdtar result in the lab header

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci: drop the cache-perf lab; the numbers and method live in the fix-log

The lab did its job (four runs, every number in
docs/fixes/2026-09-04-windows-go-caches-on-fast-disk.md) and is not
worth maintaining on main. It remains in this branch's history at
8fe6ed6 if it is ever needed again.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci: codify the GNU tar choice as a windows-gnu-tar action

The four hand-copied "Add GNU tar to PATH" steps become one idempotent
local action. setup-go-cache calls it first, since both of setup-go's
cache archives go through @actions/cache; the three jobs whose toolchain
cache step runs before Set up Go (terraform-registry-cache, test, mock)
call it directly at that point. No-op off Windows.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci: give the published actions/cache action its own GNU tar step on Windows

The Atmos Cache action is consumed from other repositories, so it cannot
reference the local windows-gnu-tar action; it carries the same
idempotent step inline instead, which also gives every consumer the
faster restores on Windows runners. With both cache-using actions
provisioning their own tar, the explicit calls before the toolchain
cache steps in test.yml go away.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* docs(fixes): toolchain cache measured; stays on C:

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* feat(actions/cache): cache-home input to put the Atmos cache root on a chosen disk

The published action's archive is whatever the consumer's ci.cache
covers, which can be exactly the small-file kind the fast work disk
helps. Since the paths derive from Atmos's cache root, the action cannot
move the archive alone; cache-home exports ATMOS_XDG_CACHE_HOME for the
rest of the job so toolchain installs, the cache save and the cached
paths agree. Opt-in: moving a consumer's cache root silently would be a
behavior change, and jobs whose tests assert the default locations (our
own acceptance shards) must not use it. README documents both Windows
levers and the one-time cold start.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* docs(fixes): first production numbers for the Windows Go cache on D:

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci(setup-go-cache): put Go's temp dirs on the work disk too

GOTMPDIR (Go's build scratch) and TEMP/TMP (what t.TempDir() and
os.TempDir() resolve from) default to %LOCALAPPDATA%\Temp on the slow C:
disk, so every fixture copy and scratch file the acceptance tests make
paid the same small-file IOPS penalty as the caches did. Spotted from a
test log path (C:\Users\RUNNER~1\AppData\Local\Temp\TestParse...).

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci(setup-go-cache): temp dir beside RUNNER_TEMP, not under it

RUNNER_TEMP is D:\a\_temp, and atmos's output layer mangles the "\_"
in such paths into "_" (a Markdown-escape bug, tracked separately), so
with TEMP under it the toolchain clean tests failed on the printed path
(D:\a_temp\... vs D:\a\_temp\...). D:\a\tmp has no such sequence; the
Go cache paths keep theirs since they never appear in atmos output.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* docs(fixes): temp dirs on the work disk: shard timings and the \_ output bug

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci(actions/cache): reject CR/LF in cache-home and pin the README example

Address CodeRabbit findings: a newline in cache-home would let it inject
extra variables into GITHUB_ENV, and the Windows example referenced @main
instead of the pinned-release convention documented just below it.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci(actions/cache): a mode input instead of a restore-only boolean

restore-and-save (default) or restore-only. A value lets a caller pass
its own mode straight through in one step; the boolean made every
caller branch on which step to run.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(actions/cache): make the post-step save work when nested in a composite action

Post steps of an action nested inside another composite action do not
see steps.*.outputs (actions/runner#2800): called from a repo-local
toolchain action, actions/cache's save ran with an empty path
("Input required and not supplied: path") and stored nothing. The key,
paths and restore-keys now also go through the job env, which post
steps do see.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* docs(fixes): nested post-step save and the mode input

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* docs: fix CodeRabbit-flagged doc issues on the cache/Defender fix notes

- Correct cache entry total to 22, matching the listed 14 setup-go-* +
  8 atmos-toolchain-* breakdown.
- Fix the python3 YAML-validation snippet: f was never bound, so
  copying it raised NameError. Wrap it in a shell loop instead.
- Add a text fence language to the unfenced diagnostic output block
  (markdownlint MD040).

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* test(testhelpers): keep one record per fake-runtime invocation with multi-line args

The fake container runtime wrote each invocation as one tab-joined
line; a forwarded -e KEY=VALUE for a multi-line environment variable
(ATMOS_CACHE_PATH, exported by the cache action for its nested post
step) split the record and the container-override tests lost the
interpreter fields on Windows shard 1. Newlines and tabs inside an
argument are now escaped in the record.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(actions/cache): CR/LF guard, collision-safe delimiter, strict mode validation

- Reject CR/LF in the resolved cache key before writing it as a
  single-line KEY=VALUE record to GITHUB_ENV (mirrors the existing
  cache-home guard in the same file); an embedded newline could
  otherwise inject arbitrary extra environment variables.
- Use a random per-run delimiter for the multiline PATH/RESTORE_KEYS
  exports instead of a fixed one, since a cache path or restore key
  containing the literal delimiter line could end the heredoc early
  and inject assignments.
- Add an explicit mode input validation step: an unrecognized value
  (e.g. a restore_only typo) previously fell through to the
  restore-and-save default silently, defeating the whole point of
  restore-only on fan-out shards.
- tests/testhelpers/fake_container_runtime.go: escape backslash before
  newline/tab in recordArgs so the encoding is unambiguous -- a literal
  "\n" in an argument and an actual embedded newline previously
  produced identical encoded output.
- docs/fixes: markdownlint MD018 fix (hard-wrapped issue reference).

* fix(test): revert backslash-escaping in fake_container_runtime recordArgs

A same-PR fix for a CodeRabbit finding (encoding ambiguity: a literal
"\n" in an argument vs. an actual embedded newline) escaped backslash
before newline/tab. That broke every Windows path argument recorded
through this helper: every consumer (pkg/runner/step,
cmd/custom_command_*_test.go, pkg/container, pkg/workflow) reads the
log with a plain strings.Split on tabs and compares fields directly
against real filesystem paths -- none of them decode escapes back out.
Confirmed via TestCustomCommandContainerBuildPassesWithBlockToDocker
failing deterministically (not flaky -- reproduced on rerun) on the
Windows acceptance shard with every path separator doubled.

The encoding ambiguity CodeRabbit flagged is real but was never
exploitable: no caller has ever decoded this format. Revert rather
than add a decoder nobody needs, restoring the behavior every existing
consumer already depends on.

* feat(ci/cache): atmos ci cache paths writes GITHUB_ENV directly; collapse action.yml bash

actions/cache/action.yml's meta/validate/export steps (~35 lines of
hand-rolled bash) existed only because a nested composite's post step
can't see the outer step's steps.*.outputs (actions/runner#2800), so
the action re-derived and re-wrote the same key/path/restore-keys to
$GITHUB_ENV by hand -- duplicating, less safely, what pkg/github/actions
already does correctly for $GITHUB_OUTPUT (collision-safe delimiter
generation, tested).

- cmd/ci/cache/paths.go: emitGitHubCachePaths now also writes
  ATMOS_CACHE_KEY/ATMOS_CACHE_PATH/ATMOS_CACHE_RESTORE_KEYS to
  $GITHUB_ENV (via the same env.Output/ghactions.FormatValue used for
  $GITHUB_OUTPUT) whenever $GITHUB_ENV is set, with explicit
  empty-key/empty-paths validation replacing the old bash checks.
- errors/errors.go: new ErrCachePathsRequired sentinel, alongside the
  existing ErrCacheKeyRequired.
- actions/cache/action.yml: meta+validate+export collapse into the one
  `atmos ci cache paths --format=github` line the action already
  mostly was. The CR/LF and delimiter-collision finding classes from
  the previous commit can't recur now that this is one tested Go code
  path instead of every consumer's own bash.

* fix(ci/cache): isolate tests from ambient GITHUB_ENV, wrap write error; update stale regression test

- cmd/ci/cache: this package's test binary runs inside real GitHub
  Actions CI, so every github-format test would otherwise inherit an
  ambient GITHUB_ENV left over from the job -- emitGitHubCachePaths
  writes to it whenever set, so an unrelated test could leak fixture
  cache metadata into the real job's environment file. initTestIO
  (called by every test in the package) now clears it by default;
  tests that specifically exercise the write path override it
  explicitly. Added a regression test proving initTestIO clears an
  ambient value. Also wrapped the GITHUB_ENV write's error so it's
  distinguishable from the preceding GITHUB_OUTPUT write's error.

- cmd/docker_and_action_regression_test.go:
  TestAtmosCacheActionValidatesMetadataBeforeActionsCache asserted the
  exact bash validation strings the previous commit removed from
  action.yml (validation now lives in Go -- see
  TestEmitGitHubCachePaths_EmptyKey/_EmptyPaths). Failing across every
  acceptance shard and the race suite. Updated to check the real
  invariant -- metadata is still derived via `atmos ci cache paths
  --format=github` before either terminal cache step runs -- instead
  of bash string literals that no longer exist.

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
jorrite pushed a commit to jorrite/atmos that referenced this pull request Sep 7, 2026
…#3038)

* ci: guard Windows DNS against harden-runner's post-step race; allowlist OS endpoints

Windows jobs have been finishing every step, including "Post Harden Runner"
and "Complete job", and then never reporting a conclusion until GitHub
cancels them 30-40 minutes later (0/day before harden-runner landed on the
Windows legs on Aug 31; 5, 9, 23/day on Sept 1-3). Root cause: harden-runner's
Windows post step waits at most 10 s for its agent, then kills it, and in the
losing case the agent is still restoring the runner's DNS settings, leaving
the adapter pointed at a DNS proxy that no longer exists.

- Add .github/actions/windows-dns-guard: a scheduled-task watchdog that
  resets DNS only once harden-runner's post step has begun, the agent is
  gone, and 127.0.0.1 is still configured. Wired into every Windows leg.
- Allowlist the Windows/macOS operating-system endpoints StepSecurity showed
  blocked on every job (NCSI probes, WNS, update/settings/telemetry, time
  sync, Sectigo OCSP/CRL, Apple update/CDN hosts); harden-runner stays in
  block mode everywhere.
- Drop the GOPROXY "|direct" fallback in block-mode workflows: it only fans
  out to blocked vanity-import hosts.
- Cancel superseded pull_request runs via a concurrency group.
- Skip SARIF uploads on merge_group runs, whose synthetic ref cannot be
  scanned and was evicting PRs from the merge queue.

Fix log: docs/fixes/2026-09-03-harden-runner-windows-dns-restore-race.md

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci: allow the whole NTP pool (*.pool.ntp.org), not just 0.pool.ntp.org

The pool advertises four rotating names (0-3.pool.ntp.org); a single one
was only what happened to be sampled. Push deferred until the first CI run
of the guard finishes so its Windows data isn't cancelled by the new
concurrency group.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci: address review on the Windows DNS guard

- Skip Harden Runner on draft-PR Windows jobs: every other Windows step
  (including checkout) is already skipped there, so its post step would
  race the agent's DNS restore with no guard available.
- Run the guard's scheduled task as the runner's own Administrator account
  (S4U) instead of SYSTEM; it grants nothing the job does not already have.
- Wrap the plain go mod download steps in pre-commit.yml and codeql.yml
  with go-mod-download-retry now that GOPROXY has no direct fallback.
- Measurement query: filter to Windows jobs and tolerate fractional-second
  timestamps.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci: Windows Defender exclusions and restore-only toolchain cache on shards

Phase 2 (part 1) of the CI-stability plan, stacked on the Phase 1 branch.

Windows Defender: on the Windows shards "Set up Go" averages 5.2 min
(max 10.5) restoring a 1.9 GB go-build+mod cache; the download is ~20 s,
the rest is tar/zstd extraction with Defender's real-time scanner
inspecting every extracted file, and the same scanner holding handles on
fresh test files surfaces as testing.TempDir cleanup failures
("unlinkat ... being used by another process"). Add a continue-on-error
pwsh step to every Windows leg of test.yml (build, terraform-registry-cache,
test, mock) and to setup-go-cache-warmup.yml that excludes D:\a,
C:\hostedtoolcache\windows, the Go caches, and the temp dirs, plus go.exe
as a process. These are ephemeral VMs and the step does not touch
harden-runner's egress policy.

Restore-only toolchain cache: the repo's Actions cache is 18.9 GB across
17 refs/pull/N/merge-scoped entries against a 10 GB LRU quota, so the
static atmos-toolchain-<os>-<arch>-v2 key never hits ("Cache not found
for input keys" on every shard), then all 10 shards race to save it
("Unable to reserve cache with key ...") and "Post Cache Atmos toolchain"
costs 43 s avg / 3 min max per shard for nothing. Add an opt-in
restore-only input (default 'false') to actions/cache/action.yml that
switches to actions/cache/restore at the same pinned SHA, keep cache-hit
and key outputs working, document it in the README, and set it on the
test job's "Cache Atmos toolchain" step for all three OSes.
terraform-registry-cache stays the single writer per OS and is unchanged.

Fix log: docs/fixes/2026-09-03-windows-defender-exclusions-and-restore-only-toolchain-cache.md

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(ci): drop the go.exe Defender process exclusion; it's spoofable

Add-MpPreference -ExclusionProcess 'go.exe' matches on image name only,
not path, so it would exempt any binary named go.exe from real-time
scanning regardless of where it actually lives - including one planted
by a compromised dependency during go build/go generate. The path
exclusions already in this step cover the actual scanning cost (file
I/O in the Go caches and workspace), so removing the process exclusion
gives up nothing measured.

(Skipped a second CodeRabbit finding on this PR: it asked test/
terraform-registry-cache to needs: a "cache-writer" job that doesn't
exist in this file - terraform-registry-cache itself is the writer,
and test is deliberately parallel to it so 30 shards don't wait on or
race the single writer job. Making test depend on it would serialize
two long-running job groups that currently run concurrently.)

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* temp: diagnostic - dump live Windows Defender state (to be reverted)

* Revert "temp: diagnostic - dump live Windows Defender state (to be reverted)"

This reverts commit 145a8c4.

* ci: drop Windows Defender exclusions, they're a no-op

GitHub's own actions/runner-images build script already disables
real-time monitoring and excludes C:\ and D:\ entirely on windows-latest
images, before any workflow step runs. Confirmed live via a temporary
diagnostic step (Get-MpComputerStatus/Get-MpPreference) on an actual
windows-latest runner: RealTimeProtectionEnabled was already False and
ExclusionPath already {C:\, D:\} before our own Add-MpPreference calls,
which only added redundant subpaths already covered by the existing C:\
exclusion. Since Defender was never doing real-time scanning to begin
with, it wasn't the cause of the measured Windows slowdown this step was
meant to fix - that root cause is still open.

Splits the fix-log doc accordingly: the restore-only-toolchain-cache half
(unrelated, unaffected) moves to its own file; a new doc records the
Defender investigation and reversal so it isn't re-attempted blind later.

* ci: add a dispatch-only Windows cache-restore perf lab

Restoring our ~1.9 GB go-build+mod cache on windows-2025 hosted runners
is ~6.5 minutes of pure tar extraction (download is ~16 s) - 40-60% of
every Windows acceptance shard's wall time. Iterating on that through the
full Tests suite costs a whole run per experiment.

This workflow restores the SAME production setup-go archive under one tar
configuration per matrix leg (gnu-tar = exactly what test.yml does today;
bsdtar = the proposed fix via a PROGRAMFILES override + System32-first
PATH, using only released @actions/cache code), asserts a real cache hit
so a miss can never masquerade as a fast restore, prints which tar was
actually selected, and writes each leg's "Set up Go" duration to the step
summary. A second job reports C:/D: disk topology and a small-file write
benchmark on each, to settle whether the D:\ that windows-2025-vs2026
still exposes is a distinct (fast) disk or a path onto the same volume.

Evidence for the two measured causes: actions/runner-images#12416/#12647
(D: removed on Windows Server 2025; C: ~540 IOPS, won't-fix) and
actions/cache#752 / actions/toolkit#2379 (MSYS GNU tar ~4x slower than
native bsdtar on many-small-files archives; PR unmerged). Windows Defender
is not a factor: real-time monitoring is disabled at the image level.

* ci: run the cache-perf lab on push, no merge to main needed

workflow_dispatch only resolves workflows that already exist on the
default branch, which would have meant merging the lab before running a
single experiment. A push trigger runs the pushed branch's own copy of the
file, so every push to a *ci-cache-perf* branch now runs it directly -
edit, push, read the step summary, repeat. A per-ref concurrency group
lets a newer push supersede a stale in-flight run. workflow_dispatch is
kept for once the file is on main.

* ci(cache-perf): seed the archive per layout; add a D:-relocated leg

The first run missed on both legs: main's setup-go archive is evicted by
the 10 GB LRU churn, and the only surviving entries are PR-scoped, which
other branches cannot read. A seed job per cache layout now populates a
real go-build+mod archive (go mod download + go build ./...) that
setup-go's post step saves under this branch, so the timed legs always
restore something real.

The topology job measured D: as a separate disk with ~8.8x the small-file
write rate of C: (4,545 vs 515 files/s), so a third leg relocates GOCACHE
and GOMODCACHE to D:\a\ before setup-go (actions/setup-go#515). It needs
its own seed: the cache version hashes the restore paths and the archive
holds absolute paths, so seed and restore must agree on layout.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci(cache-perf): pair each restore with its own seed; move steps to a composite

The second run lost the D: seed's archive before its restore leg ran:
this repo's cache sits at the 10 GB quota (9.9 GB across 5 entries,
~1.8 GB per Windows setup-go archive), so every save evicts the least
recently used entries, and the restore legs waited on both seeds - nine
minutes during which the D: archive was the oldest unread entry. Now
each layout is its own seed -> restore pair, so a restore starts (and
touches its archive) seconds after its seed saved it.

Each layout also gets its own cache key via a marker file hashed through
cache-dependency-path. The shared step sequence moves into
.github/actions/cache-perf-lab, which times the restore with its own
clock since the jobs API does not list nested composite steps.

Measured so far (both seeds through bsdtar): the cache save dropped from
590 s on C: to 175 s on D:, and go build ./... from 599 s to 455 s.
On C:, gnu-tar restored in 276 s and bsdtar in 295 s.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci(cache-perf): select bsdtar by renaming Git's tar aside; record D: numbers

Run 2's "bsdtar" legs silently used GNU tar: a step-level PROGRAMFILES
override does not take effect on Windows runners (the process keeps its
own ProgramFiles value), so @actions/cache's hardcoded
%PROGRAMFILES%\Git\usr\bin\tar.exe existence check kept passing. The
composite now takes tar: gnu|bsd and, for bsd, renames Git's tar.exe
aside for the job and puts C:\Windows\System32 first on PATH, so the
toolkit's PATH lookup lands on bsdtar. Nothing else in the job needs
Git's tar.

Measured so far with GNU tar on both sides: restore 276 s on C: vs 94 s
on D: (same 1.7 GB archive); save 590 s vs 175 s; go build 599 s vs 455 s.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci: put Windows Go caches on the fast work disk via a setup-go-cache action

New .github/actions/setup-go-cache: pinned actions/setup-go with caching,
plus one Windows-specific step before it - relocate GOCACHE and
GOMODCACHE onto the runner's work disk (derived from RUNNER_TEMP) when
that is a different drive from LOCALAPPDATA, where Go's defaults live.
On windows-latest that is D:, a separate disk with ~8.8x the small-file
write rate of C:. No-op on Linux/macOS or on an image without the split.

Measured with the cache-perf lab on our ~1.7 GB go-build+mod archive:
restore 276 s -> 94 s, save 590 s -> 175 s, go build ./... 599 s -> 455 s.

All eight setup-go call sites in test.yml that run on v5.6.0 (or on
Windows) and the cache-warmup workflow now use the action, so the pattern
lives in one place; the Linux-only coverage job stays on setup-go v6.
terraform-registry-cache moves from setup-go v6 to the action's v5.6.0.
The lab's D: layout now runs this exact action, so cache-perf.yml keeps
measuring what production runs.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* docs(fixes): Windows Go caches on the fast disk; measured tar numbers at the GNU tar steps

Run 4 of the lab settles the tar question: with real bsdtar (Git's tar
renamed aside) the restore takes 353 s on C: and 117 s on D: against GNU
tar's 264 s and 94 s, because @actions/cache's bsdtar path decompresses
the whole archive to a .tar on disk before extracting. The GNU tar steps
stay, now with the measured justification instead of the unmeasured
2024 belief; the lab keeps the bsdtar leg for re-checks.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci(cache-perf): record the bsdtar result in the lab header

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci: drop the cache-perf lab; the numbers and method live in the fix-log

The lab did its job (four runs, every number in
docs/fixes/2026-09-04-windows-go-caches-on-fast-disk.md) and is not
worth maintaining on main. It remains in this branch's history at
8fe6ed6 if it is ever needed again.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci: codify the GNU tar choice as a windows-gnu-tar action

The four hand-copied "Add GNU tar to PATH" steps become one idempotent
local action. setup-go-cache calls it first, since both of setup-go's
cache archives go through @actions/cache; the three jobs whose toolchain
cache step runs before Set up Go (terraform-registry-cache, test, mock)
call it directly at that point. No-op off Windows.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci: give the published actions/cache action its own GNU tar step on Windows

The Atmos Cache action is consumed from other repositories, so it cannot
reference the local windows-gnu-tar action; it carries the same
idempotent step inline instead, which also gives every consumer the
faster restores on Windows runners. With both cache-using actions
provisioning their own tar, the explicit calls before the toolchain
cache steps in test.yml go away.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* docs(fixes): toolchain cache measured; stays on C:

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* feat(actions/cache): cache-home input to put the Atmos cache root on a chosen disk

The published action's archive is whatever the consumer's ci.cache
covers, which can be exactly the small-file kind the fast work disk
helps. Since the paths derive from Atmos's cache root, the action cannot
move the archive alone; cache-home exports ATMOS_XDG_CACHE_HOME for the
rest of the job so toolchain installs, the cache save and the cached
paths agree. Opt-in: moving a consumer's cache root silently would be a
behavior change, and jobs whose tests assert the default locations (our
own acceptance shards) must not use it. README documents both Windows
levers and the one-time cold start.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* docs(fixes): first production numbers for the Windows Go cache on D:

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci(setup-go-cache): put Go's temp dirs on the work disk too

GOTMPDIR (Go's build scratch) and TEMP/TMP (what t.TempDir() and
os.TempDir() resolve from) default to %LOCALAPPDATA%\Temp on the slow C:
disk, so every fixture copy and scratch file the acceptance tests make
paid the same small-file IOPS penalty as the caches did. Spotted from a
test log path (C:\Users\RUNNER~1\AppData\Local\Temp\TestParse...).

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci(setup-go-cache): temp dir beside RUNNER_TEMP, not under it

RUNNER_TEMP is D:\a\_temp, and atmos's output layer mangles the "\_"
in such paths into "_" (a Markdown-escape bug, tracked separately), so
with TEMP under it the toolchain clean tests failed on the printed path
(D:\a_temp\... vs D:\a\_temp\...). D:\a\tmp has no such sequence; the
Go cache paths keep theirs since they never appear in atmos output.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* docs(fixes): temp dirs on the work disk: shard timings and the \_ output bug

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci(actions/cache): reject CR/LF in cache-home and pin the README example

Address CodeRabbit findings: a newline in cache-home would let it inject
extra variables into GITHUB_ENV, and the Windows example referenced @main
instead of the pinned-release convention documented just below it.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci(actions/cache): a mode input instead of a restore-only boolean

restore-and-save (default) or restore-only. A value lets a caller pass
its own mode straight through in one step; the boolean made every
caller branch on which step to run.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(actions/cache): make the post-step save work when nested in a composite action

Post steps of an action nested inside another composite action do not
see steps.*.outputs (actions/runner#2800): called from a repo-local
toolchain action, actions/cache's save ran with an empty path
("Input required and not supplied: path") and stored nothing. The key,
paths and restore-keys now also go through the job env, which post
steps do see.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* docs(fixes): nested post-step save and the mode input

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* docs: fix CodeRabbit-flagged doc issues on the cache/Defender fix notes

- Correct cache entry total to 22, matching the listed 14 setup-go-* +
  8 atmos-toolchain-* breakdown.
- Fix the python3 YAML-validation snippet: f was never bound, so
  copying it raised NameError. Wrap it in a shell loop instead.
- Add a text fence language to the unfenced diagnostic output block
  (markdownlint MD040).

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* test(testhelpers): keep one record per fake-runtime invocation with multi-line args

The fake container runtime wrote each invocation as one tab-joined
line; a forwarded -e KEY=VALUE for a multi-line environment variable
(ATMOS_CACHE_PATH, exported by the cache action for its nested post
step) split the record and the container-override tests lost the
interpreter fields on Windows shard 1. Newlines and tabs inside an
argument are now escaped in the record.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* ci(actions/cache): keep restore-only as a deprecated mode alias

Not fixing an actual break -- restore-only never shipped on main or
in any release, so nothing external depends on it (confirmed via git
history: introduced and replaced by mode entirely within this same
unmerged branch). Adding it back anyway as cheap, harmless insurance:
restore-only: true still maps to mode: restore-only, documented as
deprecated in favor of mode.

* fix(actions/cache): CR/LF guard, collision-safe delimiter, strict mode validation

- Reject CR/LF in the resolved cache key before writing it as a
  single-line KEY=VALUE record to GITHUB_ENV (mirrors the existing
  cache-home guard in the same file); an embedded newline could
  otherwise inject arbitrary extra environment variables.
- Use a random per-run delimiter for the multiline PATH/RESTORE_KEYS
  exports instead of a fixed one, since a cache path or restore key
  containing the literal delimiter line could end the heredoc early
  and inject assignments.
- Add an explicit mode input validation step: an unrecognized value
  (e.g. a restore_only typo) previously fell through to the
  restore-and-save default silently, defeating the whole point of
  restore-only on fan-out shards.
- tests/testhelpers/fake_container_runtime.go: escape backslash before
  newline/tab in recordArgs so the encoding is unambiguous -- a literal
  "\n" in an argument and an actual embedded newline previously
  produced identical encoded output.
- docs/fixes: markdownlint MD018 fix (hard-wrapped issue reference).

* fix(test): revert backslash-escaping in fake_container_runtime recordArgs

A same-PR fix for a CodeRabbit finding (encoding ambiguity: a literal
"\n" in an argument vs. an actual embedded newline) escaped backslash
before newline/tab. That broke every Windows path argument recorded
through this helper: every consumer (pkg/runner/step,
cmd/custom_command_*_test.go, pkg/container, pkg/workflow) reads the
log with a plain strings.Split on tabs and compares fields directly
against real filesystem paths -- none of them decode escapes back out.
Confirmed via TestCustomCommandContainerBuildPassesWithBlockToDocker
failing deterministically (not flaky -- reproduced on rerun) on the
Windows acceptance shard with every path separator doubled.

The encoding ambiguity CodeRabbit flagged is real but was never
exploitable: no caller has ever decoded this format. Revert rather
than add a decoder nobody needs, restoring the behavior every existing
consumer already depends on.

* feat(ci/cache): atmos ci cache paths writes GITHUB_ENV directly; collapse action.yml bash

actions/cache/action.yml's meta/validate/export steps (~35 lines of
hand-rolled bash) existed only because a nested composite's post step
can't see the outer step's steps.*.outputs (actions/runner#2800), so
the action re-derived and re-wrote the same key/path/restore-keys to
$GITHUB_ENV by hand -- duplicating, less safely, what pkg/github/actions
already does correctly for $GITHUB_OUTPUT (collision-safe delimiter
generation, tested).

- cmd/ci/cache/paths.go: emitGitHubCachePaths now also writes
  ATMOS_CACHE_KEY/ATMOS_CACHE_PATH/ATMOS_CACHE_RESTORE_KEYS to
  $GITHUB_ENV (via the same env.Output/ghactions.FormatValue used for
  $GITHUB_OUTPUT) whenever $GITHUB_ENV is set, with explicit
  empty-key/empty-paths validation replacing the old bash checks.
- errors/errors.go: new ErrCachePathsRequired sentinel, alongside the
  existing ErrCacheKeyRequired.
- actions/cache/action.yml: meta+validate+export collapse into the one
  `atmos ci cache paths --format=github` line the action already
  mostly was. The CR/LF and delimiter-collision finding classes from
  the previous commit can't recur now that this is one tested Go code
  path instead of every consumer's own bash.

* fix(ci/cache): isolate tests from ambient GITHUB_ENV, wrap write error; update stale regression test

- cmd/ci/cache: this package's test binary runs inside real GitHub
  Actions CI, so every github-format test would otherwise inherit an
  ambient GITHUB_ENV left over from the job -- emitGitHubCachePaths
  writes to it whenever set, so an unrelated test could leak fixture
  cache metadata into the real job's environment file. initTestIO
  (called by every test in the package) now clears it by default;
  tests that specifically exercise the write path override it
  explicitly. Added a regression test proving initTestIO clears an
  ambient value. Also wrapped the GITHUB_ENV write's error so it's
  distinguishable from the preceding GITHUB_OUTPUT write's error.

- cmd/docker_and_action_regression_test.go:
  TestAtmosCacheActionValidatesMetadataBeforeActionsCache asserted the
  exact bash validation strings the previous commit removed from
  action.yml (validation now lives in Go -- see
  TestEmitGitHubCachePaths_EmptyKey/_EmptyPaths). Failing across every
  acceptance shard and the race suite. Updated to check the real
  invariant -- metadata is still derived via `atmos ci cache paths
  --format=github` before either terminal cache step runs -- instead
  of bash string literals that no longer exist.

* docs(ci): fix stale setup-go v6 comment and race-job exception note

- .github/actions/setup-go-cache/action.yml: remove a leftover "setup-go
  v6" comment copy-pasted from a different call site; this action pins
  v5.6.0 and the v6-specific note about runner requirements doesn't apply.
- docs/fixes/2026-09-04-windows-go-caches-on-fast-disk.md: the "adopted
  everywhere on Windows or v5.6.0" claim missed the race job, which
  still pins v5.6.0 directly (no Windows disk-relocation work needed).

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>

@mjfuddel-eng mjfuddel-eng left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good one

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.

7 participants